/* Unit tests for compass inventory covering its documented public contract and regression-sensitive edge cases. Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only. Fixtures stay inline and minimal so each case states its own setup. RFC-1311: Compass header sweep — declares the compass suite's contract for test-file scaffold coverage. */ // @ai-invariant fixtures must not couple to kernel internals beyond the public surface under test import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { test, expect } from "vitest"; import { createCompassInventoryEntries } from "../compass-inventory.ts"; const input = { argv: [], flags: {} }; test("createCompassInventoryEntries excludes generation templates but keeps authored neighbors", async () => { const root = await mkdtemp(join(tmpdir(), "compass-inventory-")); try { // RFC-1096: template exclusion is consumer policy (bindings.compass.excludedPaths), // not a generic default — the fixture workspace must declare it. await writeFile( join(root, "forge.yaml"), `schema: forge/config@1 project: name: test-ws stack: [typescript] packageManager: pnpm paths: rfcsDir: docs/rfcs adrsDir: docs/adrs plansDir: docs/plans auditsDir: docs/audits specsDir: docs/specs skillsDir: .agents/skills bindings: schema: forge/bindings@1 commands: {} paths: {} compass: excludedPaths: - { pattern: "src/templates/**", reason: template-source } `, "utf8", ); await mkdir(join(root, "packages", "sample", "src", "templates"), { recursive: true }); await mkdir(join(root, "packages", "werkstatt", "src", "templates"), { recursive: true, }); await writeFile( join(root, "packages", "sample", "src", "templates", "route.template.ts"), "export const template = '{{ROUTE}}';\n", "utf8", ); await writeFile( join(root, "packages", "sample", "src", "index.ts"), "export const value = 1;\n", "utf8", ); await writeFile( join(root, "packages", "werkstatt", "src", "templates", "kernel.template.ts"), "export const template = '{{KERNEL}}';\n", "utf8", ); await writeFile( join(root, "packages", "werkstatt", "src", "runtime.ts"), "export const runtime = 1;\n", "utf8", ); const entries = await createCompassInventoryEntries(root, input); const template = entries.find( (entry) => entry.path === "packages/sample/src/templates/route.template.ts", ); const authored = entries.find((entry) => entry.path === "packages/sample/src/index.ts"); const osTemplate = entries.find( (entry) => entry.path === "packages/werkstatt/src/templates/kernel.template.ts", ); const osAuthored = entries.find((entry) => entry.path === "packages/werkstatt/src/runtime.ts"); expect(template?.authoringStatus).toBe("excluded"); expect(template?.requiredScaffolding).toBe("none"); expect(template?.exclusionReason).toBe("template-source"); expect(authored?.authoringStatus).toBe("authored"); expect(authored?.violations).toContain("missing MODULE_CONTRACT"); expect(osTemplate?.workspaceName).toBe("werkstatt"); expect(osTemplate?.authoringStatus).toBe("excluded"); expect(osTemplate?.exclusionReason).toBe("template-source"); expect(osAuthored?.workspaceName).toBe("werkstatt"); expect(osAuthored?.layer).toBe("source"); expect(osAuthored?.riskClass).toBe("low"); } finally { await rm(root, { recursive: true, force: true }); } });