import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { afterEach, describe, it } from "vitest"; import { boardSummaryBlock } from "../board-summary.ts"; const roots: string[] = []; const write = (root: string, relative: string, content: string) => { const target = path.join(root, relative); mkdirSync(path.dirname(target), { recursive: true }); writeFileSync(target, content); }; const project = (board: string): string => { const root = mkdtempSync(path.join(tmpdir(), "system-board-summary-")); roots.push(root); for (const file of ["SYSTEM.md", "MISSION.md", "RULES.md"]) write(root, `.system/${file}`, `# ${file}\n`); write(root, ".system/config.json", '{"prefix":"PX","schemaVersion":0}'); write(root, ".system/board.json", board); write( root, ".system/specs/PX-SPEC-SPEC0001-contract/index.md", "---\nid: PX-SPEC-SPEC0001\ntype: spec\ntitle: Contract\n---\n\n# Contract\n", ); write( root, ".system/plans/PX-PLAN-PLAN0001-build/index.md", "---\nid: PX-PLAN-PLAN0001\ntype: plan\ntitle: Build\nspec: PX-SPEC-SPEC0001\nstatus: approved\n---\n\n# Build\n", ); write( root, ".system/issues/PX-ISSUE-ISSUE001-bug/index.md", "---\nid: PX-ISSUE-ISSUE001\ntype: issue\ntitle: Bug\nspecs:\n - PX-SPEC-SPEC0001\n---\n\n# Bug\n", ); return root; }; afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }); }); describe("board summary block", () => { it("counts tracked items and lists unfinished work with provenance", () => { const now = Date.parse("2026-03-22T12:00:00.000Z"); const root = project( JSON.stringify({ schemaVersion: 0, items: { "PX-PLAN-PLAN0001": { state: "done", updatedAt: "2026-03-20T12:00:00.000Z", source: "agent", note: "exec verified", }, }, }), ); const block = boardSummaryBlock(root, now) ?? ""; assert.match(block, /# The System board state/); assert.match( block, /specs 1 todo, 0 done\. plans 0 todo, 1 done\. issues 1 open, 0 done\./, ); assert.match(block, /- PX-SPEC-SPEC0001 · Contract · todo · default/); assert.match(block, /- PX-ISSUE-ISSUE001 · Bug · open · default/); assert.doesNotMatch(block, /PX-PLAN-PLAN0001/); }); it("shows entry source, age, and note for unfinished items", () => { const now = Date.parse("2026-03-22T12:00:00.000Z"); const root = project( JSON.stringify({ schemaVersion: 0, items: { "PX-SPEC-SPEC0001": { state: "todo", updatedAt: "2026-03-21T12:00:00.000Z", source: "agent", note: "slice one only", }, }, }), ); assert.match( boardSummaryBlock(root, now) ?? "", /- PX-SPEC-SPEC0001 · Contract · todo · agent 1 day ago · slice one only/, ); }); it("stays silent when the board is unreadable", () => { const root = project('{"schemaVersion":9,"items":{}}'); assert.equal(boardSummaryBlock(root), undefined); rmSync(path.join(root, ".system/board.json")); assert.equal(boardSummaryBlock(root), undefined); }); });