@v11g/agents-rock 1.0.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 (223) hide show
  1. package/README.md +65 -0
  2. package/bin/agents-rock.mjs +4 -0
  3. package/package.json +13 -0
  4. package/plugins/solution-architect/.claude-plugin/plugin.json +9 -0
  5. package/plugins/solution-architect/skills/analyze-requirements/README.md +75 -0
  6. package/plugins/solution-architect/skills/analyze-requirements/SKILL.md +31 -0
  7. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/OFL.txt +98 -0
  8. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
  9. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-mono-latin-600-normal.woff2 +0 -0
  10. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-sans-latin-400-normal.woff2 +0 -0
  11. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-sans-latin-500-normal.woff2 +0 -0
  12. package/plugins/solution-architect/skills/analyze-requirements/assets/fonts/ibm-plex-sans-latin-600-normal.woff2 +0 -0
  13. package/plugins/solution-architect/skills/analyze-requirements/assets/mermaid-theme.json +52 -0
  14. package/plugins/solution-architect/skills/analyze-requirements/assets/section-help.json +101 -0
  15. package/plugins/solution-architect/skills/analyze-requirements/assets/viewer-template.html +2389 -0
  16. package/plugins/solution-architect/skills/analyze-requirements/references/interview.md +53 -0
  17. package/plugins/solution-architect/skills/analyze-requirements/references/likec4.md +157 -0
  18. package/plugins/solution-architect/skills/analyze-requirements/references/project-types.md +60 -0
  19. package/plugins/solution-architect/skills/analyze-requirements/references/research.md +78 -0
  20. package/plugins/solution-architect/skills/analyze-requirements/references/viewer.md +772 -0
  21. package/plugins/solution-architect/skills/analyze-requirements/references/writing.md +206 -0
  22. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/cdp.mjs +74 -0
  23. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/chrome.mjs +66 -0
  24. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/companion-links.mjs +20 -0
  25. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-kinds.mjs +37 -0
  26. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-links.mjs +26 -0
  27. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-routes.mjs +27 -0
  28. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-sections.mjs +78 -0
  29. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/embed.mjs +8 -0
  30. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/er-entities.mjs +16 -0
  31. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/fonts.mjs +39 -0
  32. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/frontmatter.mjs +17 -0
  33. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/inputs.mjs +41 -0
  34. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/likec4-config.mjs +41 -0
  35. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/likec4-extract.mjs +29 -0
  36. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/likec4-steps.mjs +22 -0
  37. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-defs.mjs +20 -0
  38. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-flows.mjs +46 -0
  39. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-inline.mjs +31 -0
  40. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-links.mjs +7 -0
  41. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-list.mjs +64 -0
  42. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-render.mjs +127 -0
  43. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-shape.mjs +19 -0
  44. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-tables.mjs +30 -0
  45. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-views.mjs +48 -0
  46. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-wide.mjs +44 -0
  47. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/nav.mjs +72 -0
  48. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/offline.mjs +19 -0
  49. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/port.mjs +13 -0
  50. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/quality-gate.mjs +113 -0
  51. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/section-help.mjs +49 -0
  52. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/slug-registry.mjs +11 -0
  53. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-clusters.mjs +15 -0
  54. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-deployment.mjs +8 -0
  55. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-elections.mjs +20 -0
  56. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-links.mjs +23 -0
  57. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-model-tables.mjs +24 -0
  58. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-palette.mjs +34 -0
  59. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-provenance.mjs +20 -0
  60. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-tree.mjs +16 -0
  61. package/plugins/solution-architect/skills/analyze-requirements/scripts/likec4-config.mjs +19 -0
  62. package/plugins/solution-architect/skills/analyze-requirements/scripts/likec4-export.mjs +35 -0
  63. package/plugins/solution-architect/skills/analyze-requirements/scripts/likec4-gen.mjs +39 -0
  64. package/plugins/solution-architect/skills/analyze-requirements/scripts/render.mjs +130 -0
  65. package/plugins/solution-architect/skills/analyze-requirements/scripts/serve.mjs +71 -0
  66. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/browser.test.mjs +553 -0
  67. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/companion-links.test.mjs +60 -0
  68. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-kinds.test.mjs +41 -0
  69. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-links.test.mjs +104 -0
  70. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-routes.test.mjs +54 -0
  71. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-sections.test.mjs +197 -0
  72. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/embed.test.mjs +28 -0
  73. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/er-entities.test.mjs +14 -0
  74. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/ARCHITECTURE.md +47 -0
  75. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/c4-src/broken/model.c4 +27 -0
  76. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/c4-src/pass/model.c4 +29 -0
  77. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/docs/adr/0001-sample.md +18 -0
  78. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/docs/estimate.html +2 -0
  79. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/docs/estimation.md +8 -0
  80. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/model-broken.json +1 -0
  81. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/model.json +1 -0
  82. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/docs-pass/threat-model.md +8 -0
  83. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/sample-model.json +1 -0
  84. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fixtures/sample.c4 +28 -0
  85. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/fonts.test.mjs +38 -0
  86. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/frontmatter.test.mjs +27 -0
  87. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/inputs.test.mjs +72 -0
  88. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-config-cli.test.mjs +26 -0
  89. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-config.test.mjs +74 -0
  90. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-export-cli.test.mjs +61 -0
  91. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-extract.test.mjs +37 -0
  92. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-gen-cli.test.mjs +73 -0
  93. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/likec4-steps.test.mjs +32 -0
  94. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-flows.test.mjs +82 -0
  95. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-links.test.mjs +16 -0
  96. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-provenance.test.mjs +42 -0
  97. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-render.test.mjs +226 -0
  98. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-tables.test.mjs +30 -0
  99. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-views.test.mjs +76 -0
  100. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-wide.test.mjs +76 -0
  101. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/nav.test.mjs +236 -0
  102. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/offline.test.mjs +37 -0
  103. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/quality-gate.test.mjs +86 -0
  104. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/quality-gates.test.mjs +20 -0
  105. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/render.test.mjs +171 -0
  106. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/research-workflow.test.mjs +38 -0
  107. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/section-help.test.mjs +101 -0
  108. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/serve.test.mjs +48 -0
  109. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-clusters.test.mjs +46 -0
  110. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-deployment.test.mjs +23 -0
  111. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-elections.test.mjs +30 -0
  112. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-links.test.mjs +38 -0
  113. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-model-tables.test.mjs +51 -0
  114. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-provenance.test.mjs +28 -0
  115. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-tree.test.mjs +43 -0
  116. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/viewer-template.test.mjs +1206 -0
  117. package/plugins/solution-architect/skills/analyze-requirements/scripts/validate.mjs +88 -0
  118. package/plugins/solution-architect/skills/analyze-requirements/workflows/research.js +57 -0
  119. package/plugins/solution-architect/skills/estimate/README.md +67 -0
  120. package/plugins/solution-architect/skills/estimate/SKILL.md +64 -0
  121. package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +1128 -0
  122. package/plugins/solution-architect/skills/estimate/references/ai-multipliers.md +95 -0
  123. package/plugins/solution-architect/skills/estimate/references/interview.md +80 -0
  124. package/plugins/solution-architect/skills/estimate/references/slicing.md +55 -0
  125. package/plugins/solution-architect/skills/estimate/references/techniques.md +111 -0
  126. package/plugins/solution-architect/skills/estimate/references/writing.md +211 -0
  127. package/plugins/solution-architect/skills/estimate/scripts/compute.mjs +23 -0
  128. package/plugins/solution-architect/skills/estimate/scripts/lib/checks.mjs +128 -0
  129. package/plugins/solution-architect/skills/estimate/scripts/lib/components.mjs +19 -0
  130. package/plugins/solution-architect/skills/estimate/scripts/lib/estimate-math.mjs +85 -0
  131. package/plugins/solution-architect/skills/estimate/scripts/lib/inline.mjs +10 -0
  132. package/plugins/solution-architect/skills/estimate/scripts/lib/redact.mjs +30 -0
  133. package/plugins/solution-architect/skills/estimate/scripts/lib/roadmap.mjs +32 -0
  134. package/plugins/solution-architect/skills/estimate/scripts/lib/rollup.mjs +122 -0
  135. package/plugins/solution-architect/skills/estimate/scripts/lib/schema.mjs +128 -0
  136. package/plugins/solution-architect/skills/estimate/scripts/render.mjs +65 -0
  137. package/plugins/solution-architect/skills/estimate/scripts/test/browser.test.mjs +623 -0
  138. package/plugins/solution-architect/skills/estimate/scripts/test/compute.test.mjs +88 -0
  139. package/plugins/solution-architect/skills/estimate/scripts/test/e2e.test.mjs +34 -0
  140. package/plugins/solution-architect/skills/estimate/scripts/test/estimate-math.test.mjs +112 -0
  141. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/booking-inputs.json +58 -0
  142. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-fail.md +30 -0
  143. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-pass.md +60 -0
  144. package/plugins/solution-architect/skills/estimate/scripts/test/quality-gates.test.mjs +20 -0
  145. package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +71 -0
  146. package/plugins/solution-architect/skills/estimate/scripts/test/render.test.mjs +121 -0
  147. package/plugins/solution-architect/skills/estimate/scripts/test/schema.test.mjs +129 -0
  148. package/plugins/solution-architect/skills/estimate/scripts/test/validate.test.mjs +72 -0
  149. package/plugins/solution-architect/skills/estimate/scripts/validate.mjs +20 -0
  150. package/plugins/solution-architect/skills/new-lead/README.md +48 -0
  151. package/plugins/solution-architect/skills/new-lead/SKILL.md +113 -0
  152. package/plugins/solution-architect/skills/new-lead/assets/dashboard/detail.html +842 -0
  153. package/plugins/solution-architect/skills/new-lead/assets/dashboard/index.html +655 -0
  154. package/plugins/solution-architect/skills/new-lead/assets/dashboard/start.sh +3 -0
  155. package/plugins/solution-architect/skills/new-lead/assets/dashboard/stats.mjs +98 -0
  156. package/plugins/solution-architect/skills/new-lead/assets/dashboard/vendor/reactflow-bundle.js +473 -0
  157. package/plugins/solution-architect/skills/new-lead/assets/vendor-build/entry.jsx +33 -0
  158. package/plugins/solution-architect/skills/new-lead/assets/vendor-build/package-lock.json +1055 -0
  159. package/plugins/solution-architect/skills/new-lead/assets/vendor-build/package.json +19 -0
  160. package/plugins/solution-architect/skills/new-lead/scripts/init-root.mjs +73 -0
  161. package/plugins/solution-architect/skills/new-lead/scripts/lead-upsert.mjs +31 -0
  162. package/plugins/solution-architect/skills/new-lead/scripts/lib/enrich.mjs +20 -0
  163. package/plugins/solution-architect/skills/new-lead/scripts/lib/map-nodes.mjs +124 -0
  164. package/plugins/solution-architect/skills/new-lead/scripts/lib/map.mjs +117 -0
  165. package/plugins/solution-architect/skills/new-lead/scripts/lib/port.mjs +15 -0
  166. package/plugins/solution-architect/skills/new-lead/scripts/lib/registry.mjs +116 -0
  167. package/plugins/solution-architect/skills/new-lead/scripts/serve.mjs +163 -0
  168. package/plugins/solution-architect/skills/new-lead/scripts/test/e2e-workspace.test.mjs +59 -0
  169. package/plugins/solution-architect/skills/new-lead/scripts/test/enrich.test.mjs +16 -0
  170. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/ARCHITECTURE.md +16 -0
  171. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/brief.md +4 -0
  172. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/dist/index.html +11 -0
  173. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/dist/proposal-non-tech.html +2 -0
  174. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/dist/threat-model.html +2 -0
  175. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/estimation-inputs.json +6 -0
  176. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/estimation.json +10 -0
  177. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/notes.md +3 -0
  178. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/proposal-non-tech.md +3 -0
  179. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads/acme-crm/rfp.md +3 -0
  180. package/plugins/solution-architect/skills/new-lead/scripts/test/fixtures/root/leads.json +25 -0
  181. package/plugins/solution-architect/skills/new-lead/scripts/test/init-root.test.mjs +81 -0
  182. package/plugins/solution-architect/skills/new-lead/scripts/test/lead-upsert.test.mjs +67 -0
  183. package/plugins/solution-architect/skills/new-lead/scripts/test/map.test.mjs +72 -0
  184. package/plugins/solution-architect/skills/new-lead/scripts/test/port.test.mjs +31 -0
  185. package/plugins/solution-architect/skills/new-lead/scripts/test/registry-io.test.mjs +57 -0
  186. package/plugins/solution-architect/skills/new-lead/scripts/test/registry.test.mjs +49 -0
  187. package/plugins/solution-architect/skills/new-lead/scripts/test/serve.test.mjs +205 -0
  188. package/plugins/solution-architect/skills/new-lead/scripts/test/stats.test.mjs +92 -0
  189. package/plugins/solution-architect/skills/new-lead/scripts/test/validate-cli.test.mjs +24 -0
  190. package/plugins/solution-architect/skills/new-lead/scripts/test/vendor-bundle.test.mjs +9 -0
  191. package/plugins/solution-architect/skills/new-lead/scripts/validate.mjs +9 -0
  192. package/plugins/solution-architect/skills/proposal/README.md +36 -0
  193. package/plugins/solution-architect/skills/proposal/SKILL.md +58 -0
  194. package/plugins/solution-architect/skills/proposal/assets/proposal-template.html +82 -0
  195. package/plugins/solution-architect/skills/proposal/references/interview.md +63 -0
  196. package/plugins/solution-architect/skills/proposal/references/review.md +28 -0
  197. package/plugins/solution-architect/skills/proposal/references/writing.md +102 -0
  198. package/plugins/solution-architect/skills/proposal/scripts/derive.mjs +22 -0
  199. package/plugins/solution-architect/skills/proposal/scripts/lib/checks-client.mjs +75 -0
  200. package/plugins/solution-architect/skills/proposal/scripts/lib/checks-doc.mjs +54 -0
  201. package/plugins/solution-architect/skills/proposal/scripts/lib/checks.mjs +17 -0
  202. package/plugins/solution-architect/skills/proposal/scripts/lib/figures.mjs +43 -0
  203. package/plugins/solution-architect/skills/proposal/scripts/lib/jargon.mjs +9 -0
  204. package/plugins/solution-architect/skills/proposal/scripts/lib/sections.mjs +32 -0
  205. package/plugins/solution-architect/skills/proposal/scripts/render.mjs +60 -0
  206. package/plugins/solution-architect/skills/proposal/scripts/test/checks-client.test.mjs +144 -0
  207. package/plugins/solution-architect/skills/proposal/scripts/test/checks-doc.test.mjs +93 -0
  208. package/plugins/solution-architect/skills/proposal/scripts/test/docs.test.mjs +51 -0
  209. package/plugins/solution-architect/skills/proposal/scripts/test/e2e.test.mjs +30 -0
  210. package/plugins/solution-architect/skills/proposal/scripts/test/figures.test.mjs +81 -0
  211. package/plugins/solution-architect/skills/proposal/scripts/test/fixtures/proposal-fail.md +22 -0
  212. package/plugins/solution-architect/skills/proposal/scripts/test/fixtures/proposal-pass.md +55 -0
  213. package/plugins/solution-architect/skills/proposal/scripts/test/quality-gates.test.mjs +20 -0
  214. package/plugins/solution-architect/skills/proposal/scripts/test/render.test.mjs +70 -0
  215. package/plugins/solution-architect/skills/proposal/scripts/test/validate.test.mjs +40 -0
  216. package/plugins/solution-architect/skills/proposal/scripts/validate.mjs +20 -0
  217. package/src/cli/agents.mjs +12 -0
  218. package/src/cli/args.mjs +46 -0
  219. package/src/cli/install.mjs +68 -0
  220. package/src/cli/main.mjs +124 -0
  221. package/src/cli/picker.mjs +78 -0
  222. package/src/cli/registry.mjs +26 -0
  223. package/src/cli/uninstall.mjs +38 -0
@@ -0,0 +1,59 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { execFile } from 'node:child_process';
4
+ import { promisify } from 'node:util';
5
+ import { mkdtemp, cp } from 'node:fs/promises';
6
+ import { existsSync } from 'node:fs';
7
+ import { tmpdir } from 'node:os';
8
+ import { join } from 'node:path';
9
+ import { initRoot } from '../init-root.mjs';
10
+ import { findLeadsRoot } from '../lib/registry.mjs';
11
+ import { startServer } from '../serve.mjs';
12
+ const run = promisify(execFile);
13
+ const UPSERT = new URL('../lead-upsert.mjs', import.meta.url).pathname;
14
+ const ASSETS = new URL('../../assets/dashboard', import.meta.url).pathname;
15
+ const FIXTURE_LEAD = new URL('./fixtures/root/leads/acme-crm', import.meta.url).pathname;
16
+
17
+ test('init -> register -> serve -> mark won, end to end', async () => {
18
+ // init a fresh root
19
+ const root = join(await mkdtemp(join(tmpdir(), 'e2e-')), 'leads');
20
+ await initRoot(root, ASSETS);
21
+ assert.ok(existsSync(join(root, 'scripts', 'serve.mjs')), 'server copied');
22
+ assert.ok(existsSync(join(root, 'scripts', 'index.html')), 'dashboard copied');
23
+ assert.equal(findLeadsRoot(join(root)), root);
24
+
25
+ // simulate the pipeline having produced a lead dir (fixture stands in for gates 1-3)
26
+ await cp(FIXTURE_LEAD, join(root, 'leads', 'acme-crm'), { recursive: true });
27
+ await run('node', [UPSERT, '--root', root, '--id', 'acme-crm',
28
+ '--patch', '{"client":"Acme","title":"CRM rebuild","created":"2026-08-07"}']);
29
+
30
+ // serve and exercise the API like the dashboard would
31
+ const server = await startServer(root, 0);
32
+ const base = `http://127.0.0.1:${server.address().port}`;
33
+ try {
34
+ const { leads } = await (await fetch(`${base}/api/leads`)).json();
35
+ assert.equal(leads[0].artifacts.docs, true);
36
+ const map = await (await fetch(`${base}/api/leads/acme-crm/map`)).json();
37
+ assert.ok(map.nodes.length > 3);
38
+ const won = await (await fetch(`${base}/api/leads/acme-crm`, {
39
+ method: 'POST', body: '{"status":"won"}',
40
+ headers: { 'content-type': 'application/json' } })).json();
41
+ assert.equal(won.status, 'won');
42
+ // both dashboard pages must actually open — every other route test here is
43
+ // negative-only, so a serveFile that 404s everything would otherwise ship clean
44
+ for (const [path, marker] of [['/', /id="stats"/], [`/detail/acme-crm`, /id="facts-dl"/]]) {
45
+ const page = await fetch(`${base}${path}`);
46
+ assert.equal(page.status, 200, `${path}: expected 200`);
47
+ assert.equal(page.headers.get('content-type'), 'text/html', `${path}: wrong content-type`);
48
+ assert.match(await page.text(), marker, `${path}: body is not the dashboard page`);
49
+ }
50
+ // the rendered dashboard must link artifacts at their real URLs, and must not
51
+ // reference the pre-layout flat paths
52
+ const home = await (await fetch(`${base}/`)).text();
53
+ assert.doesNotMatch(home, /["'`]\/\$\{id\}\/dist\//, 'card hrefs still use the flat layout');
54
+ const detail = await (await fetch(`${base}/detail/acme-crm`)).text();
55
+ assert.match(detail, /\/scripts\/vendor\//, 'detail page loads vendor from scripts/');
56
+ // refresh is a no-op at same stamp
57
+ assert.deepEqual((await initRoot(root, ASSETS)).copied, []);
58
+ } finally { server.close(); }
59
+ });
@@ -0,0 +1,16 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { enrichLead } from '../lib/enrich.mjs';
4
+
5
+ const ROOT = new URL('./fixtures/root', import.meta.url).pathname;
6
+
7
+ test('artifact flags reflect dist/ disk truth', async () => {
8
+ const e = await enrichLead(ROOT, { id: 'acme-crm' });
9
+ assert.deepEqual(e.artifacts, { docs: true, estimate: false, proposal: false });
10
+ assert.equal(e.hasBrief, true);
11
+ assert.equal(e.hasNotes, true);
12
+ });
13
+ test('missing lead dir -> all false', async () => {
14
+ const e = await enrichLead(ROOT, { id: 'ghost' });
15
+ assert.deepEqual(e.artifacts, { docs: false, estimate: false, proposal: false });
16
+ });
@@ -0,0 +1,16 @@
1
+ # Acme CRM — Architecture
2
+
3
+ ## 1. Introduction & Goals
4
+
5
+ Acme wants a rebuilt CRM to support omnichannel sales workflows.
6
+
7
+ ## 6. Core Components
8
+
9
+ | Component | Responsibility |
10
+ |---|---|
11
+ | `atlas.api` | Serves REST endpoints for the CRM backend |
12
+ | `atlas.web` | Renders the CRM web application |
13
+
14
+ ## 7. Runtime Behaviour
15
+
16
+ Requests flow from `atlas.web` to `atlas.api` over HTTPS.
@@ -0,0 +1,4 @@
1
+ # Brief
2
+
3
+ Acme wants a CRM rebuild to replace their aging spreadsheet-based sales
4
+ tracking with a proper pipeline tool that supports omnichannel sales.
@@ -0,0 +1,11 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Acme CRM — Architecture</title>
6
+ </head>
7
+ <body>
8
+ <h1>Acme CRM — Architecture</h1>
9
+ <p>Fixture arch viewer page. estimate.html and proposal.html are deliberately absent.</p>
10
+ </body>
11
+ </html>
@@ -0,0 +1,2 @@
1
+ <!doctype html>
2
+ <title>Non-technical proposal</title>
@@ -0,0 +1,6 @@
1
+ {
2
+ "scope": [
3
+ { "name": "Reporting", "provenance": "proposed" },
4
+ { "name": "Auth", "provenance": "stated" }
5
+ ]
6
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "scenarios": [
3
+ { "id": "balanced", "label": "Balanced" },
4
+ { "id": "fast", "label": "Fast" }
5
+ ],
6
+ "risks": [
7
+ { "name": "Legacy data migration" },
8
+ { "name": "SSO unknowns" }
9
+ ]
10
+ }
@@ -0,0 +1,3 @@
1
+ # Notes
2
+
3
+ Discovery call held 2026-07-05. Stakeholders confirmed omnichannel scope.
@@ -0,0 +1,3 @@
1
+ # Non-technical proposal
2
+
3
+ Plain-language companion to proposal.md.
@@ -0,0 +1,3 @@
1
+ # Acme CRM — Request for Proposal
2
+
3
+ Acme needs to replace an aging spreadsheet-based sales process.
@@ -0,0 +1,25 @@
1
+ {
2
+ "version": 1,
3
+ "leads": [
4
+ {
5
+ "id": "acme-crm",
6
+ "client": "Acme Corp",
7
+ "title": "CRM Rebuild",
8
+ "status": "active",
9
+ "created": "2026-07-01",
10
+ "closed": null,
11
+ "value": null,
12
+ "scenario": null
13
+ },
14
+ {
15
+ "id": "beta-shop",
16
+ "client": "Beta Shop",
17
+ "title": "Storefront Platform",
18
+ "status": "won",
19
+ "created": "2026-06-01",
20
+ "closed": "2026-07-15",
21
+ "value": { "low": 40000, "high": 60000, "currency": "USD" },
22
+ "scenario": "2eng-max5x"
23
+ }
24
+ ]
25
+ }
@@ -0,0 +1,81 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { mkdtemp, mkdir, writeFile, readFile } from 'node:fs/promises';
4
+ import { existsSync } from 'node:fs';
5
+ import { execFileSync } from 'node:child_process';
6
+ import { tmpdir } from 'node:os';
7
+ import { join } from 'node:path';
8
+ import { initRoot, stampOf, ASSET_FILES, SCRIPT_FILES } from '../init-root.mjs';
9
+
10
+ // The real shipped assets/scripts, not a synthetic stand-in: the stamp mechanism can
11
+ // only be checked against the files it actually has to refresh.
12
+ const REAL_ASSETS = new URL('../../assets/dashboard', import.meta.url).pathname;
13
+ const REAL_SCRIPTS = new URL('..', import.meta.url).pathname;
14
+ const ALL_FILES = [...ASSET_FILES, ...SCRIPT_FILES].map((f) => f.to);
15
+
16
+ const makeAssets = async (stamp) => {
17
+ const dir = await mkdtemp(join(tmpdir(), 'assets-'));
18
+ await mkdir(join(dir, 'vendor'), { recursive: true });
19
+ await writeFile(join(dir, 'index.html'), `<!-- new-lead-dashboard v${stamp} -->\n<p>d</p>`);
20
+ await writeFile(join(dir, 'start.sh'), `# new-lead-dashboard v${stamp}\nnode scripts/serve.mjs "$@"\n`);
21
+ return dir;
22
+ };
23
+
24
+ test('creates the leads/ + scripts/ tree with start.sh alone at the root', async () => {
25
+ const root = join(await mkdtemp(join(tmpdir(), 'r-')), 'leads');
26
+ const res = await initRoot(root, await makeAssets(1));
27
+ assert.equal(res.created, true);
28
+ assert.deepEqual(JSON.parse(await readFile(join(root, 'leads.json'), 'utf8')),
29
+ { version: 1, leads: [] });
30
+ assert.ok(existsSync(join(root, 'leads')), 'leads/ directory created');
31
+ assert.ok(existsSync(join(root, 'scripts', 'index.html')), 'dashboard under scripts/');
32
+ assert.ok(existsSync(join(root, 'start.sh')), 'start.sh at the root');
33
+ assert.ok(!existsSync(join(root, 'index.html')), 'nothing left at the old flat path');
34
+ assert.ok(res.copied.includes('scripts/index.html'));
35
+ });
36
+ test('start.sh launches the server from its new home under scripts/', async () => {
37
+ const root = join(await mkdtemp(join(tmpdir(), 'r-')), 'leads');
38
+ await initRoot(root, REAL_ASSETS);
39
+ assert.match(await readFile(join(root, 'start.sh'), 'utf8'), /node scripts\/serve\.mjs/);
40
+ });
41
+ test('refresh copies only newer-stamped files, keeps registry', async () => {
42
+ const root = join(await mkdtemp(join(tmpdir(), 'r-')), 'leads');
43
+ await initRoot(root, await makeAssets(2));
44
+ const first = await initRoot(root, await makeAssets(2)); // same stamp
45
+ assert.equal(first.created, false);
46
+ assert.deepEqual(first.copied, []);
47
+ const second = await initRoot(root, await makeAssets(3)); // newer
48
+ assert.ok(second.copied.includes('scripts/index.html'));
49
+ });
50
+ test('every file init-root copies carries a stamp init-root can actually read', async () => {
51
+ const sources = [...ASSET_FILES.map((f) => join(REAL_ASSETS, f.from)),
52
+ ...SCRIPT_FILES.map((f) => join(REAL_SCRIPTS, f.from))];
53
+ assert.equal(sources.length, 13, 'the copied set changed size — update this count deliberately');
54
+ for (const src of sources) {
55
+ assert.ok(await stampOf(src) >= 1, `${src}: stamp is invisible to stampOf, so it never refreshes`);
56
+ }
57
+ });
58
+ test('a fresh root copies the whole set, and a same-stamp refresh copies none', async () => {
59
+ const root = join(await mkdtemp(join(tmpdir(), 'r-')), 'leads');
60
+ const first = await initRoot(root, REAL_ASSETS);
61
+ assert.deepEqual([...first.copied].sort(), [...ALL_FILES].sort());
62
+ for (const rel of ALL_FILES) assert.ok(await stampOf(join(root, rel)) >= 1, `${rel}: unstamped in root`);
63
+ assert.deepEqual((await initRoot(root, REAL_ASSETS)).copied, []);
64
+ });
65
+ test('a fresh root can run every script SKILL.md tells a user to run', async () => {
66
+ const root = join(await mkdtemp(join(tmpdir(), 'r-')), 'leads');
67
+ await initRoot(root, REAL_ASSETS);
68
+ const run = (script, ...args) => execFileSync(process.execPath, [join(root, script), ...args], { cwd: root });
69
+ run('scripts/lead-upsert.mjs', '--root', root, '--id', 'acme-lead', '--patch', '{"title":"Acme lead","created":"2026-08-13"}');
70
+ const registry = JSON.parse(await readFile(join(root, 'leads.json'), 'utf8'));
71
+ assert.equal(registry.leads[0]?.id, 'acme-lead', 'lead-upsert.mjs writes the registry');
72
+ run('scripts/validate.mjs', '--file', join(root, 'leads.json'));
73
+ });
74
+ test('missing asset files are skipped, not fatal', async () => {
75
+ const root = join(await mkdtemp(join(tmpdir(), 'r-')), 'leads');
76
+ const assets = await mkdtemp(join(tmpdir(), 'empty-'));
77
+ const res = await initRoot(root, assets);
78
+ assert.equal(res.created, true);
79
+ const assetDests = ASSET_FILES.map((f) => f.to);
80
+ assert.deepEqual(res.copied.filter(r => assetDests.includes(r)), []);
81
+ });
@@ -0,0 +1,67 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { execFile } from 'node:child_process';
4
+ import { promisify } from 'node:util';
5
+ import { mkdtemp, writeFile, readFile } from 'node:fs/promises';
6
+ import { tmpdir } from 'node:os';
7
+ import { join } from 'node:path';
8
+ const run = promisify(execFile);
9
+ const CLI = new URL('../lead-upsert.mjs', import.meta.url).pathname;
10
+
11
+ const makeRoot = async () => {
12
+ const root = await mkdtemp(join(tmpdir(), 'up-'));
13
+ await writeFile(join(root, 'leads.json'), JSON.stringify({ version: 1, leads: [] }));
14
+ return root;
15
+ };
16
+
17
+ test('insert with defaults, then merge patch', async () => {
18
+ const root = await makeRoot();
19
+ await run('node', [CLI, '--root', root, '--id', 'acme-crm',
20
+ '--patch', '{"client":"Acme","title":"CRM","created":"2026-08-07"}']);
21
+ await run('node', [CLI, '--root', root, '--id', 'acme-crm',
22
+ '--patch', '{"value":{"low":1,"high":2,"currency":"USD"},"scenario":"balanced"}']);
23
+ const reg = JSON.parse(await readFile(join(root, 'leads.json'), 'utf8'));
24
+ assert.equal(reg.leads.length, 1);
25
+ assert.equal(reg.leads[0].client, 'Acme');
26
+ assert.equal(reg.leads[0].scenario, 'balanced');
27
+ assert.equal(reg.leads[0].status, 'active');
28
+ });
29
+ test('invalid merge rejected, registry untouched', async () => {
30
+ const root = await makeRoot();
31
+ await assert.rejects(
32
+ () => run('node', [CLI, '--root', root, '--id', 'acme-crm', '--patch', '{"status":"open"}']),
33
+ (err) => err.code === 1 && /status/.test(err.stdout + err.stderr));
34
+ const reg = JSON.parse(await readFile(join(root, 'leads.json'), 'utf8'));
35
+ assert.equal(reg.leads.length, 0);
36
+ });
37
+ test('a patch omitting title is rejected at the write boundary; client defaults to null', async () => {
38
+ const root = await makeRoot();
39
+ await assert.rejects(
40
+ () => run('node', [CLI, '--root', root, '--id', 'foo-bar', '--patch', '{"created":"2026-08-07"}']),
41
+ (err) => err.code === 1 && /title/.test(err.stdout + err.stderr));
42
+ const reg = JSON.parse(await readFile(join(root, 'leads.json'), 'utf8'));
43
+ assert.equal(reg.leads.length, 0);
44
+ });
45
+ test('unrelated patch does not revert a won lead to active', async () => {
46
+ const root = await makeRoot();
47
+ await run('node', [CLI, '--root', root, '--id', 'acme-crm',
48
+ '--patch', '{"client":"Acme","title":"CRM","created":"2026-08-07"}']);
49
+ await run('node', [CLI, '--root', root, '--id', 'acme-crm',
50
+ '--patch', '{"status":"won","closed":"2026-08-10","value":{"low":1,"high":2,"currency":"USD"}}']);
51
+ await run('node', [CLI, '--root', root, '--id', 'acme-crm', '--patch', '{"title":"CRM v2"}']);
52
+ const reg = JSON.parse(await readFile(join(root, 'leads.json'), 'utf8'));
53
+ assert.equal(reg.leads[0].status, 'won');
54
+ assert.equal(reg.leads[0].closed, '2026-08-10');
55
+ assert.deepEqual(reg.leads[0].value, { low: 1, high: 2, currency: 'USD' });
56
+ assert.equal(reg.leads[0].title, 'CRM v2');
57
+ });
58
+ test('patch id key cannot spoof the target lead id', async () => {
59
+ const root = await makeRoot();
60
+ await run('node', [CLI, '--root', root, '--id', 'acme-crm',
61
+ '--patch', '{"id":"bar-baz","client":"Acme","title":"CRM","created":"2026-08-07"}']);
62
+ await run('node', [CLI, '--root', root, '--id', 'acme-crm', '--patch', '{"title":"CRM v2"}']);
63
+ const reg = JSON.parse(await readFile(join(root, 'leads.json'), 'utf8'));
64
+ assert.equal(reg.leads.length, 1);
65
+ assert.equal(reg.leads[0].id, 'acme-crm');
66
+ assert.equal(reg.leads[0].title, 'CRM v2');
67
+ });
@@ -0,0 +1,72 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { buildLeadMap } from '../lib/map.mjs';
4
+
5
+ const ROOT = new URL('./fixtures/root', import.meta.url).pathname;
6
+ const byId = (m, id) => m.nodes.find(n => n.id === id);
7
+
8
+ test('no interview node; evidence feeds architecture directly', async () => {
9
+ const m = await buildLeadMap(ROOT, 'acme-crm');
10
+ assert.equal(byId(m, 'interview'), undefined, 'the interview node is gone');
11
+ assert.equal(byId(m, 'arch').data.status, 'ready');
12
+ assert.equal(byId(m, 'arch').data.href, '/leads/acme-crm/dist/index.html');
13
+ assert.equal(byId(m, 'estimate').data.status, 'ready'); // estimation.json exists
14
+ assert.equal(byId(m, 'estimate').data.href, null); // estimate.html absent
15
+ assert.equal(byId(m, 'proposal').data.status, 'pending');
16
+ const evidence = m.nodes.filter((n) => n.type === 'evidence');
17
+ assert.ok(evidence.length > 0, 'evidence nodes exist');
18
+ assert.ok(m.edges.some((e) => e.source === evidence[0].id && e.target === 'arch'),
19
+ 'evidence links straight to architecture');
20
+ });
21
+ test('evidence is the human-dropped files, never the generated artifacts', async () => {
22
+ const m = await buildLeadMap(ROOT, 'acme-crm');
23
+ const labels = m.nodes.filter((n) => n.type === 'evidence').map((n) => n.data.label);
24
+ assert.deepEqual(labels, ['rfp.md']);
25
+ for (const generated of ['ARCHITECTURE.md', 'estimation.json', 'brief.md', 'notes.md', 'dist']) {
26
+ assert.ok(!labels.includes(generated), `${generated} must not be listed as evidence`);
27
+ }
28
+ });
29
+ test('components parsed from ARCHITECTURE.md §6 table', async () => {
30
+ const m = await buildLeadMap(ROOT, 'acme-crm');
31
+ assert.ok(byId(m, 'component-atlas.api'));
32
+ assert.ok(byId(m, 'component-atlas.web'));
33
+ assert.ok(m.edges.some(e => e.source === 'arch' && e.target === 'component-atlas.api'));
34
+ });
35
+ test('scenario nodes from estimation.json', async () => {
36
+ const m = await buildLeadMap(ROOT, 'acme-crm');
37
+ assert.ok(byId(m, 'scenario-balanced'));
38
+ });
39
+ test('extra html pages in dist/ become clickable doc nodes', async () => {
40
+ const m = await buildLeadMap(ROOT, 'acme-crm');
41
+ const page = byId(m, 'page-threat-model.html');
42
+ assert.equal(page.data.status, 'ready');
43
+ assert.equal(page.data.href, '/leads/acme-crm/dist/threat-model.html');
44
+ assert.equal(byId(m, 'page-index.html'), undefined, 'known pages keep their own nodes');
45
+ });
46
+ test('proposal-prefixed md files are proposal nodes fed by estimate', async () => {
47
+ const m = await buildLeadMap(ROOT, 'acme-crm');
48
+ const n = byId(m, 'proposal-non-tech.md');
49
+ assert.equal(n.data.status, 'ready');
50
+ assert.equal(n.data.href, '/leads/acme-crm/dist/proposal-non-tech.html');
51
+ assert.ok(m.edges.some((e) => e.source === 'estimate' && e.target === 'proposal-non-tech.md'),
52
+ 'estimate feeds every proposal-family node');
53
+ assert.ok(!m.nodes.some((x) => x.type === 'evidence' && x.data.label === 'proposal-non-tech.md'),
54
+ 'proposal-family md is generated, not evidence');
55
+ assert.equal(byId(m, 'page-proposal-non-tech.html'), undefined, 'no duplicate generic page node');
56
+ });
57
+ test('facts panel is the registry entry, not an answers file', async () => {
58
+ const m = await buildLeadMap(ROOT, 'acme-crm');
59
+ assert.equal(m.panels.facts.client, 'Acme Corp');
60
+ assert.equal(m.panels.facts.title, 'CRM Rebuild');
61
+ assert.equal(m.panels.facts.status, 'active');
62
+ assert.equal(m.panels.facts.created, '2026-07-01');
63
+ assert.match(m.panels.brief, /Acme/);
64
+ assert.deepEqual(m.panels.risks, ['Legacy data migration', 'SSO unknowns']);
65
+ assert.deepEqual(m.panels.openQuestions, ['Reporting']);
66
+ });
67
+ test('sparse lead dir degrades to pending nodes, empty panels', async () => {
68
+ const m = await buildLeadMap(ROOT, 'ghost');
69
+ assert.equal(byId(m, 'arch').data.status, 'pending');
70
+ assert.equal(m.panels.brief, null);
71
+ assert.deepEqual(m.panels.risks, []);
72
+ });
@@ -0,0 +1,31 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import net from 'node:net';
4
+ import { mkdtemp } from 'node:fs/promises';
5
+ import { tmpdir } from 'node:os';
6
+ import { join } from 'node:path';
7
+ import { startServer } from '../serve.mjs';
8
+ import { findFreePort } from '../lib/port.mjs';
9
+
10
+ // A bare net server occupies the port; no dashboard fixture is needed, and
11
+ // startServer only realpaths its root, so an empty dir satisfies it.
12
+ const occupy = () => new Promise((ok) => {
13
+ const srv = net.createServer();
14
+ srv.listen(0, '127.0.0.1', () => ok(srv));
15
+ });
16
+
17
+ test('startServer rejects with the port number when it is already taken', { timeout: 5000 }, async () => {
18
+ const srv = await occupy();
19
+ const taken = srv.address().port;
20
+ const root = await mkdtemp(join(tmpdir(), 'srv-'));
21
+ await assert.rejects(startServer(root, taken), new RegExp(`port ${taken} in use`));
22
+ await new Promise((resolve) => srv.close(resolve));
23
+ });
24
+
25
+ test('findFreePort scans past a taken port instead of failing', { timeout: 5000 }, async () => {
26
+ const srv = await occupy();
27
+ const taken = srv.address().port;
28
+ const free = await findFreePort(taken);
29
+ assert.ok(free > taken, `expected a port above ${taken}, got ${free}`);
30
+ await new Promise((resolve) => srv.close(resolve));
31
+ });
@@ -0,0 +1,57 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { mkdtemp, mkdir, writeFile, readFile, symlink, lstat } from 'node:fs/promises';
4
+ import { existsSync } from 'node:fs';
5
+ import { tmpdir } from 'node:os';
6
+ import { join } from 'node:path';
7
+ import { findLeadsRoot, readRegistry, writeRegistry, leadDir } from '../lib/registry.mjs';
8
+
9
+ const EMPTY = { version: 1, leads: [] };
10
+ const makeRoot = async () => {
11
+ const root = await mkdtemp(join(tmpdir(), 'leads-'));
12
+ await writeFile(join(root, 'leads.json'), JSON.stringify(EMPTY));
13
+ return root;
14
+ };
15
+
16
+ test('findLeadsRoot walks up from nested dir', async () => {
17
+ const root = await makeRoot();
18
+ const nested = join(root, 'acme-crm', 'dist');
19
+ await mkdir(nested, { recursive: true });
20
+ assert.equal(findLeadsRoot(nested), root);
21
+ });
22
+ test('findLeadsRoot returns null when no marker', async () => {
23
+ const dir = await mkdtemp(join(tmpdir(), 'nomark-'));
24
+ assert.equal(findLeadsRoot(dir), null);
25
+ });
26
+ test('writeRegistry is atomic and validated', async () => {
27
+ const root = await makeRoot();
28
+ await assert.rejects(() => writeRegistry(root, { version: 9, leads: [] }), /invalid/);
29
+ const lead = { id: 'a-b', client: 'A', title: 'T', status: 'active',
30
+ created: '2026-08-07', closed: null, value: null, scenario: null };
31
+ await writeRegistry(root, { version: 1, leads: [lead] });
32
+ assert.deepEqual((await readRegistry(root)).leads[0], lead);
33
+ assert.ok(!existsSync(join(root, 'leads.json.tmp')));
34
+ assert.ok(!existsSync(join(root, 'leads.json.lock')));
35
+ });
36
+ test('writeRegistry refuses when locked', async () => {
37
+ const root = await makeRoot();
38
+ await writeFile(join(root, 'leads.json.lock'), '');
39
+ await assert.rejects(() => writeRegistry(root, EMPTY), /locked/);
40
+ });
41
+ // A symlinked temp file is followed by an ordinary write, so the registry lands on
42
+ // the target AND the rename then moves the symlink itself into place - leaving
43
+ // leads.json a permanent redirect out of the root. Same class as the notes route.
44
+ test('writeRegistry refuses to write through a symlinked temp file', async () => {
45
+ const root = await makeRoot();
46
+ const outside = join(await mkdtemp(join(tmpdir(), 'outside-')), 'victim.txt');
47
+ await writeFile(outside, 'ORIGINAL SECRET\n');
48
+ await symlink(outside, join(root, 'leads.json.tmp'));
49
+
50
+ await assert.rejects(() => writeRegistry(root, EMPTY), /symlink/i);
51
+ assert.equal(await readFile(outside, 'utf8'), 'ORIGINAL SECRET\n', 'target must be untouched');
52
+ assert.ok(!(await lstat(join(root, 'leads.json'))).isSymbolicLink(), 'registry must not become a symlink');
53
+ assert.ok(!existsSync(join(root, 'leads.json.lock')), 'lock must be released');
54
+ });
55
+ test('leadDir places a lead under the root leads/ directory', () => {
56
+ assert.equal(leadDir('/srv/pipeline', 'acme-crm'), '/srv/pipeline/leads/acme-crm');
57
+ });
@@ -0,0 +1,49 @@
1
+ // scripts/test/registry.test.mjs
2
+ import { test } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { validateRegistry } from '../lib/registry.mjs';
5
+
6
+ const lead = (over = {}) => ({
7
+ id: 'acme-crm', client: 'Acme', title: 'CRM rebuild', status: 'active',
8
+ created: '2026-08-07', closed: null, value: null, scenario: null, ...over,
9
+ });
10
+ const reg = (leads) => ({ version: 1, leads });
11
+
12
+ test('valid registry -> no findings', () => {
13
+ assert.deepEqual(validateRegistry(reg([lead()])), []);
14
+ });
15
+ test('wrong version flagged', () => {
16
+ assert.match(validateRegistry({ version: 2, leads: [] })[0], /version/);
17
+ });
18
+ test('non-array leads flagged', () => {
19
+ assert.match(validateRegistry({ version: 1, leads: {} })[0], /array/);
20
+ });
21
+ test('bad id, bad status, duplicate id flagged', () => {
22
+ const findings = validateRegistry(reg([
23
+ lead({ id: 'Bad_ID' }), lead({ status: 'open' }), lead({}),
24
+ ]));
25
+ assert.equal(findings.filter(f => /kebab-case/.test(f)).length, 1);
26
+ assert.equal(findings.filter(f => /status/.test(f)).length, 1);
27
+ assert.equal(findings.filter(f => /duplicate/.test(f)).length, 1);
28
+ });
29
+ test('closed must be null while active, date once won', () => {
30
+ assert.match(validateRegistry(reg([lead({ closed: '2026-08-08' })]))[0], /closed/);
31
+ assert.match(validateRegistry(reg([lead({ status: 'won' })]))[0], /closed/);
32
+ assert.deepEqual(validateRegistry(reg([lead({ status: 'won', closed: '2026-08-08' })])), []);
33
+ });
34
+ test('client may be null — adoption can skip the question', () => {
35
+ assert.deepEqual(validateRegistry(reg([lead({ client: null })])), []);
36
+ });
37
+ test('client rejects empty and missing; title is still hard-required', () => {
38
+ assert.match(validateRegistry(reg([lead({ client: '' })]))[0], /client/);
39
+ assert.match(validateRegistry(reg([lead({ client: undefined })]))[0], /client/);
40
+ const findings = validateRegistry(reg([lead({ title: undefined })]));
41
+ assert.equal(findings.filter(f => /title/.test(f)).length, 1);
42
+ assert.match(validateRegistry(reg([lead({ title: null })]))[0], /title/);
43
+ assert.match(validateRegistry(reg([lead({ title: '' })]))[0], /title/);
44
+ });
45
+ test('value shape checked', () => {
46
+ assert.match(validateRegistry(reg([lead({ value: { low: 5 } })]))[0], /value/);
47
+ assert.deepEqual(validateRegistry(reg([lead({ value: { low: 1, high: 2, currency: 'USD' } })])), []);
48
+ assert.match(validateRegistry(reg([lead({ value: { low: 9, high: 2, currency: 'USD' } })]))[0], /value/);
49
+ });