daftari 3.7.0 → 3.9.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 (248) hide show
  1. package/CHANGELOG.md +40 -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/board/board.d.ts +37 -0
  8. package/dist/board/board.d.ts.map +1 -0
  9. package/dist/board/board.js +233 -0
  10. package/dist/board/board.js.map +1 -0
  11. package/dist/board/board.test.d.ts +2 -0
  12. package/dist/board/board.test.d.ts.map +1 -0
  13. package/dist/board/board.test.js +753 -0
  14. package/dist/board/board.test.js.map +1 -0
  15. package/dist/board/dormancy.test.d.ts +2 -0
  16. package/dist/board/dormancy.test.d.ts.map +1 -0
  17. package/dist/board/dormancy.test.js +79 -0
  18. package/dist/board/dormancy.test.js.map +1 -0
  19. package/dist/board/identity.d.ts +5 -0
  20. package/dist/board/identity.d.ts.map +1 -0
  21. package/dist/board/identity.js +146 -0
  22. package/dist/board/identity.js.map +1 -0
  23. package/dist/board/identity.test.d.ts +2 -0
  24. package/dist/board/identity.test.d.ts.map +1 -0
  25. package/dist/board/identity.test.js +291 -0
  26. package/dist/board/identity.test.js.map +1 -0
  27. package/dist/board/ledger.d.ts +41 -0
  28. package/dist/board/ledger.d.ts.map +1 -0
  29. package/dist/board/ledger.js +197 -0
  30. package/dist/board/ledger.js.map +1 -0
  31. package/dist/board/ledger.test.d.ts +2 -0
  32. package/dist/board/ledger.test.d.ts.map +1 -0
  33. package/dist/board/ledger.test.js +873 -0
  34. package/dist/board/ledger.test.js.map +1 -0
  35. package/dist/board/principals.d.ts +4 -0
  36. package/dist/board/principals.d.ts.map +1 -0
  37. package/dist/board/principals.js +37 -0
  38. package/dist/board/principals.js.map +1 -0
  39. package/dist/board/principals.test.d.ts +2 -0
  40. package/dist/board/principals.test.d.ts.map +1 -0
  41. package/dist/board/principals.test.js +296 -0
  42. package/dist/board/principals.test.js.map +1 -0
  43. package/dist/board/reconcile.d.ts +12 -0
  44. package/dist/board/reconcile.d.ts.map +1 -0
  45. package/dist/board/reconcile.js +293 -0
  46. package/dist/board/reconcile.js.map +1 -0
  47. package/dist/board/reconcile.test.d.ts +2 -0
  48. package/dist/board/reconcile.test.d.ts.map +1 -0
  49. package/dist/board/reconcile.test.js +788 -0
  50. package/dist/board/reconcile.test.js.map +1 -0
  51. package/dist/board/sources/index.d.ts +24 -0
  52. package/dist/board/sources/index.d.ts.map +1 -0
  53. package/dist/board/sources/index.js +64 -0
  54. package/dist/board/sources/index.js.map +1 -0
  55. package/dist/board/sources/lint.d.ts +3 -0
  56. package/dist/board/sources/lint.d.ts.map +1 -0
  57. package/dist/board/sources/lint.js +218 -0
  58. package/dist/board/sources/lint.js.map +1 -0
  59. package/dist/board/sources/lint.test.d.ts +2 -0
  60. package/dist/board/sources/lint.test.d.ts.map +1 -0
  61. package/dist/board/sources/lint.test.js +616 -0
  62. package/dist/board/sources/lint.test.js.map +1 -0
  63. package/dist/board/sources/staged.d.ts +3 -0
  64. package/dist/board/sources/staged.d.ts.map +1 -0
  65. package/dist/board/sources/staged.js +116 -0
  66. package/dist/board/sources/staged.js.map +1 -0
  67. package/dist/board/sources/staged.test.d.ts +2 -0
  68. package/dist/board/sources/staged.test.d.ts.map +1 -0
  69. package/dist/board/sources/staged.test.js +418 -0
  70. package/dist/board/sources/staged.test.js.map +1 -0
  71. package/dist/board/sources/staleness.d.ts +43 -0
  72. package/dist/board/sources/staleness.d.ts.map +1 -0
  73. package/dist/board/sources/staleness.js +346 -0
  74. package/dist/board/sources/staleness.js.map +1 -0
  75. package/dist/board/sources/staleness.test.d.ts +2 -0
  76. package/dist/board/sources/staleness.test.d.ts.map +1 -0
  77. package/dist/board/sources/staleness.test.js +923 -0
  78. package/dist/board/sources/staleness.test.js.map +1 -0
  79. package/dist/board/sources/tension.d.ts +3 -0
  80. package/dist/board/sources/tension.d.ts.map +1 -0
  81. package/dist/board/sources/tension.js +152 -0
  82. package/dist/board/sources/tension.js.map +1 -0
  83. package/dist/board/sources/tension.test.d.ts +2 -0
  84. package/dist/board/sources/tension.test.d.ts.map +1 -0
  85. package/dist/board/sources/tension.test.js +440 -0
  86. package/dist/board/sources/tension.test.js.map +1 -0
  87. package/dist/board/sources/tier2.d.ts +17 -0
  88. package/dist/board/sources/tier2.d.ts.map +1 -0
  89. package/dist/board/sources/tier2.js +233 -0
  90. package/dist/board/sources/tier2.js.map +1 -0
  91. package/dist/board/sources/tier2.test.d.ts +2 -0
  92. package/dist/board/sources/tier2.test.d.ts.map +1 -0
  93. package/dist/board/sources/tier2.test.js +480 -0
  94. package/dist/board/sources/tier2.test.js.map +1 -0
  95. package/dist/board/types.d.ts +161 -0
  96. package/dist/board/types.d.ts.map +1 -0
  97. package/dist/board/types.js +37 -0
  98. package/dist/board/types.js.map +1 -0
  99. package/dist/canon/index.d.ts +3 -1
  100. package/dist/canon/index.d.ts.map +1 -1
  101. package/dist/canon/index.js +35 -8
  102. package/dist/canon/index.js.map +1 -1
  103. package/dist/canon/types.d.ts +3 -0
  104. package/dist/canon/types.d.ts.map +1 -1
  105. package/dist/cli.d.ts.map +1 -1
  106. package/dist/cli.js +9 -0
  107. package/dist/cli.js.map +1 -1
  108. package/dist/consolidate/birth.d.ts +1 -1
  109. package/dist/consolidate/birth.d.ts.map +1 -1
  110. package/dist/consolidate/birth.js +22 -0
  111. package/dist/consolidate/birth.js.map +1 -1
  112. package/dist/consolidate/edge-write.d.ts +11 -0
  113. package/dist/consolidate/edge-write.d.ts.map +1 -1
  114. package/dist/consolidate/edge-write.js +41 -0
  115. package/dist/consolidate/edge-write.js.map +1 -1
  116. package/dist/consolidate/index.js +5 -2
  117. package/dist/consolidate/index.js.map +1 -1
  118. package/dist/consolidate/revision.d.ts +4 -2
  119. package/dist/consolidate/revision.d.ts.map +1 -1
  120. package/dist/consolidate/revision.js +23 -0
  121. package/dist/consolidate/revision.js.map +1 -1
  122. package/dist/curation/edge-staleness.d.ts +4 -2
  123. package/dist/curation/edge-staleness.d.ts.map +1 -1
  124. package/dist/curation/edge-staleness.js +36 -3
  125. package/dist/curation/edge-staleness.js.map +1 -1
  126. package/dist/curation/edges.d.ts +7 -0
  127. package/dist/curation/edges.d.ts.map +1 -1
  128. package/dist/curation/edges.js +13 -7
  129. package/dist/curation/edges.js.map +1 -1
  130. package/dist/curation/tension-access.d.ts +1 -0
  131. package/dist/curation/tension-access.d.ts.map +1 -1
  132. package/dist/curation/tension-access.js +18 -1
  133. package/dist/curation/tension-access.js.map +1 -1
  134. package/dist/curation/tension.d.ts +3 -0
  135. package/dist/curation/tension.d.ts.map +1 -1
  136. package/dist/curation/tension.js +36 -0
  137. package/dist/curation/tension.js.map +1 -1
  138. package/dist/curation/vault-docs.d.ts +1 -0
  139. package/dist/curation/vault-docs.d.ts.map +1 -1
  140. package/dist/curation/vault-docs.js +1 -0
  141. package/dist/curation/vault-docs.js.map +1 -1
  142. package/dist/distill/cli.d.ts.map +1 -1
  143. package/dist/distill/cli.js +6 -0
  144. package/dist/distill/cli.js.map +1 -1
  145. package/dist/distill/cost.d.ts +6 -0
  146. package/dist/distill/cost.d.ts.map +1 -1
  147. package/dist/distill/cost.js +2 -3
  148. package/dist/distill/cost.js.map +1 -1
  149. package/dist/distill/extract.d.ts +52 -0
  150. package/dist/distill/extract.d.ts.map +1 -1
  151. package/dist/distill/extract.js +24 -2
  152. package/dist/distill/extract.js.map +1 -1
  153. package/dist/distill/propose.d.ts +44 -1
  154. package/dist/distill/propose.d.ts.map +1 -1
  155. package/dist/distill/propose.js +84 -2
  156. package/dist/distill/propose.js.map +1 -1
  157. package/dist/distill/reader-fingerprint.d.ts +69 -0
  158. package/dist/distill/reader-fingerprint.d.ts.map +1 -0
  159. package/dist/distill/reader-fingerprint.js +145 -0
  160. package/dist/distill/reader-fingerprint.js.map +1 -0
  161. package/dist/distill/receipt-store.d.ts +5 -0
  162. package/dist/distill/receipt-store.d.ts.map +1 -0
  163. package/dist/distill/receipt-store.js +24 -0
  164. package/dist/distill/receipt-store.js.map +1 -0
  165. package/dist/eval/llm-openrouter.d.ts.map +1 -1
  166. package/dist/eval/llm-openrouter.js +4 -0
  167. package/dist/eval/llm-openrouter.js.map +1 -1
  168. package/dist/eval/llm.d.ts +22 -0
  169. package/dist/eval/llm.d.ts.map +1 -1
  170. package/dist/eval/llm.js +94 -24
  171. package/dist/eval/llm.js.map +1 -1
  172. package/dist/federation/classification.d.ts.map +1 -1
  173. package/dist/federation/classification.js +3 -0
  174. package/dist/federation/classification.js.map +1 -1
  175. package/dist/index.d.ts.map +1 -1
  176. package/dist/index.js +31 -0
  177. package/dist/index.js.map +1 -1
  178. package/dist/search/coverage.d.ts +5 -1
  179. package/dist/search/coverage.d.ts.map +1 -1
  180. package/dist/search/coverage.js +47 -15
  181. package/dist/search/coverage.js.map +1 -1
  182. package/dist/search/hybrid.d.ts +7 -1
  183. package/dist/search/hybrid.d.ts.map +1 -1
  184. package/dist/search/hybrid.js +31 -8
  185. package/dist/search/hybrid.js.map +1 -1
  186. package/dist/search/retrieval-metrics.d.ts +5 -0
  187. package/dist/search/retrieval-metrics.d.ts.map +1 -0
  188. package/dist/search/retrieval-metrics.js +60 -0
  189. package/dist/search/retrieval-metrics.js.map +1 -0
  190. package/dist/search/suppression.d.ts +9 -0
  191. package/dist/search/suppression.d.ts.map +1 -0
  192. package/dist/search/suppression.js +107 -0
  193. package/dist/search/suppression.js.map +1 -0
  194. package/dist/serve/index.d.ts +11 -0
  195. package/dist/serve/index.d.ts.map +1 -1
  196. package/dist/serve/index.js +547 -8
  197. package/dist/serve/index.js.map +1 -1
  198. package/dist/serve/session.d.ts +9 -0
  199. package/dist/serve/session.d.ts.map +1 -0
  200. package/dist/serve/session.js +65 -0
  201. package/dist/serve/session.js.map +1 -0
  202. package/dist/server.d.ts.map +1 -1
  203. package/dist/server.js +4 -6
  204. package/dist/server.js.map +1 -1
  205. package/dist/tools/board.d.ts +32 -0
  206. package/dist/tools/board.d.ts.map +1 -0
  207. package/dist/tools/board.js +615 -0
  208. package/dist/tools/board.js.map +1 -0
  209. package/dist/tools/board.test.d.ts +2 -0
  210. package/dist/tools/board.test.d.ts.map +1 -0
  211. package/dist/tools/board.test.js +964 -0
  212. package/dist/tools/board.test.js.map +1 -0
  213. package/dist/tools/edge-staleness.d.ts.map +1 -1
  214. package/dist/tools/edge-staleness.js +18 -4
  215. package/dist/tools/edge-staleness.js.map +1 -1
  216. package/dist/tools/read.d.ts +2 -0
  217. package/dist/tools/read.d.ts.map +1 -1
  218. package/dist/tools/read.js +43 -13
  219. package/dist/tools/read.js.map +1 -1
  220. package/dist/tools/search.d.ts.map +1 -1
  221. package/dist/tools/search.js +79 -17
  222. package/dist/tools/search.js.map +1 -1
  223. package/dist/tools/write.d.ts.map +1 -1
  224. package/dist/tools/write.js +172 -2
  225. package/dist/tools/write.js.map +1 -1
  226. package/dist/utils/config.d.ts +24 -0
  227. package/dist/utils/config.d.ts.map +1 -1
  228. package/dist/utils/config.js +151 -1
  229. package/dist/utils/config.js.map +1 -1
  230. package/dist/version.d.ts +2 -0
  231. package/dist/version.d.ts.map +1 -0
  232. package/dist/version.js +8 -0
  233. package/dist/version.js.map +1 -0
  234. package/dist/view/board-page.d.ts +4 -0
  235. package/dist/view/board-page.d.ts.map +1 -0
  236. package/dist/view/board-page.js +339 -0
  237. package/dist/view/board-page.js.map +1 -0
  238. package/dist/view/board-page.test.d.ts +2 -0
  239. package/dist/view/board-page.test.d.ts.map +1 -0
  240. package/dist/view/board-page.test.js +548 -0
  241. package/dist/view/board-page.test.js.map +1 -0
  242. package/dist/view/pages.d.ts.map +1 -1
  243. package/dist/view/pages.js +13 -2
  244. package/dist/view/pages.js.map +1 -1
  245. package/dist/view/render.d.ts.map +1 -1
  246. package/dist/view/render.js +2 -1
  247. package/dist/view/render.js.map +1 -1
  248. package/package.json +2 -2
@@ -0,0 +1,964 @@
1
+ // board.test.ts — TDD test suite for U11: Board MCP tools (trust boundary).
2
+ //
3
+ // Tests cover every trust-boundary requirement:
4
+ // R13/R16 — canDispose gate: agent role (no dispose) rejected for ALL four events.
5
+ // R14 — vault_board_resolve: still-reproduces → no resolved; gone → exactly one resolved.
6
+ // R15 — reopened is never a tool entry point (no code path can emit it via tools).
7
+ // R20 — RBAC on dispose target: scoped role cannot dispose finding it cannot read.
8
+ // R31 — reassign: unconfigured principal rejected; configured principal succeeds.
9
+ //
10
+ // Also verifies:
11
+ // - principal_type "human" on all dispose events.
12
+ // - principal_type "system" on resolve events.
13
+ // - descriptor stamped on every dispose event.
14
+ // - Non-disclosing error: dispose of non-existent vs. unreadable finding yields same error.
15
+ // - vault_board_list delegates cleanly to listBoard (no extra gating).
16
+ //
17
+ // Run with:
18
+ // npx vitest run src/tools/board.test.ts
19
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
20
+ import { tmpdir } from "node:os";
21
+ import { join } from "node:path";
22
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
23
+ import { boardDispositionsPath } from "../board/ledger.js";
24
+ import { vaultBoardDispose, vaultBoardList, vaultBoardResolve } from "./board.js";
25
+ // ---------------------------------------------------------------------------
26
+ // Helpers — vault fixture construction
27
+ // ---------------------------------------------------------------------------
28
+ function frontmatter(overrides = {}) {
29
+ const fm = {
30
+ title: "Test Document",
31
+ domain: "accumulation",
32
+ collection: "notes",
33
+ status: "canonical",
34
+ confidence: "medium",
35
+ created: "2020-01-01",
36
+ updated: "2020-01-01",
37
+ updated_by: "agent:seed",
38
+ provenance: "direct",
39
+ sources: [],
40
+ superseded_by: null,
41
+ ttl_days: null,
42
+ ...overrides,
43
+ };
44
+ const lines = [];
45
+ for (const [k, v] of Object.entries(fm)) {
46
+ if (v === null) {
47
+ lines.push(`${k}: null`);
48
+ }
49
+ else if (Array.isArray(v)) {
50
+ if (v.length === 0) {
51
+ lines.push(`${k}: []`);
52
+ }
53
+ else {
54
+ lines.push(`${k}:`);
55
+ for (const item of v) {
56
+ lines.push(` - ${JSON.stringify(item)}`);
57
+ }
58
+ }
59
+ }
60
+ else {
61
+ lines.push(`${k}: ${JSON.stringify(v)}`);
62
+ }
63
+ }
64
+ return `---\n${lines.join("\n")}\n---\n`;
65
+ }
66
+ /**
67
+ * Build a .daftari/config.yaml with given roles and optional extra principals.
68
+ * `server.tokens` is kept empty in tests (principals are exercised via `principals:` list).
69
+ */
70
+ function writeConfig(vaultRoot, roles, extraPrincipals = []) {
71
+ const daftariDir = join(vaultRoot, ".daftari");
72
+ mkdirSync(daftariDir, { recursive: true });
73
+ const roleLines = Object.entries(roles)
74
+ .map(([name, cfg]) => {
75
+ const lines = [` ${name}:`];
76
+ for (const [k, v] of Object.entries(cfg)) {
77
+ if (Array.isArray(v)) {
78
+ lines.push(` ${k}: [${v.map((s) => JSON.stringify(s)).join(", ")}]`);
79
+ }
80
+ else {
81
+ lines.push(` ${k}: ${JSON.stringify(v)}`);
82
+ }
83
+ }
84
+ return lines.join("\n");
85
+ })
86
+ .join("\n");
87
+ const principalLines = extraPrincipals.length > 0
88
+ ? `\nprincipals:\n${extraPrincipals.map((p) => ` - ${JSON.stringify(p)}`).join("\n")}\n`
89
+ : "";
90
+ const yaml = `version: 1\nvault_name: test-vault\nroles:\n${roleLines}\n` +
91
+ `server:\n tokens: []\n` +
92
+ principalLines;
93
+ writeFileSync(join(daftariDir, "config.yaml"), yaml, "utf-8");
94
+ }
95
+ function writeDoc(vaultRoot, path, content) {
96
+ const full = join(vaultRoot, path);
97
+ const dir = join(vaultRoot, path.split("/").slice(0, -1).join("/"));
98
+ mkdirSync(dir, { recursive: true });
99
+ writeFileSync(full, content, "utf-8");
100
+ }
101
+ /** Read all ledger events from the vault JSONL file. */
102
+ function readLedgerEvents(vaultRoot) {
103
+ const p = boardDispositionsPath(vaultRoot);
104
+ if (!existsSync(p))
105
+ return [];
106
+ return readFileSync(p, "utf-8")
107
+ .split("\n")
108
+ .filter((l) => l.trim().length > 0)
109
+ .map((l) => JSON.parse(l));
110
+ }
111
+ /** Find all ledger events with a given event type. */
112
+ function eventsOfType(vaultRoot, eventType) {
113
+ return readLedgerEvents(vaultRoot).filter((e) => e.event === eventType);
114
+ }
115
+ // ---------------------------------------------------------------------------
116
+ // Role + AccessContext fixtures
117
+ // ---------------------------------------------------------------------------
118
+ // Human operator: dispose:true, read:["*"]
119
+ const humanRole = {
120
+ read: ["*"],
121
+ write: ["*"],
122
+ promote: true,
123
+ ratify: true,
124
+ dispose: true,
125
+ };
126
+ // Agent role: no dispose capability, read:["*"]
127
+ const agentRole = {
128
+ read: ["*"],
129
+ write: ["*"],
130
+ promote: false,
131
+ ratify: false,
132
+ // dispose intentionally absent → canDispose returns false
133
+ };
134
+ // Scoped human: dispose:true but only read:["notes"]
135
+ const scopedHumanRole = {
136
+ read: ["notes"],
137
+ write: ["notes"],
138
+ promote: false,
139
+ ratify: false,
140
+ dispose: true,
141
+ };
142
+ const humanAccess = {
143
+ user: "human:operator",
144
+ roleName: "human",
145
+ role: humanRole,
146
+ };
147
+ const agentAccess = {
148
+ user: "agent:curation-loop",
149
+ roleName: "agent",
150
+ role: agentRole,
151
+ };
152
+ const scopedHumanAccess = {
153
+ user: "human:scoped",
154
+ roleName: "scoped",
155
+ role: scopedHumanRole,
156
+ };
157
+ // ---------------------------------------------------------------------------
158
+ // DaftariConfig fixture for principals tests
159
+ // ---------------------------------------------------------------------------
160
+ function makeConfig(roles, principals = []) {
161
+ return {
162
+ roles,
163
+ schemaExtensions: [],
164
+ hooks: { preWrite: [], preWriteTransform: [] },
165
+ autoCommit: false,
166
+ watch: false,
167
+ warmEmbeddings: false,
168
+ embeddingProvider: "local-minilm",
169
+ search: {
170
+ coverage: false,
171
+ vecKnnK: 64,
172
+ weights: { bm25: 0.8, vector: 0.2 },
173
+ suppressSuperseded: false,
174
+ },
175
+ backfillIdentityMap: {},
176
+ holderAliases: {},
177
+ shadowMode: false,
178
+ shadowModeSet: false,
179
+ gitDir: undefined,
180
+ lintVoice: "plain",
181
+ tensionScan: {
182
+ maxLlmCalls: 10,
183
+ maxDocs: 10,
184
+ agent: "agent:test",
185
+ },
186
+ tools: { tier: "full", include: [], exclude: [] },
187
+ server: {
188
+ tokens: [],
189
+ limits: {
190
+ ratePerMinute: 120,
191
+ burst: 40,
192
+ authFailureBurst: 10,
193
+ authFailuresPerMinute: 6,
194
+ maxInFlight: 32,
195
+ },
196
+ audit: false,
197
+ },
198
+ storage: undefined,
199
+ codeRepos: {},
200
+ jitAnchors: false,
201
+ autoRepin: false,
202
+ distill: undefined,
203
+ federation: undefined,
204
+ principals,
205
+ };
206
+ }
207
+ // ---------------------------------------------------------------------------
208
+ // Fixed clock so staleness findings are deterministic
209
+ // ---------------------------------------------------------------------------
210
+ const FIXED_NOW = new Date("2026-01-01T00:00:00Z");
211
+ const STALE_DATE = new Date(FIXED_NOW.getTime() - 200 * 86_400_000).toISOString().slice(0, 10);
212
+ // ---------------------------------------------------------------------------
213
+ // Vault seeders
214
+ // ---------------------------------------------------------------------------
215
+ /**
216
+ * Seeds a vault with a single lint finding (orphan doc).
217
+ * Returns the vaultRoot.
218
+ */
219
+ function seedLintVault(roles, principals = []) {
220
+ const vaultRoot = mkdtempSync(join(tmpdir(), "daftari-board-tools-test-"));
221
+ writeConfig(vaultRoot, roles, principals);
222
+ // Lint: orphan doc (no back-references)
223
+ writeDoc(vaultRoot, "notes/orphan-doc.md", frontmatter({ title: "Orphan", collection: "notes", updated: "2020-01-01", ttl_days: null }) +
224
+ "# Orphan\n\nNo one links here.\n");
225
+ return vaultRoot;
226
+ }
227
+ /**
228
+ * Seeds a vault that has findings in BOTH "notes" and "restricted" collections.
229
+ * Used for scoped-role RBAC tests (R20).
230
+ */
231
+ function seedMultiCollectionVault() {
232
+ const vaultRoot = mkdtempSync(join(tmpdir(), "daftari-board-tools-test-"));
233
+ writeConfig(vaultRoot, {
234
+ human: { read: ["*"], write: ["*"], promote: true, ratify: true, dispose: true },
235
+ scoped: { read: ["notes"], write: ["notes"], dispose: true },
236
+ agent: { read: ["*"], write: ["*"] },
237
+ });
238
+ // notes collection doc — scoped role CAN read this
239
+ writeDoc(vaultRoot, "notes/orphan-doc.md", frontmatter({ title: "Orphan", collection: "notes", updated: "2020-01-01", ttl_days: null }) +
240
+ "# Orphan\n\nNo one links here.\n");
241
+ // restricted collection doc — scoped role CANNOT read this
242
+ writeDoc(vaultRoot, "restricted/secret-doc.md", frontmatter({
243
+ title: "Secret",
244
+ collection: "restricted",
245
+ updated: "2020-01-01",
246
+ ttl_days: null,
247
+ }) + "# Secret\n\nNobody can see me if scoped.\n");
248
+ return vaultRoot;
249
+ }
250
+ // ---------------------------------------------------------------------------
251
+ // Tests
252
+ // ---------------------------------------------------------------------------
253
+ describe("vault_board_list", () => {
254
+ let vaultRoot;
255
+ beforeEach(() => {
256
+ vaultRoot = seedLintVault({
257
+ admin: { read: ["*"], write: ["*"], promote: true, ratify: true },
258
+ });
259
+ });
260
+ afterEach(() => {
261
+ rmSync(vaultRoot, { recursive: true, force: true });
262
+ });
263
+ it("returns board findings for a readable vault", async () => {
264
+ const config = makeConfig({
265
+ admin: { read: ["*"], write: ["*"], promote: true, ratify: true },
266
+ });
267
+ const result = await vaultBoardList(vaultRoot, humanAccess, config);
268
+ expect(result.ok).toBe(true);
269
+ if (!result.ok)
270
+ return;
271
+ // The board has columns
272
+ expect(result.value).toHaveProperty("columns");
273
+ expect(result.value).toHaveProperty("all");
274
+ });
275
+ it("accepts optional filters without error", async () => {
276
+ const config = makeConfig({
277
+ admin: { read: ["*"], write: ["*"], promote: true, ratify: true },
278
+ });
279
+ const result = await vaultBoardList(vaultRoot, humanAccess, config, { collection: "notes" });
280
+ expect(result.ok).toBe(true);
281
+ });
282
+ });
283
+ // ---------------------------------------------------------------------------
284
+ // R13 / R16 — canDispose gate: agent role rejected for ALL four events
285
+ // ---------------------------------------------------------------------------
286
+ describe("vault_board_dispose — R13/R16 canDispose gate", () => {
287
+ let vaultRoot;
288
+ let config;
289
+ beforeEach(() => {
290
+ vaultRoot = seedLintVault({
291
+ human: { read: ["*"], write: ["*"], promote: true, ratify: true, dispose: true },
292
+ agent: { read: ["*"], write: ["*"] },
293
+ });
294
+ config = makeConfig({
295
+ human: humanRole,
296
+ agent: agentRole,
297
+ });
298
+ });
299
+ afterEach(() => {
300
+ rmSync(vaultRoot, { recursive: true, force: true });
301
+ });
302
+ for (const event of ["accept", "defer", "dismiss", "reassign"]) {
303
+ it(`rejects agent role for event '${event}'`, async () => {
304
+ // First get a real finding_id via list
305
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
306
+ expect(listResult.ok).toBe(true);
307
+ if (!listResult.ok)
308
+ return;
309
+ const allFindings = listResult.value.all;
310
+ // We need at least one finding to attempt the dispose
311
+ const findingId = allFindings.length > 0 ? allFindings[0].identity_key : "fake-finding-id-does-not-matter";
312
+ const result = await vaultBoardDispose(vaultRoot, agentAccess, config, {
313
+ finding_id: findingId,
314
+ event,
315
+ rationale: "agent trying to dispose",
316
+ ...(event === "reassign" ? { owner: "human:operator" } : {}),
317
+ });
318
+ expect(result.ok).toBe(false);
319
+ if (result.ok)
320
+ return;
321
+ // Error must mention disposition denial — not the finding-not-found path
322
+ expect(result.error.message).toMatch(/dispose|permission|denied|capability/i);
323
+ });
324
+ }
325
+ it("confirms: NO ledger events written when agent is rejected", async () => {
326
+ const result = await vaultBoardDispose(vaultRoot, agentAccess, config, {
327
+ finding_id: "any-id",
328
+ event: "accept",
329
+ rationale: "should not land",
330
+ });
331
+ expect(result.ok).toBe(false);
332
+ // Ledger must be empty
333
+ const events = readLedgerEvents(vaultRoot);
334
+ expect(events.filter((e) => e.event === "accept")).toHaveLength(0);
335
+ });
336
+ });
337
+ // ---------------------------------------------------------------------------
338
+ // Human operator can dispose — all four events appended with principal_type "human"
339
+ // ---------------------------------------------------------------------------
340
+ describe("vault_board_dispose — human operator, all four events", () => {
341
+ let vaultRoot;
342
+ let config;
343
+ beforeEach(() => {
344
+ vaultRoot = seedLintVault({
345
+ human: { read: ["*"], write: ["*"], promote: true, ratify: true, dispose: true },
346
+ agent: { read: ["*"], write: ["*"] },
347
+ }, ["human:other-operator"]);
348
+ config = makeConfig({ human: humanRole, agent: agentRole }, [
349
+ "human:operator",
350
+ "human:other-operator",
351
+ ]);
352
+ });
353
+ afterEach(() => {
354
+ rmSync(vaultRoot, { recursive: true, force: true });
355
+ });
356
+ it("accept — appended with principal_type 'human'", async () => {
357
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
358
+ expect(listResult.ok).toBe(true);
359
+ if (!listResult.ok)
360
+ return;
361
+ const finding = listResult.value.all.find((f) => f.source === "lint");
362
+ expect(finding).toBeDefined();
363
+ if (!finding)
364
+ return;
365
+ const result = await vaultBoardDispose(vaultRoot, humanAccess, config, {
366
+ finding_id: finding.identity_key,
367
+ event: "accept",
368
+ rationale: "accepting lint finding",
369
+ });
370
+ expect(result.ok).toBe(true);
371
+ if (!result.ok)
372
+ return;
373
+ // Verify ledger
374
+ const events = readLedgerEvents(vaultRoot).filter((e) => e.finding_id === finding.identity_key && e.event === "accept");
375
+ expect(events).toHaveLength(1);
376
+ expect(events[0].principal_type).toBe("human");
377
+ expect(events[0].by).toBe("human:operator");
378
+ // Descriptor must be stamped
379
+ expect(events[0].descriptor).toBeDefined();
380
+ expect(events[0].descriptor?.source).toBe("lint");
381
+ });
382
+ it("defer — appended with principal_type 'human' and expiry", async () => {
383
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
384
+ expect(listResult.ok).toBe(true);
385
+ if (!listResult.ok)
386
+ return;
387
+ const finding = listResult.value.all.find((f) => f.source === "lint");
388
+ expect(finding).toBeDefined();
389
+ if (!finding)
390
+ return;
391
+ const expiry = "2026-06-01T00:00:00Z";
392
+ const result = await vaultBoardDispose(vaultRoot, humanAccess, config, {
393
+ finding_id: finding.identity_key,
394
+ event: "defer",
395
+ rationale: "deferring for now",
396
+ expiry,
397
+ });
398
+ expect(result.ok).toBe(true);
399
+ const events = readLedgerEvents(vaultRoot).filter((e) => e.finding_id === finding.identity_key && e.event === "defer");
400
+ expect(events).toHaveLength(1);
401
+ expect(events[0].principal_type).toBe("human");
402
+ expect(events[0].expiry).toBe(expiry);
403
+ expect(events[0].descriptor).toBeDefined();
404
+ });
405
+ it("dismiss — appended with principal_type 'human'", async () => {
406
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
407
+ expect(listResult.ok).toBe(true);
408
+ if (!listResult.ok)
409
+ return;
410
+ const finding = listResult.value.all.find((f) => f.source === "lint");
411
+ expect(finding).toBeDefined();
412
+ if (!finding)
413
+ return;
414
+ const result = await vaultBoardDispose(vaultRoot, humanAccess, config, {
415
+ finding_id: finding.identity_key,
416
+ event: "dismiss",
417
+ rationale: "won't fix",
418
+ });
419
+ expect(result.ok).toBe(true);
420
+ const events = readLedgerEvents(vaultRoot).filter((e) => e.finding_id === finding.identity_key && e.event === "dismiss");
421
+ expect(events).toHaveLength(1);
422
+ expect(events[0].principal_type).toBe("human");
423
+ expect(events[0].descriptor).toBeDefined();
424
+ });
425
+ it("reassign to configured principal — appended with principal_type 'human'", async () => {
426
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
427
+ expect(listResult.ok).toBe(true);
428
+ if (!listResult.ok)
429
+ return;
430
+ const finding = listResult.value.all.find((f) => f.source === "lint");
431
+ expect(finding).toBeDefined();
432
+ if (!finding)
433
+ return;
434
+ const result = await vaultBoardDispose(vaultRoot, humanAccess, config, {
435
+ finding_id: finding.identity_key,
436
+ event: "reassign",
437
+ rationale: "reassigning",
438
+ owner: "human:other-operator",
439
+ });
440
+ expect(result.ok).toBe(true);
441
+ const events = readLedgerEvents(vaultRoot).filter((e) => e.finding_id === finding.identity_key && e.event === "reassign");
442
+ expect(events).toHaveLength(1);
443
+ expect(events[0].principal_type).toBe("human");
444
+ expect(events[0].owner).toBe("human:other-operator");
445
+ expect(events[0].descriptor).toBeDefined();
446
+ });
447
+ });
448
+ // ---------------------------------------------------------------------------
449
+ // R31 — reassign to unconfigured principal rejected
450
+ // ---------------------------------------------------------------------------
451
+ describe("vault_board_dispose — R31 reassign principal gate", () => {
452
+ let vaultRoot;
453
+ let config;
454
+ beforeEach(() => {
455
+ vaultRoot = seedLintVault({ human: { read: ["*"], write: ["*"], promote: true, ratify: true, dispose: true } }, ["human:allowed-person"]);
456
+ config = makeConfig({ human: humanRole }, ["human:allowed-person"]);
457
+ });
458
+ afterEach(() => {
459
+ rmSync(vaultRoot, { recursive: true, force: true });
460
+ });
461
+ it("rejects reassign to a name NOT in configured principals", async () => {
462
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
463
+ expect(listResult.ok).toBe(true);
464
+ if (!listResult.ok)
465
+ return;
466
+ const finding = listResult.value.all.find((f) => f.source === "lint");
467
+ expect(finding).toBeDefined();
468
+ if (!finding)
469
+ return;
470
+ const result = await vaultBoardDispose(vaultRoot, humanAccess, config, {
471
+ finding_id: finding.identity_key,
472
+ event: "reassign",
473
+ rationale: "reassigning to unknown",
474
+ owner: "human:unknown-person",
475
+ });
476
+ expect(result.ok).toBe(false);
477
+ if (result.ok)
478
+ return;
479
+ expect(result.error.message).toMatch(/principal|owner|unknown|not configured/i);
480
+ // No event written
481
+ const events = readLedgerEvents(vaultRoot).filter((e) => e.event === "reassign");
482
+ expect(events).toHaveLength(0);
483
+ });
484
+ it("allows reassign to a configured principal", async () => {
485
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
486
+ expect(listResult.ok).toBe(true);
487
+ if (!listResult.ok)
488
+ return;
489
+ const finding = listResult.value.all.find((f) => f.source === "lint");
490
+ expect(finding).toBeDefined();
491
+ if (!finding)
492
+ return;
493
+ const result = await vaultBoardDispose(vaultRoot, humanAccess, config, {
494
+ finding_id: finding.identity_key,
495
+ event: "reassign",
496
+ rationale: "reassigning to allowed",
497
+ owner: "human:allowed-person",
498
+ });
499
+ expect(result.ok).toBe(true);
500
+ });
501
+ });
502
+ // ---------------------------------------------------------------------------
503
+ // R20 — RBAC on dispose target: non-disclosing error
504
+ // The scoped role (notes-only) cannot dispose a finding from "restricted".
505
+ // The error message must be THE SAME as for a non-existent finding_id.
506
+ // ---------------------------------------------------------------------------
507
+ describe("vault_board_dispose — R20 RBAC non-disclosure", () => {
508
+ let vaultRoot;
509
+ let config;
510
+ beforeEach(() => {
511
+ vaultRoot = seedMultiCollectionVault();
512
+ config = makeConfig({
513
+ human: humanRole,
514
+ scoped: scopedHumanRole,
515
+ agent: agentRole,
516
+ }, ["human:operator", "human:scoped"]);
517
+ });
518
+ afterEach(() => {
519
+ rmSync(vaultRoot, { recursive: true, force: true });
520
+ });
521
+ it("scoped role: error for unreadable finding is byte-identical to error for nonexistent id", async () => {
522
+ // Get the restricted finding via admin (humanAccess)
523
+ const adminListResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
524
+ expect(adminListResult.ok).toBe(true);
525
+ if (!adminListResult.ok)
526
+ return;
527
+ const restrictedFinding = adminListResult.value.all.find((f) => f.target.kind === "lint" && "path" in f.target && f.target.path.startsWith("restricted/"));
528
+ expect(restrictedFinding).toBeDefined();
529
+ if (!restrictedFinding)
530
+ return;
531
+ // Attempt 1: dispose a finding the scoped role CANNOT read
532
+ const blockedResult = await vaultBoardDispose(vaultRoot, scopedHumanAccess, config, {
533
+ finding_id: restrictedFinding.identity_key,
534
+ event: "accept",
535
+ rationale: "trying to accept restricted finding",
536
+ });
537
+ // Attempt 2: dispose a completely fake finding_id
538
+ const fakeResult = await vaultBoardDispose(vaultRoot, scopedHumanAccess, config, {
539
+ finding_id: "totally-fake-id-that-does-not-exist",
540
+ event: "accept",
541
+ rationale: "trying to accept nonexistent",
542
+ });
543
+ expect(blockedResult.ok).toBe(false);
544
+ expect(fakeResult.ok).toBe(false);
545
+ if (blockedResult.ok || fakeResult.ok)
546
+ return;
547
+ // The error messages must be byte-identical — no existence disclosure (R20).
548
+ // IMPORTANT: the message must NOT contain the finding_id, since the two ids
549
+ // differ (one is a sha256, the other is a literal string) — including the id
550
+ // would reveal which one was "found but blocked" vs "not found at all".
551
+ expect(blockedResult.error.message).toBe(fakeResult.error.message);
552
+ // Also confirm neither message contains the finding_id
553
+ expect(blockedResult.error.message).not.toContain(restrictedFinding.identity_key);
554
+ expect(fakeResult.error.message).not.toContain("totally-fake-id");
555
+ });
556
+ it("scoped role CAN dispose a finding in its readable collection", async () => {
557
+ const scopedListResult = await vaultBoardList(vaultRoot, scopedHumanAccess, config, undefined, FIXED_NOW);
558
+ expect(scopedListResult.ok).toBe(true);
559
+ if (!scopedListResult.ok)
560
+ return;
561
+ const notesFinding = scopedListResult.value.all.find((f) => f.target.kind === "lint" && "path" in f.target && f.target.path.startsWith("notes/"));
562
+ expect(notesFinding).toBeDefined();
563
+ if (!notesFinding)
564
+ return;
565
+ const result = await vaultBoardDispose(vaultRoot, scopedHumanAccess, config, {
566
+ finding_id: notesFinding.identity_key,
567
+ event: "accept",
568
+ rationale: "accepting notes finding",
569
+ });
570
+ expect(result.ok).toBe(true);
571
+ });
572
+ });
573
+ // ---------------------------------------------------------------------------
574
+ // R14 — vault_board_resolve: still-reproduces → no resolved; gone → exactly one resolved
575
+ // ---------------------------------------------------------------------------
576
+ describe("vault_board_resolve — R14 reproduces gate", () => {
577
+ let vaultRoot;
578
+ let config;
579
+ beforeEach(() => {
580
+ vaultRoot = seedLintVault({
581
+ human: { read: ["*"], write: ["*"], promote: true, ratify: true, dispose: true },
582
+ agent: { read: ["*"], write: ["*"] },
583
+ });
584
+ config = makeConfig({ human: humanRole, agent: agentRole });
585
+ });
586
+ afterEach(() => {
587
+ rmSync(vaultRoot, { recursive: true, force: true });
588
+ });
589
+ it("still-reproduces → NOT resolved, returns 'still reproduces' indicator", async () => {
590
+ // Get a live finding
591
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
592
+ expect(listResult.ok).toBe(true);
593
+ if (!listResult.ok)
594
+ return;
595
+ const finding = listResult.value.all.find((f) => f.source === "lint");
596
+ expect(finding).toBeDefined();
597
+ if (!finding)
598
+ return;
599
+ // First accept it so there's a ledger entry (resolve needs prior events)
600
+ const disposeResult = await vaultBoardDispose(vaultRoot, humanAccess, config, {
601
+ finding_id: finding.identity_key,
602
+ event: "accept",
603
+ rationale: "accepting before resolve attempt",
604
+ });
605
+ expect(disposeResult.ok).toBe(true);
606
+ // Now attempt resolve — the orphan doc still exists → still reproduces
607
+ const resolveResult = await vaultBoardResolve(vaultRoot, humanAccess, config, { finding_id: finding.identity_key }, FIXED_NOW);
608
+ expect(resolveResult.ok).toBe(true);
609
+ if (!resolveResult.ok)
610
+ return;
611
+ expect(resolveResult.value.still_reproduces).toBe(true);
612
+ expect(resolveResult.value.resolved).toBe(false);
613
+ // No "resolved" event in ledger
614
+ const resolvedEvents = readLedgerEvents(vaultRoot).filter((e) => e.event === "resolved");
615
+ expect(resolvedEvents.filter((e) => e.finding_id === finding.identity_key)).toHaveLength(0);
616
+ });
617
+ it("no longer reproduces → exactly ONE resolved event, principal_type 'system'", async () => {
618
+ // Get a live finding
619
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
620
+ expect(listResult.ok).toBe(true);
621
+ if (!listResult.ok)
622
+ return;
623
+ const finding = listResult.value.all.find((f) => f.source === "lint");
624
+ expect(finding).toBeDefined();
625
+ if (!finding)
626
+ return;
627
+ // Accept the finding so there's a ledger entry for RBAC lookup
628
+ const disposeResult = await vaultBoardDispose(vaultRoot, humanAccess, config, {
629
+ finding_id: finding.identity_key,
630
+ event: "accept",
631
+ rationale: "accepting",
632
+ });
633
+ expect(disposeResult.ok).toBe(true);
634
+ // FIX the underlying condition: delete the orphan doc so it no longer reproduces
635
+ const target = finding.target;
636
+ if (target.kind === "lint") {
637
+ const docPath = join(vaultRoot, target.path);
638
+ rmSync(docPath, { force: true });
639
+ }
640
+ // Now resolve — the condition is gone → should write resolved
641
+ const resolveResult = await vaultBoardResolve(vaultRoot, humanAccess, config, { finding_id: finding.identity_key }, FIXED_NOW);
642
+ expect(resolveResult.ok).toBe(true);
643
+ if (!resolveResult.ok)
644
+ return;
645
+ expect(resolveResult.value.resolved).toBe(true);
646
+ expect(resolveResult.value.still_reproduces).toBe(false);
647
+ // Exactly ONE resolved event in ledger
648
+ const resolvedEvents = readLedgerEvents(vaultRoot).filter((e) => e.event === "resolved" && e.finding_id === finding.identity_key);
649
+ expect(resolvedEvents).toHaveLength(1);
650
+ expect(resolvedEvents[0].principal_type).toBe("system");
651
+ expect(resolvedEvents[0].by).toBe("system");
652
+ // Calling resolve again does not add a second resolved event (idempotent)
653
+ const secondResolveResult = await vaultBoardResolve(vaultRoot, humanAccess, config, { finding_id: finding.identity_key }, FIXED_NOW);
654
+ // Second call: condition still gone; already resolved — check no double-write
655
+ const resolvedEventsAfter = readLedgerEvents(vaultRoot).filter((e) => e.event === "resolved" && e.finding_id === finding.identity_key);
656
+ // Either it returns already-resolved or adds another (we only assert ≤ 1 unique write per call)
657
+ // The test contract is: each fresh call to resolve on a still-gone condition appends at most one.
658
+ // We verify the second call didn't add a second event.
659
+ if (secondResolveResult.ok && secondResolveResult.value.resolved) {
660
+ // If it says resolved again, we expect the total is now 2 (one per call)
661
+ // But per R14 spec: we only care that one resolved is emitted per successful check.
662
+ // The important invariant is that each individual call writes at most 1.
663
+ expect(resolvedEventsAfter.length).toBeGreaterThanOrEqual(1);
664
+ }
665
+ });
666
+ it("resolve with no prior ledger events → rejected (nothing to resolve)", async () => {
667
+ const result = await vaultBoardResolve(vaultRoot, humanAccess, config, { finding_id: "finding-with-no-prior-events" }, FIXED_NOW);
668
+ expect(result.ok).toBe(false);
669
+ });
670
+ it("agent role CAN call resolve (resolve is not gated by canDispose)", async () => {
671
+ // First create a prior event via human (so ledger has an entry)
672
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
673
+ expect(listResult.ok).toBe(true);
674
+ if (!listResult.ok)
675
+ return;
676
+ const finding = listResult.value.all.find((f) => f.source === "lint");
677
+ expect(finding).toBeDefined();
678
+ if (!finding)
679
+ return;
680
+ await vaultBoardDispose(vaultRoot, humanAccess, config, {
681
+ finding_id: finding.identity_key,
682
+ event: "accept",
683
+ rationale: "seed event",
684
+ });
685
+ // Agent tries resolve — should NOT be rejected by canDispose gate
686
+ const result = await vaultBoardResolve(vaultRoot, agentAccess, config, { finding_id: finding.identity_key }, FIXED_NOW);
687
+ // It may succeed or fail (still reproduces), but it must NOT fail with a "dispose" error
688
+ if (!result.ok) {
689
+ expect(result.error.message).not.toMatch(/dispose|capability/i);
690
+ }
691
+ });
692
+ });
693
+ // ---------------------------------------------------------------------------
694
+ // R15 — reopened is never a tool entry point
695
+ // ---------------------------------------------------------------------------
696
+ describe("R15 — no tool path can emit or accept 'reopened'", () => {
697
+ let vaultRoot;
698
+ let config;
699
+ beforeEach(() => {
700
+ vaultRoot = seedLintVault({
701
+ human: { read: ["*"], write: ["*"], promote: true, ratify: true, dispose: true },
702
+ });
703
+ config = makeConfig({ human: humanRole });
704
+ });
705
+ afterEach(() => {
706
+ rmSync(vaultRoot, { recursive: true, force: true });
707
+ });
708
+ it("vault_board_dispose rejects event 'reopened'", async () => {
709
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
710
+ expect(listResult.ok).toBe(true);
711
+ if (!listResult.ok)
712
+ return;
713
+ const finding = listResult.value.all[0];
714
+ const result = await vaultBoardDispose(vaultRoot, humanAccess, config, {
715
+ // Deliberately passing illegal event to test runtime guard.
716
+ // The type includes `string` to allow runtime validation of untrusted input.
717
+ finding_id: finding?.identity_key ?? "fake",
718
+ event: "reopened",
719
+ rationale: "trying to inject reopened",
720
+ });
721
+ expect(result.ok).toBe(false);
722
+ if (result.ok)
723
+ return;
724
+ expect(result.error.message).toMatch(/invalid event|reopened|not allowed/i);
725
+ // No reopened event in ledger
726
+ const reopenedEvents = readLedgerEvents(vaultRoot).filter((e) => e.event === "reopened");
727
+ expect(reopenedEvents).toHaveLength(0);
728
+ });
729
+ it("vault_board_resolve never writes a 'reopened' event", async () => {
730
+ // Call resolve with a nonexistent finding — it will fail, but must not write reopened
731
+ await vaultBoardResolve(vaultRoot, humanAccess, config, {
732
+ finding_id: "any-fake-id",
733
+ });
734
+ const reopenedEvents = readLedgerEvents(vaultRoot).filter((e) => e.event === "reopened");
735
+ expect(reopenedEvents).toHaveLength(0);
736
+ });
737
+ it("vault_board_resolve also rejects 'new' as an event (system events not injectable)", async () => {
738
+ // vault_board_resolve has no 'event' parameter — it only writes 'resolved'.
739
+ // This test confirms the resolve tool's output is constrained to 'resolved'.
740
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
741
+ expect(listResult.ok).toBe(true);
742
+ if (!listResult.ok)
743
+ return;
744
+ const finding = listResult.value.all.find((f) => f.source === "lint");
745
+ if (!finding)
746
+ return;
747
+ await vaultBoardDispose(vaultRoot, humanAccess, config, {
748
+ finding_id: finding.identity_key,
749
+ event: "accept",
750
+ rationale: "seed",
751
+ });
752
+ // Resolve while condition still exists
753
+ const result = await vaultBoardResolve(vaultRoot, humanAccess, config, {
754
+ finding_id: finding.identity_key,
755
+ });
756
+ // Whether ok or not, verify no "new" or "reopened" events were written
757
+ const systemInjectedEvents = readLedgerEvents(vaultRoot).filter((e) => e.event === "reopened" || (e.event === "new" && e.principal_type !== "system"));
758
+ expect(systemInjectedEvents).toHaveLength(0);
759
+ });
760
+ });
761
+ // ---------------------------------------------------------------------------
762
+ // Descriptor stamping — verify descriptor on all dispose events
763
+ // ---------------------------------------------------------------------------
764
+ describe("descriptor stamped on dispose events", () => {
765
+ let vaultRoot;
766
+ let config;
767
+ beforeEach(() => {
768
+ vaultRoot = seedLintVault({ human: { read: ["*"], write: ["*"], promote: true, ratify: true, dispose: true } }, ["human:operator"]);
769
+ config = makeConfig({ human: humanRole }, ["human:operator"]);
770
+ });
771
+ afterEach(() => {
772
+ rmSync(vaultRoot, { recursive: true, force: true });
773
+ });
774
+ it("descriptor.source, .check, .target, .label all present on accept event", async () => {
775
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
776
+ expect(listResult.ok).toBe(true);
777
+ if (!listResult.ok)
778
+ return;
779
+ const finding = listResult.value.all.find((f) => f.source === "lint");
780
+ expect(finding).toBeDefined();
781
+ if (!finding)
782
+ return;
783
+ await vaultBoardDispose(vaultRoot, humanAccess, config, {
784
+ finding_id: finding.identity_key,
785
+ event: "accept",
786
+ rationale: "checking descriptor",
787
+ });
788
+ const events = readLedgerEvents(vaultRoot).filter((e) => e.finding_id === finding.identity_key && e.event === "accept");
789
+ expect(events).toHaveLength(1);
790
+ const desc = events[0].descriptor;
791
+ expect(desc).toBeDefined();
792
+ expect(desc?.source).toBe(finding.source);
793
+ expect(desc?.check).toBe(finding.check);
794
+ expect(desc?.target).toMatchObject(finding.target);
795
+ expect(typeof desc?.label).toBe("string");
796
+ expect(desc.label.length).toBeGreaterThan(0);
797
+ });
798
+ });
799
+ // ---------------------------------------------------------------------------
800
+ // R20 resolve — RBAC non-disclosure (byte-identical error for hidden vs. nonexistent)
801
+ // Also covers: legacy descriptor (no rbacPaths) fails closed.
802
+ // ---------------------------------------------------------------------------
803
+ describe("vault_board_resolve — R20 RBAC non-disclosure + legacy fail-closed", () => {
804
+ let vaultRoot;
805
+ let config;
806
+ beforeEach(() => {
807
+ vaultRoot = seedMultiCollectionVault();
808
+ config = makeConfig({
809
+ human: humanRole,
810
+ scoped: scopedHumanRole,
811
+ agent: agentRole,
812
+ }, ["human:operator", "human:scoped"]);
813
+ });
814
+ afterEach(() => {
815
+ rmSync(vaultRoot, { recursive: true, force: true });
816
+ });
817
+ it("resolve: error for RBAC-hidden finding is byte-identical to error for nonexistent finding_id", async () => {
818
+ // Admin accepts the restricted finding so there IS a ledger entry for it.
819
+ const adminList = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
820
+ expect(adminList.ok).toBe(true);
821
+ if (!adminList.ok)
822
+ return;
823
+ const restrictedFinding = adminList.value.all.find((f) => f.target.kind === "lint" && "path" in f.target && f.target.path.startsWith("restricted/"));
824
+ expect(restrictedFinding).toBeDefined();
825
+ if (!restrictedFinding)
826
+ return;
827
+ // Human accepts it — creates ledger event with descriptor.rbacPaths pointing to restricted/
828
+ await vaultBoardDispose(vaultRoot, humanAccess, config, {
829
+ finding_id: restrictedFinding.identity_key,
830
+ event: "accept",
831
+ rationale: "admin seed",
832
+ });
833
+ // Scoped role tries to resolve the restricted finding (visible to admin, not to scoped)
834
+ const hiddenResult = await vaultBoardResolve(vaultRoot, scopedHumanAccess, config, { finding_id: restrictedFinding.identity_key }, FIXED_NOW);
835
+ // Scoped role tries to resolve a completely nonexistent finding_id
836
+ const nonexistentResult = await vaultBoardResolve(vaultRoot, scopedHumanAccess, config, { finding_id: "totally-nonexistent-finding-id-xyz" }, FIXED_NOW);
837
+ expect(hiddenResult.ok).toBe(false);
838
+ expect(nonexistentResult.ok).toBe(false);
839
+ if (hiddenResult.ok || nonexistentResult.ok)
840
+ return;
841
+ // Byte-identical error messages — no existence disclosure (R20).
842
+ expect(hiddenResult.error.message).toBe(nonexistentResult.error.message);
843
+ // Neither message must contain the finding_id
844
+ expect(hiddenResult.error.message).not.toContain(restrictedFinding.identity_key);
845
+ expect(nonexistentResult.error.message).not.toContain("totally-nonexistent");
846
+ });
847
+ it("resolve: legacy descriptor (no rbacPaths) fails closed — same non-disclosing error", async () => {
848
+ // Build a ledger entry with a descriptor that has NO rbacPaths field (pre-U11 data).
849
+ const { appendEvent: _appendEvent } = await import("../board/ledger.js");
850
+ const legacyFindingId = "legacy-finding-no-rbac-paths";
851
+ // Write a ledger event with a descriptor that omits rbacPaths (legacy).
852
+ const legacyDescriptor = {
853
+ source: "lint",
854
+ check: "orphanFiles",
855
+ target: { kind: "lint", path: "notes/orphan-doc.md" },
856
+ label: "Orphan document",
857
+ // rbacPaths intentionally absent — simulates pre-U11 data
858
+ };
859
+ await _appendEvent(vaultRoot, {
860
+ finding_id: legacyFindingId,
861
+ event: "accept",
862
+ by: "human:operator",
863
+ principal_type: "human",
864
+ at: FIXED_NOW.toISOString(),
865
+ against_fingerprint: "fp-legacy",
866
+ descriptor: legacyDescriptor,
867
+ });
868
+ // Even the wildcard-read scoped role cannot resolve a legacy-no-rbacPaths descriptor.
869
+ // The behavior: fail closed with the same non-disclosing error.
870
+ const legacyResult = await vaultBoardResolve(vaultRoot, scopedHumanAccess, config, { finding_id: legacyFindingId }, FIXED_NOW);
871
+ const nonexistentResult = await vaultBoardResolve(vaultRoot, scopedHumanAccess, config, { finding_id: "totally-nonexistent-xyz-789" }, FIXED_NOW);
872
+ expect(legacyResult.ok).toBe(false);
873
+ expect(nonexistentResult.ok).toBe(false);
874
+ if (legacyResult.ok || nonexistentResult.ok)
875
+ return;
876
+ // Must be byte-identical (same non-disclosing error).
877
+ expect(legacyResult.error.message).toBe(nonexistentResult.error.message);
878
+ });
879
+ it("scoped role CAN resolve a lint finding it can fully read via rbacPaths", async () => {
880
+ // Get the notes finding (scoped role CAN read "notes" collection)
881
+ const scopedList = await vaultBoardList(vaultRoot, scopedHumanAccess, config, undefined, FIXED_NOW);
882
+ expect(scopedList.ok).toBe(true);
883
+ if (!scopedList.ok)
884
+ return;
885
+ const notesFinding = scopedList.value.all.find((f) => f.target.kind === "lint" && "path" in f.target && f.target.path.startsWith("notes/"));
886
+ expect(notesFinding).toBeDefined();
887
+ if (!notesFinding)
888
+ return;
889
+ // Scoped role accepts it first (creates ledger event with rbacPaths for notes/)
890
+ const disposeResult = await vaultBoardDispose(vaultRoot, scopedHumanAccess, config, {
891
+ finding_id: notesFinding.identity_key,
892
+ event: "accept",
893
+ rationale: "accepting notes finding",
894
+ });
895
+ expect(disposeResult.ok).toBe(true);
896
+ // Now try resolve — it will return still_reproduces (orphan doc still exists)
897
+ // but it must NOT be rejected due to RBAC (scoped role CAN read this).
898
+ const resolveResult = await vaultBoardResolve(vaultRoot, scopedHumanAccess, config, { finding_id: notesFinding.identity_key }, FIXED_NOW);
899
+ // Must succeed (ok=true) — RBAC gate passed; result is still_reproduces=true (doc still there)
900
+ expect(resolveResult.ok).toBe(true);
901
+ if (!resolveResult.ok)
902
+ return;
903
+ expect(resolveResult.value.still_reproduces).toBe(true);
904
+ });
905
+ });
906
+ // ---------------------------------------------------------------------------
907
+ // FIX 4 — double-resolve exact count
908
+ // ---------------------------------------------------------------------------
909
+ describe("vault_board_resolve — double-resolve writes exactly ONE resolved event", () => {
910
+ let vaultRoot;
911
+ let config;
912
+ beforeEach(() => {
913
+ vaultRoot = seedLintVault({
914
+ human: { read: ["*"], write: ["*"], promote: true, ratify: true, dispose: true },
915
+ agent: { read: ["*"], write: ["*"] },
916
+ });
917
+ config = makeConfig({ human: humanRole, agent: agentRole });
918
+ });
919
+ afterEach(() => {
920
+ rmSync(vaultRoot, { recursive: true, force: true });
921
+ });
922
+ it("resolving twice on a gone finding yields exactly ONE resolved event in the ledger", async () => {
923
+ const listResult = await vaultBoardList(vaultRoot, humanAccess, config, undefined, FIXED_NOW);
924
+ expect(listResult.ok).toBe(true);
925
+ if (!listResult.ok)
926
+ return;
927
+ const finding = listResult.value.all.find((f) => f.source === "lint");
928
+ expect(finding).toBeDefined();
929
+ if (!finding)
930
+ return;
931
+ // Accept so there are prior events
932
+ await vaultBoardDispose(vaultRoot, humanAccess, config, {
933
+ finding_id: finding.identity_key,
934
+ event: "accept",
935
+ rationale: "seed",
936
+ });
937
+ // Delete the doc so the finding no longer reproduces
938
+ const target = finding.target;
939
+ if (target.kind === "lint") {
940
+ const docPath = join(vaultRoot, target.path);
941
+ rmSync(docPath, { force: true });
942
+ }
943
+ // First resolve — should write resolved
944
+ const r1 = await vaultBoardResolve(vaultRoot, humanAccess, config, { finding_id: finding.identity_key }, FIXED_NOW);
945
+ expect(r1.ok).toBe(true);
946
+ if (!r1.ok)
947
+ return;
948
+ expect(r1.value.resolved).toBe(true);
949
+ // Second resolve on the same already-resolved finding
950
+ const r2 = await vaultBoardResolve(vaultRoot, humanAccess, config, { finding_id: finding.identity_key }, FIXED_NOW);
951
+ // Exactly ONE resolved event regardless of second call outcome
952
+ const resolvedEvents = readLedgerEvents(vaultRoot).filter((e) => e.event === "resolved" && e.finding_id === finding.identity_key);
953
+ expect(resolvedEvents).toHaveLength(1);
954
+ // The second call should be a no-op write: it should not add a second resolved.
955
+ // If it returns ok=true with resolved=true, that's a double-write bug.
956
+ // If it returns ok=false or still_reproduces=true (already resolved = treated as no-op), that's correct.
957
+ if (r2.ok && r2.value.resolved) {
958
+ // This would indicate a double-write — the assertion above already catches it,
959
+ // but make the expectation explicit for clear test output.
960
+ expect(resolvedEvents).toHaveLength(1); // already asserted above; repeated for clarity
961
+ }
962
+ });
963
+ });
964
+ //# sourceMappingURL=board.test.js.map