From f91d0098eae2939fe10fda83e7023ada263e847c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 8 May 2026 12:10:26 +0100 Subject: [PATCH] chore: keep generated db types codegen-stable --- scripts/pre-commit/filter-staged-files.mjs | 5 +++- src/proxy-capture/db.generated.d.ts | 7 +++--- src/state/openclaw-agent-db.generated.d.ts | 7 +++--- src/state/openclaw-state-db.generated.d.ts | 7 +++--- .../pre-commit-filter-staged-files.test.ts | 23 +++++++++++++++++++ 5 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 test/scripts/pre-commit-filter-staged-files.test.ts diff --git a/scripts/pre-commit/filter-staged-files.mjs b/scripts/pre-commit/filter-staged-files.mjs index 2206a0240ce..dbaa2329030 100644 --- a/scripts/pre-commit/filter-staged-files.mjs +++ b/scripts/pre-commit/filter-staged-files.mjs @@ -22,7 +22,10 @@ if (mode !== "lint" && mode !== "format") { const lintExts = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]); const formatExts = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".md", ".mdx"]); -const formatIgnoredPathPatterns = [/^extensions\/[^/]+\/src\/host\/.+\/[^/]+\.bundle\.js$/u]; +const formatIgnoredPathPatterns = [ + /^extensions\/[^/]+\/src\/host\/.+\/[^/]+\.bundle\.js$/u, + /\.generated\.d\.ts$/u, +]; const shouldSelect = (filePath) => { const ext = path.extname(filePath).toLowerCase(); diff --git a/src/proxy-capture/db.generated.d.ts b/src/proxy-capture/db.generated.d.ts index 3cced1136d1..f561805f67f 100644 --- a/src/proxy-capture/db.generated.d.ts +++ b/src/proxy-capture/db.generated.d.ts @@ -5,10 +5,9 @@ import type { ColumnType } from "kysely"; -export type Generated = - T extends ColumnType - ? ColumnType - : ColumnType; +export type Generated = T extends ColumnType + ? ColumnType + : ColumnType; export interface CaptureBlobs { blob_id: string; diff --git a/src/state/openclaw-agent-db.generated.d.ts b/src/state/openclaw-agent-db.generated.d.ts index 14ca3c260f2..a7cbd290821 100644 --- a/src/state/openclaw-agent-db.generated.d.ts +++ b/src/state/openclaw-agent-db.generated.d.ts @@ -5,10 +5,9 @@ import type { ColumnType } from "kysely"; -export type Generated = - T extends ColumnType - ? ColumnType - : ColumnType; +export type Generated = T extends ColumnType + ? ColumnType + : ColumnType; export interface AcpParentStreamEvents { created_at: number; diff --git a/src/state/openclaw-state-db.generated.d.ts b/src/state/openclaw-state-db.generated.d.ts index 1f850ce4942..13c1d03c9c2 100644 --- a/src/state/openclaw-state-db.generated.d.ts +++ b/src/state/openclaw-state-db.generated.d.ts @@ -5,10 +5,9 @@ import type { ColumnType } from "kysely"; -export type Generated = - T extends ColumnType - ? ColumnType - : ColumnType; +export type Generated = T extends ColumnType + ? ColumnType + : ColumnType; export interface AgentDatabases { agent_id: string; diff --git a/test/scripts/pre-commit-filter-staged-files.test.ts b/test/scripts/pre-commit-filter-staged-files.test.ts new file mode 100644 index 00000000000..9318ebb3483 --- /dev/null +++ b/test/scripts/pre-commit-filter-staged-files.test.ts @@ -0,0 +1,23 @@ +import { execFileSync } from "node:child_process"; +import path from "node:path"; +import { describe, expect, it } from "vitest"; + +const scriptPath = path.join(process.cwd(), "scripts", "pre-commit", "filter-staged-files.mjs"); + +function filterFiles(mode: "format" | "lint", files: string[]): string[] { + const output = execFileSync(process.execPath, [scriptPath, mode, "--", ...files], { + encoding: "utf8", + }); + return output.split("\0").filter(Boolean); +} + +describe("pre-commit staged-file filter", () => { + it("does not format generated Kysely declaration files", () => { + expect( + filterFiles("format", [ + "src/state/openclaw-state-db.generated.d.ts", + "src/state/openclaw-state-db.ts", + ]), + ).toEqual(["src/state/openclaw-state-db.ts"]); + }); +});