Files
siftlode/frontend/src/components/clientLogWiring.dom.test.tsx
T
peter 4aaaaa7860 chore(comments): drop epic, sprint and review-round ids from the code
The code cited its plan instead of saying why: `E28 review J4`, `(R6 S3b)`, `S1 justified…`,
`deep-review round 5`. That plan lives in the private ops repo, so for every reader of this one the
citation was noise, and a sentence whose subject was the plan step ("round 2 showed…") hid its
lesson behind an id. Each one is gone and the "why" kept: a bare citation is deleted, a sentence
carrying a lesson is reworded around it ("a later attempt showed…").

Measured (`scripts/audit_metrics.py`, product code): 652 lines in 270 files carried an epic code by
the definition the next commit holds (507 / 241 by the old, two-digit-only one) -> 0. Across all
code, tests, scripts and configs: ~1100 epic-code lines plus ~320 sprint/round ids.

Behaviour unchanged, checked mechanically: every changed .py file has the same AST once docstrings
are blanked; css/sh/toml/yml/json files are identical once comments are stripped; the only
non-comment changes in TS/JS are test titles, one description string in a contract table, and five
ESLint messages, whose text is all the gates snapshot diff holds. Not touched: Markdown (docs and
the changelog keep their history), Alembic migrations, TV episode notation (`S2 · E5`), DESIGN.md
ids (`C1`, `B4`, `S3h`), tracker ids (`SEC-16`, `DX-17`).

One stale claim fixed on the way: test_hls_reaper's docstring said the player checkpoints "every
10 s whether or not it is playing", which plex/stream.py calls wrong; it now says what the code does.
2026-10-05 00:19:39 +02:00

83 lines
3.1 KiB
TypeScript

// @vitest-environment jsdom
//
// What the user was SHOWN — a toast, the blocking error dialog, the crash screen — and what
// failed behind the scenes (a query, a mutation) all land in the client log. Each producer is its
// own module, so each is asserted here through the real thing, not a mock of it.
import { afterEach, describe, expect, it, vi } from "vitest";
import { cleanup, render } from "@testing-library/react";
import { clear, events } from "../lib/log";
import { notify } from "../lib/notifications";
import { reportError } from "../lib/errorDialog";
import { createQueryClient } from "../lib/queryClient";
import ErrorBoundary from "./ErrorBoundary";
import { HttpError } from "../lib/api/core";
afterEach(() => {
cleanup();
clear();
vi.restoreAllMocks();
});
const logged = (code: string) => events().filter((e) => e.event === code);
describe("client log wiring", () => {
it("records every notification at its level", () => {
notify({ level: "success", title: "Saved", message: "Playlist renamed" });
notify({ level: "error", message: "Could not reach someone@mail.example" });
expect(logged("ui.notify").map((e) => [e.level, e.msg, e.attrs])).toEqual([
["INFO", "Playlist renamed", { level: "success", title: "Saved" }],
["ERROR", "Could not reach [email]", { level: "error" }],
]);
});
it("records the blocking error dialog", () => {
reportError("The server refused", "Couldn't save");
expect(logged("ui.error_dialog")).toMatchObject([
{ level: "ERROR", msg: "The server refused", attrs: { title: "Couldn't save" } },
]);
});
it("records a failed query by its resource only — the rest of the key is filter state", async () => {
const client = createQueryClient();
await client
.fetchQuery({
queryKey: ["videos", { tags: ["private-tag"] }],
queryFn: () => Promise.reject(new HttpError(503, "down")),
})
.catch(() => {});
expect(logged("query.failed")).toMatchObject([
{ level: "WARNING", attrs: { key: "videos", status: 503, message: "down" } },
]);
expect(JSON.stringify(events())).not.toContain("private-tag");
});
it("records a failed mutation", async () => {
const client = createQueryClient();
const mutation = client.getMutationCache().build(client, {
mutationKey: ["playlists", 42],
mutationFn: () => Promise.reject(new HttpError(409, "conflict")),
meta: { errorShownInline: true },
});
await mutation.execute(undefined).catch(() => {});
expect(logged("mutation.failed")).toMatchObject([
{ level: "WARNING", attrs: { key: "playlists", status: 409 } },
]);
});
it("records a render crash with its component stack", () => {
vi.spyOn(console, "error").mockImplementation(() => {}); // React reports the crash itself too
const Boom = () => {
throw new Error("render exploded");
};
render(
<ErrorBoundary>
<Boom />
</ErrorBoundary>,
);
const [crash] = logged("ui.crash");
expect(crash).toMatchObject({ level: "CRITICAL", attrs: { message: "render exploded" } });
expect(String(crash!.attrs!.component_stack)).toContain("Boom");
});
});