From f1793ad2eb7ce8ea3485e4521bc8119379a177a2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 30 Mar 2026 14:46:42 -0700 Subject: [PATCH] Generate and preserve keybindings schemas - Add marketing JSON Schema artifacts for keybindings - Reuse shared JSON schema writer for server settings and keybindings - Preserve top-level `$schema` when rewriting settings --- apps/marketing/package.json | 5 +- .../public/schemas/keybindings.schema.json | 63 ++++++++++++++++ .../schemas/keybindings/0.0.15.schema.json | 63 ++++++++++++++++ apps/server/src/keybindings.ts | 16 +--- apps/server/src/serverSettings.test.ts | 46 ++++++++++++ apps/server/src/serverSettings.ts | 33 +++++++- docs/release.md | 4 +- packages/shared/src/schemaJson.test.ts | 33 ++++++++ packages/shared/src/schemaJson.ts | 14 ++++ ...ttings-schema.ts => build-json-schemas.ts} | 7 ++ scripts/lib/json-schema.ts | 75 +++++++++++++++++++ scripts/lib/keybindings-schema.test.ts | 50 +++++++++++++ scripts/lib/keybindings-schema.ts | 32 ++++++++ scripts/lib/server-settings-schema.ts | 60 +++------------ scripts/release-smoke.ts | 24 ++++++ .../update-release-package-versions.test.ts | 20 ++++- scripts/update-release-package-versions.ts | 2 + 17 files changed, 476 insertions(+), 71 deletions(-) create mode 100644 apps/marketing/public/schemas/keybindings.schema.json create mode 100644 apps/marketing/public/schemas/keybindings/0.0.15.schema.json create mode 100644 packages/shared/src/schemaJson.test.ts rename scripts/{build-server-settings-schema.ts => build-json-schemas.ts} (64%) create mode 100644 scripts/lib/json-schema.ts create mode 100644 scripts/lib/keybindings-schema.test.ts create mode 100644 scripts/lib/keybindings-schema.ts diff --git a/apps/marketing/package.json b/apps/marketing/package.json index a641e7bb2a..1763a00102 100644 --- a/apps/marketing/package.json +++ b/apps/marketing/package.json @@ -4,9 +4,8 @@ "private": true, "type": "module", "scripts": { - "build:schemas": "bun ../../scripts/build-server-settings-schema.ts", - "dev": "bun run build:schemas && astro dev", - "build": "bun run build:schemas && astro build", + "dev": "astro dev", + "build": "astro build", "preview": "astro preview", "typecheck": "astro check" }, diff --git a/apps/marketing/public/schemas/keybindings.schema.json b/apps/marketing/public/schemas/keybindings.schema.json new file mode 100644 index 0000000000..605380eb49 --- /dev/null +++ b/apps/marketing/public/schemas/keybindings.schema.json @@ -0,0 +1,63 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "T3 Code Keybindings", + "description": "JSON Schema for the keybindings.json file consumed by T3 Code.", + "type": "array", + "items": { + "type": "object", + "properties": { + "key": { + "type": "string" + }, + "command": { + "anyOf": [ + { + "type": "string", + "enum": [ + "terminal.toggle", + "terminal.split", + "terminal.new", + "terminal.close", + "diff.toggle", + "chat.new", + "chat.newLocal", + "editor.openFavorite", + "thread.previous", + "thread.next", + "thread.jump.1", + "thread.jump.2", + "thread.jump.3", + "thread.jump.4", + "thread.jump.5", + "thread.jump.6", + "thread.jump.7", + "thread.jump.8", + "thread.jump.9" + ] + }, + { + "type": "string", + "pattern": "^script\\.[\\s\\S]*?\\.run$" + } + ] + }, + "when": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "required": ["key", "command"], + "additionalProperties": false + }, + "allOf": [ + { + "maxItems": 256 + } + ] +} diff --git a/apps/marketing/public/schemas/keybindings/0.0.15.schema.json b/apps/marketing/public/schemas/keybindings/0.0.15.schema.json new file mode 100644 index 0000000000..605380eb49 --- /dev/null +++ b/apps/marketing/public/schemas/keybindings/0.0.15.schema.json @@ -0,0 +1,63 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "T3 Code Keybindings", + "description": "JSON Schema for the keybindings.json file consumed by T3 Code.", + "type": "array", + "items": { + "type": "object", + "properties": { + "key": { + "type": "string" + }, + "command": { + "anyOf": [ + { + "type": "string", + "enum": [ + "terminal.toggle", + "terminal.split", + "terminal.new", + "terminal.close", + "diff.toggle", + "chat.new", + "chat.newLocal", + "editor.openFavorite", + "thread.previous", + "thread.next", + "thread.jump.1", + "thread.jump.2", + "thread.jump.3", + "thread.jump.4", + "thread.jump.5", + "thread.jump.6", + "thread.jump.7", + "thread.jump.8", + "thread.jump.9" + ] + }, + { + "type": "string", + "pattern": "^script\\.[\\s\\S]*?\\.run$" + } + ] + }, + "when": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "required": ["key", "command"], + "additionalProperties": false + }, + "allOf": [ + { + "maxItems": 256 + } + ] +} diff --git a/apps/server/src/keybindings.ts b/apps/server/src/keybindings.ts index 176e0300ad..a3d73b459b 100644 --- a/apps/server/src/keybindings.ts +++ b/apps/server/src/keybindings.ts @@ -34,7 +34,6 @@ import { Predicate, PubSub, Schema, - SchemaGetter, SchemaIssue, SchemaTransformation, Ref, @@ -44,7 +43,7 @@ import { } from "effect"; import * as Semaphore from "effect/Semaphore"; import { ServerConfig } from "./config"; -import { fromLenientJson } from "@t3tools/shared/schemaJson"; +import { encodePrettyJsonEffect, fromLenientJson } from "@t3tools/shared/schemaJson"; export class KeybindingsConfigError extends Schema.TaggedErrorClass()( "KeybindingsConfigParseError", @@ -418,16 +417,7 @@ function encodeWhenAst(node: KeybindingWhenNode): string { const DEFAULT_RESOLVED_KEYBINDINGS = compileResolvedKeybindingsConfig(DEFAULT_KEYBINDINGS); const RawKeybindingsEntries = fromLenientJson(Schema.Array(Schema.Unknown)); -const KeybindingsConfigJson = Schema.fromJsonString(KeybindingsConfig); -const PrettyJsonString = SchemaGetter.parseJson().compose( - SchemaGetter.stringifyJson({ space: 2 }), -); -const KeybindingsConfigPrettyJson = KeybindingsConfigJson.pipe( - Schema.encode({ - decode: PrettyJsonString, - encode: PrettyJsonString, - }), -); +const encodeKeybindingsConfigPrettyJson = encodePrettyJsonEffect(KeybindingsConfig); export interface KeybindingsConfigState { readonly keybindings: ResolvedKeybindingsConfig; @@ -676,7 +666,7 @@ const makeKeybindings = Effect.gen(function* () { const writeConfigAtomically = (rules: readonly KeybindingRule[]) => { const tempPath = `${keybindingsConfigPath}.${process.pid}.${Date.now()}.tmp`; - return Schema.encodeEffect(KeybindingsConfigPrettyJson)(rules).pipe( + return encodeKeybindingsConfigPrettyJson(rules).pipe( Effect.map((encoded) => `${encoded}\n`), Effect.tap(() => fs.makeDirectory(path.dirname(keybindingsConfigPath), { recursive: true })), Effect.tap((encoded) => fs.writeFileString(tempPath, encoded)), diff --git a/apps/server/src/serverSettings.test.ts b/apps/server/src/serverSettings.test.ts index c0aec009a0..232286aa14 100644 --- a/apps/server/src/serverSettings.test.ts +++ b/apps/server/src/serverSettings.test.ts @@ -216,4 +216,50 @@ it.layer(NodeServices.layer)("server settings", (it) => { }); }).pipe(Effect.provide(makeServerSettingsLayer())), ); + + it.effect("preserves a top-level $schema declaration when rewriting settings", () => + Effect.gen(function* () { + const serverConfig = yield* ServerConfig; + const fileSystem = yield* FileSystem.FileSystem; + + yield* fileSystem.writeFileString( + serverConfig.settingsPath, + `${JSON.stringify( + { + $schema: "https://t3.chat/schemas/server-settings/0.0.15.schema.json", + providers: { + codex: { + binaryPath: "/usr/local/bin/codex", + }, + }, + }, + null, + 2, + )}\n`, + ); + + const serverSettings = yield* ServerSettingsService; + yield* serverSettings.start; + yield* serverSettings.updateSettings({ + providers: { + claudeAgent: { + binaryPath: "/usr/local/bin/claude", + }, + }, + }); + + const raw = yield* fileSystem.readFileString(serverConfig.settingsPath); + assert.deepEqual(JSON.parse(raw), { + $schema: "https://t3.chat/schemas/server-settings/0.0.15.schema.json", + providers: { + codex: { + binaryPath: "/usr/local/bin/codex", + }, + claudeAgent: { + binaryPath: "/usr/local/bin/claude", + }, + }, + }); + }).pipe(Effect.provide(makeServerSettingsLayer())), + ); }); diff --git a/apps/server/src/serverSettings.ts b/apps/server/src/serverSettings.ts index a5b4345d50..06e38e2465 100644 --- a/apps/server/src/serverSettings.ts +++ b/apps/server/src/serverSettings.ts @@ -39,7 +39,7 @@ import { import * as Semaphore from "effect/Semaphore"; import { ServerConfig } from "./config"; import { type DeepPartial, deepMerge } from "@t3tools/shared/Struct"; -import { fromLenientJson } from "@t3tools/shared/schemaJson"; +import { encodePrettyJsonEffect, fromLenientJson } from "@t3tools/shared/schemaJson"; export class ServerSettingsError extends Schema.TaggedErrorClass()( "ServerSettingsError", @@ -101,6 +101,9 @@ export class ServerSettingsService extends ServiceMap.Service< } const ServerSettingsJson = fromLenientJson(ServerSettings); +const UnknownJson = fromLenientJson(Schema.Unknown); +const encodeServerSettingsDocument = encodePrettyJsonEffect(Schema.Unknown); +const SETTINGS_SCHEMA_DECLARATION_KEY = "$schema"; const PROVIDER_ORDER: readonly ProviderKind[] = ["codex", "claudeAgent"]; @@ -177,6 +180,7 @@ const makeServerSettings = Effect.gen(function* () { const changesPubSub = yield* PubSub.unbounded(); const startedRef = yield* Ref.make(false); const startedDeferred = yield* Deferred.make(); + const schemaDeclarationRef = yield* Ref.make(undefined); const watcherScope = yield* Scope.make("sequential"); yield* Effect.addFinalizer(() => Scope.close(watcherScope, Exit.void)); @@ -207,10 +211,25 @@ const makeServerSettings = Effect.gen(function* () { const loadSettingsFromDisk = Effect.gen(function* () { if (!(yield* readConfigExists)) { + yield* Ref.set(schemaDeclarationRef, undefined); return DEFAULT_SERVER_SETTINGS; } const raw = yield* readRawConfig; + const rawJson = Schema.decodeUnknownExit(UnknownJson)(raw); + if (rawJson._tag === "Success") { + const value = rawJson.value; + const valueRecord = + value && typeof value === "object" && !Array.isArray(value) + ? (value as Record) + : undefined; + const schemaDeclaration = + valueRecord && typeof valueRecord[SETTINGS_SCHEMA_DECLARATION_KEY] === "string" + ? valueRecord[SETTINGS_SCHEMA_DECLARATION_KEY] + : undefined; + yield* Ref.set(schemaDeclarationRef, schemaDeclaration); + } + const decoded = Schema.decodeUnknownExit(ServerSettingsJson)(raw); if (decoded._tag === "Failure") { yield* Effect.logWarning("failed to parse settings.json, using defaults", { @@ -232,7 +251,17 @@ const makeServerSettings = Effect.gen(function* () { const tempPath = `${settingsPath}.${process.pid}.${Date.now()}.tmp`; const sparseSettings = stripDefaultServerSettings(settings, DEFAULT_SERVER_SETTINGS) ?? {}; - return Effect.succeed(`${JSON.stringify(sparseSettings, null, 2)}\n`).pipe( + return Ref.get(schemaDeclarationRef).pipe( + Effect.map((schemaDeclaration) => + schemaDeclaration + ? { + [SETTINGS_SCHEMA_DECLARATION_KEY]: schemaDeclaration, + ...sparseSettings, + } + : sparseSettings, + ), + Effect.flatMap(encodeServerSettingsDocument), + Effect.map((encoded) => `${encoded}\n`), Effect.tap(() => fs.makeDirectory(pathService.dirname(settingsPath), { recursive: true })), Effect.tap((encoded) => fs.writeFileString(tempPath, encoded)), Effect.flatMap(() => fs.rename(tempPath, settingsPath)), diff --git a/docs/release.md b/docs/release.md index 526f7c931f..cd890c2cf0 100644 --- a/docs/release.md +++ b/docs/release.md @@ -17,8 +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`. +- Refreshes the marketing-site JSON Schemas for `settings.json` and `keybindings.json` at `/schemas/server-settings.schema.json` and `/schemas/keybindings.schema.json`. +- Commits immutable versioned JSON Schema copies at `/schemas/server-settings/.schema.json` and `/schemas/keybindings/.schema.json`. ## Desktop auto-update notes diff --git a/packages/shared/src/schemaJson.test.ts b/packages/shared/src/schemaJson.test.ts new file mode 100644 index 0000000000..fba4cf3d97 --- /dev/null +++ b/packages/shared/src/schemaJson.test.ts @@ -0,0 +1,33 @@ +import { assert, it } from "@effect/vitest"; +import { Effect, Schema } from "effect"; +import { encodePrettyJsonEffect } from "./schemaJson"; + +it.effect("encodePrettyJsonEffect writes indented JSON", () => + Effect.gen(function* () { + const encodePrettyJson = encodePrettyJsonEffect( + Schema.Struct({ + provider: Schema.String, + options: Schema.Struct({ + enabled: Schema.Boolean, + }), + }), + ); + + const encoded = yield* encodePrettyJson({ + provider: "codex", + options: { + enabled: true, + }, + }); + + assert.strictEqual( + encoded, + `{ + "provider": "codex", + "options": { + "enabled": true + } +}`, + ); + }), +); diff --git a/packages/shared/src/schemaJson.ts b/packages/shared/src/schemaJson.ts index fb556172f5..010c4eccf6 100644 --- a/packages/shared/src/schemaJson.ts +++ b/packages/shared/src/schemaJson.ts @@ -36,6 +36,20 @@ export const decodeUnknownJsonResult = ().compose( + SchemaGetter.stringifyJson({ space: 2 }), +); + +export const encodePrettyJsonEffect = (schema: S) => + Schema.encodeEffect( + Schema.fromJsonString(schema).pipe( + Schema.encode({ + decode: PrettyJsonString, + encode: PrettyJsonString, + }), + ), + ); + export const formatSchemaError = (cause: Cause.Cause) => { const squashed = Cause.squash(cause); return Schema.isSchemaError(squashed) diff --git a/scripts/build-server-settings-schema.ts b/scripts/build-json-schemas.ts similarity index 64% rename from scripts/build-server-settings-schema.ts rename to scripts/build-json-schemas.ts index 243beb2c3b..cf667ab68f 100644 --- a/scripts/build-server-settings-schema.ts +++ b/scripts/build-json-schemas.ts @@ -1,12 +1,19 @@ import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; +import { + KEYBINDINGS_SCHEMA_RELATIVE_PATH, + writeKeybindingsJsonSchemas, +} from "./lib/keybindings-schema.ts"; import { SERVER_SETTINGS_SCHEMA_RELATIVE_PATH, writeServerSettingsJsonSchemas, } from "./lib/server-settings-schema.ts"; const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), ".."); + writeServerSettingsJsonSchemas({ rootDir }); +writeKeybindingsJsonSchemas({ rootDir }); console.log(`Wrote ${SERVER_SETTINGS_SCHEMA_RELATIVE_PATH}`); +console.log(`Wrote ${KEYBINDINGS_SCHEMA_RELATIVE_PATH}`); diff --git a/scripts/lib/json-schema.ts b/scripts/lib/json-schema.ts new file mode 100644 index 0000000000..53fa5408ac --- /dev/null +++ b/scripts/lib/json-schema.ts @@ -0,0 +1,75 @@ +import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { dirname, resolve } from "node:path"; + +import { type Schema } from "effect"; + +import { toJsonSchemaObject } from "@t3tools/shared/schemaJson"; + +const JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema"; + +export function buildJsonSchemaDocument( + schema: Schema.Top, + options: { + readonly title: string; + readonly description: string; + }, +): Record { + const jsonSchema = toJsonSchemaObject(schema); + if (!jsonSchema || typeof jsonSchema !== "object" || Array.isArray(jsonSchema)) { + throw new Error( + `${options.title} JSON schema must be an object or array JSON schema document.`, + ); + } + + return { + $schema: JSON_SCHEMA_DRAFT_2020_12, + title: options.title, + description: options.description, + ...jsonSchema, + }; +} + +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 writeJsonSchemaArtifacts(options: { + readonly rootDir?: string; + readonly version?: string; + readonly latestRelativePath: string; + readonly getVersionedRelativePath: (version: string) => string; + readonly document: Record; +}): { + readonly changed: boolean; +} { + const rootDir = resolve(options.rootDir ?? process.cwd()); + let changed = writeJsonFileIfChanged( + resolve(rootDir, options.latestRelativePath), + options.document, + ); + + if (options.version) { + changed = + writeJsonFileIfChanged( + resolve(rootDir, options.getVersionedRelativePath(options.version)), + options.document, + ) || changed; + } + + return { changed }; +} diff --git a/scripts/lib/keybindings-schema.test.ts b/scripts/lib/keybindings-schema.test.ts new file mode 100644 index 0000000000..cf7be3d475 --- /dev/null +++ b/scripts/lib/keybindings-schema.test.ts @@ -0,0 +1,50 @@ +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 { + buildKeybindingsJsonSchema, + getVersionedKeybindingsSchemaRelativePath, + KEYBINDINGS_SCHEMA_RELATIVE_PATH, + writeKeybindingsJsonSchemas, +} from "./keybindings-schema"; + +describe("buildKeybindingsJsonSchema", () => { + it("builds a JSON schema document for keybindings.json", () => { + const schema = buildKeybindingsJsonSchema(); + + expect(schema.$schema).toBe("https://json-schema.org/draft/2020-12/schema"); + expect(schema.title).toBe("T3 Code Keybindings"); + expect(schema.type).toBe("array"); + expect(schema.items).toMatchObject({ + type: "object", + properties: { + key: expect.any(Object), + command: expect.any(Object), + }, + }); + }); + + it("writes latest and versioned schema files", () => { + const rootDir = mkdtempSync(join(tmpdir(), "t3-keybindings-schema-")); + + try { + const result = writeKeybindingsJsonSchemas({ rootDir, version: "1.2.3" }); + expect(result.changed).toBe(true); + + const latestSchema = JSON.parse( + readFileSync(resolve(rootDir, KEYBINDINGS_SCHEMA_RELATIVE_PATH), "utf8"), + ) as Record; + const versionedSchema = JSON.parse( + readFileSync(resolve(rootDir, getVersionedKeybindingsSchemaRelativePath("1.2.3")), "utf8"), + ) as Record; + + expect(latestSchema).toEqual(versionedSchema); + expect(latestSchema.title).toBe("T3 Code Keybindings"); + } finally { + rmSync(rootDir, { recursive: true, force: true }); + } + }); +}); diff --git a/scripts/lib/keybindings-schema.ts b/scripts/lib/keybindings-schema.ts new file mode 100644 index 0000000000..72cb83cb78 --- /dev/null +++ b/scripts/lib/keybindings-schema.ts @@ -0,0 +1,32 @@ +import { KeybindingsConfig } from "@t3tools/contracts"; +import { buildJsonSchemaDocument, writeJsonSchemaArtifacts } from "./json-schema"; + +export const KEYBINDINGS_SCHEMA_RELATIVE_PATH = + "apps/marketing/public/schemas/keybindings.schema.json"; +export const KEYBINDINGS_VERSIONED_SCHEMA_DIRECTORY_RELATIVE_PATH = + "apps/marketing/public/schemas/keybindings"; + +export const getVersionedKeybindingsSchemaRelativePath = (version: string) => + `${KEYBINDINGS_VERSIONED_SCHEMA_DIRECTORY_RELATIVE_PATH}/${version}.schema.json`; + +export function buildKeybindingsJsonSchema(): Record { + return buildJsonSchemaDocument(KeybindingsConfig, { + title: "T3 Code Keybindings", + description: "JSON Schema for the keybindings.json file consumed by T3 Code.", + }); +} + +export function writeKeybindingsJsonSchemas(options?: { + readonly rootDir?: string; + readonly version?: string; +}): { + readonly changed: boolean; +} { + return writeJsonSchemaArtifacts({ + latestRelativePath: KEYBINDINGS_SCHEMA_RELATIVE_PATH, + getVersionedRelativePath: getVersionedKeybindingsSchemaRelativePath, + document: buildKeybindingsJsonSchema(), + ...(options?.rootDir === undefined ? {} : { rootDir: options.rootDir }), + ...(options?.version === undefined ? {} : { version: options.version }), + }); +} diff --git a/scripts/lib/server-settings-schema.ts b/scripts/lib/server-settings-schema.ts index 096135c38a..22caf55f97 100644 --- a/scripts/lib/server-settings-schema.ts +++ b/scripts/lib/server-settings-schema.ts @@ -1,10 +1,5 @@ -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"; +import { buildJsonSchemaDocument, writeJsonSchemaArtifacts } from "./json-schema"; export const SERVER_SETTINGS_SCHEMA_RELATIVE_PATH = "apps/marketing/public/schemas/server-settings.schema.json"; @@ -15,36 +10,10 @@ 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, + return buildJsonSchemaDocument(ServerSettings, { 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?: { @@ -53,20 +22,11 @@ export function writeServerSettingsJsonSchemas(options?: { }): { 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 }; + return writeJsonSchemaArtifacts({ + latestRelativePath: SERVER_SETTINGS_SCHEMA_RELATIVE_PATH, + getVersionedRelativePath: getVersionedServerSettingsSchemaRelativePath, + document: buildServerSettingsJsonSchema(), + ...(options?.rootDir === undefined ? {} : { rootDir: options.rootDir }), + ...(options?.version === undefined ? {} : { version: options.version }), + }); } diff --git a/scripts/release-smoke.ts b/scripts/release-smoke.ts index 704ef3c8aa..6e550d3a4a 100644 --- a/scripts/release-smoke.ts +++ b/scripts/release-smoke.ts @@ -122,6 +122,14 @@ try { tempRoot, "apps/marketing/public/schemas/server-settings/9.9.9-smoke.0.schema.json", ); + const latestKeybindingsSchemaPath = resolve( + tempRoot, + "apps/marketing/public/schemas/keybindings.schema.json", + ); + const versionedKeybindingsSchemaPath = resolve( + tempRoot, + "apps/marketing/public/schemas/keybindings/9.9.9-smoke.0.schema.json", + ); if (!existsSync(latestSchemaPath)) { throw new Error( "Expected release version alignment to generate the latest server settings schema.", @@ -132,12 +140,28 @@ try { "Expected release version alignment to generate the versioned server settings schema.", ); } + if (!existsSync(latestKeybindingsSchemaPath)) { + throw new Error( + "Expected release version alignment to generate the latest keybindings schema.", + ); + } + if (!existsSync(versionedKeybindingsSchemaPath)) { + throw new Error( + "Expected release version alignment to generate the versioned keybindings schema.", + ); + } const versionedSchema = readFileSync(versionedSchemaPath, "utf8"); assertContains( versionedSchema, '"title": "T3 Code Server Settings"', "Expected versioned server settings schema to contain schema metadata.", ); + const versionedKeybindingsSchema = readFileSync(versionedKeybindingsSchemaPath, "utf8"); + assertContains( + versionedKeybindingsSchema, + '"title": "T3 Code Keybindings"', + "Expected versioned keybindings schema to contain schema metadata.", + ); const { arm64Path, x64Path } = writeMacManifestFixtures(tempRoot); execFileSync( diff --git a/scripts/update-release-package-versions.test.ts b/scripts/update-release-package-versions.test.ts index 29332f1fc2..43bf7568c7 100644 --- a/scripts/update-release-package-versions.test.ts +++ b/scripts/update-release-package-versions.test.ts @@ -10,7 +10,7 @@ import { } from "./update-release-package-versions"; describe("updateReleasePackageVersions", () => { - it("updates package versions and writes latest plus versioned server settings schemas", () => { + it("updates package versions and writes latest plus versioned config schemas", () => { const rootDir = mkdtempSync(join(tmpdir(), "t3-release-version-bump-")); try { @@ -50,6 +50,24 @@ describe("updateReleasePackageVersions", () => { ), ), ).toMatchObject({ title: "T3 Code Server Settings" }); + + expect( + JSON.parse( + readFileSync( + resolve(rootDir, "apps/marketing/public/schemas/keybindings.schema.json"), + "utf8", + ), + ), + ).toMatchObject({ title: "T3 Code Keybindings" }); + + expect( + JSON.parse( + readFileSync( + resolve(rootDir, "apps/marketing/public/schemas/keybindings/1.2.3.schema.json"), + "utf8", + ), + ), + ).toMatchObject({ title: "T3 Code Keybindings" }); } finally { rmSync(rootDir, { recursive: true, force: true }); } diff --git a/scripts/update-release-package-versions.ts b/scripts/update-release-package-versions.ts index a812f4f17f..785cc32ff7 100644 --- a/scripts/update-release-package-versions.ts +++ b/scripts/update-release-package-versions.ts @@ -2,6 +2,7 @@ import { appendFileSync, readFileSync, writeFileSync } from "node:fs"; import { resolve } from "node:path"; import { fileURLToPath } from "node:url"; +import { writeKeybindingsJsonSchemas } from "./lib/keybindings-schema.ts"; import { writeServerSettingsJsonSchemas } from "./lib/server-settings-schema.ts"; export const releasePackageFiles = [ @@ -40,6 +41,7 @@ export function updateReleasePackageVersions( } changed = writeServerSettingsJsonSchemas({ rootDir, version }).changed || changed; + changed = writeKeybindingsJsonSchemas({ rootDir, version }).changed || changed; return { changed }; }