From 6214dd7585563ae1ac480dd49ee24b88d5298bab Mon Sep 17 00:00:00 2001 From: daocuong11 Date: Sat, 28 Nov 2026 07:28:39 +0700 Subject: [PATCH 1/3] fix(core): stop the profile test failing on a chance hex match (#146) Signed-off-by: daocuong11 --- packages/core/test/profile.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/test/profile.test.ts b/packages/core/test/profile.test.ts index 302de98..d7bc770 100644 --- a/packages/core/test/profile.test.ts +++ b/packages/core/test/profile.test.ts @@ -76,7 +76,9 @@ describe("profile values (US-FORM-03)", () => { test("a sealed value opens only with its key and for its own kind", async () => { const key = webcrypto.getRandomValues(new Uint8Array(32)); const sealed = await sealProfileValue(cipher, key, "id_number", "1-2345-6789"); - expect(sealed).not.toContain("2345"); + // The sealed value is hex: check the decoded bytes, not the hex text. + const sealedBytes = Buffer.from(sealed, "hex"); + expect(sealedBytes.includes(Buffer.from("1-2345-6789", "utf8"))).toBe(false); expect(await openProfileValue(cipher, key, "id_number", sealed)).toBe("1-2345-6789"); await expect(openProfileValue(cipher, key, "passport_number", sealed)).rejects.toThrow(); await expect(openProfileValue(cipher, new Uint8Array(32), "id_number", sealed)).rejects.toThrow(); From c4f0f2f7cb5c2f0d0591250398347edb72410fcb Mon Sep 17 00:00:00 2001 From: MugunthPerumal Date: Sat, 28 Nov 2026 22:41:06 +0530 Subject: [PATCH 2/3] test(mobile): scan nested route folders in a11y-scan --- apps/mobile/src/a11y-scan.test.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/mobile/src/a11y-scan.test.ts b/apps/mobile/src/a11y-scan.test.ts index 941d661..fe76127 100644 --- a/apps/mobile/src/a11y-scan.test.ts +++ b/apps/mobile/src/a11y-scan.test.ts @@ -5,11 +5,25 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import { readdirSync, readFileSync } from "node:fs"; import { join } from "node:path"; +import { fileURLToPath } from "node:url"; import { contrast, stripComments, unlabelledControls } from "./a11y-scan.ts"; import { palettes } from "./theme.ts"; -const SRC = new URL(".", import.meta.url).pathname; -const files = ["app", "components"].flatMap((dir) => readdirSync(join(SRC, dir)).filter((f) => f.endsWith(".tsx")).map((f) => join(dir, f))).concat(["app-lock.tsx"]); +const SRC = fileURLToPath(new URL(".", import.meta.url)); +const files = [ + ...["app", "components"].flatMap((dir) => + readdirSync(join(SRC, dir), { recursive: true }) + .map(String) + .filter((f) => f.endsWith(".tsx")) + .map((f) => join(dir, f)) + ), + ...readdirSync(SRC).filter((f) => f.endsWith(".tsx")), +]; + +test("the scanner walks nested route folders and top-level screens", () => { + assert.ok(files.includes(join("app", "oauth", "mcp.tsx"))); + assert.ok(files.includes("app-lock.tsx")); +}); test("the scanner flags a Pressable without a role or a label", () => { const src = ` go("/x")} style={s}>\n{t("a.b")}`; From 10c5ff3e6106f289b67f332cf261ef530e2d08bc Mon Sep 17 00:00:00 2001 From: MugunthPerumal Date: Sat, 28 Nov 2026 22:41:13 +0530 Subject: [PATCH 3/3] test(mobile): verify literal copy keys exist in both locales --- apps/mobile/src/copy-keys.test.ts | 60 +++++++++++++++++++++++++++++++ apps/mobile/src/copy-keys.ts | 16 +++++++++ 2 files changed, 76 insertions(+) create mode 100644 apps/mobile/src/copy-keys.test.ts create mode 100644 apps/mobile/src/copy-keys.ts diff --git a/apps/mobile/src/copy-keys.test.ts b/apps/mobile/src/copy-keys.test.ts new file mode 100644 index 0000000..45d5985 --- /dev/null +++ b/apps/mobile/src/copy-keys.test.ts @@ -0,0 +1,60 @@ +/// +// CT-10: every literal copy key named in apps/mobile/src and packages/*/src exists in both locales. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { readdirSync, readFileSync } from "node:fs"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { extractCopyKeys } from "./copy-keys.ts"; + +const SRC = fileURLToPath(new URL(".", import.meta.url)); +const ROOT = fileURLToPath(new URL("../../..", import.meta.url)); + +const loadLocale = (name: string): Record => + JSON.parse(readFileSync(join(ROOT, "packages", "copy", "locales", `${name}.json`), "utf8")) as Record; + +function collectSourceFiles(dir: string, labelPrefix: string): Array<{ label: string; fullPath: string }> { + return readdirSync(dir, { recursive: true }) + .map(String) + .filter((f) => /\.(ts|tsx)$/.test(f) && !/\.test\.(ts|tsx)$/.test(f)) + .map((f) => ({ label: join(labelPrefix, f), fullPath: join(dir, f) })); +} + +test("extractCopyKeys finds literal keys and skips templates and non-keys", () => { + const src = [ + `const a = t("HM-SET-01.title");`, + `const b = t('common.ok');`, + "const c = `HM-APPR-01.approve`;", + "const dyn = `HM-SET-10.failed.${reason}`;", + `const other = "not a copy key";`, + `const partial = "HM-SET-10";`, + ].join("\n"); + assert.deepEqual(extractCopyKeys(src), ["HM-SET-01.title", "common.ok", "HM-APPR-01.approve"]); +}); + +test("CT-10: every literal copy key in code exists in both en and es-419 locales", () => { + const locales: Array<[string, Record]> = [ + ["en", loadLocale("en")], + ["es-419", loadLocale("es-419")], + ]; + const packagesDir = join(ROOT, "packages"); + const pkgFiles = readdirSync(packagesDir).flatMap((pkg) => { + const srcDir = join(packagesDir, pkg, "src"); + try { + return collectSourceFiles(srcDir, join("packages", pkg, "src")); + } catch { + return []; + } + }); + const allFiles = [...collectSourceFiles(SRC, join("apps", "mobile", "src")), ...pkgFiles]; + const missing: string[] = []; + for (const { label, fullPath } of allFiles) { + const text = readFileSync(fullPath, "utf8"); + for (const key of extractCopyKeys(text)) { + for (const [localeName, dict] of locales) { + if (!Object.hasOwn(dict, key)) missing.push(`${label}: missing ${key} in ${localeName}`); + } + } + } + assert.deepEqual(missing, []); +}); diff --git a/apps/mobile/src/copy-keys.ts b/apps/mobile/src/copy-keys.ts new file mode 100644 index 0000000..fc32e8d --- /dev/null +++ b/apps/mobile/src/copy-keys.ts @@ -0,0 +1,16 @@ +// CT-10: pure source scan for copy keys written as whole string literals. +import { KEY_PATTERN } from "@hermit/copy"; + +const LITERAL_RE = /"([^"\\\n]*)"|'([^'\\\n]*)'|`([^`\\\n]*)`/g; + +/** Returns every copy key written as a whole string literal ("...", '...', or `...` without `${`). */ +export function extractCopyKeys(source: string): string[] { + const keys: string[] = []; + for (const match of source.matchAll(LITERAL_RE)) { + const template = match[3]; + if (template !== undefined && template.includes("${")) continue; + const value = match[1] ?? match[2] ?? template ?? ""; + if (KEY_PATTERN.test(value)) keys.push(value); + } + return keys; +}