daftari 3.7.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 (243) 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/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.map +1 -1
  195. package/dist/serve/index.js +273 -4
  196. package/dist/serve/index.js.map +1 -1
  197. package/dist/server.d.ts.map +1 -1
  198. package/dist/server.js +4 -6
  199. package/dist/server.js.map +1 -1
  200. package/dist/tools/board.d.ts +32 -0
  201. package/dist/tools/board.d.ts.map +1 -0
  202. package/dist/tools/board.js +615 -0
  203. package/dist/tools/board.js.map +1 -0
  204. package/dist/tools/board.test.d.ts +2 -0
  205. package/dist/tools/board.test.d.ts.map +1 -0
  206. package/dist/tools/board.test.js +964 -0
  207. package/dist/tools/board.test.js.map +1 -0
  208. package/dist/tools/edge-staleness.d.ts.map +1 -1
  209. package/dist/tools/edge-staleness.js +18 -4
  210. package/dist/tools/edge-staleness.js.map +1 -1
  211. package/dist/tools/read.d.ts +2 -0
  212. package/dist/tools/read.d.ts.map +1 -1
  213. package/dist/tools/read.js +43 -13
  214. package/dist/tools/read.js.map +1 -1
  215. package/dist/tools/search.d.ts.map +1 -1
  216. package/dist/tools/search.js +79 -17
  217. package/dist/tools/search.js.map +1 -1
  218. package/dist/tools/write.d.ts.map +1 -1
  219. package/dist/tools/write.js +172 -2
  220. package/dist/tools/write.js.map +1 -1
  221. package/dist/utils/config.d.ts +13 -0
  222. package/dist/utils/config.d.ts.map +1 -1
  223. package/dist/utils/config.js +88 -0
  224. package/dist/utils/config.js.map +1 -1
  225. package/dist/version.d.ts +2 -0
  226. package/dist/version.d.ts.map +1 -0
  227. package/dist/version.js +8 -0
  228. package/dist/version.js.map +1 -0
  229. package/dist/view/board-page.d.ts +4 -0
  230. package/dist/view/board-page.d.ts.map +1 -0
  231. package/dist/view/board-page.js +278 -0
  232. package/dist/view/board-page.js.map +1 -0
  233. package/dist/view/board-page.test.d.ts +2 -0
  234. package/dist/view/board-page.test.d.ts.map +1 -0
  235. package/dist/view/board-page.test.js +548 -0
  236. package/dist/view/board-page.test.js.map +1 -0
  237. package/dist/view/pages.d.ts.map +1 -1
  238. package/dist/view/pages.js +13 -2
  239. package/dist/view/pages.js.map +1 -1
  240. package/dist/view/render.d.ts.map +1 -1
  241. package/dist/view/render.js +2 -1
  242. package/dist/view/render.js.map +1 -1
  243. package/package.json +2 -2
@@ -0,0 +1,616 @@
1
+ // lint.test.ts — TDD test suite for U5: lint source adapter.
2
+ //
3
+ // Uses a real temp vault dir seeded with markdown files that trigger lint
4
+ // findings. RBAC is exercised via role fixtures (admin + scoped).
5
+ //
6
+ // Run with:
7
+ // npx vitest run src/board/sources/lint.test.ts
8
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
12
+ import { deriveIdentity, fingerprint } from "../identity.js";
13
+ import { SOURCE_ADAPTERS } from "./index.js";
14
+ import { lintAdapter } from "./lint.js";
15
+ // ---------------------------------------------------------------------------
16
+ // Vault fixture helpers
17
+ // ---------------------------------------------------------------------------
18
+ /** Minimal valid frontmatter for a document. collection = first path segment. */
19
+ function frontmatter(overrides = {}) {
20
+ const fm = {
21
+ title: "Test Document",
22
+ domain: "accumulation",
23
+ collection: "notes",
24
+ status: "canonical",
25
+ confidence: "medium",
26
+ created: "2020-01-01",
27
+ updated: "2020-01-01",
28
+ updated_by: "agent:seed",
29
+ provenance: "direct",
30
+ sources: [],
31
+ superseded_by: null,
32
+ ttl_days: null,
33
+ ...overrides,
34
+ };
35
+ const lines = [];
36
+ for (const [k, v] of Object.entries(fm)) {
37
+ if (v === null) {
38
+ lines.push(`${k}: null`);
39
+ }
40
+ else if (Array.isArray(v)) {
41
+ if (v.length === 0) {
42
+ lines.push(`${k}: []`);
43
+ }
44
+ else {
45
+ // Emit as a YAML block sequence so each item is on its own line.
46
+ lines.push(`${k}:`);
47
+ for (const item of v) {
48
+ lines.push(` - ${JSON.stringify(item)}`);
49
+ }
50
+ }
51
+ }
52
+ else {
53
+ lines.push(`${k}: ${JSON.stringify(v)}`);
54
+ }
55
+ }
56
+ return `---\n${lines.join("\n")}\n---\n`;
57
+ }
58
+ /** Write a minimal config.yaml with given roles into the vault. */
59
+ function writeConfig(vaultRoot, roles) {
60
+ const daftariDir = join(vaultRoot, ".daftari");
61
+ mkdirSync(daftariDir, { recursive: true });
62
+ const roleLines = Object.entries(roles)
63
+ .map(([name, cfg]) => {
64
+ const lines = [` ${name}:`];
65
+ for (const [k, v] of Object.entries(cfg)) {
66
+ if (Array.isArray(v)) {
67
+ lines.push(` ${k}: [${v.map((s) => JSON.stringify(s)).join(", ")}]`);
68
+ }
69
+ else {
70
+ lines.push(` ${k}: ${JSON.stringify(v)}`);
71
+ }
72
+ }
73
+ return lines.join("\n");
74
+ })
75
+ .join("\n");
76
+ const yaml = `version: 1\nvault_name: test-vault\nroles:\n${roleLines}\n`;
77
+ writeFileSync(join(daftariDir, "config.yaml"), yaml, "utf-8");
78
+ }
79
+ /** Write a vault doc at a vault-relative path. */
80
+ function writeDoc(vaultRoot, path, content) {
81
+ const full = join(vaultRoot, path);
82
+ mkdirSync(join(vaultRoot, path.split("/").slice(0, -1).join("/")), { recursive: true });
83
+ writeFileSync(full, content, "utf-8");
84
+ }
85
+ // ---------------------------------------------------------------------------
86
+ // Role fixtures
87
+ // ---------------------------------------------------------------------------
88
+ const adminRole = {
89
+ read: ["*"],
90
+ write: ["*"],
91
+ promote: true,
92
+ ratify: true,
93
+ };
94
+ const scopedRole = {
95
+ // can only read "notes" collection; "restricted" collection is denied
96
+ read: ["notes"],
97
+ write: ["notes"],
98
+ promote: false,
99
+ ratify: false,
100
+ };
101
+ const adminAccess = {
102
+ user: "human:admin",
103
+ roleName: "admin",
104
+ role: adminRole,
105
+ };
106
+ const scopedAccess = {
107
+ user: "human:analyst",
108
+ roleName: "analyst",
109
+ role: scopedRole,
110
+ };
111
+ // ---------------------------------------------------------------------------
112
+ // Suite
113
+ // ---------------------------------------------------------------------------
114
+ describe("lintAdapter", () => {
115
+ let vaultRoot;
116
+ beforeEach(() => {
117
+ vaultRoot = mkdtempSync(join(tmpdir(), "daftari-lint-adapter-test-"));
118
+ writeConfig(vaultRoot, {
119
+ admin: { read: ["*"], write: ["*"], promote: true, ratify: true },
120
+ analyst: { read: ["notes"], write: ["notes"] },
121
+ });
122
+ });
123
+ afterEach(() => {
124
+ rmSync(vaultRoot, { recursive: true, force: true });
125
+ });
126
+ // -------------------------------------------------------------------------
127
+ // Scenario 1: orphan doc → lint adapter emits a Finding with correct
128
+ // identity + fingerprint.
129
+ // -------------------------------------------------------------------------
130
+ describe("Scenario 1: orphan doc emits a Finding", () => {
131
+ beforeEach(() => {
132
+ // An orphan doc: no other doc links to it → orphanFiles finding.
133
+ writeDoc(vaultRoot, "notes/orphan-doc.md", `${frontmatter({
134
+ title: "Orphan",
135
+ collection: "notes",
136
+ // updated 1 day ago — not stale unless ttl is very short
137
+ updated: "2025-01-01",
138
+ ttl_days: null,
139
+ })}# Orphan\n\nNo one links here.\n`);
140
+ });
141
+ it("emits at least one Finding for the orphan path", async () => {
142
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
143
+ const orphanFindings = findings.filter((f) => f.check === "orphanFiles" && f.target.kind === "lint");
144
+ expect(orphanFindings.length).toBeGreaterThan(0);
145
+ const f = orphanFindings.find((f) => f.target.kind === "lint" && f.target.path === "notes/orphan-doc.md");
146
+ expect(f).toBeDefined();
147
+ });
148
+ it("Finding has source='lint', correct check, and LintTarget with the path", async () => {
149
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
150
+ const f = findings.find((f) => f.check === "orphanFiles" &&
151
+ f.target.kind === "lint" &&
152
+ f.target.path === "notes/orphan-doc.md");
153
+ expect(f).toBeDefined();
154
+ expect(f.source).toBe("lint");
155
+ expect(f.target).toEqual({ kind: "lint", path: "notes/orphan-doc.md" });
156
+ });
157
+ it("Finding identity_key matches deriveIdentity('lint', checkName, target)", async () => {
158
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
159
+ const f = findings.find((f) => f.check === "orphanFiles" &&
160
+ f.target.kind === "lint" &&
161
+ f.target.path === "notes/orphan-doc.md");
162
+ expect(f).toBeDefined();
163
+ const expected = deriveIdentity("lint", "orphanFiles", {
164
+ kind: "lint",
165
+ path: "notes/orphan-doc.md",
166
+ });
167
+ expect(f.identity_key).toBe(expected);
168
+ });
169
+ it("Finding fingerprint matches fingerprint({ detail })", async () => {
170
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
171
+ const f = findings.find((f) => f.check === "orphanFiles" &&
172
+ f.target.kind === "lint" &&
173
+ f.target.path === "notes/orphan-doc.md");
174
+ expect(f).toBeDefined();
175
+ const expectedFp = fingerprint({ detail: f.evidence.detail });
176
+ expect(f.fingerprint).toBe(expectedFp);
177
+ });
178
+ it("identityOf(raw) returns the same identity_key as stored on the Finding", async () => {
179
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
180
+ const f = findings.find((f) => f.check === "orphanFiles" &&
181
+ f.target.kind === "lint" &&
182
+ f.target.path === "notes/orphan-doc.md");
183
+ expect(f).toBeDefined();
184
+ expect(lintAdapter.identityOf(f)).toBe(f.identity_key);
185
+ });
186
+ it("fingerprintOf(raw) returns the same fingerprint as stored on the Finding", async () => {
187
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
188
+ const f = findings.find((f) => f.check === "orphanFiles" &&
189
+ f.target.kind === "lint" &&
190
+ f.target.path === "notes/orphan-doc.md");
191
+ expect(f).toBeDefined();
192
+ expect(lintAdapter.fingerprintOf(f)).toBe(f.fingerprint);
193
+ });
194
+ });
195
+ // -------------------------------------------------------------------------
196
+ // Scenario 2: RBAC — denied-collection finding is omitted for scoped role.
197
+ // The scoped role can only read "notes"; a finding in "restricted" is dropped.
198
+ // -------------------------------------------------------------------------
199
+ describe("Scenario 2: RBAC omits denied-collection findings", () => {
200
+ beforeEach(() => {
201
+ // An orphan doc in "notes" collection — readable by scopedRole.
202
+ writeDoc(vaultRoot, "notes/readable.md", frontmatter({ title: "Readable", collection: "notes", updated: "2020-01-01" }) +
203
+ "# Readable\n");
204
+ // An orphan doc in "restricted" collection — NOT readable by scopedRole.
205
+ writeDoc(vaultRoot, "restricted/secret.md", frontmatter({ title: "Secret", collection: "restricted", updated: "2020-01-01" }) +
206
+ "# Secret\n");
207
+ });
208
+ it("admin sees findings from both collections", async () => {
209
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
210
+ const paths = findings.map((f) => (f.target.kind === "lint" ? f.target.path : ""));
211
+ expect(paths).toContain("notes/readable.md");
212
+ expect(paths).toContain("restricted/secret.md");
213
+ });
214
+ it("scoped role sees findings in 'notes' but not 'restricted'", async () => {
215
+ const findings = await lintAdapter.list(vaultRoot, scopedAccess);
216
+ const paths = findings.map((f) => (f.target.kind === "lint" ? f.target.path : ""));
217
+ expect(paths).toContain("notes/readable.md");
218
+ expect(paths).not.toContain("restricted/secret.md");
219
+ });
220
+ it("omission is total — no zero card or placeholder for denied finding", async () => {
221
+ const adminFindings = await lintAdapter.list(vaultRoot, adminAccess);
222
+ const scopedFindings = await lintAdapter.list(vaultRoot, scopedAccess);
223
+ // Admin has more findings (or equal) because it can see restricted collection.
224
+ // The scoped view must NOT have more findings than admin.
225
+ expect(scopedFindings.length).toBeLessThanOrEqual(adminFindings.length);
226
+ // No finding in scopedFindings references restricted/
227
+ for (const f of scopedFindings) {
228
+ if (f.target.kind === "lint") {
229
+ expect(f.target.path).not.toMatch(/^restricted\//);
230
+ }
231
+ }
232
+ });
233
+ });
234
+ // -------------------------------------------------------------------------
235
+ // Scenario 3: stale doc → staleFiles finding with certainty mapping.
236
+ // A stale doc has exceeded its ttl — we verify the certainty field is set.
237
+ // -------------------------------------------------------------------------
238
+ describe("Scenario 3: stale doc emits staleFiles Finding with certainty", () => {
239
+ const FIXED_NOW = new Date("2026-01-01T00:00:00Z");
240
+ beforeEach(() => {
241
+ // A doc updated 200 days before FIXED_NOW with ttl_days: 90 → stale.
242
+ const staleDate = new Date(FIXED_NOW.getTime() - 200 * 86_400_000).toISOString().slice(0, 10);
243
+ writeDoc(vaultRoot, "notes/stale-doc.md", `${frontmatter({
244
+ title: "Stale",
245
+ collection: "notes",
246
+ updated: staleDate,
247
+ ttl_days: 90,
248
+ })}# Stale doc\n`);
249
+ });
250
+ it("emits a staleFiles finding for the stale doc", async () => {
251
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, FIXED_NOW);
252
+ const f = findings.find((f) => f.check === "staleFiles" &&
253
+ f.target.kind === "lint" &&
254
+ f.target.path === "notes/stale-doc.md");
255
+ expect(f).toBeDefined();
256
+ });
257
+ it("staleFiles finding has certainty 'medium' (non-tier0 check)", async () => {
258
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, FIXED_NOW);
259
+ const f = findings.find((f) => f.check === "staleFiles" &&
260
+ f.target.kind === "lint" &&
261
+ f.target.path === "notes/stale-doc.md");
262
+ expect(f).toBeDefined();
263
+ expect(f.certainty).toBe("medium");
264
+ });
265
+ it("staleFiles Finding has suggested_action and verify_predicate set", async () => {
266
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, FIXED_NOW);
267
+ const f = findings.find((f) => f.check === "staleFiles" &&
268
+ f.target.kind === "lint" &&
269
+ f.target.path === "notes/stale-doc.md");
270
+ expect(f).toBeDefined();
271
+ expect(typeof f.suggested_action).toBe("string");
272
+ expect(f.suggested_action.length).toBeGreaterThan(0);
273
+ expect(typeof f.verify_predicate).toBe("string");
274
+ expect(f.verify_predicate).toContain("staleFiles");
275
+ expect(f.verify_predicate).toContain("notes/stale-doc.md");
276
+ });
277
+ });
278
+ // -------------------------------------------------------------------------
279
+ // Scenario 4: tier-0 check (brokenSourceRefs) → certainty "high".
280
+ // -------------------------------------------------------------------------
281
+ describe("Scenario 4: tier-0 check emits Finding with certainty 'high'", () => {
282
+ beforeEach(() => {
283
+ // A doc with a broken sources entry (path-like ref to a nonexistent doc).
284
+ writeDoc(vaultRoot, "notes/broken-ref-doc.md", `${frontmatter({
285
+ title: "Broken Ref",
286
+ collection: "notes",
287
+ updated: "2025-01-01",
288
+ sources: ["notes/nonexistent-source.md"],
289
+ })}# Broken Ref\n`);
290
+ });
291
+ it("emits a brokenSourceRefs finding for the doc with broken sources", async () => {
292
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
293
+ const f = findings.find((f) => f.check === "brokenSourceRefs" &&
294
+ f.target.kind === "lint" &&
295
+ f.target.path === "notes/broken-ref-doc.md");
296
+ expect(f).toBeDefined();
297
+ });
298
+ it("brokenSourceRefs finding has certainty 'high' (tier-0 check)", async () => {
299
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
300
+ const f = findings.find((f) => f.check === "brokenSourceRefs" &&
301
+ f.target.kind === "lint" &&
302
+ f.target.path === "notes/broken-ref-doc.md");
303
+ expect(f).toBeDefined();
304
+ expect(f.certainty).toBe("high");
305
+ });
306
+ });
307
+ // -------------------------------------------------------------------------
308
+ // Scenario 5: reproduces() returns true while condition holds, false after fix.
309
+ // We test with a stale doc:
310
+ // - reproduces returns true when doc is still stale (same now)
311
+ // - list returns no staleFiles finding when the doc is no longer stale
312
+ // (i.e., a newer now where the doc's updated date is within ttl)
313
+ // -------------------------------------------------------------------------
314
+ describe("Scenario 5: reproduces() true while condition holds, false after fix", () => {
315
+ const STALE_NOW = new Date("2026-01-01T00:00:00Z");
316
+ const staleDate = new Date(STALE_NOW.getTime() - 200 * 86_400_000).toISOString().slice(0, 10);
317
+ beforeEach(() => {
318
+ writeDoc(vaultRoot, "notes/staleness-check.md", `${frontmatter({
319
+ title: "Staleness Check",
320
+ collection: "notes",
321
+ updated: staleDate,
322
+ ttl_days: 90,
323
+ })}# Staleness Check\n`);
324
+ });
325
+ it("reproduces returns true when the stale condition still holds", async () => {
326
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, STALE_NOW);
327
+ const f = findings.find((f) => f.check === "staleFiles" &&
328
+ f.target.kind === "lint" &&
329
+ f.target.path === "notes/staleness-check.md");
330
+ expect(f).toBeDefined();
331
+ const result = await lintAdapter.reproduces(f.identity_key, vaultRoot, adminAccess, STALE_NOW);
332
+ expect(result).toBe(true);
333
+ });
334
+ it("reproduces returns false when the condition no longer holds (different now makes doc fresh)", async () => {
335
+ // Using a "now" close to the updated date means the doc is NOT stale (< 90 days).
336
+ const freshNow = new Date(`${staleDate}T00:00:00Z`);
337
+ freshNow.setDate(freshNow.getDate() + 10); // only 10 days after update → not stale
338
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, STALE_NOW);
339
+ const f = findings.find((f) => f.check === "staleFiles" &&
340
+ f.target.kind === "lint" &&
341
+ f.target.path === "notes/staleness-check.md");
342
+ expect(f).toBeDefined();
343
+ // Now re-run reproduces with a fresh now → the stale condition no longer holds.
344
+ const result = await lintAdapter.reproduces(f.identity_key, vaultRoot, adminAccess, freshNow);
345
+ expect(result).toBe(false);
346
+ });
347
+ });
348
+ // -------------------------------------------------------------------------
349
+ // Scenario 6: positionIntegrity can emit multiple findings per path.
350
+ // Two position integrity issues for one doc → they map to the SAME identity
351
+ // (no discriminator by default). This is the current conservative stance.
352
+ // TODO: if distinct-per-issue identity is needed, add stable discriminators
353
+ // from position IDs (which are stable and available in the detail).
354
+ //
355
+ // We verify the structural correctness: the adapter emits a positionIntegrity
356
+ // finding for a doc with a position issue. Since multiple issues fold to one
357
+ // identity, the adapter emits exactly one finding for that path+check.
358
+ // -------------------------------------------------------------------------
359
+ describe("Scenario 6: same identity regardless of check detail count", () => {
360
+ beforeEach(() => {
361
+ // A doc with a dangling superseded_by reference in positions.
362
+ // position pos-1 claims superseded_by: pos-999 which doesn't exist in the
363
+ // positions array. positionIntegrity will flag this.
364
+ //
365
+ // Use the full position YAML shape that the parser expects (see
366
+ // test/witness/track-record.test.ts positionYaml helper for field names).
367
+ const positionsYaml = [
368
+ "positions:",
369
+ ' - id: "pos-1"',
370
+ ' principal: "alice"',
371
+ ' stance: "assert"',
372
+ " statement: null",
373
+ ' confidence: "medium"',
374
+ ' provenance: "direct"',
375
+ " valid_from: null",
376
+ ' superseded_by: "pos-999"',
377
+ ' created: "2025-01-01"',
378
+ " sources: []",
379
+ ].join("\n");
380
+ writeDoc(vaultRoot, "notes/position-doc.md", `---\ntitle: Position Doc\ndomain: accumulation\ncollection: notes\nstatus: canonical\nconfidence: medium\ncreated: 2025-01-01\nupdated: 2025-01-01\nupdated_by: agent:seed\nprovenance: direct\nsources: []\nsuperseded_by: null\nttl_days: null\n${positionsYaml}\n---\n# Position Doc\n`);
381
+ });
382
+ it("emits a positionIntegrity finding for the position doc", async () => {
383
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
384
+ const f = findings.find((f) => f.check === "positionIntegrity" &&
385
+ f.target.kind === "lint" &&
386
+ f.target.path === "notes/position-doc.md");
387
+ expect(f).toBeDefined();
388
+ });
389
+ it("positionIntegrity finding has a stable identity key", async () => {
390
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
391
+ const f = findings.find((f) => f.check === "positionIntegrity" &&
392
+ f.target.kind === "lint" &&
393
+ f.target.path === "notes/position-doc.md");
394
+ expect(f).toBeDefined();
395
+ const expected = deriveIdentity("lint", "positionIntegrity", {
396
+ kind: "lint",
397
+ path: "notes/position-doc.md",
398
+ });
399
+ expect(f.identity_key).toBe(expected);
400
+ });
401
+ });
402
+ // -------------------------------------------------------------------------
403
+ // Scenario 7: Registry iteration yields the lint source (R22 shape).
404
+ // -------------------------------------------------------------------------
405
+ describe("Scenario 7: SOURCE_ADAPTERS registry contains the lint adapter", () => {
406
+ it("SOURCE_ADAPTERS is a non-empty array", () => {
407
+ expect(Array.isArray(SOURCE_ADAPTERS)).toBe(true);
408
+ expect(SOURCE_ADAPTERS.length).toBeGreaterThan(0);
409
+ });
410
+ it("SOURCE_ADAPTERS contains the lintAdapter (same reference)", () => {
411
+ expect(SOURCE_ADAPTERS).toContain(lintAdapter);
412
+ });
413
+ it("every adapter in SOURCE_ADAPTERS implements the FindingSourceAdapter interface", () => {
414
+ for (const adapter of SOURCE_ADAPTERS) {
415
+ expect(typeof adapter.list).toBe("function");
416
+ expect(typeof adapter.identityOf).toBe("function");
417
+ expect(typeof adapter.fingerprintOf).toBe("function");
418
+ expect(typeof adapter.reproduces).toBe("function");
419
+ }
420
+ });
421
+ });
422
+ // -------------------------------------------------------------------------
423
+ // Scenario 8: disposition defaults, owner, history shape
424
+ // -------------------------------------------------------------------------
425
+ describe("Scenario 8: Finding shape defaults", () => {
426
+ beforeEach(() => {
427
+ writeDoc(vaultRoot, "notes/any-doc.md", `${frontmatter({ title: "Any", collection: "notes", updated: "2020-01-01" })}# Any\n`);
428
+ });
429
+ it("findings have disposition='new', owner='', history=[]", async () => {
430
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
431
+ for (const f of findings) {
432
+ expect(f.disposition).toBe("new");
433
+ expect(f.owner).toBe("");
434
+ expect(f.history).toEqual([]);
435
+ }
436
+ });
437
+ it("first_seen and last_seen are ISO 8601 strings", async () => {
438
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
439
+ for (const f of findings) {
440
+ expect(typeof f.first_seen).toBe("string");
441
+ expect(new Date(f.first_seen).toISOString()).toBe(f.first_seen);
442
+ expect(typeof f.last_seen).toBe("string");
443
+ expect(new Date(f.last_seen).toISOString()).toBe(f.last_seen);
444
+ }
445
+ });
446
+ });
447
+ // -------------------------------------------------------------------------
448
+ // Scenario 9 (C1): verbatimQuoteOverrun — two conditions fire on same doc
449
+ // → two DISTINCT Findings with distinct identity_keys and discriminators.
450
+ // Resolving/removing one finding (by its identity_key) leaves the other.
451
+ // -------------------------------------------------------------------------
452
+ describe("Scenario 9 (C1): verbatimQuoteOverrun yields two independent findings", () => {
453
+ const FIXED_NOW = new Date("2026-01-01T00:00:00Z");
454
+ beforeEach(() => {
455
+ // Trigger BOTH verbatimQuoteOverrun conditions:
456
+ // 1. char-overrun: totalChars > 8000 (DISTILL_NUMERIC_DEFAULTS.maxVerbatimChars)
457
+ // 2. no-attribution: provenance=synthesized, sources=[], has verbatim quotes
458
+ //
459
+ // Build a body with 8001+ chars of verbatim-quoted text.
460
+ // verbatimQuotes() matches "quoted text" and curly "quoted text" patterns.
461
+ // Use straight-double-quoted spans, each on its own line.
462
+ const oneQuote = `"${"x".repeat(200)}"`; // 202 chars per quote
463
+ const manyQuotes = Array.from({ length: 41 }, () => oneQuote).join("\n"); // 41*202=8282 chars
464
+ writeDoc(vaultRoot, "notes/verbatim-both.md", frontmatter({
465
+ title: "Verbatim Both",
466
+ collection: "notes",
467
+ provenance: "synthesized",
468
+ sources: [],
469
+ updated: "2025-01-01",
470
+ }) +
471
+ "# Verbatim Both\n\n" +
472
+ manyQuotes +
473
+ "\n");
474
+ });
475
+ it("emits exactly two verbatimQuoteOverrun findings for the doc", async () => {
476
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, FIXED_NOW);
477
+ const vqFindings = findings.filter((f) => f.check === "verbatimQuoteOverrun" &&
478
+ f.target.kind === "lint" &&
479
+ f.target.path === "notes/verbatim-both.md");
480
+ expect(vqFindings.length).toBe(2);
481
+ });
482
+ it("the two findings have distinct identity_keys", async () => {
483
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, FIXED_NOW);
484
+ const vqFindings = findings.filter((f) => f.check === "verbatimQuoteOverrun" &&
485
+ f.target.kind === "lint" &&
486
+ f.target.path === "notes/verbatim-both.md");
487
+ expect(vqFindings.length).toBe(2);
488
+ const keys = vqFindings.map((f) => f.identity_key);
489
+ expect(keys[0]).not.toBe(keys[1]);
490
+ });
491
+ it("one finding has discriminator 'char-overrun' and the other 'no-attribution'", async () => {
492
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, FIXED_NOW);
493
+ const vqFindings = findings.filter((f) => f.check === "verbatimQuoteOverrun" &&
494
+ f.target.kind === "lint" &&
495
+ f.target.path === "notes/verbatim-both.md");
496
+ const discriminators = new Set(vqFindings.map((f) => f.discriminator));
497
+ expect(discriminators).toContain("char-overrun");
498
+ expect(discriminators).toContain("no-attribution");
499
+ });
500
+ it("each finding's identity_key matches deriveIdentity with its discriminator", async () => {
501
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, FIXED_NOW);
502
+ const vqFindings = findings.filter((f) => f.check === "verbatimQuoteOverrun" &&
503
+ f.target.kind === "lint" &&
504
+ f.target.path === "notes/verbatim-both.md");
505
+ for (const f of vqFindings) {
506
+ const expected = deriveIdentity("lint", "verbatimQuoteOverrun", f.target, f.discriminator);
507
+ expect(f.identity_key).toBe(expected);
508
+ }
509
+ });
510
+ it("removing one finding by identity_key leaves the other intact", async () => {
511
+ const findings = await lintAdapter.list(vaultRoot, adminAccess, FIXED_NOW);
512
+ const vqFindings = findings.filter((f) => f.check === "verbatimQuoteOverrun" &&
513
+ f.target.kind === "lint" &&
514
+ f.target.path === "notes/verbatim-both.md");
515
+ expect(vqFindings.length).toBe(2);
516
+ // Simulate "resolving" the char-overrun finding (filter it out).
517
+ const charOverrunKey = vqFindings.find((f) => f.discriminator === "char-overrun")?.identity_key;
518
+ const noAttrKey = vqFindings.find((f) => f.discriminator === "no-attribution")?.identity_key;
519
+ expect(charOverrunKey).toBeDefined();
520
+ expect(noAttrKey).toBeDefined();
521
+ // After removing the char-overrun finding, the no-attribution one is still present.
522
+ const remaining = findings.filter((f) => f.identity_key !== charOverrunKey);
523
+ expect(remaining.some((f) => f.identity_key === noAttrKey)).toBe(true);
524
+ // After removing the no-attribution finding, the char-overrun one is still present.
525
+ const remaining2 = findings.filter((f) => f.identity_key !== noAttrKey);
526
+ expect(remaining2.some((f) => f.identity_key === charOverrunKey)).toBe(true);
527
+ });
528
+ });
529
+ // -------------------------------------------------------------------------
530
+ // Scenario 10 (I1): malformedPins — two malformed describes entries on the
531
+ // same doc → two DISTINCT Findings with distinct identity_keys.
532
+ // -------------------------------------------------------------------------
533
+ describe("Scenario 10 (I1): malformedPins yields distinct findings per malformed entry", () => {
534
+ beforeEach(() => {
535
+ // Two malformed pin entries: pin suffix end < start.
536
+ // Format: "repo:path#L<start>-<end>@<sha>" (no brackets — see describes.ts PIN_SUFFIX)
537
+ // SHA must be 7-40 lowercase hex chars.
538
+ const sha = "a".repeat(40);
539
+ writeDoc(vaultRoot, "notes/malformed-pins-doc.md", `${frontmatter({
540
+ title: "Malformed Pins",
541
+ collection: "notes",
542
+ updated: "2025-01-01",
543
+ describes: [
544
+ // end (5) < start (10) → malformed
545
+ `myrepo:src/foo.ts#L10-5@${sha}`,
546
+ // end (3) < start (20) → malformed (different entry)
547
+ `myrepo:src/bar.ts#L20-3@${sha}`,
548
+ ],
549
+ })}# Malformed Pins\n`);
550
+ });
551
+ it("emits exactly two malformedPins findings for the doc", async () => {
552
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
553
+ const mpFindings = findings.filter((f) => f.check === "malformedPins" &&
554
+ f.target.kind === "lint" &&
555
+ f.target.path === "notes/malformed-pins-doc.md");
556
+ expect(mpFindings.length).toBe(2);
557
+ });
558
+ it("the two malformedPins findings have distinct identity_keys", async () => {
559
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
560
+ const mpFindings = findings.filter((f) => f.check === "malformedPins" &&
561
+ f.target.kind === "lint" &&
562
+ f.target.path === "notes/malformed-pins-doc.md");
563
+ expect(mpFindings.length).toBe(2);
564
+ expect(mpFindings[0].identity_key).not.toBe(mpFindings[1].identity_key);
565
+ });
566
+ it("each malformedPins finding has a discriminator derived from its describes entry", async () => {
567
+ const findings = await lintAdapter.list(vaultRoot, adminAccess);
568
+ const mpFindings = findings.filter((f) => f.check === "malformedPins" &&
569
+ f.target.kind === "lint" &&
570
+ f.target.path === "notes/malformed-pins-doc.md");
571
+ for (const f of mpFindings) {
572
+ expect(typeof f.discriminator).toBe("string");
573
+ expect(f.discriminator.length).toBeGreaterThan(0);
574
+ }
575
+ // The two discriminators must differ.
576
+ expect(mpFindings[0].discriminator).not.toBe(mpFindings[1].discriminator);
577
+ });
578
+ });
579
+ // -------------------------------------------------------------------------
580
+ // Scenario 11 (I3): FindingSourceAdapter interface carries now parameter.
581
+ // A FindingSourceAdapter-typed variable accepts lintAdapter and can call
582
+ // list/reproduces with now injected — confirming the engine can inject now
583
+ // through the interface type without requiring an intersection-type hack.
584
+ // -------------------------------------------------------------------------
585
+ describe("Scenario 11 (I3): FindingSourceAdapter interface supports now injection", () => {
586
+ beforeEach(() => {
587
+ writeDoc(vaultRoot, "notes/interface-check.md", frontmatter({ title: "Interface Check", collection: "notes", updated: "2020-01-01" }) +
588
+ "# Interface Check\n");
589
+ });
590
+ it("lintAdapter is assignable to FindingSourceAdapter (no intersection hack needed)", () => {
591
+ // If lintAdapter required an intersection type to carry now, this
592
+ // assignment would fail at the TypeScript level. The fact that this test
593
+ // file compiles confirms the interface itself carries now.
594
+ const adapter = lintAdapter;
595
+ expect(typeof adapter.list).toBe("function");
596
+ expect(typeof adapter.reproduces).toBe("function");
597
+ });
598
+ it("engine can inject now via FindingSourceAdapter interface", async () => {
599
+ const adapter = lintAdapter;
600
+ const FIXED_NOW = new Date("2026-01-01T00:00:00Z");
601
+ // Call list with now through the interface type — this would be a type
602
+ // error if FindingSourceAdapter.list didn't carry now?.
603
+ const findings = await adapter.list(vaultRoot, adminAccess, FIXED_NOW);
604
+ // We just care that the call compiles and returns an array.
605
+ expect(Array.isArray(findings)).toBe(true);
606
+ });
607
+ it("engine can inject now via reproduces through the interface", async () => {
608
+ const adapter = lintAdapter;
609
+ const FIXED_NOW = new Date("2026-01-01T00:00:00Z");
610
+ // reproduces called through the interface with now — type-level proof.
611
+ const result = await adapter.reproduces("nonexistent-key", vaultRoot, adminAccess, FIXED_NOW);
612
+ expect(result).toBe(false);
613
+ });
614
+ });
615
+ });
616
+ //# sourceMappingURL=lint.test.js.map