The browser now keeps its half of the one event shape logs.py defines: lib/log.ts is a levelled, redacted, bounded (2000 events) in-memory ring with the server's level names and severity numbers. Nothing leaves the browser yet; sending is the consented diagnostics level (S5). - lib/http.ts `send` is the one fetch: every request carries an X-Request-Id and becomes one http.request event. The server echoes the matched route template in X-Route (only for a matched route, so a raw path with a value in it is never sent back); without one the client templates the path itself. req, beacon, the upload XHR, the public watch page and the legal pages all go through it. - Hooks: app start snapshot, uncaught errors and rejections, History push/replace/popstate (a scroll-only replace is not an event; parameter values only at DEBUG, typed search only at TRACE), notifications, the error dialog, the crash boundary, failed queries and mutations (key head only), and the messages socket (lifecycle, frame types at DEBUG). - Redaction is one contract: backend/tests/fixtures/log_redaction_cases.json runs against both redact() implementations. - Lint: fetch, XMLHttpRequest and WebSocket each belong to one logging module, console to none; a contract test proves the rules fire. Fixes a socket takeover: the close of a socket released by the last subscriber cleared the newer socket a quick re-subscribe had opened and scheduled a third, leaving two live sockets that delivered every message twice (measured in Chromium: 3 created / 2 live before, 2 / 1 after).
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
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);
|
|
});
|
|
});
|