Cotton code
45 lines · 2.5 KB · TypeScriptRaw
/** * LOOM'S FACE REGISTRY IS GENERATED, AND NEVER STALE. * * `FaceRegistry.swift` and `apps/loom/faces.json` are written by * `scripts/gen-faces-registry.py` from the face files (one file per face, a * folder per app). A face file added, moved or renamed without regenerating * leaves the app drawing a kind plain with no test failing, so the generated * files are held to a fresh generation here. */import { execFileSync } from "node:child_process";import { readFileSync } from "node:fs";import { dirname, resolve } from "node:path";import { fileURLToPath } from "node:url";import { describe, expect, it } from "vitest";const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../..");describe("Loom's face registry", () => {  /// RULE: FaceRegistry.swift and apps/loom/faces.json are what scripts/gen-faces-registry.py writes from the face files today: a face added without regenerating fails here, not on a phone.  it("is what the generator writes from the face files today", () => {    expect(() => execFileSync("python3", ["scripts/gen-faces-registry.py", "--check"], { cwd: REPO_ROOT, stdio: "pipe" })).not.toThrow();  });  it("keeps the generator's own rules (scripts/test-gen-faces-registry.py)", () => {    expect(() => execFileSync("python3", ["scripts/test-gen-faces-registry.py"], { cwd: REPO_ROOT, stdio: "pipe" })).not.toThrow();  });  it("resolves offered face titles from the kit", () => {    const registry = readFileSync(resolve(REPO_ROOT, "apps/loom/Sources/CottonFaces/Generated/FaceRegistry.swift"), "utf8");    expect(registry).toContain('ShellLines.line("cards"');    const cards = JSON.parse(readFileSync(resolve(REPO_ROOT, "crates/cotton-core/kits/shell/lines/cards.json"), "utf8"));    expect(cards.faces.titles.person_rolodex).toBe("Rolodex");    expect(cards.faces.titles.person, "the index card left with its face").toBeUndefined();  });  /// RULE: Every face in faces.json lives in its app's folder (Cotton, Sharmila, Nancy, Rigby, Shared), and no id is listed twice.  it("lists each face once, in its app's folder", () => {    const rows: { id: string; app: string; file: string }[] = JSON.parse(readFileSync(resolve(REPO_ROOT, "apps/loom/faces.json"), "utf8"));    expect(new Set(rows.map((row) => row.id)).size).toBe(rows.length);    for (const row of rows) {      expect(["Cotton", "Sharmila", "Nancy", "Rigby", "Shared"]).toContain(row.app);      expect(row.file.startsWith(`Sources/CottonFaces/${row.app}/`), row.file).toBe(true);    }  });});