/** * v1.4.49.3 — call-site i18n coverage guard. * * The maintainer surfaced raw `insights.relativeHoursAgo`, `notifications.event * MoodReminder`, and `notifications.eventMoodReminderDesc` strings * leaking into the UI in v1.4.49. Audit found 28 keys called from real * code that never existed in any locale bundle — silent regressions * that accumulated across v1.4.41 (notifications matrix), v1.4.44 * (measurements.loadError), and v1.4.45 (onboarding.welcome.*). * * This test walks every TypeScript / TSX file under `src/` (excluding * tests + generated code), extracts every literal `t("namespace.key")` * call, and asserts that each key resolves to a string leaf in * `messages/en.json`. JSDoc-block matches and known dynamic patterns * are filtered explicitly. * * The existing `i18n-drift-guard.test.ts` pins specific groups; this * test catches drift on every other call site. The * `i18n-locale-integrity.test.ts` test then propagates the EN guarantee * to every other locale via key-set parity. */ import { describe, it, expect } from "vitest"; import { readFileSync, readdirSync, statSync } from "node:fs"; import { join } from "node:path"; const ROOT = join(__dirname, "../.."); const SRC = join(ROOT, "src"); const EN_BUNDLE_PATH = join(ROOT, "messages/en.json"); /** * Pruned on purpose: the generated Prisma client, build output, vendored * dependencies, and the suites themselves are not the tree under audit. Note * what is NOT pruned — this walk descends into dot-prefixed directories, so * `src/app/.well-known` is inside the sweep. `fs.globSync` would drop it. */ const SKIP_DIRS = new Set(["__tests__", "node_modules", ".next", "generated"]); function walk(dir: string, out: string[] = []): string[] { for (const name of readdirSync(dir)) { if (SKIP_DIRS.has(name)) continue; const p = join(dir, name); const stat = statSync(p); if (stat.isDirectory()) { walk(p, out); } else if (name.endsWith(".ts") || name.endsWith(".tsx")) { out.push(p); } } return out; } const KEY_PATTERN = /(?) ) { cur = (cur as Record)[p]; } else { return null; } } return typeof cur === "string" ? cur : null; } describe("i18n call-site coverage", () => { it("every literal t() key has a matching leaf in messages/en.json", () => { const en = JSON.parse(readFileSync(EN_BUNDLE_PATH, "utf8")); const sites = extractKeys(); expect(sites.length).toBeGreaterThan(100); const missing: CallSite[] = []; for (const site of sites) { if (resolveLeaf(en, site.key) === null) { missing.push(site); } } if (missing.length > 0) { const report = missing .map((m) => ` ❌ ${m.key} (${m.file}:${m.line})`) .join("\n"); // v1.4.49.3 — these 28 keys were the gap that reached production. // The list below stays empty once the audit passes; future // regressions print as a structured punch list so the offender // can fix every site in one commit. throw new Error( `Found ${missing.length} t() call sites referencing keys that are missing from messages/en.json:\n${report}`, ); } }); });