test(i18n): a 404 target the scan cannot read fails the backend-id contract

what=SOME_CONSTANT reached no locale check at all; only _common.py's own
pass-through may name the target by variable.
This commit is contained in:
2026-09-19 21:38:53 +02:00
parent 3987cd4260
commit 44a792c34f
+14 -3
View File
@@ -88,16 +88,26 @@ const DETAIL = "downloads.errors.fail.catalog.";
// What a structured 404 says is gone → `errors.notFound.<what>`: every `not_found("x")` and every
// `owned_or_404(..., what="x")` / `get_or_404(..., what="x")` under routes/, read from the sources.
const routeSources = (dir = "routes"): string[] =>
const routeFiles = (dir = "routes"): string[] =>
readdirSync(new URL(`../../../backend/app/${dir}/`, import.meta.url), {
withFileTypes: true,
}).flatMap((e) =>
e.isDirectory()
? routeSources(`${dir}/${e.name}`)
? routeFiles(`${dir}/${e.name}`)
: e.name.endsWith(".py")
? [backend(`${dir}/${e.name}`)]
? [`${dir}/${e.name}`]
: [],
);
const routeSources = (): string[] => routeFiles().map(backend);
// A target the scan cannot read — `what=SOME_CONSTANT` — is a 404 no locale is checked for (one hid
// `debug_session`). Only the helpers' own pass-through in `_common.py` may name it by variable.
const opaqueWhats = routeFiles()
.filter((f) => !f.endsWith("/_common.py"))
.flatMap((f) =>
[...backend(f).matchAll(/not_found\((?!"|\))[^)]*\)|what=(?!")\S+/g)].map(
(m) => `${f}: ${m[0]}`,
),
);
const goneWhats = [
...new Set(
routeSources().flatMap((src) =>
@@ -158,6 +168,7 @@ describe("backend ids have their names in both languages", () => {
expect(adminCodes).toEqual(expect.arrayContaining(["activate", "setpw"]));
expect(failDetails).toEqual(expect.arrayContaining(["facebook.login_wall"]));
expect(goneWhats).toEqual(expect.arrayContaining(["playlist", "download", "job"]));
expect(opaqueWhats).toEqual([]);
expect(youtubeReasons).toEqual(["quota", "reconnect", "unavailable"]);
expect(refusedReasons).toEqual(
expect.arrayContaining(["weak_password", "setting_too_low", "plex_write_failed"]),