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.
84 lines
3.2 KiB
TypeScript
84 lines
3.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// The two shared channel write flows report their own failures, with the real error.
|
|
// Before: the channel detail page's tag toggle and both pages' priority stepper only refetched, so a
|
|
// refused write just snapped back; and the manager reported a failed tag toggle by handing the
|
|
// CHANNEL ID to the reporter as though it were the error.
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { ReactNode } from "react";
|
|
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
|
vi.mock("./notifications", () => ({ notify: vi.fn(() => 0) }));
|
|
|
|
import { api, HttpError } from "./api";
|
|
import { notify } from "./notifications";
|
|
import { useChannelTagActions } from "./useChannelTagActions";
|
|
import { useChannelPriority } from "./useChannelPriority";
|
|
import i18n from "../i18n";
|
|
|
|
const notifyMock = vi.mocked(notify);
|
|
beforeEach(() => notifyMock.mockClear());
|
|
afterEach(() => vi.restoreAllMocks());
|
|
|
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
<QueryClientProvider client={new QueryClient()}>{children}</QueryClientProvider>
|
|
);
|
|
|
|
describe("useChannelTagActions", () => {
|
|
it("names a refused tag toggle with its real reason, then lets the caller revert", async () => {
|
|
vi.spyOn(api, "attachChannelTag").mockRejectedValue(new HttpError(403, "nope"));
|
|
const onError = vi.fn();
|
|
const { result } = renderHook(
|
|
() => useChannelTagActions({ optimisticToggle: () => {}, onError }),
|
|
{ wrapper },
|
|
);
|
|
act(() => result.current.toggleTag("UC1", 7, false));
|
|
await waitFor(() => expect(onError).toHaveBeenCalledWith("UC1"));
|
|
expect(notifyMock).toHaveBeenCalledWith({
|
|
level: "error",
|
|
title: i18n.t("channels.tags.updateFailed"),
|
|
message: i18n.t("errors.reason.forbidden"),
|
|
});
|
|
});
|
|
|
|
it("names a refused create-and-attach", async () => {
|
|
vi.spyOn(api, "createTag").mockRejectedValue(new HttpError(429, "slow"));
|
|
const { result } = renderHook(
|
|
() => useChannelTagActions({ optimisticToggle: () => {}, onError: () => {} }),
|
|
{ wrapper },
|
|
);
|
|
act(() => result.current.createAndAttachTag("UC1", "Music"));
|
|
await waitFor(() =>
|
|
expect(notifyMock).toHaveBeenCalledWith({
|
|
level: "error",
|
|
title: i18n.t("channels.tags.createFailed"),
|
|
message: i18n.t("errors.reason.rateLimited"),
|
|
}),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("useChannelPriority", () => {
|
|
it("names a refused priority save, then lets the caller revert", async () => {
|
|
vi.spyOn(api, "updateChannel").mockRejectedValue(new TypeError("Failed to fetch"));
|
|
const onError = vi.fn();
|
|
let priority = 1;
|
|
const { result } = renderHook(() =>
|
|
useChannelPriority({
|
|
read: () => priority,
|
|
optimistic: (_id, next) => void (priority = next),
|
|
onError,
|
|
delay: 0,
|
|
}),
|
|
);
|
|
act(() => result.current.bumpPriority("UC1", 1));
|
|
await waitFor(() => expect(onError).toHaveBeenCalledWith("UC1"));
|
|
expect(notifyMock).toHaveBeenCalledWith({
|
|
level: "error",
|
|
title: i18n.t("errors.writeFailed.channelPriority"),
|
|
message: i18n.t("errors.reason.unreachable"),
|
|
});
|
|
});
|
|
});
|