From e835adeb16491563353eb1c007a28bde9cd6ff82 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 30 Mar 2026 14:24:19 -0700 Subject: [PATCH] Publish server settings schema with release versions - Generate the marketing schema and versioned copies during release version bumps - Move JSON Schema export helper into shared utilities - Update release smoke coverage and schema generation tests --- .github/workflows/release.yml | 10 +- apps/marketing/package.json | 5 +- .../schemas/server-settings.schema.json | 258 ++++++++++++++++++ .../server-settings/0.0.15.schema.json | 258 ++++++++++++++++++ .../src/git/Layers/ClaudeTextGeneration.ts | 2 +- .../src/git/Layers/CodexTextGeneration.ts | 2 +- apps/server/src/git/Utils.ts | 9 - docs/release.md | 2 + packages/shared/src/schemaJson.ts | 9 + scripts/build-server-settings-schema.ts | 12 + scripts/lib/server-settings-schema.test.ts | 53 ++++ scripts/lib/server-settings-schema.ts | 72 +++++ scripts/release-smoke.ts | 39 ++- .../update-release-package-versions.test.ts | 57 ++++ scripts/update-release-package-versions.ts | 6 +- 15 files changed, 772 insertions(+), 22 deletions(-) create mode 100644 apps/marketing/public/schemas/server-settings.schema.json create mode 100644 apps/marketing/public/schemas/server-settings/0.0.15.schema.json create mode 100644 scripts/build-server-settings-schema.ts create mode 100644 scripts/lib/server-settings-schema.test.ts create mode 100644 scripts/lib/server-settings-schema.ts create mode 100644 scripts/update-release-package-versions.test.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 504952e3aa..e91918d455 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -126,7 +126,7 @@ jobs: run: bun install --frozen-lockfile - name: Align package versions to release version - run: node scripts/update-release-package-versions.ts "${{ needs.preflight.outputs.version }}" + run: bun scripts/update-release-package-versions.ts "${{ needs.preflight.outputs.version }}" - name: Build desktop artifact shell: bash @@ -248,7 +248,7 @@ jobs: run: bun install --frozen-lockfile - name: Align package versions to release version - run: node scripts/update-release-package-versions.ts "${{ needs.preflight.outputs.version }}" + run: bun scripts/update-release-package-versions.ts "${{ needs.preflight.outputs.version }}" - name: Build CLI package run: bun run build --filter=@t3tools/web --filter=t3 @@ -348,7 +348,7 @@ jobs: name: Update version strings env: RELEASE_VERSION: ${{ needs.preflight.outputs.version }} - run: node scripts/update-release-package-versions.ts "$RELEASE_VERSION" --github-output + run: bun scripts/update-release-package-versions.ts "$RELEASE_VERSION" --github-output - name: Format package.json files if: steps.update_versions.outputs.changed == 'true' @@ -364,7 +364,7 @@ jobs: env: RELEASE_TAG: ${{ needs.preflight.outputs.tag }} run: | - if git diff --quiet -- apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock; then + if git diff --quiet -- apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json apps/marketing/public/schemas bun.lock; then echo "No version changes to commit." exit 0 fi @@ -372,6 +372,6 @@ jobs: git config user.name "${{ steps.app_bot.outputs.name }}" git config user.email "${{ steps.app_bot.outputs.email }}" - git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock + git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json apps/marketing/public/schemas bun.lock git commit -m "chore(release): prepare $RELEASE_TAG" git push origin HEAD:main diff --git a/apps/marketing/package.json b/apps/marketing/package.json index 1763a00102..a641e7bb2a 100644 --- a/apps/marketing/package.json +++ b/apps/marketing/package.json @@ -4,8 +4,9 @@ "private": true, "type": "module", "scripts": { - "dev": "astro dev", - "build": "astro build", + "build:schemas": "bun ../../scripts/build-server-settings-schema.ts", + "dev": "bun run build:schemas && astro dev", + "build": "bun run build:schemas && astro build", "preview": "astro preview", "typecheck": "astro check" }, diff --git a/apps/marketing/public/schemas/server-settings.schema.json b/apps/marketing/public/schemas/server-settings.schema.json new file mode 100644 index 0000000000..7726f42718 --- /dev/null +++ b/apps/marketing/public/schemas/server-settings.schema.json @@ -0,0 +1,258 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "T3 Code Server Settings", + "description": "JSON Schema for the server-authoritative settings.json file consumed by T3 Code.", + "type": "object", + "properties": { + "enableAssistantStreaming": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "defaultThreadEnvMode": { + "anyOf": [ + { + "type": "string", + "enum": ["local", "worktree"] + }, + { + "type": "null" + } + ] + }, + "textGenerationModelSelection": { + "anyOf": [ + { + "anyOf": [ + { + "type": "object", + "properties": { + "provider": { + "type": "string", + "enum": ["codex"] + }, + "model": { + "type": "string" + }, + "options": { + "type": "object", + "properties": { + "reasoningEffort": { + "anyOf": [ + { + "type": "string", + "enum": ["xhigh", "high", "medium", "low"] + }, + { + "type": "null" + } + ] + }, + "fastMode": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + } + }, + "required": ["provider", "model"], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "provider": { + "type": "string", + "enum": ["claudeAgent"] + }, + "model": { + "type": "string" + }, + "options": { + "type": "object", + "properties": { + "thinking": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "effort": { + "anyOf": [ + { + "type": "string", + "enum": ["low", "medium", "high", "max", "ultrathink"] + }, + { + "type": "null" + } + ] + }, + "fastMode": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "contextWindow": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + } + }, + "required": ["provider", "model"], + "additionalProperties": false + } + ] + }, + { + "type": "null" + } + ] + }, + "providers": { + "anyOf": [ + { + "type": "object", + "properties": { + "codex": { + "anyOf": [ + { + "type": "object", + "properties": { + "enabled": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "binaryPath": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "homePath": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "customModels": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + }, + "claudeAgent": { + "anyOf": [ + { + "type": "object", + "properties": { + "enabled": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "binaryPath": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "customModels": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false +} diff --git a/apps/marketing/public/schemas/server-settings/0.0.15.schema.json b/apps/marketing/public/schemas/server-settings/0.0.15.schema.json new file mode 100644 index 0000000000..7726f42718 --- /dev/null +++ b/apps/marketing/public/schemas/server-settings/0.0.15.schema.json @@ -0,0 +1,258 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "T3 Code Server Settings", + "description": "JSON Schema for the server-authoritative settings.json file consumed by T3 Code.", + "type": "object", + "properties": { + "enableAssistantStreaming": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "defaultThreadEnvMode": { + "anyOf": [ + { + "type": "string", + "enum": ["local", "worktree"] + }, + { + "type": "null" + } + ] + }, + "textGenerationModelSelection": { + "anyOf": [ + { + "anyOf": [ + { + "type": "object", + "properties": { + "provider": { + "type": "string", + "enum": ["codex"] + }, + "model": { + "type": "string" + }, + "options": { + "type": "object", + "properties": { + "reasoningEffort": { + "anyOf": [ + { + "type": "string", + "enum": ["xhigh", "high", "medium", "low"] + }, + { + "type": "null" + } + ] + }, + "fastMode": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + } + }, + "required": ["provider", "model"], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "provider": { + "type": "string", + "enum": ["claudeAgent"] + }, + "model": { + "type": "string" + }, + "options": { + "type": "object", + "properties": { + "thinking": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "effort": { + "anyOf": [ + { + "type": "string", + "enum": ["low", "medium", "high", "max", "ultrathink"] + }, + { + "type": "null" + } + ] + }, + "fastMode": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "contextWindow": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + } + }, + "required": ["provider", "model"], + "additionalProperties": false + } + ] + }, + { + "type": "null" + } + ] + }, + "providers": { + "anyOf": [ + { + "type": "object", + "properties": { + "codex": { + "anyOf": [ + { + "type": "object", + "properties": { + "enabled": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "binaryPath": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "homePath": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "customModels": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + }, + "claudeAgent": { + "anyOf": [ + { + "type": "object", + "properties": { + "enabled": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, + "binaryPath": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "customModels": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false +} diff --git a/apps/server/src/git/Layers/ClaudeTextGeneration.ts b/apps/server/src/git/Layers/ClaudeTextGeneration.ts index 19ed40e65b..78baf26444 100644 --- a/apps/server/src/git/Layers/ClaudeTextGeneration.ts +++ b/apps/server/src/git/Layers/ClaudeTextGeneration.ts @@ -13,6 +13,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"; import { ClaudeModelSelection } from "@t3tools/contracts"; import { resolveApiModelId } from "@t3tools/shared/model"; import { sanitizeBranchFragment, sanitizeFeatureBranchName } from "@t3tools/shared/git"; +import { toJsonSchemaObject } from "@t3tools/shared/schemaJson"; import { TextGenerationError } from "../Errors.ts"; import { type TextGenerationShape, TextGeneration } from "../Services/TextGeneration.ts"; @@ -27,7 +28,6 @@ import { sanitizeCommitSubject, sanitizePrTitle, sanitizeThreadTitle, - toJsonSchemaObject, } from "../Utils.ts"; import { normalizeClaudeModelOptionsWithCapabilities } from "@t3tools/shared/model"; import { ServerSettingsService } from "../../serverSettings.ts"; diff --git a/apps/server/src/git/Layers/CodexTextGeneration.ts b/apps/server/src/git/Layers/CodexTextGeneration.ts index 8f0556ee34..7d62015812 100644 --- a/apps/server/src/git/Layers/CodexTextGeneration.ts +++ b/apps/server/src/git/Layers/CodexTextGeneration.ts @@ -5,6 +5,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"; import { CodexModelSelection } from "@t3tools/contracts"; import { sanitizeBranchFragment, sanitizeFeatureBranchName } from "@t3tools/shared/git"; +import { toJsonSchemaObject } from "@t3tools/shared/schemaJson"; import { resolveAttachmentPath } from "../../attachmentStore.ts"; import { ServerConfig } from "../../config.ts"; @@ -26,7 +27,6 @@ import { sanitizeCommitSubject, sanitizePrTitle, sanitizeThreadTitle, - toJsonSchemaObject, } from "../Utils.ts"; import { getCodexModelCapabilities } from "../../provider/Layers/CodexProvider.ts"; import { ServerSettingsService } from "../../serverSettings.ts"; diff --git a/apps/server/src/git/Utils.ts b/apps/server/src/git/Utils.ts index 8f0321fd52..1f026abf38 100644 --- a/apps/server/src/git/Utils.ts +++ b/apps/server/src/git/Utils.ts @@ -14,15 +14,6 @@ export function isGitRepository(cwd: string): boolean { return existsSync(join(cwd, ".git")); } -/** Convert an Effect Schema to a flat JSON Schema object, inlining `$defs` when present. */ -export function toJsonSchemaObject(schema: Schema.Top): unknown { - const document = Schema.toJsonSchemaDocument(schema); - if (document.definitions && Object.keys(document.definitions).length > 0) { - return { ...document.schema, $defs: document.definitions }; - } - return document.schema; -} - /** Truncate a text section to `maxChars`, appending a `[truncated]` marker when needed. */ export function limitSection(value: string, maxChars: number): string { if (value.length <= maxChars) return value; diff --git a/docs/release.md b/docs/release.md index 4aec150f33..526f7c931f 100644 --- a/docs/release.md +++ b/docs/release.md @@ -17,6 +17,8 @@ This document covers how to run desktop releases from one tag, first without sig - Includes Electron auto-update metadata (for example `latest*.yml` and `*.blockmap`) in release assets. - Publishes the CLI package (`apps/server`, npm package `t3`) with OIDC trusted publishing. - Signing is optional and auto-detected per platform from secrets. +- Refreshes the marketing-site JSON Schema for `settings.json` at `/schemas/server-settings.schema.json`. +- Commits an immutable versioned JSON Schema copy at `/schemas/server-settings/.schema.json`. ## Desktop auto-update notes diff --git a/packages/shared/src/schemaJson.ts b/packages/shared/src/schemaJson.ts index 9e38b1f8b8..fb556172f5 100644 --- a/packages/shared/src/schemaJson.ts +++ b/packages/shared/src/schemaJson.ts @@ -43,6 +43,15 @@ export const formatSchemaError = (cause: Cause.Cause) => { : Cause.pretty(cause); }; +/** Convert an Effect Schema to a flat JSON Schema object, inlining `$defs` when present. */ +export const toJsonSchemaObject = (schema: Schema.Top): unknown => { + const document = Schema.toJsonSchemaDocument(schema); + if (document.definitions && Object.keys(document.definitions).length > 0) { + return { ...document.schema, $defs: document.definitions }; + } + return document.schema; +}; + /** * A `Getter` that parses a lenient JSON string (tolerating trailing commas * and JS-style comments) into an unknown value. diff --git a/scripts/build-server-settings-schema.ts b/scripts/build-server-settings-schema.ts new file mode 100644 index 0000000000..243beb2c3b --- /dev/null +++ b/scripts/build-server-settings-schema.ts @@ -0,0 +1,12 @@ +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { + SERVER_SETTINGS_SCHEMA_RELATIVE_PATH, + writeServerSettingsJsonSchemas, +} from "./lib/server-settings-schema.ts"; + +const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +writeServerSettingsJsonSchemas({ rootDir }); + +console.log(`Wrote ${SERVER_SETTINGS_SCHEMA_RELATIVE_PATH}`); diff --git a/scripts/lib/server-settings-schema.test.ts b/scripts/lib/server-settings-schema.test.ts new file mode 100644 index 0000000000..0015aa9a08 --- /dev/null +++ b/scripts/lib/server-settings-schema.test.ts @@ -0,0 +1,53 @@ +import { mkdtempSync, readFileSync, rmSync } from "node:fs"; +import { join, resolve } from "node:path"; +import { tmpdir } from "node:os"; + +import { describe, expect, it } from "vitest"; + +import { + buildServerSettingsJsonSchema, + getVersionedServerSettingsSchemaRelativePath, + SERVER_SETTINGS_SCHEMA_RELATIVE_PATH, + writeServerSettingsJsonSchemas, +} from "./server-settings-schema"; + +describe("buildServerSettingsJsonSchema", () => { + it("builds a JSON schema document for settings.json", () => { + const schema = buildServerSettingsJsonSchema(); + + expect(schema.$schema).toBe("https://json-schema.org/draft/2020-12/schema"); + expect(schema.title).toBe("T3 Code Server Settings"); + expect(schema.type).toBe("object"); + expect(schema.additionalProperties).toBe(false); + expect(schema.properties).toMatchObject({ + enableAssistantStreaming: expect.any(Object), + defaultThreadEnvMode: expect.any(Object), + textGenerationModelSelection: expect.any(Object), + providers: expect.any(Object), + }); + }); + + it("writes latest and versioned schema files", () => { + const rootDir = mkdtempSync(join(tmpdir(), "t3-server-settings-schema-")); + + try { + const result = writeServerSettingsJsonSchemas({ rootDir, version: "1.2.3" }); + expect(result.changed).toBe(true); + + const latestSchema = JSON.parse( + readFileSync(resolve(rootDir, SERVER_SETTINGS_SCHEMA_RELATIVE_PATH), "utf8"), + ) as Record; + const versionedSchema = JSON.parse( + readFileSync( + resolve(rootDir, getVersionedServerSettingsSchemaRelativePath("1.2.3")), + "utf8", + ), + ) as Record; + + expect(latestSchema).toEqual(versionedSchema); + expect(latestSchema.title).toBe("T3 Code Server Settings"); + } finally { + rmSync(rootDir, { recursive: true, force: true }); + } + }); +}); diff --git a/scripts/lib/server-settings-schema.ts b/scripts/lib/server-settings-schema.ts new file mode 100644 index 0000000000..096135c38a --- /dev/null +++ b/scripts/lib/server-settings-schema.ts @@ -0,0 +1,72 @@ +import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { resolve, dirname } from "node:path"; + +import { ServerSettings } from "@t3tools/contracts/settings"; +import { toJsonSchemaObject } from "@t3tools/shared/schemaJson"; + +const JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema"; + +export const SERVER_SETTINGS_SCHEMA_RELATIVE_PATH = + "apps/marketing/public/schemas/server-settings.schema.json"; +export const SERVER_SETTINGS_VERSIONED_SCHEMA_DIRECTORY_RELATIVE_PATH = + "apps/marketing/public/schemas/server-settings"; + +export const getVersionedServerSettingsSchemaRelativePath = (version: string) => + `${SERVER_SETTINGS_VERSIONED_SCHEMA_DIRECTORY_RELATIVE_PATH}/${version}.schema.json`; + +export function buildServerSettingsJsonSchema(): Record { + const schema = toJsonSchemaObject(ServerSettings); + if (!schema || typeof schema !== "object" || Array.isArray(schema)) { + throw new Error("ServerSettings JSON schema must be an object schema."); + } + + return { + $schema: JSON_SCHEMA_DRAFT_2020_12, + title: "T3 Code Server Settings", + description: "JSON Schema for the server-authoritative settings.json file consumed by T3 Code.", + ...schema, + }; +} + +function writeJsonFileIfChanged(filePath: string, document: Record): boolean { + const nextContent = `${JSON.stringify(document, null, 2)}\n`; + const previousContent = (() => { + try { + return readFileSync(filePath, "utf8"); + } catch { + return null; + } + })(); + + if (previousContent === nextContent) { + return false; + } + + mkdirSync(dirname(filePath), { recursive: true }); + writeFileSync(filePath, nextContent); + return true; +} + +export function writeServerSettingsJsonSchemas(options?: { + readonly rootDir?: string; + readonly version?: string; +}): { + readonly changed: boolean; +} { + const rootDir = resolve(options?.rootDir ?? process.cwd()); + const latestSchema = buildServerSettingsJsonSchema(); + let changed = writeJsonFileIfChanged( + resolve(rootDir, SERVER_SETTINGS_SCHEMA_RELATIVE_PATH), + latestSchema, + ); + + if (options?.version) { + changed = + writeJsonFileIfChanged( + resolve(rootDir, getVersionedServerSettingsSchemaRelativePath(options.version)), + latestSchema, + ) || changed; + } + + return { changed }; +} diff --git a/scripts/release-smoke.ts b/scripts/release-smoke.ts index bf9d9f5c6a..6b24a4f2ad 100644 --- a/scripts/release-smoke.ts +++ b/scripts/release-smoke.ts @@ -1,5 +1,13 @@ import { execFileSync } from "node:child_process"; -import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { + cpSync, + existsSync, + mkdirSync, + mkdtempSync, + readFileSync, + rmSync, + writeFileSync, +} from "node:fs"; import { tmpdir } from "node:os"; import { dirname, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; @@ -81,7 +89,7 @@ try { copyWorkspaceManifestFixture(tempRoot); execFileSync( - process.execPath, + "bun", [ resolve(repoRoot, "scripts/update-release-package-versions.ts"), "9.9.9-smoke.0", @@ -106,9 +114,34 @@ try { "Expected bun.lock to contain the smoke version.", ); + const latestSchemaPath = resolve( + tempRoot, + "apps/marketing/public/schemas/server-settings.schema.json", + ); + const versionedSchemaPath = resolve( + tempRoot, + "apps/marketing/public/schemas/server-settings/9.9.9-smoke.0.schema.json", + ); + if (!existsSync(latestSchemaPath)) { + throw new Error( + "Expected release version alignment to generate the latest server settings schema.", + ); + } + if (!existsSync(versionedSchemaPath)) { + throw new Error( + "Expected release version alignment to generate the versioned server settings schema.", + ); + } + const versionedSchema = readFileSync(versionedSchemaPath, "utf8"); + assertContains( + versionedSchema, + '"title": "T3 Code Server Settings"', + "Expected versioned server settings schema to contain schema metadata.", + ); + const { arm64Path, x64Path } = writeMacManifestFixtures(tempRoot); execFileSync( - process.execPath, + "bun", [resolve(repoRoot, "scripts/merge-mac-update-manifests.ts"), arm64Path, x64Path], { cwd: repoRoot, diff --git a/scripts/update-release-package-versions.test.ts b/scripts/update-release-package-versions.test.ts new file mode 100644 index 0000000000..29332f1fc2 --- /dev/null +++ b/scripts/update-release-package-versions.test.ts @@ -0,0 +1,57 @@ +import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join, resolve } from "node:path"; + +import { describe, expect, it } from "vitest"; + +import { + releasePackageFiles, + updateReleasePackageVersions, +} from "./update-release-package-versions"; + +describe("updateReleasePackageVersions", () => { + it("updates package versions and writes latest plus versioned server settings schemas", () => { + const rootDir = mkdtempSync(join(tmpdir(), "t3-release-version-bump-")); + + try { + for (const relativePath of releasePackageFiles) { + const filePath = resolve(rootDir, relativePath); + mkdirSync(dirname(filePath), { recursive: true }); + writeFileSync( + filePath, + `${JSON.stringify({ name: relativePath, version: "0.0.0" }, null, 2)}\n`, + ); + } + + const result = updateReleasePackageVersions("1.2.3", { rootDir }); + expect(result.changed).toBe(true); + + for (const relativePath of releasePackageFiles) { + const packageJson = JSON.parse(readFileSync(resolve(rootDir, relativePath), "utf8")) as { + version?: string; + }; + expect(packageJson.version).toBe("1.2.3"); + } + + expect( + JSON.parse( + readFileSync( + resolve(rootDir, "apps/marketing/public/schemas/server-settings.schema.json"), + "utf8", + ), + ), + ).toMatchObject({ title: "T3 Code Server Settings" }); + + expect( + JSON.parse( + readFileSync( + resolve(rootDir, "apps/marketing/public/schemas/server-settings/1.2.3.schema.json"), + "utf8", + ), + ), + ).toMatchObject({ title: "T3 Code Server Settings" }); + } finally { + rmSync(rootDir, { recursive: true, force: true }); + } + }); +}); diff --git a/scripts/update-release-package-versions.ts b/scripts/update-release-package-versions.ts index b860b85e8e..a812f4f17f 100644 --- a/scripts/update-release-package-versions.ts +++ b/scripts/update-release-package-versions.ts @@ -2,6 +2,8 @@ import { appendFileSync, readFileSync, writeFileSync } from "node:fs"; import { resolve } from "node:path"; import { fileURLToPath } from "node:url"; +import { writeServerSettingsJsonSchemas } from "./lib/server-settings-schema.ts"; + export const releasePackageFiles = [ "apps/server/package.json", "apps/desktop/package.json", @@ -37,6 +39,8 @@ export function updateReleasePackageVersions( changed = true; } + changed = writeServerSettingsJsonSchemas({ rootDir, version }).changed || changed; + return { changed }; } @@ -99,7 +103,7 @@ if (isMain) { ); if (!changed) { - console.log("All package.json versions already match release version."); + console.log("All release version artifacts already match the requested version."); } if (writeGithubOutput) {