From 5841e3b4935dccbb06df121e62cc16817200e5a7 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 19 Mar 2026 14:48:32 -0700 Subject: [PATCH] fix(ci): split redact snapshot schema coverage --- src/config/redact-snapshot.schema.test.ts | 88 +++++++++++++++++++++++ src/config/redact-snapshot.test.ts | 40 ----------- test/fixtures/test-parallel.behavior.json | 4 ++ 3 files changed, 92 insertions(+), 40 deletions(-) create mode 100644 src/config/redact-snapshot.schema.test.ts diff --git a/src/config/redact-snapshot.schema.test.ts b/src/config/redact-snapshot.schema.test.ts new file mode 100644 index 00000000000..3c67d2cb92b --- /dev/null +++ b/src/config/redact-snapshot.schema.test.ts @@ -0,0 +1,88 @@ +import { describe, expect, it } from "vitest"; +import { + REDACTED_SENTINEL, + redactConfigSnapshot, + restoreRedactedValues as restoreRedactedValues_orig, +} from "./redact-snapshot.js"; +import { __test__ } from "./schema.hints.js"; +import type { ConfigUiHints } from "./schema.js"; +import type { ConfigFileSnapshot } from "./types.openclaw.js"; +import { OpenClawSchema } from "./zod-schema.js"; + +const { mapSensitivePaths } = __test__; +const mainSchemaHints = mapSensitivePaths(OpenClawSchema, "", {}); + +type TestSnapshot> = ConfigFileSnapshot & { + parsed: TConfig; + resolved: TConfig; + config: TConfig; +}; + +function makeSnapshot>( + config: TConfig, + raw?: string, +): TestSnapshot { + return { + path: "/home/user/.openclaw/config.json5", + exists: true, + raw: raw ?? JSON.stringify(config), + parsed: config, + resolved: config as ConfigFileSnapshot["resolved"], + valid: true, + config: config as ConfigFileSnapshot["config"], + hash: "abc123", + issues: [], + warnings: [], + legacyIssues: [], + } as unknown as TestSnapshot; +} + +function restoreRedactedValues( + incoming: unknown, + original: TOriginal, + hints?: ConfigUiHints, +): TOriginal { + const result = restoreRedactedValues_orig(incoming, original, hints); + expect(result.ok).toBe(true); + return result.result as TOriginal; +} + +describe("realredactConfigSnapshot_real", () => { + it("main schema redact works (samples)", () => { + const schema = OpenClawSchema.toJSONSchema({ + target: "draft-07", + unrepresentable: "any", + }); + schema.title = "OpenClawConfig"; + const hints = mainSchemaHints; + + const snapshot = makeSnapshot({ + agents: { + defaults: { + memorySearch: { + remote: { + apiKey: "1234", + }, + }, + }, + list: [ + { + memorySearch: { + remote: { + apiKey: "6789", + }, + }, + }, + ], + }, + }); + + const result = redactConfigSnapshot(snapshot, hints); + const config = result.config as typeof snapshot.config; + expect(config.agents.defaults.memorySearch.remote.apiKey).toBe(REDACTED_SENTINEL); + expect(config.agents.list[0].memorySearch.remote.apiKey).toBe(REDACTED_SENTINEL); + const restored = restoreRedactedValues(result.config, snapshot.config, hints); + expect(restored.agents.defaults.memorySearch.remote.apiKey).toBe("1234"); + expect(restored.agents.list[0].memorySearch.remote.apiKey).toBe("6789"); + }); +}); diff --git a/src/config/redact-snapshot.test.ts b/src/config/redact-snapshot.test.ts index d4c14b29ae6..dd754a44fac 100644 --- a/src/config/redact-snapshot.test.ts +++ b/src/config/redact-snapshot.test.ts @@ -918,43 +918,3 @@ describe("redactConfigSnapshot", () => { expect(channels.slack.accounts[1].botToken).toBe(REDACTED_SENTINEL); }); }); - -describe("realredactConfigSnapshot_real", () => { - it("main schema redact works (samples)", () => { - const schema = OpenClawSchema.toJSONSchema({ - target: "draft-07", - unrepresentable: "any", - }); - schema.title = "OpenClawConfig"; - const hints = mainSchemaHints; - - const snapshot = makeSnapshot({ - agents: { - defaults: { - memorySearch: { - remote: { - apiKey: "1234", - }, - }, - }, - list: [ - { - memorySearch: { - remote: { - apiKey: "6789", - }, - }, - }, - ], - }, - }); - - const result = redactConfigSnapshot(snapshot, hints); - const config = result.config as typeof snapshot.config; - expect(config.agents.defaults.memorySearch.remote.apiKey).toBe(REDACTED_SENTINEL); - expect(config.agents.list[0].memorySearch.remote.apiKey).toBe(REDACTED_SENTINEL); - const restored = restoreRedactedValues(result.config, snapshot.config, hints); - expect(restored.agents.defaults.memorySearch.remote.apiKey).toBe("1234"); - expect(restored.agents.list[0].memorySearch.remote.apiKey).toBe("6789"); - }); -}); diff --git a/test/fixtures/test-parallel.behavior.json b/test/fixtures/test-parallel.behavior.json index 15bb986fa8d..bdbb4583913 100644 --- a/test/fixtures/test-parallel.behavior.json +++ b/test/fixtures/test-parallel.behavior.json @@ -55,6 +55,10 @@ "file": "src/config/redact-snapshot.restore.test.ts", "reason": "Snapshot restore coverage retains a broad schema/redaction graph and is safer outside the shared lane." }, + { + "file": "src/config/redact-snapshot.schema.test.ts", + "reason": "Schema-backed redaction round-trip coverage loads the full config schema graph and is safer outside the shared lane." + }, { "file": "src/infra/outbound/message-action-runner.media.test.ts", "reason": "Outbound media action coverage retained a large media/plugin graph in unit-fast."