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.
95 lines
4.1 KiB
TypeScript
95 lines
4.1 KiB
TypeScript
import { describe, it, expect, beforeAll } from "vitest";
|
|
|
|
// The façade guard: lib/api.ts is a spread-only façade over per-domain slice modules. These tests
|
|
// mechanise the two invariants that make that structure safe — so a future edit that reintroduces
|
|
// the interleave (a method dropped into two slices → a silent last-wins spread override) or bloats
|
|
// the barrel (a method defined inline instead of in a domain module) fails CI instead of shipping.
|
|
//
|
|
// Scope, on purpose: this covers RUNTIME method-key collisions — the only *silent* failure mode,
|
|
// since tsc does not flag overlapping spread keys. It deliberately does NOT cover exported-TYPE-name
|
|
// clashes across slices (two slices exporting the same interface name): types are erased at runtime
|
|
// so they're invisible here, and that case is already build-caught — the barrel's `export type *`
|
|
// makes the ambiguous name a downstream tsc "no exported member" error, so nothing ships. Left to
|
|
// tsc rather than re-checked by a fragile source parse.
|
|
|
|
type Slice = Record<string, unknown>;
|
|
|
|
// Names line up with the modules below; kept as a list so the wiring stays a single source.
|
|
const SLICE_MODULES = [
|
|
["accountApi", () => import("./account")],
|
|
["authApi", () => import("./auth")],
|
|
["setupApi", () => import("./setup")],
|
|
["feedApi", () => import("./feed")],
|
|
["discoverApi", () => import("./discover")],
|
|
["channelsApi", () => import("./channels")],
|
|
["syncApi", () => import("./sync")],
|
|
["playlistsApi", () => import("./playlists")],
|
|
["tagsApi", () => import("./tags")],
|
|
["notificationsApi", () => import("./notifications")],
|
|
["savedViewsApi", () => import("./savedViews")],
|
|
["quotaApi", () => import("./quota")],
|
|
["adminApi", () => import("./admin")],
|
|
["plexApi", () => import("./plex")],
|
|
["downloadsApi", () => import("./downloads")],
|
|
["diagnosticsApi", () => import("./diagnostics")],
|
|
["debugSessionsApi", () => import("./diagnostics")],
|
|
] as const;
|
|
|
|
let api: Slice;
|
|
const slices: Record<string, Slice> = {};
|
|
|
|
beforeAll(async () => {
|
|
// The runtime api graph pulls i18n at module-load, which reads localStorage/navigator. Under
|
|
// vitest's node env (no jsdom — see vitest.config.ts) stub the minimum so the import succeeds.
|
|
if (typeof globalThis.localStorage === "undefined") {
|
|
const store = new Map<string, string>();
|
|
globalThis.localStorage = {
|
|
getItem: (k: string) => store.get(k) ?? null,
|
|
setItem: (k: string, v: string) => void store.set(k, String(v)),
|
|
removeItem: (k: string) => void store.delete(k),
|
|
clear: () => store.clear(),
|
|
key: (i: number) => [...store.keys()][i] ?? null,
|
|
get length() {
|
|
return store.size;
|
|
},
|
|
} as Storage;
|
|
}
|
|
if (typeof globalThis.navigator === "undefined") {
|
|
globalThis.navigator = { language: "en" } as Navigator;
|
|
}
|
|
if (typeof globalThis.document === "undefined") {
|
|
globalThis.document = { documentElement: {} } as Document;
|
|
}
|
|
|
|
for (const [name, load] of SLICE_MODULES) {
|
|
const mod = (await load()) as Record<string, Slice>;
|
|
const slice = mod[name];
|
|
if (!slice) throw new Error(`slice module did not export ${name}`);
|
|
slices[name] = slice;
|
|
}
|
|
api = ((await import("../api")) as { api: Slice }).api;
|
|
});
|
|
|
|
describe("api façade is a collision-free spread of domain slices", () => {
|
|
it("defines no method name in more than one slice (object spread would silently drop one)", () => {
|
|
const owner = new Map<string, string>();
|
|
const collisions: string[] = [];
|
|
for (const [sliceName, slice] of Object.entries(slices)) {
|
|
for (const key of Object.keys(slice)) {
|
|
const prev = owner.get(key);
|
|
if (prev) collisions.push(`"${key}" is defined in both ${prev} and ${sliceName}`);
|
|
else owner.set(key, sliceName);
|
|
}
|
|
}
|
|
expect(collisions).toEqual([]);
|
|
});
|
|
|
|
it("exposes exactly the union of the slices — nothing added inline in the barrel, nothing lost", () => {
|
|
const union = new Set<string>();
|
|
for (const slice of Object.values(slices)) {
|
|
for (const key of Object.keys(slice)) union.add(key);
|
|
}
|
|
expect(new Set(Object.keys(api))).toEqual(union);
|
|
});
|
|
});
|