import { readdirSync, readFileSync, statSync } from "node:fs"; import path from "node:path"; import { describe, expect, it } from "vitest"; // RULE (owner, 22 Nov 2026): Words writes in the person's ink, blue by default; red is one ink among others. Every // colour a Words screen draws comes from the core's themes (kits/notes/writing.json), so no screen on either phone // names the old red, or any paper's red, itself: a hard-coded red would stay red in a blue ink. const ROOT = path.resolve(__dirname, "../.."); const WORDS_SOURCES = [ "apps/android/app/src/notes", "apps/android/writing/src/main", "apps/cotton/Sources/CottonUI/Notes", ]; function files(dir: string): string[] { return readdirSync(dir).flatMap((name) => { const full = path.join(dir, name); return statSync(full).isDirectory() ? files(full) : /\.(kt|swift)$/.test(name) ? [full] : []; }); } describe("Words' ink", () => { const writing = JSON.parse(readFileSync(path.join(ROOT, "crates/cotton-core/kits/notes/writing.json"), "utf8")); // Every paper's red, light and dark (its `danger`, which was its accent), and the red ink's own values. const reds = new Set(); for (const theme of writing.themes) for (const look of [theme.light, theme.dark]) reds.add(look.danger.slice(1).toUpperCase()); for (const ink of writing.inks.filter((i: { id: string }) => i.id === "red")) { reds.add(ink.light.accent.slice(1).toUpperCase()); reds.add(ink.dark.accent.slice(1).toUpperCase()); } it("is blue by default, and red is still a choice", () => { expect(writing.defaults.ink).toBe("blue"); expect(writing.inks.map((i: { id: string }) => i.id)).toContain("red"); expect(reds.size).toBeGreaterThan(4); }); it("no Words screen hard-codes a red", () => { const found: string[] = []; for (const dir of WORDS_SOURCES) { for (const file of files(path.join(ROOT, dir))) { const text = readFileSync(file, "utf8").toUpperCase(); for (const red of reds) if (text.includes(red)) found.push(`${path.relative(ROOT, file)}: #${red}`); } } expect(found).toEqual([]); }); });