feat: client log with request ids, joined to the server's
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).
This commit is contained in:
@@ -14,6 +14,36 @@ import globals from "globals";
|
||||
//
|
||||
// reportUnusedDisableDirectives: a `// eslint-disable` that no longer suppresses anything is itself
|
||||
// an error — that is what keeps inert disable comments from re-accumulating (the S1b mandate).
|
||||
|
||||
// E22 S4: every way out of the browser goes through the one module that LOGS it — a request line
|
||||
// with a request id (lib/http.ts), the upload XHR (lib/api/core.ts), the messages socket
|
||||
// (lib/messagesSocket.ts). A bare `fetch` elsewhere is a request the client log never sees, which is
|
||||
// exactly how the baseline survey found four. Each owner is exempt from its OWN global only.
|
||||
const NETWORK_OWNERS = {
|
||||
fetch: "src/lib/http.ts",
|
||||
XMLHttpRequest: "src/lib/api/core.ts",
|
||||
WebSocket: "src/lib/messagesSocket.ts",
|
||||
EventSource: null,
|
||||
};
|
||||
const networkGlobals = (exempt) =>
|
||||
Object.entries(NETWORK_OWNERS)
|
||||
.filter(([name]) => name !== exempt)
|
||||
.map(([name, owner]) => ({
|
||||
name,
|
||||
message: owner
|
||||
? `Use the logged request layer: \`${name}\` belongs to ${owner} only (E22 S4 — a request outside it never reaches the client log).`
|
||||
: `No \`${name}\` without a logged owner module (E22 S4).`,
|
||||
}));
|
||||
const networkProperties = [
|
||||
{ object: "window", property: "fetch", message: "Use lib/http.ts `send` (E22 S4)." },
|
||||
{ object: "globalThis", property: "fetch", message: "Use lib/http.ts `send` (E22 S4)." },
|
||||
{
|
||||
object: "navigator",
|
||||
property: "sendBeacon",
|
||||
message: "Use lib/api/core.ts `beacon` (E22 S4).",
|
||||
},
|
||||
];
|
||||
|
||||
export default tseslint.config(
|
||||
{ ignores: ["dist", "node_modules", "playwright-report", "test-results", "e2e/.auth"] },
|
||||
{
|
||||
@@ -42,6 +72,11 @@ export default tseslint.config(
|
||||
// types; i18n `t` props → TFunction), so the rule is now enforced to keep new ones from
|
||||
// creeping back in. Prefer `unknown` + narrowing, or a typed boundary, over `any`.
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
// E22 S4: the client log (lib/log.ts) is the one place diagnostics go — redacted, levelled,
|
||||
// bounded. A `console.*` call is none of those, and it is invisible to the user's own log.
|
||||
"no-console": "error",
|
||||
"no-restricted-globals": ["error", ...networkGlobals(null)],
|
||||
"no-restricted-properties": ["error", ...networkProperties],
|
||||
// Side-effect ternaries/short-circuits are an established idiom here (`cond ? a() : b()`,
|
||||
// `v.paused ? v.play() : v.pause()`) — allow them rather than rewrite working code to if/else.
|
||||
"@typescript-eslint/no-unused-expressions": [
|
||||
@@ -131,5 +166,17 @@ export default tseslint.config(
|
||||
],
|
||||
},
|
||||
},
|
||||
// The network owners (see NETWORK_OWNERS), each exempt from its own global only.
|
||||
...Object.entries(NETWORK_OWNERS)
|
||||
.filter(([, owner]) => owner)
|
||||
.map(([name, owner]) => ({
|
||||
files: [owner],
|
||||
rules: { "no-restricted-globals": ["error", ...networkGlobals(name)] },
|
||||
})),
|
||||
{
|
||||
// Tests stand doubles in for the network (`vi.stubGlobal("fetch", …)`) and may reach it directly.
|
||||
files: ["src/**/*.test.{ts,tsx}"],
|
||||
rules: { "no-restricted-globals": "off", "no-restricted-properties": "off" },
|
||||
},
|
||||
prettier,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user