import { describe, expect, it } from "vitest"; import { redactConnectorPayload } from "./connector-safety.js"; describe("redactConnectorPayload", () => { it("redacts secrets that JSON escapes in property names and values", () => { const secret = 'api"key'; expect( redactConnectorPayload( { [secret]: `prefix ${secret} suffix`, nested: { value: secret }, }, [secret], ), ).toEqual({ "[redacted]": "prefix [redacted] suffix", nested: { value: "[redacted]" }, }); }); it("falls back to an inert result when the payload is not JSON serializable", () => { const circular: Record = {}; circular.self = circular; expect(redactConnectorPayload(circular, ["secret"])).toEqual({ ok: true }); }); it("redacts secrets represented by non-string JSON leaves", () => { expect( redactConnectorPayload({ number: 123, boolean: true, empty: null }, ["123", "true", "null"]), ).toEqual({ number: "[redacted]", boolean: "[redacted]", empty: "[redacted]" }); }); });