daftari 3.6.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +4 -0
  3. package/dist/access/rbac.d.ts +1 -0
  4. package/dist/access/rbac.d.ts.map +1 -1
  5. package/dist/access/rbac.js +8 -0
  6. package/dist/access/rbac.js.map +1 -1
  7. package/dist/attest/bundle.d.ts +53 -0
  8. package/dist/attest/bundle.d.ts.map +1 -0
  9. package/dist/attest/bundle.js +141 -0
  10. package/dist/attest/bundle.js.map +1 -0
  11. package/dist/attest/index.d.ts +2 -0
  12. package/dist/attest/index.d.ts.map +1 -0
  13. package/dist/attest/index.js +139 -0
  14. package/dist/attest/index.js.map +1 -0
  15. package/dist/attest/sign.d.ts +16 -0
  16. package/dist/attest/sign.d.ts.map +1 -0
  17. package/dist/attest/sign.js +75 -0
  18. package/dist/attest/sign.js.map +1 -0
  19. package/dist/attest/verify.d.ts +21 -0
  20. package/dist/attest/verify.d.ts.map +1 -0
  21. package/dist/attest/verify.js +148 -0
  22. package/dist/attest/verify.js.map +1 -0
  23. package/dist/board/board.d.ts +37 -0
  24. package/dist/board/board.d.ts.map +1 -0
  25. package/dist/board/board.js +233 -0
  26. package/dist/board/board.js.map +1 -0
  27. package/dist/board/board.test.d.ts +2 -0
  28. package/dist/board/board.test.d.ts.map +1 -0
  29. package/dist/board/board.test.js +753 -0
  30. package/dist/board/board.test.js.map +1 -0
  31. package/dist/board/dormancy.test.d.ts +2 -0
  32. package/dist/board/dormancy.test.d.ts.map +1 -0
  33. package/dist/board/dormancy.test.js +79 -0
  34. package/dist/board/dormancy.test.js.map +1 -0
  35. package/dist/board/identity.d.ts +5 -0
  36. package/dist/board/identity.d.ts.map +1 -0
  37. package/dist/board/identity.js +146 -0
  38. package/dist/board/identity.js.map +1 -0
  39. package/dist/board/identity.test.d.ts +2 -0
  40. package/dist/board/identity.test.d.ts.map +1 -0
  41. package/dist/board/identity.test.js +291 -0
  42. package/dist/board/identity.test.js.map +1 -0
  43. package/dist/board/ledger.d.ts +41 -0
  44. package/dist/board/ledger.d.ts.map +1 -0
  45. package/dist/board/ledger.js +197 -0
  46. package/dist/board/ledger.js.map +1 -0
  47. package/dist/board/ledger.test.d.ts +2 -0
  48. package/dist/board/ledger.test.d.ts.map +1 -0
  49. package/dist/board/ledger.test.js +873 -0
  50. package/dist/board/ledger.test.js.map +1 -0
  51. package/dist/board/principals.d.ts +4 -0
  52. package/dist/board/principals.d.ts.map +1 -0
  53. package/dist/board/principals.js +37 -0
  54. package/dist/board/principals.js.map +1 -0
  55. package/dist/board/principals.test.d.ts +2 -0
  56. package/dist/board/principals.test.d.ts.map +1 -0
  57. package/dist/board/principals.test.js +296 -0
  58. package/dist/board/principals.test.js.map +1 -0
  59. package/dist/board/reconcile.d.ts +12 -0
  60. package/dist/board/reconcile.d.ts.map +1 -0
  61. package/dist/board/reconcile.js +293 -0
  62. package/dist/board/reconcile.js.map +1 -0
  63. package/dist/board/reconcile.test.d.ts +2 -0
  64. package/dist/board/reconcile.test.d.ts.map +1 -0
  65. package/dist/board/reconcile.test.js +788 -0
  66. package/dist/board/reconcile.test.js.map +1 -0
  67. package/dist/board/sources/index.d.ts +24 -0
  68. package/dist/board/sources/index.d.ts.map +1 -0
  69. package/dist/board/sources/index.js +64 -0
  70. package/dist/board/sources/index.js.map +1 -0
  71. package/dist/board/sources/lint.d.ts +3 -0
  72. package/dist/board/sources/lint.d.ts.map +1 -0
  73. package/dist/board/sources/lint.js +218 -0
  74. package/dist/board/sources/lint.js.map +1 -0
  75. package/dist/board/sources/lint.test.d.ts +2 -0
  76. package/dist/board/sources/lint.test.d.ts.map +1 -0
  77. package/dist/board/sources/lint.test.js +616 -0
  78. package/dist/board/sources/lint.test.js.map +1 -0
  79. package/dist/board/sources/staged.d.ts +3 -0
  80. package/dist/board/sources/staged.d.ts.map +1 -0
  81. package/dist/board/sources/staged.js +116 -0
  82. package/dist/board/sources/staged.js.map +1 -0
  83. package/dist/board/sources/staged.test.d.ts +2 -0
  84. package/dist/board/sources/staged.test.d.ts.map +1 -0
  85. package/dist/board/sources/staged.test.js +418 -0
  86. package/dist/board/sources/staged.test.js.map +1 -0
  87. package/dist/board/sources/staleness.d.ts +43 -0
  88. package/dist/board/sources/staleness.d.ts.map +1 -0
  89. package/dist/board/sources/staleness.js +346 -0
  90. package/dist/board/sources/staleness.js.map +1 -0
  91. package/dist/board/sources/staleness.test.d.ts +2 -0
  92. package/dist/board/sources/staleness.test.d.ts.map +1 -0
  93. package/dist/board/sources/staleness.test.js +923 -0
  94. package/dist/board/sources/staleness.test.js.map +1 -0
  95. package/dist/board/sources/tension.d.ts +3 -0
  96. package/dist/board/sources/tension.d.ts.map +1 -0
  97. package/dist/board/sources/tension.js +152 -0
  98. package/dist/board/sources/tension.js.map +1 -0
  99. package/dist/board/sources/tension.test.d.ts +2 -0
  100. package/dist/board/sources/tension.test.d.ts.map +1 -0
  101. package/dist/board/sources/tension.test.js +440 -0
  102. package/dist/board/sources/tension.test.js.map +1 -0
  103. package/dist/board/sources/tier2.d.ts +17 -0
  104. package/dist/board/sources/tier2.d.ts.map +1 -0
  105. package/dist/board/sources/tier2.js +233 -0
  106. package/dist/board/sources/tier2.js.map +1 -0
  107. package/dist/board/sources/tier2.test.d.ts +2 -0
  108. package/dist/board/sources/tier2.test.d.ts.map +1 -0
  109. package/dist/board/sources/tier2.test.js +480 -0
  110. package/dist/board/sources/tier2.test.js.map +1 -0
  111. package/dist/board/types.d.ts +161 -0
  112. package/dist/board/types.d.ts.map +1 -0
  113. package/dist/board/types.js +37 -0
  114. package/dist/board/types.js.map +1 -0
  115. package/dist/canon/index.d.ts +3 -1
  116. package/dist/canon/index.d.ts.map +1 -1
  117. package/dist/canon/index.js +35 -8
  118. package/dist/canon/index.js.map +1 -1
  119. package/dist/canon/types.d.ts +3 -0
  120. package/dist/canon/types.d.ts.map +1 -1
  121. package/dist/cli.d.ts.map +1 -1
  122. package/dist/cli.js +15 -0
  123. package/dist/cli.js.map +1 -1
  124. package/dist/consolidate/birth.d.ts +1 -1
  125. package/dist/consolidate/birth.d.ts.map +1 -1
  126. package/dist/consolidate/birth.js +22 -0
  127. package/dist/consolidate/birth.js.map +1 -1
  128. package/dist/consolidate/edge-write.d.ts +11 -0
  129. package/dist/consolidate/edge-write.d.ts.map +1 -1
  130. package/dist/consolidate/edge-write.js +41 -0
  131. package/dist/consolidate/edge-write.js.map +1 -1
  132. package/dist/consolidate/index.js +5 -2
  133. package/dist/consolidate/index.js.map +1 -1
  134. package/dist/consolidate/revision.d.ts +4 -2
  135. package/dist/consolidate/revision.d.ts.map +1 -1
  136. package/dist/consolidate/revision.js +23 -0
  137. package/dist/consolidate/revision.js.map +1 -1
  138. package/dist/curation/edge-staleness.d.ts +4 -2
  139. package/dist/curation/edge-staleness.d.ts.map +1 -1
  140. package/dist/curation/edge-staleness.js +36 -3
  141. package/dist/curation/edge-staleness.js.map +1 -1
  142. package/dist/curation/edges.d.ts +7 -0
  143. package/dist/curation/edges.d.ts.map +1 -1
  144. package/dist/curation/edges.js +13 -7
  145. package/dist/curation/edges.js.map +1 -1
  146. package/dist/curation/staged-actions.d.ts +2 -0
  147. package/dist/curation/staged-actions.d.ts.map +1 -1
  148. package/dist/curation/staged-actions.js +5 -0
  149. package/dist/curation/staged-actions.js.map +1 -1
  150. package/dist/curation/tension-access.d.ts +1 -0
  151. package/dist/curation/tension-access.d.ts.map +1 -1
  152. package/dist/curation/tension-access.js +18 -1
  153. package/dist/curation/tension-access.js.map +1 -1
  154. package/dist/curation/tension.d.ts +3 -0
  155. package/dist/curation/tension.d.ts.map +1 -1
  156. package/dist/curation/tension.js +36 -0
  157. package/dist/curation/tension.js.map +1 -1
  158. package/dist/curation/vault-docs.d.ts +1 -0
  159. package/dist/curation/vault-docs.d.ts.map +1 -1
  160. package/dist/curation/vault-docs.js +1 -0
  161. package/dist/curation/vault-docs.js.map +1 -1
  162. package/dist/distill/adapters/claude-session.d.ts +6 -0
  163. package/dist/distill/adapters/claude-session.d.ts.map +1 -0
  164. package/dist/distill/adapters/claude-session.js +71 -0
  165. package/dist/distill/adapters/claude-session.js.map +1 -0
  166. package/dist/distill/cli.d.ts.map +1 -1
  167. package/dist/distill/cli.js +119 -9
  168. package/dist/distill/cli.js.map +1 -1
  169. package/dist/distill/cost.d.ts +6 -0
  170. package/dist/distill/cost.d.ts.map +1 -1
  171. package/dist/distill/cost.js +2 -3
  172. package/dist/distill/cost.js.map +1 -1
  173. package/dist/distill/extract.d.ts +52 -0
  174. package/dist/distill/extract.d.ts.map +1 -1
  175. package/dist/distill/extract.js +24 -2
  176. package/dist/distill/extract.js.map +1 -1
  177. package/dist/distill/index.d.ts +1 -0
  178. package/dist/distill/index.d.ts.map +1 -1
  179. package/dist/distill/index.js +3 -0
  180. package/dist/distill/index.js.map +1 -1
  181. package/dist/distill/propose.d.ts +67 -6
  182. package/dist/distill/propose.d.ts.map +1 -1
  183. package/dist/distill/propose.js +142 -32
  184. package/dist/distill/propose.js.map +1 -1
  185. package/dist/distill/reader-fingerprint.d.ts +69 -0
  186. package/dist/distill/reader-fingerprint.d.ts.map +1 -0
  187. package/dist/distill/reader-fingerprint.js +145 -0
  188. package/dist/distill/reader-fingerprint.js.map +1 -0
  189. package/dist/distill/receipt-store.d.ts +5 -0
  190. package/dist/distill/receipt-store.d.ts.map +1 -0
  191. package/dist/distill/receipt-store.js +24 -0
  192. package/dist/distill/receipt-store.js.map +1 -0
  193. package/dist/eval/llm-openrouter.d.ts.map +1 -1
  194. package/dist/eval/llm-openrouter.js +4 -0
  195. package/dist/eval/llm-openrouter.js.map +1 -1
  196. package/dist/eval/llm.d.ts +22 -0
  197. package/dist/eval/llm.d.ts.map +1 -1
  198. package/dist/eval/llm.js +94 -24
  199. package/dist/eval/llm.js.map +1 -1
  200. package/dist/federation/classification.d.ts.map +1 -1
  201. package/dist/federation/classification.js +3 -0
  202. package/dist/federation/classification.js.map +1 -1
  203. package/dist/index.d.ts.map +1 -1
  204. package/dist/index.js +31 -0
  205. package/dist/index.js.map +1 -1
  206. package/dist/search/coverage.d.ts +5 -1
  207. package/dist/search/coverage.d.ts.map +1 -1
  208. package/dist/search/coverage.js +47 -15
  209. package/dist/search/coverage.js.map +1 -1
  210. package/dist/search/hybrid.d.ts +7 -1
  211. package/dist/search/hybrid.d.ts.map +1 -1
  212. package/dist/search/hybrid.js +31 -8
  213. package/dist/search/hybrid.js.map +1 -1
  214. package/dist/search/retrieval-metrics.d.ts +5 -0
  215. package/dist/search/retrieval-metrics.d.ts.map +1 -0
  216. package/dist/search/retrieval-metrics.js +60 -0
  217. package/dist/search/retrieval-metrics.js.map +1 -0
  218. package/dist/search/suppression.d.ts +9 -0
  219. package/dist/search/suppression.d.ts.map +1 -0
  220. package/dist/search/suppression.js +107 -0
  221. package/dist/search/suppression.js.map +1 -0
  222. package/dist/serve/index.d.ts.map +1 -1
  223. package/dist/serve/index.js +286 -4
  224. package/dist/serve/index.js.map +1 -1
  225. package/dist/server.d.ts.map +1 -1
  226. package/dist/server.js +4 -6
  227. package/dist/server.js.map +1 -1
  228. package/dist/storage/index-db.d.ts +1 -0
  229. package/dist/storage/index-db.d.ts.map +1 -1
  230. package/dist/storage/index-db.js.map +1 -1
  231. package/dist/tools/board.d.ts +32 -0
  232. package/dist/tools/board.d.ts.map +1 -0
  233. package/dist/tools/board.js +615 -0
  234. package/dist/tools/board.js.map +1 -0
  235. package/dist/tools/board.test.d.ts +2 -0
  236. package/dist/tools/board.test.d.ts.map +1 -0
  237. package/dist/tools/board.test.js +964 -0
  238. package/dist/tools/board.test.js.map +1 -0
  239. package/dist/tools/edge-staleness.d.ts.map +1 -1
  240. package/dist/tools/edge-staleness.js +18 -4
  241. package/dist/tools/edge-staleness.js.map +1 -1
  242. package/dist/tools/positions.d.ts.map +1 -1
  243. package/dist/tools/positions.js +6 -0
  244. package/dist/tools/positions.js.map +1 -1
  245. package/dist/tools/read.d.ts +2 -0
  246. package/dist/tools/read.d.ts.map +1 -1
  247. package/dist/tools/read.js +43 -13
  248. package/dist/tools/read.js.map +1 -1
  249. package/dist/tools/receipt.d.ts +6 -0
  250. package/dist/tools/receipt.d.ts.map +1 -1
  251. package/dist/tools/receipt.js +47 -1
  252. package/dist/tools/receipt.js.map +1 -1
  253. package/dist/tools/search.d.ts.map +1 -1
  254. package/dist/tools/search.js +79 -17
  255. package/dist/tools/search.js.map +1 -1
  256. package/dist/tools/staged-actions.d.ts.map +1 -1
  257. package/dist/tools/staged-actions.js +26 -2
  258. package/dist/tools/staged-actions.js.map +1 -1
  259. package/dist/tools/write.d.ts +1 -0
  260. package/dist/tools/write.d.ts.map +1 -1
  261. package/dist/tools/write.js +475 -227
  262. package/dist/tools/write.js.map +1 -1
  263. package/dist/utils/config.d.ts +21 -0
  264. package/dist/utils/config.d.ts.map +1 -1
  265. package/dist/utils/config.js +104 -1
  266. package/dist/utils/config.js.map +1 -1
  267. package/dist/utils/git.d.ts +18 -2
  268. package/dist/utils/git.d.ts.map +1 -1
  269. package/dist/utils/git.js +116 -13
  270. package/dist/utils/git.js.map +1 -1
  271. package/dist/version.d.ts +2 -0
  272. package/dist/version.d.ts.map +1 -0
  273. package/dist/version.js +8 -0
  274. package/dist/version.js.map +1 -0
  275. package/dist/view/board-page.d.ts +4 -0
  276. package/dist/view/board-page.d.ts.map +1 -0
  277. package/dist/view/board-page.js +278 -0
  278. package/dist/view/board-page.js.map +1 -0
  279. package/dist/view/board-page.test.d.ts +2 -0
  280. package/dist/view/board-page.test.d.ts.map +1 -0
  281. package/dist/view/board-page.test.js +548 -0
  282. package/dist/view/board-page.test.js.map +1 -0
  283. package/dist/view/pages.d.ts.map +1 -1
  284. package/dist/view/pages.js +13 -2
  285. package/dist/view/pages.js.map +1 -1
  286. package/dist/view/render.d.ts.map +1 -1
  287. package/dist/view/render.js +2 -1
  288. package/dist/view/render.js.map +1 -1
  289. package/package.json +2 -2
@@ -0,0 +1,753 @@
1
+ // board.test.ts — TDD test suite for U9: board engine (listBoard).
2
+ //
3
+ // Uses real temp vaults seeded with multiple source types:
4
+ // lint — orphan doc (notes/orphan-doc.md)
5
+ // staleness — expired-TTL doc (notes/expired-doc.md)
6
+ // staged — pending staged action against notes/orphan-doc.md
7
+ // tension — unresolved tension between notes/doc-a.md and notes/doc-b.md
8
+ //
9
+ // Tests cover:
10
+ // 1. Mixed-source vault → all findings surface, correct columns.
11
+ // 2. Role RBAC: scoped role (notes-only) vs admin; hidden collection yields
12
+ // zero cards without changing admin totals (R18).
13
+ // 3. Unused board → no ledger writes (R7).
14
+ // 4. Reopen idempotency: resolved finding reappears → exactly ONE reopened
15
+ // event appended; second listBoard call → no duplicate (R6).
16
+ // 5. Filter by collection / check / certainty / owner / age / document (R26).
17
+ //
18
+ // Run with:
19
+ // npx vitest run src/board/board.test.ts
20
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
21
+ import { tmpdir } from "node:os";
22
+ import { join } from "node:path";
23
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
24
+ import { renderBoardPage } from "../view/board-page.js";
25
+ import { listBoard } from "./board.js";
26
+ import { appendEvent, boardDispositionsPath } from "./ledger.js";
27
+ // ---------------------------------------------------------------------------
28
+ // Vault fixture helpers (mirrors lint.test.ts, staleness.test.ts, etc.)
29
+ // ---------------------------------------------------------------------------
30
+ function frontmatter(overrides = {}) {
31
+ const fm = {
32
+ title: "Test Document",
33
+ domain: "accumulation",
34
+ collection: "notes",
35
+ status: "canonical",
36
+ confidence: "medium",
37
+ created: "2020-01-01",
38
+ updated: "2020-01-01",
39
+ updated_by: "agent:seed",
40
+ provenance: "direct",
41
+ sources: [],
42
+ superseded_by: null,
43
+ ttl_days: null,
44
+ ...overrides,
45
+ };
46
+ const lines = [];
47
+ for (const [k, v] of Object.entries(fm)) {
48
+ if (v === null) {
49
+ lines.push(`${k}: null`);
50
+ }
51
+ else if (Array.isArray(v)) {
52
+ if (v.length === 0) {
53
+ lines.push(`${k}: []`);
54
+ }
55
+ else {
56
+ lines.push(`${k}:`);
57
+ for (const item of v) {
58
+ lines.push(` - ${JSON.stringify(item)}`);
59
+ }
60
+ }
61
+ }
62
+ else {
63
+ lines.push(`${k}: ${JSON.stringify(v)}`);
64
+ }
65
+ }
66
+ return `---\n${lines.join("\n")}\n---\n`;
67
+ }
68
+ function writeConfig(vaultRoot, roles) {
69
+ const daftariDir = join(vaultRoot, ".daftari");
70
+ mkdirSync(daftariDir, { recursive: true });
71
+ const roleLines = Object.entries(roles)
72
+ .map(([name, cfg]) => {
73
+ const lines = [` ${name}:`];
74
+ for (const [k, v] of Object.entries(cfg)) {
75
+ if (Array.isArray(v)) {
76
+ lines.push(` ${k}: [${v.map((s) => JSON.stringify(s)).join(", ")}]`);
77
+ }
78
+ else {
79
+ lines.push(` ${k}: ${JSON.stringify(v)}`);
80
+ }
81
+ }
82
+ return lines.join("\n");
83
+ })
84
+ .join("\n");
85
+ const yaml = `version: 1\nvault_name: test-vault\nroles:\n${roleLines}\n`;
86
+ writeFileSync(join(daftariDir, "config.yaml"), yaml, "utf-8");
87
+ }
88
+ function writeDoc(vaultRoot, path, content) {
89
+ const full = join(vaultRoot, path);
90
+ const dir = join(vaultRoot, path.split("/").slice(0, -1).join("/"));
91
+ mkdirSync(dir, { recursive: true });
92
+ writeFileSync(full, content, "utf-8");
93
+ }
94
+ function writeStagedActionProposal(vaultRoot, record) {
95
+ const daftariDir = join(vaultRoot, ".daftari");
96
+ mkdirSync(daftariDir, { recursive: true });
97
+ const filePath = join(daftariDir, "staged-actions.jsonl");
98
+ let existing = "";
99
+ try {
100
+ existing = readFileSync(filePath, "utf-8");
101
+ }
102
+ catch {
103
+ existing = "";
104
+ }
105
+ writeFileSync(filePath, `${existing + JSON.stringify(record)}\n`, "utf-8");
106
+ }
107
+ function writeTension(vaultRoot, entry) {
108
+ const daftariDir = join(vaultRoot, ".daftari");
109
+ mkdirSync(daftariDir, { recursive: true });
110
+ const filePath = join(daftariDir, "tensions.md");
111
+ const lines = [`## ${entry.date} — ${entry.title}`];
112
+ if (entry.id !== undefined)
113
+ lines.push(`- **Id:** ${entry.id}`);
114
+ const kind = entry.kind ?? "factual";
115
+ if (kind !== "unspecified")
116
+ lines.push(`- **Kind:** ${kind}`);
117
+ lines.push(`- **Source A:** ${entry.sourceA} says ${entry.claimA}`);
118
+ lines.push(`- **Source B:** ${entry.sourceB} says ${entry.claimB}`);
119
+ lines.push(`- **Status:** ${entry.status ?? "unresolved"}`);
120
+ lines.push(`- **Logged by:** ${entry.loggedBy ?? "agent:test"}`);
121
+ let existing = "";
122
+ try {
123
+ existing = readFileSync(filePath, "utf-8");
124
+ }
125
+ catch {
126
+ existing = "";
127
+ }
128
+ writeFileSync(filePath, `${existing}\n${lines.join("\n")}\n`, "utf-8");
129
+ }
130
+ // ---------------------------------------------------------------------------
131
+ // Role fixtures
132
+ // ---------------------------------------------------------------------------
133
+ const adminRole = {
134
+ read: ["*"],
135
+ write: ["*"],
136
+ promote: true,
137
+ ratify: true,
138
+ };
139
+ const scopedRole = {
140
+ // can read "notes" but NOT "restricted"
141
+ read: ["notes"],
142
+ write: ["notes"],
143
+ promote: false,
144
+ ratify: false,
145
+ };
146
+ const adminAccess = {
147
+ user: "human:admin",
148
+ roleName: "admin",
149
+ role: adminRole,
150
+ };
151
+ const scopedAccess = {
152
+ user: "human:analyst",
153
+ roleName: "analyst",
154
+ role: scopedRole,
155
+ };
156
+ // ---------------------------------------------------------------------------
157
+ // Clock fixture — fixed "now" so staleness and expiry are deterministic.
158
+ // Documents updated 200 days before FIXED_NOW, ttl_days: 90 → expired.
159
+ // ---------------------------------------------------------------------------
160
+ const FIXED_NOW = new Date("2026-01-01T00:00:00Z");
161
+ const STALE_DATE = new Date(FIXED_NOW.getTime() - 200 * 86_400_000).toISOString().slice(0, 10); // "2025-06-15"
162
+ // ---------------------------------------------------------------------------
163
+ // Helpers
164
+ // ---------------------------------------------------------------------------
165
+ /** Read the raw ledger JSONL lines from a vault. Returns [] if file absent. */
166
+ function readLedgerLines(vaultRoot) {
167
+ const p = boardDispositionsPath(vaultRoot);
168
+ if (!existsSync(p))
169
+ return [];
170
+ return readFileSync(p, "utf-8")
171
+ .split("\n")
172
+ .filter((l) => l.trim().length > 0);
173
+ }
174
+ /** Count events in the ledger for a given finding_id. */
175
+ function countLedgerEventsFor(vaultRoot, findingId) {
176
+ return readLedgerLines(vaultRoot).filter((line) => {
177
+ try {
178
+ const e = JSON.parse(line);
179
+ return e.finding_id === findingId;
180
+ }
181
+ catch {
182
+ return false;
183
+ }
184
+ }).length;
185
+ }
186
+ // ---------------------------------------------------------------------------
187
+ // Shared vault seeder — seeds lint + staleness + staged + tension findings.
188
+ // Returns the seeded vaultRoot.
189
+ // ---------------------------------------------------------------------------
190
+ function seedMixedVault() {
191
+ const vaultRoot = mkdtempSync(join(tmpdir(), "daftari-board-test-"));
192
+ writeConfig(vaultRoot, {
193
+ admin: { read: ["*"], write: ["*"], promote: true, ratify: true },
194
+ analyst: { read: ["notes"], write: ["notes"] },
195
+ });
196
+ // Lint: orphan doc (no other doc links to it)
197
+ writeDoc(vaultRoot, "notes/orphan-doc.md", frontmatter({ title: "Orphan", collection: "notes", updated: "2020-01-01", ttl_days: null }) +
198
+ "# Orphan\n\nNo one links here.\n");
199
+ // Staleness: TTL-expired doc
200
+ writeDoc(vaultRoot, "notes/expired-doc.md", `${frontmatter({
201
+ title: "Expired",
202
+ collection: "notes",
203
+ updated: STALE_DATE,
204
+ ttl_days: 90,
205
+ })}# Expired\n`);
206
+ // Staged: pending action against notes/orphan-doc.md
207
+ writeStagedActionProposal(vaultRoot, {
208
+ id: "stage-001",
209
+ action_type: "promote",
210
+ target_path: "notes/orphan-doc.md",
211
+ proposed_by: "human:admin",
212
+ proposed_at: "2025-12-01T00:00:00Z",
213
+ expires_at: "2027-01-01T00:00:00Z",
214
+ status: "pending",
215
+ rationale: "promote the orphan",
216
+ proposed_diff: "",
217
+ });
218
+ // Tension: unresolved between notes/doc-a.md and notes/doc-b.md
219
+ writeTension(vaultRoot, {
220
+ id: "tension-001",
221
+ date: "2026-01-01",
222
+ title: "Doc A vs Doc B",
223
+ kind: "factual",
224
+ sourceA: "notes/doc-a.md",
225
+ claimA: "The sky is blue",
226
+ sourceB: "notes/doc-b.md",
227
+ claimB: "The sky is green",
228
+ status: "unresolved",
229
+ });
230
+ return vaultRoot;
231
+ }
232
+ // ---------------------------------------------------------------------------
233
+ // Scenario 1: Mixed vault → all findings surface, correct columns.
234
+ // ---------------------------------------------------------------------------
235
+ describe("listBoard — Scenario 1: mixed vault, all sources surface", () => {
236
+ let vaultRoot;
237
+ beforeEach(() => {
238
+ vaultRoot = seedMixedVault();
239
+ });
240
+ afterEach(() => {
241
+ rmSync(vaultRoot, { recursive: true, force: true });
242
+ });
243
+ it("returns a result with columns and all arrays", async () => {
244
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
245
+ expect(result).toHaveProperty("columns");
246
+ expect(result).toHaveProperty("all");
247
+ expect(Array.isArray(result.all)).toBe(true);
248
+ });
249
+ it("all findings start in the 'new' column (no ledger yet)", async () => {
250
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
251
+ for (const f of result.all) {
252
+ expect(f.disposition).toBe("new");
253
+ }
254
+ });
255
+ it("includes findings from at least lint, staleness, and tension sources", async () => {
256
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
257
+ const sources = new Set(result.all.map((f) => f.source));
258
+ expect(sources.has("lint")).toBe(true);
259
+ expect(sources.has("staleness")).toBe(true);
260
+ expect(sources.has("tension")).toBe(true);
261
+ });
262
+ it("includes a staged finding for stage-001", async () => {
263
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
264
+ const staged = result.all.filter((f) => f.source === "staged");
265
+ expect(staged.length).toBeGreaterThan(0);
266
+ const s = staged.find((f) => f.target.kind === "staged" && f.target.stagedActionId === "stage-001");
267
+ expect(s).toBeDefined();
268
+ });
269
+ it("includes the tension finding for tension-001", async () => {
270
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
271
+ const tensions = result.all.filter((f) => f.source === "tension");
272
+ expect(tensions.length).toBeGreaterThan(0);
273
+ const t = tensions.find((f) => f.target.kind === "tension" && f.target.tensionId === "tension-001");
274
+ expect(t).toBeDefined();
275
+ });
276
+ it("columns.new contains all findings (no dispositions)", async () => {
277
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
278
+ expect(result.columns.new.length).toBe(result.all.length);
279
+ expect(result.columns.accepted.length).toBe(0);
280
+ expect(result.columns.waiting.length).toBe(0);
281
+ expect(result.columns.resolved.length).toBe(0);
282
+ expect(result.columns.dismissed.length).toBe(0);
283
+ });
284
+ });
285
+ // ---------------------------------------------------------------------------
286
+ // Scenario 2: RBAC — scoped role sees strict subset; hidden collection yields
287
+ // zero cards (R17/R18).
288
+ // ---------------------------------------------------------------------------
289
+ describe("listBoard — Scenario 2: RBAC role fixtures", () => {
290
+ let vaultRoot;
291
+ beforeEach(() => {
292
+ // Seed notes/ + restricted/ collections.
293
+ vaultRoot = mkdtempSync(join(tmpdir(), "daftari-board-rbac-test-"));
294
+ writeConfig(vaultRoot, {
295
+ admin: { read: ["*"], write: ["*"], promote: true, ratify: true },
296
+ analyst: { read: ["notes"], write: ["notes"] },
297
+ });
298
+ // notes/ collection — visible to both roles
299
+ writeDoc(vaultRoot, "notes/orphan-doc.md", frontmatter({ title: "Orphan", collection: "notes", updated: "2020-01-01", ttl_days: null }) +
300
+ "# Orphan\n\nNo one links here.\n");
301
+ writeDoc(vaultRoot, "notes/expired-doc.md", `${frontmatter({
302
+ title: "Expired Notes",
303
+ collection: "notes",
304
+ updated: STALE_DATE,
305
+ ttl_days: 90,
306
+ })}# Expired\n`);
307
+ // restricted/ collection — hidden from scopedRole
308
+ writeDoc(vaultRoot, "restricted/secret-orphan.md", `${frontmatter({
309
+ title: "Secret Orphan",
310
+ collection: "restricted",
311
+ updated: "2020-01-01",
312
+ ttl_days: null,
313
+ })}# Secret\n\nNo one links here.\n`);
314
+ writeDoc(vaultRoot, "restricted/secret-expired.md", `${frontmatter({
315
+ title: "Secret Expired",
316
+ collection: "restricted",
317
+ updated: STALE_DATE,
318
+ ttl_days: 90,
319
+ })}# Secret Expired\n`);
320
+ });
321
+ afterEach(() => {
322
+ rmSync(vaultRoot, { recursive: true, force: true });
323
+ });
324
+ it("admin sees findings from both notes and restricted collections", async () => {
325
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
326
+ const paths = result.all
327
+ .map((f) => {
328
+ if (f.target.kind === "lint")
329
+ return f.target.path;
330
+ if (f.target.kind === "staleness")
331
+ return f.target.path;
332
+ return null;
333
+ })
334
+ .filter(Boolean);
335
+ const hasNotes = paths.some((p) => p.startsWith("notes/"));
336
+ const hasRestricted = paths.some((p) => p.startsWith("restricted/"));
337
+ expect(hasNotes).toBe(true);
338
+ expect(hasRestricted).toBe(true);
339
+ });
340
+ it("scoped role sees only notes findings (strict subset of admin)", async () => {
341
+ const adminResult = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
342
+ const scopedResult = await listBoard(vaultRoot, scopedAccess, undefined, FIXED_NOW);
343
+ // Scoped must be a strict subset
344
+ expect(scopedResult.all.length).toBeGreaterThan(0);
345
+ expect(scopedResult.all.length).toBeLessThan(adminResult.all.length);
346
+ // Scoped sees no restricted findings
347
+ for (const f of scopedResult.all) {
348
+ if (f.target.kind === "lint" || f.target.kind === "staleness") {
349
+ expect(f.target.path.startsWith("restricted/")).toBe(false);
350
+ }
351
+ }
352
+ });
353
+ it("hidden collection yields zero cards for scoped role (R18)", async () => {
354
+ const scopedResult = await listBoard(vaultRoot, scopedAccess, undefined, FIXED_NOW);
355
+ const restrictedFindings = scopedResult.all.filter((f) => {
356
+ if (f.target.kind === "lint")
357
+ return f.target.path.startsWith("restricted/");
358
+ if (f.target.kind === "staleness")
359
+ return f.target.path.startsWith("restricted/");
360
+ return false;
361
+ });
362
+ expect(restrictedFindings.length).toBe(0);
363
+ });
364
+ it("admin totals are unchanged by what scoped role can see (R18)", async () => {
365
+ const adminResult1 = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
366
+ // scoped role call does not affect admin's view
367
+ await listBoard(vaultRoot, scopedAccess, undefined, FIXED_NOW);
368
+ const adminResult2 = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
369
+ // Admin count stable (no writes to ledger since no dispositions)
370
+ expect(adminResult2.all.length).toBe(adminResult1.all.length);
371
+ });
372
+ });
373
+ // ---------------------------------------------------------------------------
374
+ // Scenario 3: Unused board → zero ledger writes (R7).
375
+ // ---------------------------------------------------------------------------
376
+ describe("listBoard — Scenario 3: unused board writes nothing (R7)", () => {
377
+ let vaultRoot;
378
+ beforeEach(() => {
379
+ vaultRoot = seedMixedVault();
380
+ });
381
+ afterEach(() => {
382
+ rmSync(vaultRoot, { recursive: true, force: true });
383
+ });
384
+ it("ledger file does not exist after listBoard when no dispositions exist", async () => {
385
+ const ledgerPath = boardDispositionsPath(vaultRoot);
386
+ expect(existsSync(ledgerPath)).toBe(false);
387
+ await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
388
+ // With no prior dispositions, reconcile emits nothing → no writes
389
+ expect(existsSync(ledgerPath)).toBe(false);
390
+ });
391
+ it("ledger file is unchanged (still absent) on second call with no dispositions", async () => {
392
+ await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
393
+ await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
394
+ expect(existsSync(boardDispositionsPath(vaultRoot))).toBe(false);
395
+ });
396
+ });
397
+ // ---------------------------------------------------------------------------
398
+ // Scenario 4: Reopen idempotency.
399
+ // - Seed a vault with one lint finding.
400
+ // - Write an "accept" ledger event for it → CASE C will emit "resolved" on
401
+ // first listBoard (finding reproduced while accepted → wait, finding NOT
402
+ // in live: that's CASE C. Actually for reopen we need: finding IS in live
403
+ // AND ledger says "resolved").
404
+ //
405
+ // Correct setup for reopen (CASE B, shouldEmitReopen):
406
+ // - Live finding is present.
407
+ // - Ledger has [accept, resolved] events for its identity_key.
408
+ // - reconcile detects latest=resolved + live present → emit reopened.
409
+ // - Call listBoard once: reopened event appended.
410
+ // - Call listBoard again: latest=reopened + live present → NO new emit.
411
+ // ---------------------------------------------------------------------------
412
+ describe("listBoard — Scenario 4: reopen idempotency (end-to-end)", () => {
413
+ let vaultRoot;
414
+ beforeEach(() => {
415
+ vaultRoot = mkdtempSync(join(tmpdir(), "daftari-board-reopen-test-"));
416
+ writeConfig(vaultRoot, {
417
+ admin: { read: ["*"], write: ["*"], promote: true, ratify: true },
418
+ });
419
+ // Lint: orphan doc that will remain in the live set
420
+ writeDoc(vaultRoot, "notes/orphan-doc.md", frontmatter({ title: "Orphan", collection: "notes", updated: "2020-01-01", ttl_days: null }) +
421
+ "# Orphan\n\nNo one links here.\n");
422
+ });
423
+ afterEach(() => {
424
+ rmSync(vaultRoot, { recursive: true, force: true });
425
+ });
426
+ it("persists exactly one 'reopened' event on first call, none on second", async () => {
427
+ // First call to get the orphan finding's identity_key
428
+ const first = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
429
+ const orphanFinding = first.all.find((f) => f.source === "lint" &&
430
+ f.target.kind === "lint" &&
431
+ f.target.path === "notes/orphan-doc.md" &&
432
+ f.check === "orphanFiles");
433
+ expect(orphanFinding).toBeDefined();
434
+ const id = orphanFinding.identity_key;
435
+ const fp = orphanFinding.fingerprint;
436
+ // Manually seed the ledger: [accept, resolved] — simulating a prior
437
+ // run where the user accepted it and then it was auto-resolved.
438
+ await appendEvent(vaultRoot, {
439
+ finding_id: id,
440
+ event: "accept",
441
+ by: "human:admin",
442
+ principal_type: "human",
443
+ at: "2025-12-01T00:00:00Z",
444
+ against_fingerprint: fp,
445
+ });
446
+ await appendEvent(vaultRoot, {
447
+ finding_id: id,
448
+ event: "resolved",
449
+ by: "system",
450
+ principal_type: "system",
451
+ at: "2025-12-10T00:00:00Z",
452
+ against_fingerprint: fp,
453
+ });
454
+ // Confirm ledger has exactly 2 events before first board call
455
+ expect(countLedgerEventsFor(vaultRoot, id)).toBe(2);
456
+ // Call listBoard: finding is live + ledger says "resolved" → reconcile
457
+ // emits "reopened" → engine persists it.
458
+ const second = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
459
+ expect(countLedgerEventsFor(vaultRoot, id)).toBe(3);
460
+ // The finding should be in the reopened state (prior human disposition was accept → "accepted")
461
+ const f2 = second.all.find((f) => f.identity_key === id);
462
+ expect(f2).toBeDefined();
463
+ expect(f2.disposition).toBe("accepted");
464
+ // Call listBoard again: latest event is "reopened" → no new emit.
465
+ await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
466
+ expect(countLedgerEventsFor(vaultRoot, id)).toBe(3); // unchanged
467
+ });
468
+ });
469
+ // ---------------------------------------------------------------------------
470
+ // Scenario 5: Filters (R26) — narrowing by collection/check/certainty/
471
+ // owner/age/document.
472
+ // ---------------------------------------------------------------------------
473
+ describe("listBoard — Scenario 5: filters (R26)", () => {
474
+ let vaultRoot;
475
+ beforeEach(() => {
476
+ vaultRoot = mkdtempSync(join(tmpdir(), "daftari-board-filter-test-"));
477
+ writeConfig(vaultRoot, {
478
+ admin: { read: ["*"], write: ["*"], promote: true, ratify: true },
479
+ });
480
+ // notes/ collection
481
+ writeDoc(vaultRoot, "notes/orphan-doc.md", frontmatter({ title: "Orphan", collection: "notes", updated: "2020-01-01", ttl_days: null }) +
482
+ "# Orphan\n\nNo one links here.\n");
483
+ writeDoc(vaultRoot, "notes/expired-doc.md", `${frontmatter({
484
+ title: "Expired",
485
+ collection: "notes",
486
+ updated: STALE_DATE,
487
+ ttl_days: 90,
488
+ })}# Expired\n`);
489
+ // decisions/ collection
490
+ writeDoc(vaultRoot, "decisions/orphan-decision.md", `${frontmatter({
491
+ title: "Orphan Decision",
492
+ collection: "decisions",
493
+ updated: "2020-01-01",
494
+ ttl_days: null,
495
+ })}# Decision\n\nNo one links here.\n`);
496
+ // Staged action
497
+ writeStagedActionProposal(vaultRoot, {
498
+ id: "stage-001",
499
+ action_type: "promote",
500
+ target_path: "notes/orphan-doc.md",
501
+ proposed_by: "human:admin",
502
+ proposed_at: "2025-12-01T00:00:00Z",
503
+ expires_at: "2027-01-01T00:00:00Z",
504
+ status: "pending",
505
+ rationale: "promote orphan",
506
+ proposed_diff: "",
507
+ });
508
+ // Tension between notes/doc-a.md and notes/doc-b.md
509
+ writeTension(vaultRoot, {
510
+ id: "tension-001",
511
+ date: "2026-01-01",
512
+ title: "Doc A vs Doc B",
513
+ kind: "factual",
514
+ sourceA: "notes/doc-a.md",
515
+ claimA: "blue",
516
+ sourceB: "notes/doc-b.md",
517
+ claimB: "green",
518
+ status: "unresolved",
519
+ });
520
+ });
521
+ afterEach(() => {
522
+ rmSync(vaultRoot, { recursive: true, force: true });
523
+ });
524
+ it("filter by collection='notes' returns only notes findings", async () => {
525
+ const all = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
526
+ const filtered = await listBoard(vaultRoot, adminAccess, { collection: "notes" }, FIXED_NOW);
527
+ expect(filtered.all.length).toBeGreaterThan(0);
528
+ expect(filtered.all.length).toBeLessThan(all.all.length);
529
+ for (const f of filtered.all) {
530
+ // lint/staleness: path starts with "notes/"
531
+ if (f.target.kind === "lint" || f.target.kind === "staleness") {
532
+ expect(f.target.path.startsWith("notes/")).toBe(true);
533
+ }
534
+ // staged: targetPath resolved to notes/ — covered by engine's collection resolution
535
+ // tension: sourceA starts with "notes/" — documented semantic
536
+ }
537
+ });
538
+ it("filter by collection='decisions' returns only decisions findings", async () => {
539
+ const filtered = await listBoard(vaultRoot, adminAccess, { collection: "decisions" }, FIXED_NOW);
540
+ expect(filtered.all.length).toBeGreaterThan(0);
541
+ for (const f of filtered.all) {
542
+ if (f.target.kind === "lint" || f.target.kind === "staleness") {
543
+ expect(f.target.path.startsWith("decisions/")).toBe(true);
544
+ }
545
+ }
546
+ });
547
+ it("filter by check='orphanFiles' returns only orphanFiles findings", async () => {
548
+ const filtered = await listBoard(vaultRoot, adminAccess, { check: "orphanFiles" }, FIXED_NOW);
549
+ expect(filtered.all.length).toBeGreaterThan(0);
550
+ for (const f of filtered.all) {
551
+ expect(f.check).toBe("orphanFiles");
552
+ }
553
+ });
554
+ it("filter by check='ttl-staleness' returns only staleness findings", async () => {
555
+ const filtered = await listBoard(vaultRoot, adminAccess, { check: "ttl-staleness" }, FIXED_NOW);
556
+ expect(filtered.all.length).toBeGreaterThan(0);
557
+ for (const f of filtered.all) {
558
+ expect(f.check).toBe("ttl-staleness");
559
+ }
560
+ });
561
+ it("filter by certainty='high' returns only high-certainty findings", async () => {
562
+ const all = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
563
+ const highCertainty = all.all.filter((f) => f.certainty === "high");
564
+ const filtered = await listBoard(vaultRoot, adminAccess, { certainty: "high" }, FIXED_NOW);
565
+ expect(filtered.all.length).toBe(highCertainty.length);
566
+ for (const f of filtered.all) {
567
+ expect(f.certainty).toBe("high");
568
+ }
569
+ });
570
+ it("filter by document='notes/orphan-doc.md' narrows to findings referencing that path", async () => {
571
+ const filtered = await listBoard(vaultRoot, adminAccess, { document: "notes/orphan-doc.md" }, FIXED_NOW);
572
+ expect(filtered.all.length).toBeGreaterThan(0);
573
+ for (const f of filtered.all) {
574
+ const t = f.target;
575
+ let matches = false;
576
+ if (t.kind === "lint")
577
+ matches = t.path === "notes/orphan-doc.md";
578
+ else if (t.kind === "staleness")
579
+ matches = t.path === "notes/orphan-doc.md";
580
+ else if (t.kind === "staged")
581
+ matches = true; // staged targets notes/orphan-doc.md
582
+ else if (t.kind === "tension")
583
+ matches =
584
+ f.evidence.sourceA ===
585
+ "notes/orphan-doc.md" ||
586
+ f.evidence.sourceB === "notes/orphan-doc.md";
587
+ else if (t.kind === "tier2")
588
+ matches = t.artifact === "notes/orphan-doc.md" || t.unit === "notes/orphan-doc.md";
589
+ expect(matches).toBe(true);
590
+ }
591
+ });
592
+ it("filter by minAgeDays=1 keeps only findings first_seen >= 1 day old", async () => {
593
+ // All findings are brand-new (first_seen = FIXED_NOW from adapter) so a large
594
+ // minAgeDays filter should return empty if first_seen is recent.
595
+ // Use 0 to confirm it passes all through.
596
+ const filtered0 = await listBoard(vaultRoot, adminAccess, { minAgeDays: 0 }, FIXED_NOW);
597
+ const all = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
598
+ // minAgeDays=0 means "at least 0 days old" → everything passes
599
+ expect(filtered0.all.length).toBe(all.all.length);
600
+ });
601
+ it("filter by minAgeDays=99999 returns empty when all findings are brand-new", async () => {
602
+ const filtered = await listBoard(vaultRoot, adminAccess, { minAgeDays: 99999 }, FIXED_NOW);
603
+ // first_seen for brand-new findings is FIXED_NOW itself → age = 0 days → excluded
604
+ expect(filtered.all.length).toBe(0);
605
+ });
606
+ it("filter by owner='' returns findings with no owner (all new findings)", async () => {
607
+ // New findings have owner:"" by default. Filter by owner:"" should return all.
608
+ const all = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
609
+ const filtered = await listBoard(vaultRoot, adminAccess, { owner: "" }, FIXED_NOW);
610
+ expect(filtered.all.length).toBe(all.all.length);
611
+ for (const f of filtered.all) {
612
+ expect(f.owner).toBe("");
613
+ }
614
+ });
615
+ it("filter by owner='human:admin' narrows to zero when no findings are owned", async () => {
616
+ // No reassign events → all owners are ""; filter by a named owner returns empty.
617
+ const filtered = await listBoard(vaultRoot, adminAccess, { owner: "human:admin" }, FIXED_NOW);
618
+ expect(filtered.all.length).toBe(0);
619
+ });
620
+ it("filters are applied after reconcile: emit persists regardless of filter", async () => {
621
+ // Set up a finding with [accept, resolved] so reconcile will emit "reopened".
622
+ const baseResult = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
623
+ const orphan = baseResult.all.find((f) => f.source === "lint" &&
624
+ f.target.kind === "lint" &&
625
+ f.target.path === "notes/orphan-doc.md" &&
626
+ f.check === "orphanFiles");
627
+ expect(orphan).toBeDefined();
628
+ const id = orphan.identity_key;
629
+ const fp = orphan.fingerprint;
630
+ await appendEvent(vaultRoot, {
631
+ finding_id: id,
632
+ event: "accept",
633
+ by: "human:admin",
634
+ principal_type: "human",
635
+ at: "2025-12-01T00:00:00Z",
636
+ against_fingerprint: fp,
637
+ });
638
+ await appendEvent(vaultRoot, {
639
+ finding_id: id,
640
+ event: "resolved",
641
+ by: "system",
642
+ principal_type: "system",
643
+ at: "2025-12-10T00:00:00Z",
644
+ against_fingerprint: fp,
645
+ });
646
+ const beforeCount = countLedgerEventsFor(vaultRoot, id);
647
+ expect(beforeCount).toBe(2);
648
+ // Apply a filter that would EXCLUDE the reopened finding (e.g. wrong check)
649
+ await listBoard(vaultRoot, adminAccess, { check: "ttl-staleness" }, FIXED_NOW);
650
+ // Even though the filter excluded the orphan finding, the emit was still persisted
651
+ expect(countLedgerEventsFor(vaultRoot, id)).toBe(3);
652
+ });
653
+ });
654
+ // ---------------------------------------------------------------------------
655
+ // Scenario 6: columns shape integrity
656
+ // ---------------------------------------------------------------------------
657
+ describe("listBoard — Scenario 6: columns shape", () => {
658
+ let vaultRoot;
659
+ beforeEach(() => {
660
+ vaultRoot = seedMixedVault();
661
+ });
662
+ afterEach(() => {
663
+ rmSync(vaultRoot, { recursive: true, force: true });
664
+ });
665
+ it("columns has exactly the five BoardColumn keys", async () => {
666
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
667
+ expect(Object.keys(result.columns).sort()).toEqual(["accepted", "dismissed", "new", "resolved", "waiting"].sort());
668
+ });
669
+ it("sum of column counts equals all.length", async () => {
670
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
671
+ const colTotal = Object.values(result.columns).reduce((n, col) => n + col.length, 0);
672
+ expect(colTotal).toBe(result.all.length);
673
+ });
674
+ it("each finding in all[] is also in its disposition column", async () => {
675
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
676
+ for (const f of result.all) {
677
+ const col = result.columns[f.disposition];
678
+ expect(col.some((c) => c.identity_key === f.identity_key)).toBe(true);
679
+ }
680
+ });
681
+ });
682
+ // ---------------------------------------------------------------------------
683
+ // Scenario 7: Staged evidence seam — end-to-end contract (#455)
684
+ //
685
+ // Verifies that a real staged adapter finding (evidence.targetPath, NOT
686
+ // evidence.target_path) flows through listBoard and:
687
+ // (a) is matched by collection=<its collection> filter (collectionOf)
688
+ // (b) is matched by document=<its targetPath> filter (documentMatches)
689
+ // (c) its back-link renders to /doc/<targetPath> via renderBoardPage
690
+ //
691
+ // This test uses the REAL staged adapter (via listBoard with a filesystem
692
+ // vault), not a hand-written mock, so it fails if the adapter and engine
693
+ // disagree on the field name.
694
+ // ---------------------------------------------------------------------------
695
+ describe("listBoard — Scenario 7: staged evidence targetPath seam (#455)", () => {
696
+ let vaultRoot;
697
+ beforeEach(() => {
698
+ vaultRoot = mkdtempSync(join(tmpdir(), "daftari-board-staged-seam-"));
699
+ writeConfig(vaultRoot, {
700
+ admin: { read: ["*"], write: ["*"], promote: true, ratify: true },
701
+ });
702
+ // notes/ collection document (needed for RBAC collection resolution)
703
+ writeDoc(vaultRoot, "notes/target-doc.md", frontmatter({ title: "Target", collection: "notes", updated: "2020-01-01", ttl_days: null }) +
704
+ "# Target\n\nContent.\n");
705
+ // Staged action targeting notes/target-doc.md
706
+ writeStagedActionProposal(vaultRoot, {
707
+ id: "seam-001",
708
+ action_type: "promote",
709
+ target_path: "notes/target-doc.md",
710
+ proposed_by: "human:admin",
711
+ proposed_at: "2025-12-01T00:00:00Z",
712
+ expires_at: "2027-01-01T00:00:00Z",
713
+ status: "pending",
714
+ rationale: "seam test promote",
715
+ proposed_diff: "",
716
+ });
717
+ });
718
+ afterEach(() => {
719
+ rmSync(vaultRoot, { recursive: true, force: true });
720
+ });
721
+ it("(a) staged finding is matched by collection='notes' filter", async () => {
722
+ const filtered = await listBoard(vaultRoot, adminAccess, { collection: "notes" }, FIXED_NOW);
723
+ const stagedFindings = filtered.all.filter((f) => f.source === "staged");
724
+ expect(stagedFindings.length).toBeGreaterThan(0);
725
+ const seam = stagedFindings.find((f) => f.target.kind === "staged" && f.target.stagedActionId === "seam-001");
726
+ expect(seam).toBeDefined();
727
+ });
728
+ it("(b) staged finding is matched by document='notes/target-doc.md' filter", async () => {
729
+ const filtered = await listBoard(vaultRoot, adminAccess, { document: "notes/target-doc.md" }, FIXED_NOW);
730
+ const stagedFindings = filtered.all.filter((f) => f.source === "staged");
731
+ expect(stagedFindings.length).toBeGreaterThan(0);
732
+ const seam = stagedFindings.find((f) => f.target.kind === "staged" && f.target.stagedActionId === "seam-001");
733
+ expect(seam).toBeDefined();
734
+ });
735
+ it("(c) staged finding evidence uses targetPath (not target_path)", async () => {
736
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
737
+ const seam = result.all.find((f) => f.source === "staged" &&
738
+ f.target.kind === "staged" &&
739
+ f.target.stagedActionId === "seam-001");
740
+ expect(seam).toBeDefined();
741
+ // The adapter emits evidence.targetPath — verify the field name is correct
742
+ expect(seam.evidence.targetPath).toBe("notes/target-doc.md");
743
+ // The wrong field name must NOT be present
744
+ expect(seam.evidence.target_path).toBeUndefined();
745
+ });
746
+ it("(d) renderBoardPage renders back-link to /doc/notes/target-doc.md (not /doc/undefined)", async () => {
747
+ const result = await listBoard(vaultRoot, adminAccess, undefined, FIXED_NOW);
748
+ const html = renderBoardPage(result);
749
+ expect(html).toContain('href="/doc/notes/target-doc.md"');
750
+ expect(html).not.toContain('href="/doc/undefined"');
751
+ });
752
+ });
753
+ //# sourceMappingURL=board.test.js.map