/* Source files must stay text. TaskHost.tsx carried a literal NUL byte, used as a delimiter in a drag-and-drop payload. It worked at runtime, and it made the file binary to git, grep and diff -- every search for that component's markup came back empty, including the one meant to find an accessibility defect in it. Written as the escape \\u0000 it behaves identically and stays text. */ import { describe, it, expect } from "vitest"; import { readdirSync, readFileSync, statSync } from "node:fs"; import { join } from "node:path"; const ROOTS = ["app/src", "server/src", "shared", "tools", "test", "types"]; const SKIP = new Set(["node_modules", "dist", "android", ".vite"]); const TEXT = /\.(ts|tsx|mjs|js|css|json|md|html|yml|yaml|sql)$/; function walk(dir: string, out: string[] = []): string[] { for (const e of readdirSync(dir)) { if (SKIP.has(e)) continue; const full = join(dir, e); if (statSync(full).isDirectory()) walk(full, out); else if (TEXT.test(e)) out.push(full); } return out; } describe("source hygiene", () => { const files = ROOTS.flatMap((r) => walk(r)); it("scans a meaningful number of files", () => { expect(files.length).toBeGreaterThan(50); }); it("has no control bytes that would make a file binary to git and grep", () => { const offenders: string[] = []; for (const f of files) { const buf = readFileSync(f); for (let i = 0; i < buf.length; i++) { const b = buf[i]!; // Everything below 0x20 except tab, LF and CR. if (b < 0x20 && b !== 0x09 && b !== 0x0a && b !== 0x0d) { const line = buf.subarray(0, i).toString("utf8").split("\n").length; offenders.push(`${f}:${line} -- byte 0x${b.toString(16).padStart(2, "0")}`); break; } } } expect(offenders).toEqual([]); }); });