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:
@@ -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
|
// 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.
|
// `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), {
|
readdirSync(new URL(`../../../backend/app/${dir}/`, import.meta.url), {
|
||||||
withFileTypes: true,
|
withFileTypes: true,
|
||||||
}).flatMap((e) =>
|
}).flatMap((e) =>
|
||||||
e.isDirectory()
|
e.isDirectory()
|
||||||
? routeSources(`${dir}/${e.name}`)
|
? routeFiles(`${dir}/${e.name}`)
|
||||||
: e.name.endsWith(".py")
|
: 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 = [
|
const goneWhats = [
|
||||||
...new Set(
|
...new Set(
|
||||||
routeSources().flatMap((src) =>
|
routeSources().flatMap((src) =>
|
||||||
@@ -158,6 +168,7 @@ describe("backend ids have their names in both languages", () => {
|
|||||||
expect(adminCodes).toEqual(expect.arrayContaining(["activate", "setpw"]));
|
expect(adminCodes).toEqual(expect.arrayContaining(["activate", "setpw"]));
|
||||||
expect(failDetails).toEqual(expect.arrayContaining(["facebook.login_wall"]));
|
expect(failDetails).toEqual(expect.arrayContaining(["facebook.login_wall"]));
|
||||||
expect(goneWhats).toEqual(expect.arrayContaining(["playlist", "download", "job"]));
|
expect(goneWhats).toEqual(expect.arrayContaining(["playlist", "download", "job"]));
|
||||||
|
expect(opaqueWhats).toEqual([]);
|
||||||
expect(youtubeReasons).toEqual(["quota", "reconnect", "unavailable"]);
|
expect(youtubeReasons).toEqual(["quota", "reconnect", "unavailable"]);
|
||||||
expect(refusedReasons).toEqual(
|
expect(refusedReasons).toEqual(
|
||||||
expect.arrayContaining(["weak_password", "setting_too_low", "plex_write_failed"]),
|
expect.arrayContaining(["weak_password", "setting_too_low", "plex_write_failed"]),
|
||||||
|
|||||||
Reference in New Issue
Block a user