Skip to content

Commit 5841e3b

Browse files
committed
fix(ci): split redact snapshot schema coverage
1 parent aeb2adf commit 5841e3b

3 files changed

Lines changed: 92 additions & 40 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
REDACTED_SENTINEL,
4+
redactConfigSnapshot,
5+
restoreRedactedValues as restoreRedactedValues_orig,
6+
} from "./redact-snapshot.js";
7+
import { __test__ } from "./schema.hints.js";
8+
import type { ConfigUiHints } from "./schema.js";
9+
import type { ConfigFileSnapshot } from "./types.openclaw.js";
10+
import { OpenClawSchema } from "./zod-schema.js";
11+
12+
const { mapSensitivePaths } = __test__;
13+
const mainSchemaHints = mapSensitivePaths(OpenClawSchema, "", {});
14+
15+
type TestSnapshot<TConfig extends Record<string, unknown>> = ConfigFileSnapshot & {
16+
parsed: TConfig;
17+
resolved: TConfig;
18+
config: TConfig;
19+
};
20+
21+
function makeSnapshot<TConfig extends Record<string, unknown>>(
22+
config: TConfig,
23+
raw?: string,
24+
): TestSnapshot<TConfig> {
25+
return {
26+
path: "/home/user/.openclaw/config.json5",
27+
exists: true,
28+
raw: raw ?? JSON.stringify(config),
29+
parsed: config,
30+
resolved: config as ConfigFileSnapshot["resolved"],
31+
valid: true,
32+
config: config as ConfigFileSnapshot["config"],
33+
hash: "abc123",
34+
issues: [],
35+
warnings: [],
36+
legacyIssues: [],
37+
} as unknown as TestSnapshot<TConfig>;
38+
}
39+
40+
function restoreRedactedValues<TOriginal>(
41+
incoming: unknown,
42+
original: TOriginal,
43+
hints?: ConfigUiHints,
44+
): TOriginal {
45+
const result = restoreRedactedValues_orig(incoming, original, hints);
46+
expect(result.ok).toBe(true);
47+
return result.result as TOriginal;
48+
}
49+
50+
describe("realredactConfigSnapshot_real", () => {
51+
it("main schema redact works (samples)", () => {
52+
const schema = OpenClawSchema.toJSONSchema({
53+
target: "draft-07",
54+
unrepresentable: "any",
55+
});
56+
schema.title = "OpenClawConfig";
57+
const hints = mainSchemaHints;
58+
59+
const snapshot = makeSnapshot({
60+
agents: {
61+
defaults: {
62+
memorySearch: {
63+
remote: {
64+
apiKey: "1234",
65+
},
66+
},
67+
},
68+
list: [
69+
{
70+
memorySearch: {
71+
remote: {
72+
apiKey: "6789",
73+
},
74+
},
75+
},
76+
],
77+
},
78+
});
79+
80+
const result = redactConfigSnapshot(snapshot, hints);
81+
const config = result.config as typeof snapshot.config;
82+
expect(config.agents.defaults.memorySearch.remote.apiKey).toBe(REDACTED_SENTINEL);
83+
expect(config.agents.list[0].memorySearch.remote.apiKey).toBe(REDACTED_SENTINEL);
84+
const restored = restoreRedactedValues(result.config, snapshot.config, hints);
85+
expect(restored.agents.defaults.memorySearch.remote.apiKey).toBe("1234");
86+
expect(restored.agents.list[0].memorySearch.remote.apiKey).toBe("6789");
87+
});
88+
});

src/config/redact-snapshot.test.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -918,43 +918,3 @@ describe("redactConfigSnapshot", () => {
918918
expect(channels.slack.accounts[1].botToken).toBe(REDACTED_SENTINEL);
919919
});
920920
});
921-
922-
describe("realredactConfigSnapshot_real", () => {
923-
it("main schema redact works (samples)", () => {
924-
const schema = OpenClawSchema.toJSONSchema({
925-
target: "draft-07",
926-
unrepresentable: "any",
927-
});
928-
schema.title = "OpenClawConfig";
929-
const hints = mainSchemaHints;
930-
931-
const snapshot = makeSnapshot({
932-
agents: {
933-
defaults: {
934-
memorySearch: {
935-
remote: {
936-
apiKey: "1234",
937-
},
938-
},
939-
},
940-
list: [
941-
{
942-
memorySearch: {
943-
remote: {
944-
apiKey: "6789",
945-
},
946-
},
947-
},
948-
],
949-
},
950-
});
951-
952-
const result = redactConfigSnapshot(snapshot, hints);
953-
const config = result.config as typeof snapshot.config;
954-
expect(config.agents.defaults.memorySearch.remote.apiKey).toBe(REDACTED_SENTINEL);
955-
expect(config.agents.list[0].memorySearch.remote.apiKey).toBe(REDACTED_SENTINEL);
956-
const restored = restoreRedactedValues(result.config, snapshot.config, hints);
957-
expect(restored.agents.defaults.memorySearch.remote.apiKey).toBe("1234");
958-
expect(restored.agents.list[0].memorySearch.remote.apiKey).toBe("6789");
959-
});
960-
});

test/fixtures/test-parallel.behavior.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
"file": "src/config/redact-snapshot.restore.test.ts",
5656
"reason": "Snapshot restore coverage retains a broad schema/redaction graph and is safer outside the shared lane."
5757
},
58+
{
59+
"file": "src/config/redact-snapshot.schema.test.ts",
60+
"reason": "Schema-backed redaction round-trip coverage loads the full config schema graph and is safer outside the shared lane."
61+
},
5862
{
5963
"file": "src/infra/outbound/message-action-runner.media.test.ts",
6064
"reason": "Outbound media action coverage retained a large media/plugin graph in unit-fast."

0 commit comments

Comments
 (0)