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.
105 lines
4.0 KiB
TypeScript
105 lines
4.0 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// The ONE app-wide reporter for a failed mutation. `req` shows its blocking dialog for
|
|
// 400/409/422/5xx only, so before this every mutation without a reporting `onError` failed in
|
|
// silence on a 403/404/429 or a lost connection — 34 of them.
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("./notifications", () => ({ notify: vi.fn(() => 0) }));
|
|
vi.mock("./errorDialog", () => ({ reportError: vi.fn() }));
|
|
|
|
import { MutationObserver, type MutationObserverOptions } from "@tanstack/react-query";
|
|
import { createQueryClient } from "./queryClient";
|
|
import { HttpError, req } from "./api/core";
|
|
import { notify } from "./notifications";
|
|
import { reportError } from "./errorDialog";
|
|
import { notifyActionError } from "./actionErrors";
|
|
import i18n from "../i18n";
|
|
|
|
const notifyMock = vi.mocked(notify);
|
|
beforeEach(() => {
|
|
notifyMock.mockClear();
|
|
vi.mocked(reportError).mockClear();
|
|
});
|
|
afterEach(() => vi.restoreAllMocks());
|
|
|
|
async function fail(options: MutationObserverOptions<unknown, unknown, void>): Promise<void> {
|
|
const observer = new MutationObserver(createQueryClient(), options);
|
|
await observer.mutate().catch(() => {});
|
|
// The reporter waits a task for the mutation's own onError; give it that task.
|
|
await new Promise((r) => setTimeout(r, 5));
|
|
}
|
|
|
|
const TITLE = "errors.writeFailed.hideChannel";
|
|
|
|
describe("a failed mutation", () => {
|
|
it("is named, with the reason under it, when the mutation did not report it itself", async () => {
|
|
await fail({
|
|
mutationFn: () => Promise.reject(new HttpError(404, "Not subscribed")),
|
|
meta: { failTitle: TITLE },
|
|
});
|
|
expect(notifyMock.mock.calls).toEqual([
|
|
[{ level: "error", title: i18n.t(TITLE), message: i18n.t("errors.notFound.generic") }],
|
|
]);
|
|
});
|
|
|
|
it("is still reported under the generic title when the mutation names nothing", async () => {
|
|
await fail({ mutationFn: () => Promise.reject(new HttpError(429, "slow down")) });
|
|
expect(notifyMock).toHaveBeenCalledWith({
|
|
level: "error",
|
|
title: i18n.t("errors.title"),
|
|
message: i18n.t("errors.reason.rateLimited"),
|
|
});
|
|
});
|
|
|
|
it("says a lost connection is why the change did not go through", async () => {
|
|
await fail({
|
|
mutationFn: () => Promise.reject(new TypeError("Failed to fetch")),
|
|
meta: { failTitle: TITLE },
|
|
});
|
|
expect(notifyMock).toHaveBeenCalledWith(
|
|
expect.objectContaining({ message: i18n.t("errors.reason.unreachable") }),
|
|
);
|
|
});
|
|
|
|
it("gets ONE toast when the mutation's own onError reported it — react-query runs that one second", async () => {
|
|
await fail({
|
|
mutationFn: () => Promise.reject(new HttpError(404, "gone")),
|
|
meta: { failTitle: TITLE },
|
|
onError: (e) => notifyActionError(e, "OWN TITLE"),
|
|
});
|
|
expect(notifyMock.mock.calls.map(([n]) => n.title)).toEqual(["OWN TITLE"]);
|
|
});
|
|
|
|
it("is still reported when the mutation's onError only rolls back", async () => {
|
|
const rollback = vi.fn();
|
|
await fail({
|
|
mutationFn: () => Promise.reject(new HttpError(403, "nope")),
|
|
meta: { failTitle: TITLE },
|
|
onError: rollback,
|
|
});
|
|
expect(rollback).toHaveBeenCalled();
|
|
expect(notifyMock.mock.calls.map(([n]) => n.title)).toEqual([i18n.t(TITLE)]);
|
|
});
|
|
|
|
it("gets no toast when the page shows the failure itself", async () => {
|
|
await fail({
|
|
mutationFn: () => Promise.reject(new HttpError(403, "nope")),
|
|
meta: { errorShownInline: true },
|
|
});
|
|
expect(notifyMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("gets no toast on top of the error dialog the request layer already opened", async () => {
|
|
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
|
new Response(JSON.stringify({ detail: "conflict" }), {
|
|
status: 409,
|
|
headers: { "content-type": "application/json" },
|
|
}),
|
|
);
|
|
await fail({ mutationFn: () => req("/api/x", { method: "POST" }), meta: { failTitle: TITLE } });
|
|
expect(reportError).toHaveBeenCalled();
|
|
expect(notifyMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|