import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; import { redact, SEVERITY } from "./log"; // The browser log and the server log are ONE log (E22): a client batch lands in `log_events` beside // the server's rows. So the two must agree on what is safe to keep and on what a level is worth — // asserted against the backend's own files, not a copy of them. const backend = (path: string) => readFileSync(new URL(`../../../backend/${path}`, import.meta.url), "utf-8"); const { cases } = JSON.parse(backend("tests/fixtures/log_redaction_cases.json")) as { cases: { name: string; key: string; value: unknown; expected: unknown }[]; }; describe("redaction matches the server's (shared cases)", () => { it.each(cases.map((c) => [c.name, c] as const))("%s", (_name, c) => { expect(redact(c.value, c.key)).toEqual(c.expected); }); }); describe("severity numbers match logs.SEVERITY", () => { it("names the same levels with the same numbers", () => { const block = /SEVERITY: dict\[str, int\] = \{([^}]*)\}/.exec(backend("app/logs.py"))?.[1]; expect(block).toBeTruthy(); const server = Object.fromEntries( [...block!.matchAll(/"(\w+)":\s*(\d+)/g)].map((m) => [m[1], Number(m[2])]), ); expect(SEVERITY).toEqual(server); }); });