mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-21 16:41:56 +00:00
test(config): dedupe nested redaction round-trip assertions
This commit is contained in:
@@ -392,6 +392,32 @@ describe("redactConfigSnapshot", () => {
|
||||
});
|
||||
|
||||
it("round-trips nested and array sensitivity cases", () => {
|
||||
const customSecretValue = "this-is-a-custom-secret-value";
|
||||
const buildNestedValuesSnapshot = () =>
|
||||
makeSnapshot({
|
||||
custom1: { anykey: { mySecret: customSecretValue } },
|
||||
custom2: [{ mySecret: customSecretValue }],
|
||||
});
|
||||
const assertNestedValuesRoundTrip = ({
|
||||
redacted,
|
||||
restored,
|
||||
}: {
|
||||
redacted: Record<string, unknown>;
|
||||
restored: Record<string, unknown>;
|
||||
}) => {
|
||||
const cfg = redacted as Record<string, Record<string, unknown>>;
|
||||
const cfgCustom2 = cfg.custom2 as unknown as unknown[];
|
||||
expect(cfgCustom2.length).toBeGreaterThan(0);
|
||||
expect((cfg.custom1.anykey as Record<string, unknown>).mySecret).toBe(REDACTED_SENTINEL);
|
||||
expect((cfgCustom2[0] as Record<string, unknown>).mySecret).toBe(REDACTED_SENTINEL);
|
||||
|
||||
const out = restored as Record<string, Record<string, unknown>>;
|
||||
const outCustom2 = out.custom2 as unknown as unknown[];
|
||||
expect(outCustom2.length).toBeGreaterThan(0);
|
||||
expect((out.custom1.anykey as Record<string, unknown>).mySecret).toBe(customSecretValue);
|
||||
expect((outCustom2[0] as Record<string, unknown>).mySecret).toBe(customSecretValue);
|
||||
};
|
||||
|
||||
const cases: Array<{
|
||||
name: string;
|
||||
snapshot: TestSnapshot<Record<string, unknown>>;
|
||||
@@ -403,28 +429,8 @@ describe("redactConfigSnapshot", () => {
|
||||
}> = [
|
||||
{
|
||||
name: "nested values (schema)",
|
||||
snapshot: makeSnapshot({
|
||||
custom1: { anykey: { mySecret: "this-is-a-custom-secret-value" } },
|
||||
custom2: [{ mySecret: "this-is-a-custom-secret-value" }],
|
||||
}),
|
||||
assert: ({ redacted, restored }) => {
|
||||
const cfg = redacted;
|
||||
const cfgCustom2 = Array.isArray(cfg.custom2) ? cfg.custom2 : [];
|
||||
expect(cfgCustom2.length).toBeGreaterThan(0);
|
||||
expect(
|
||||
((cfg.custom1 as Record<string, unknown>).anykey as Record<string, unknown>).mySecret,
|
||||
).toBe(REDACTED_SENTINEL);
|
||||
expect((cfgCustom2[0] as Record<string, unknown>).mySecret).toBe(REDACTED_SENTINEL);
|
||||
const out = restored;
|
||||
const outCustom2 = Array.isArray(out.custom2) ? out.custom2 : [];
|
||||
expect(outCustom2.length).toBeGreaterThan(0);
|
||||
expect(
|
||||
((out.custom1 as Record<string, unknown>).anykey as Record<string, unknown>).mySecret,
|
||||
).toBe("this-is-a-custom-secret-value");
|
||||
expect((outCustom2[0] as Record<string, unknown>).mySecret).toBe(
|
||||
"this-is-a-custom-secret-value",
|
||||
);
|
||||
},
|
||||
snapshot: buildNestedValuesSnapshot(),
|
||||
assert: assertNestedValuesRoundTrip,
|
||||
},
|
||||
{
|
||||
name: "nested values (uiHints)",
|
||||
@@ -432,28 +438,8 @@ describe("redactConfigSnapshot", () => {
|
||||
"custom1.*.mySecret": { sensitive: true },
|
||||
"custom2[].mySecret": { sensitive: true },
|
||||
},
|
||||
snapshot: makeSnapshot({
|
||||
custom1: { anykey: { mySecret: "this-is-a-custom-secret-value" } },
|
||||
custom2: [{ mySecret: "this-is-a-custom-secret-value" }],
|
||||
}),
|
||||
assert: ({ redacted, restored }) => {
|
||||
const cfg = redacted;
|
||||
const cfgCustom2 = Array.isArray(cfg.custom2) ? cfg.custom2 : [];
|
||||
expect(cfgCustom2.length).toBeGreaterThan(0);
|
||||
expect(
|
||||
((cfg.custom1 as Record<string, unknown>).anykey as Record<string, unknown>).mySecret,
|
||||
).toBe(REDACTED_SENTINEL);
|
||||
expect((cfgCustom2[0] as Record<string, unknown>).mySecret).toBe(REDACTED_SENTINEL);
|
||||
const out = restored;
|
||||
const outCustom2 = Array.isArray(out.custom2) ? out.custom2 : [];
|
||||
expect(outCustom2.length).toBeGreaterThan(0);
|
||||
expect(
|
||||
((out.custom1 as Record<string, unknown>).anykey as Record<string, unknown>).mySecret,
|
||||
).toBe("this-is-a-custom-secret-value");
|
||||
expect((outCustom2[0] as Record<string, unknown>).mySecret).toBe(
|
||||
"this-is-a-custom-secret-value",
|
||||
);
|
||||
},
|
||||
snapshot: buildNestedValuesSnapshot(),
|
||||
assert: assertNestedValuesRoundTrip,
|
||||
},
|
||||
{
|
||||
name: "directly sensitive records and arrays",
|
||||
|
||||
Reference in New Issue
Block a user