akm-cli 0.6.1 → 0.7.0-rc1

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 (319) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/{cli.js → src/cli.js} +620 -26
  3. package/dist/{commands → src/commands}/config-cli.js +5 -4
  4. package/dist/src/commands/distill.js +283 -0
  5. package/dist/src/commands/events.js +108 -0
  6. package/dist/src/commands/history.js +120 -0
  7. package/dist/{commands → src/commands}/installed-stashes.js +1 -1
  8. package/dist/src/commands/proposal.js +119 -0
  9. package/dist/src/commands/propose.js +171 -0
  10. package/dist/src/commands/reflect.js +193 -0
  11. package/dist/{commands → src/commands}/registry-search.js +2 -1
  12. package/dist/{commands → src/commands}/remember.js +12 -0
  13. package/dist/{commands → src/commands}/search.js +74 -1
  14. package/dist/{commands → src/commands}/self-update.js +4 -3
  15. package/dist/{commands → src/commands}/show.js +44 -0
  16. package/dist/{core → src/core}/asset-ref.js +5 -5
  17. package/dist/{core → src/core}/asset-spec.js +12 -0
  18. package/dist/{core → src/core}/common.js +1 -1
  19. package/dist/{core → src/core}/config.js +175 -121
  20. package/dist/{core → src/core}/errors.js +4 -0
  21. package/dist/src/core/events.js +239 -0
  22. package/dist/src/core/lesson-lint.js +86 -0
  23. package/dist/src/core/proposals.js +406 -0
  24. package/dist/src/core/warn.js +72 -0
  25. package/dist/{core → src/core}/write-source.js +80 -5
  26. package/dist/{indexer → src/indexer}/db-search.js +113 -24
  27. package/dist/{indexer → src/indexer}/db.js +76 -23
  28. package/dist/{indexer → src/indexer}/file-context.js +0 -3
  29. package/dist/src/indexer/graph-boost.js +179 -0
  30. package/dist/src/indexer/graph-extraction.js +212 -0
  31. package/dist/{indexer → src/indexer}/indexer.js +73 -6
  32. package/dist/src/indexer/memory-inference.js +263 -0
  33. package/dist/{indexer → src/indexer}/metadata.js +111 -3
  34. package/dist/src/integrations/agent/config.js +292 -0
  35. package/dist/src/integrations/agent/detect.js +94 -0
  36. package/dist/src/integrations/agent/index.js +17 -0
  37. package/dist/src/integrations/agent/profiles.js +65 -0
  38. package/dist/src/integrations/agent/prompts.js +167 -0
  39. package/dist/src/integrations/agent/spawn.js +221 -0
  40. package/dist/{integrations → src/integrations}/lockfile.js +0 -26
  41. package/dist/{llm → src/llm}/client.js +33 -2
  42. package/dist/src/llm/feature-gate.js +108 -0
  43. package/dist/src/llm/graph-extract.js +107 -0
  44. package/dist/src/llm/index-passes.js +35 -0
  45. package/dist/src/llm/memory-infer.js +86 -0
  46. package/dist/{output → src/output}/renderers.js +60 -1
  47. package/dist/src/output/shapes.js +516 -0
  48. package/dist/{output → src/output}/text.js +447 -4
  49. package/dist/{registry → src/registry}/build-index.js +14 -4
  50. package/dist/{registry → src/registry}/factory.js +0 -8
  51. package/dist/{registry → src/registry}/providers/static-index.js +3 -2
  52. package/dist/{registry → src/registry}/resolve.js +68 -2
  53. package/dist/{setup → src/setup}/setup.js +43 -5
  54. package/dist/{sources → src/sources}/providers/git.js +7 -15
  55. package/dist/tests/add-website-source.test.js +119 -0
  56. package/dist/tests/agent/agent-config-loader.test.js +70 -0
  57. package/dist/tests/agent/agent-config.test.js +221 -0
  58. package/dist/tests/agent/agent-detect.test.js +100 -0
  59. package/dist/tests/agent/agent-spawn.test.js +234 -0
  60. package/dist/tests/agent-output.test.js +186 -0
  61. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +103 -0
  62. package/dist/tests/architecture/agent-spawn-seam.test.js +193 -0
  63. package/dist/tests/architecture/llm-stateless-seam.test.js +112 -0
  64. package/dist/tests/asset-ref.test.js +192 -0
  65. package/dist/tests/asset-registry.test.js +103 -0
  66. package/dist/tests/asset-spec.test.js +241 -0
  67. package/dist/tests/bench/attribution.test.js +995 -0
  68. package/dist/tests/bench/cleanup-sigint.test.js +83 -0
  69. package/dist/tests/bench/cleanup.js +203 -0
  70. package/dist/tests/bench/cleanup.test.js +166 -0
  71. package/dist/tests/bench/cli.js +683 -0
  72. package/dist/tests/bench/cli.test.js +177 -0
  73. package/dist/tests/bench/compare.test.js +556 -0
  74. package/dist/tests/bench/corpus.js +314 -0
  75. package/dist/tests/bench/corpus.test.js +258 -0
  76. package/dist/tests/bench/driver.js +346 -0
  77. package/dist/tests/bench/driver.test.js +443 -0
  78. package/dist/tests/bench/evolve-metrics.js +179 -0
  79. package/dist/tests/bench/evolve-metrics.test.js +187 -0
  80. package/dist/tests/bench/evolve.js +580 -0
  81. package/dist/tests/bench/evolve.test.js +616 -0
  82. package/dist/tests/bench/failure-modes.test.js +300 -0
  83. package/dist/tests/bench/feedback-integrity.test.js +456 -0
  84. package/dist/tests/bench/leakage.test.js +125 -0
  85. package/dist/tests/bench/learning-curve.test.js +133 -0
  86. package/dist/tests/bench/metrics.js +2319 -0
  87. package/dist/tests/bench/metrics.test.js +1144 -0
  88. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +43 -0
  89. package/dist/tests/bench/report.js +1821 -0
  90. package/dist/tests/bench/report.test.js +989 -0
  91. package/dist/tests/bench/runner.js +536 -0
  92. package/dist/tests/bench/runner.test.js +958 -0
  93. package/dist/tests/bench/search-bridge.test.js +331 -0
  94. package/dist/tests/bench/tmp.js +41 -0
  95. package/dist/tests/bench/trajectory.js +116 -0
  96. package/dist/tests/bench/trajectory.test.js +127 -0
  97. package/dist/tests/bench/verifier.js +109 -0
  98. package/dist/tests/bench/verifier.test.js +118 -0
  99. package/dist/tests/bench/workflow-evaluator.js +557 -0
  100. package/dist/tests/bench/workflow-evaluator.test.js +421 -0
  101. package/dist/tests/bench/workflow-spec.js +358 -0
  102. package/dist/tests/bench/workflow-spec.test.js +363 -0
  103. package/dist/tests/bench/workflow-trace.js +438 -0
  104. package/dist/tests/bench/workflow-trace.test.js +254 -0
  105. package/dist/tests/benchmark-search-quality.js +536 -0
  106. package/dist/tests/benchmark-suite.js +1441 -0
  107. package/dist/tests/capture-cli.test.js +112 -0
  108. package/dist/tests/cli-errors.test.js +203 -0
  109. package/dist/tests/commands/events.test.js +370 -0
  110. package/dist/tests/commands/history.test.js +223 -0
  111. package/dist/tests/commands/import.test.js +103 -0
  112. package/dist/tests/commands/proposal-cli.test.js +209 -0
  113. package/dist/tests/commands/reflect-propose-cli.test.js +333 -0
  114. package/dist/tests/commands/remember.test.js +97 -0
  115. package/dist/tests/commands/scope-flags.test.js +300 -0
  116. package/dist/tests/commands/search.test.js +537 -0
  117. package/dist/tests/commands/show-indexer-parity.test.js +117 -0
  118. package/dist/tests/commands/show.test.js +294 -0
  119. package/dist/tests/common.test.js +266 -0
  120. package/dist/tests/completions.test.js +142 -0
  121. package/dist/tests/config-cli.test.js +193 -0
  122. package/dist/tests/config-llm-features.test.js +139 -0
  123. package/dist/tests/config.test.js +544 -0
  124. package/dist/tests/contracts/migration-baseline.test.js +43 -0
  125. package/dist/tests/contracts/reflect-propose-envelope.test.js +139 -0
  126. package/dist/tests/contracts/spec-helpers.js +46 -0
  127. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +228 -0
  128. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +56 -0
  129. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +34 -0
  130. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +94 -0
  131. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +39 -0
  132. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +44 -0
  133. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +47 -0
  134. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +40 -0
  135. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +58 -0
  136. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +34 -0
  137. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +75 -0
  138. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +36 -0
  139. package/dist/tests/core/write-source.test.js +366 -0
  140. package/dist/tests/curate-command.test.js +87 -0
  141. package/dist/tests/db-scoring.test.js +201 -0
  142. package/dist/tests/db.test.js +654 -0
  143. package/dist/tests/distill-cli-flag.test.js +208 -0
  144. package/dist/tests/distill.test.js +515 -0
  145. package/dist/tests/docker-install.test.js +120 -0
  146. package/dist/tests/e2e.test.js +1398 -0
  147. package/dist/tests/embedder.test.js +340 -0
  148. package/dist/tests/embedding-model-config.test.js +379 -0
  149. package/dist/tests/feedback-command.test.js +172 -0
  150. package/dist/tests/file-context.test.js +552 -0
  151. package/dist/tests/fixtures/scripts/git/summarize-diff.js +9 -0
  152. package/dist/tests/fixtures/scripts/lint/eslint-check.js +7 -0
  153. package/dist/tests/fixtures/stashes/load.js +166 -0
  154. package/dist/tests/fixtures/stashes/load.test.js +88 -0
  155. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +12 -0
  156. package/dist/tests/frontmatter.test.js +190 -0
  157. package/dist/tests/fts-field-weighting.test.js +254 -0
  158. package/dist/tests/fuzzy-search.test.js +230 -0
  159. package/dist/tests/git-provider-clone.test.js +45 -0
  160. package/dist/tests/github.test.js +161 -0
  161. package/dist/tests/graph-boost-ranking.test.js +305 -0
  162. package/dist/tests/graph-extraction.test.js +282 -0
  163. package/dist/tests/helpers/usage-events.js +8 -0
  164. package/dist/tests/index-pass-llm.test.js +161 -0
  165. package/dist/tests/indexer.test.js +559 -0
  166. package/dist/tests/info-command.test.js +166 -0
  167. package/dist/tests/init.test.js +69 -0
  168. package/dist/tests/install-script.test.js +246 -0
  169. package/dist/tests/integration/agent-real-profile.test.js +94 -0
  170. package/dist/tests/issue-36-repro.test.js +304 -0
  171. package/dist/tests/issues-191-194.test.js +160 -0
  172. package/dist/tests/lesson-lint.test.js +111 -0
  173. package/dist/tests/llm-client.test.js +115 -0
  174. package/dist/tests/llm-feature-gate.test.js +151 -0
  175. package/dist/tests/llm.test.js +139 -0
  176. package/dist/tests/lockfile.test.js +216 -0
  177. package/dist/tests/manifest.test.js +205 -0
  178. package/dist/tests/markdown.test.js +126 -0
  179. package/dist/tests/matchers-unit.test.js +189 -0
  180. package/dist/tests/memory-inference.test.js +299 -0
  181. package/dist/tests/merge-scoring.test.js +136 -0
  182. package/dist/tests/metadata.test.js +313 -0
  183. package/dist/tests/migration-help.test.js +89 -0
  184. package/dist/tests/origin-resolve.test.js +124 -0
  185. package/dist/tests/output-baseline.test.js +217 -0
  186. package/dist/tests/output-shapes-unit.test.js +476 -0
  187. package/dist/tests/parallel-search.test.js +272 -0
  188. package/dist/tests/parameter-metadata.test.js +365 -0
  189. package/dist/tests/paths.test.js +177 -0
  190. package/dist/tests/progressive-disclosure.test.js +280 -0
  191. package/dist/tests/proposals.test.js +279 -0
  192. package/dist/tests/proposed-quality.test.js +271 -0
  193. package/dist/tests/provider-registry.test.js +32 -0
  194. package/dist/tests/ranking-regression.test.js +548 -0
  195. package/dist/tests/reflect-propose.test.js +455 -0
  196. package/dist/tests/registry-build-index.test.js +378 -0
  197. package/dist/tests/registry-cli.test.js +290 -0
  198. package/dist/tests/registry-index-v2.test.js +430 -0
  199. package/dist/tests/registry-install.test.js +728 -0
  200. package/dist/tests/registry-providers/parity.test.js +189 -0
  201. package/dist/tests/registry-providers/skills-sh.test.js +309 -0
  202. package/dist/tests/registry-providers/static-index.test.js +204 -0
  203. package/dist/tests/registry-resolve.test.js +126 -0
  204. package/dist/tests/registry-search.test.js +723 -0
  205. package/dist/tests/remember-frontmatter.test.js +380 -0
  206. package/dist/tests/remember-unit.test.js +123 -0
  207. package/dist/tests/ripgrep-install.test.js +251 -0
  208. package/dist/tests/ripgrep-resolve.test.js +108 -0
  209. package/dist/tests/ripgrep.test.js +163 -0
  210. package/dist/tests/save-command.test.js +94 -0
  211. package/dist/tests/save-trust-qa-fixes.test.js +270 -0
  212. package/dist/tests/scoring-pipeline.test.js +648 -0
  213. package/dist/tests/search-include-proposed-cli.test.js +118 -0
  214. package/dist/tests/self-update.test.js +442 -0
  215. package/dist/tests/semantic-search-e2e.test.js +512 -0
  216. package/dist/tests/semantic-status.test.js +471 -0
  217. package/dist/tests/setup-run.integration.js +877 -0
  218. package/dist/tests/setup-wizard.test.js +198 -0
  219. package/dist/tests/setup.test.js +131 -0
  220. package/dist/tests/source-add.test.js +11 -0
  221. package/dist/tests/source-clone.test.js +254 -0
  222. package/dist/tests/source-manage.test.js +366 -0
  223. package/dist/tests/source-providers/filesystem.test.js +82 -0
  224. package/dist/tests/source-providers/git.test.js +252 -0
  225. package/dist/tests/source-providers/website.test.js +128 -0
  226. package/dist/tests/source-qa-fixes.test.js +268 -0
  227. package/dist/tests/source-registry.test.js +350 -0
  228. package/dist/tests/source-resolve.test.js +100 -0
  229. package/dist/tests/source-source.test.js +221 -0
  230. package/dist/tests/source.test.js +533 -0
  231. package/dist/tests/tar-utils-scan.test.js +73 -0
  232. package/dist/tests/toggle-components.test.js +73 -0
  233. package/dist/tests/usage-telemetry.test.js +265 -0
  234. package/dist/tests/utility-scoring.test.js +558 -0
  235. package/dist/tests/vault-load-error.test.js +78 -0
  236. package/dist/tests/vault-qa-fixes.test.js +194 -0
  237. package/dist/tests/vault.test.js +429 -0
  238. package/dist/tests/vector-search.test.js +608 -0
  239. package/dist/tests/walker.test.js +252 -0
  240. package/dist/tests/wave2-cluster-bc.test.js +228 -0
  241. package/dist/tests/wave2-cluster-d.test.js +180 -0
  242. package/dist/tests/wave2-cluster-e.test.js +179 -0
  243. package/dist/tests/wiki-qa-fixes.test.js +270 -0
  244. package/dist/tests/wiki.test.js +529 -0
  245. package/dist/tests/workflow-cli.test.js +271 -0
  246. package/dist/tests/workflow-markdown.test.js +171 -0
  247. package/dist/tests/workflow-path-escape.test.js +132 -0
  248. package/dist/tests/workflow-qa-fixes.test.js +377 -0
  249. package/dist/tests/workflows/indexer-rejection.test.js +213 -0
  250. package/docs/README.md +8 -0
  251. package/docs/migration/release-notes/0.7.0.md +244 -0
  252. package/package.json +2 -2
  253. package/dist/core/warn.js +0 -27
  254. package/dist/output/shapes.js +0 -212
  255. /package/dist/{commands → src/commands}/completions.js +0 -0
  256. /package/dist/{commands → src/commands}/curate.js +0 -0
  257. /package/dist/{commands → src/commands}/info.js +0 -0
  258. /package/dist/{commands → src/commands}/init.js +0 -0
  259. /package/dist/{commands → src/commands}/install-audit.js +0 -0
  260. /package/dist/{commands → src/commands}/migration-help.js +0 -0
  261. /package/dist/{commands → src/commands}/source-add.js +0 -0
  262. /package/dist/{commands → src/commands}/source-clone.js +0 -0
  263. /package/dist/{commands → src/commands}/source-manage.js +0 -0
  264. /package/dist/{commands → src/commands}/vault.js +0 -0
  265. /package/dist/{core → src/core}/asset-registry.js +0 -0
  266. /package/dist/{core → src/core}/frontmatter.js +0 -0
  267. /package/dist/{core → src/core}/markdown.js +0 -0
  268. /package/dist/{core → src/core}/paths.js +0 -0
  269. /package/dist/{indexer → src/indexer}/manifest.js +0 -0
  270. /package/dist/{indexer → src/indexer}/matchers.js +0 -0
  271. /package/dist/{indexer → src/indexer}/search-fields.js +0 -0
  272. /package/dist/{indexer → src/indexer}/search-source.js +0 -0
  273. /package/dist/{indexer → src/indexer}/semantic-status.js +0 -0
  274. /package/dist/{indexer → src/indexer}/usage-events.js +0 -0
  275. /package/dist/{indexer → src/indexer}/walker.js +0 -0
  276. /package/dist/{integrations → src/integrations}/github.js +0 -0
  277. /package/dist/{llm → src/llm}/embedder.js +0 -0
  278. /package/dist/{llm → src/llm}/embedders/cache.js +0 -0
  279. /package/dist/{llm → src/llm}/embedders/local.js +0 -0
  280. /package/dist/{llm → src/llm}/embedders/remote.js +0 -0
  281. /package/dist/{llm → src/llm}/embedders/types.js +0 -0
  282. /package/dist/{llm → src/llm}/metadata-enhance.js +0 -0
  283. /package/dist/{output → src/output}/cli-hints.js +0 -0
  284. /package/dist/{output → src/output}/context.js +0 -0
  285. /package/dist/{registry → src/registry}/create-provider-registry.js +0 -0
  286. /package/dist/{registry → src/registry}/origin-resolve.js +0 -0
  287. /package/dist/{registry → src/registry}/providers/index.js +0 -0
  288. /package/dist/{registry → src/registry}/providers/skills-sh.js +0 -0
  289. /package/dist/{registry → src/registry}/providers/types.js +0 -0
  290. /package/dist/{registry → src/registry}/types.js +0 -0
  291. /package/dist/{setup → src/setup}/detect.js +0 -0
  292. /package/dist/{setup → src/setup}/ripgrep-install.js +0 -0
  293. /package/dist/{setup → src/setup}/ripgrep-resolve.js +0 -0
  294. /package/dist/{setup → src/setup}/steps.js +0 -0
  295. /package/dist/{sources → src/sources}/include.js +0 -0
  296. /package/dist/{sources → src/sources}/provider-factory.js +0 -0
  297. /package/dist/{sources → src/sources}/provider.js +0 -0
  298. /package/dist/{sources → src/sources}/providers/filesystem.js +0 -0
  299. /package/dist/{sources → src/sources}/providers/index.js +0 -0
  300. /package/dist/{sources → src/sources}/providers/install-types.js +0 -0
  301. /package/dist/{sources → src/sources}/providers/npm.js +0 -0
  302. /package/dist/{sources → src/sources}/providers/provider-utils.js +0 -0
  303. /package/dist/{sources → src/sources}/providers/sync-from-ref.js +0 -0
  304. /package/dist/{sources → src/sources}/providers/tar-utils.js +0 -0
  305. /package/dist/{sources → src/sources}/providers/website.js +0 -0
  306. /package/dist/{sources → src/sources}/resolve.js +0 -0
  307. /package/dist/{sources → src/sources}/types.js +0 -0
  308. /package/dist/{templates → src/templates}/wiki-templates.js +0 -0
  309. /package/dist/{version.js → src/version.js} +0 -0
  310. /package/dist/{wiki → src/wiki}/wiki.js +0 -0
  311. /package/dist/{workflows → src/workflows}/authoring.js +0 -0
  312. /package/dist/{workflows → src/workflows}/cli.js +0 -0
  313. /package/dist/{workflows → src/workflows}/db.js +0 -0
  314. /package/dist/{workflows → src/workflows}/document-cache.js +0 -0
  315. /package/dist/{workflows → src/workflows}/parser.js +0 -0
  316. /package/dist/{workflows → src/workflows}/renderer.js +0 -0
  317. /package/dist/{workflows → src/workflows}/runs.js +0 -0
  318. /package/dist/{workflows → src/workflows}/schema.js +0 -0
  319. /package/dist/{workflows → src/workflows}/validator.js +0 -0
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Envelope-shape contract tests for `akm reflect` and `akm propose` (#226).
3
+ *
4
+ * Locks the structural shape of the success and failure envelopes so a
5
+ * future refactor cannot silently rename or drop a field. The producer-shape
6
+ * functions in `src/output/shapes.ts` are the production rendering path —
7
+ * we exercise them with realistic command result objects.
8
+ *
9
+ * Backfill for issue #284 GAP-MED 2.
10
+ */
11
+ import { describe, expect, test } from "bun:test";
12
+ import { shapeProposalProducerOutput } from "../../src/output/shapes";
13
+ const proposal = {
14
+ id: "uuid-1",
15
+ ref: "lesson:rg-over-grep",
16
+ status: "pending",
17
+ source: "reflect",
18
+ sourceRun: "run-7",
19
+ createdAt: "2026-04-27T00:00:00Z",
20
+ updatedAt: "2026-04-27T00:00:00Z",
21
+ payload: { content: "BODY" },
22
+ };
23
+ describe("reflect/propose success envelope contract", () => {
24
+ test("normal: required fields present", () => {
25
+ const result = {
26
+ schemaVersion: 1,
27
+ ok: true,
28
+ ref: "lesson:rg-over-grep",
29
+ agentProfile: "claude",
30
+ durationMs: 12,
31
+ proposal,
32
+ };
33
+ const out = shapeProposalProducerOutput(result, "normal");
34
+ expect(out.ok).toBe(true);
35
+ expect(out.ref).toBe("lesson:rg-over-grep");
36
+ expect(out.agentProfile).toBe("claude");
37
+ expect(out.durationMs).toBe(12);
38
+ expect(out).toHaveProperty("proposal");
39
+ // schemaVersion only at full
40
+ expect(out).not.toHaveProperty("schemaVersion");
41
+ });
42
+ test("full: success envelope adds schemaVersion", () => {
43
+ const result = {
44
+ schemaVersion: 1,
45
+ ok: true,
46
+ ref: "lesson:rg-over-grep",
47
+ agentProfile: "claude",
48
+ durationMs: 12,
49
+ proposal,
50
+ };
51
+ const out = shapeProposalProducerOutput(result, "full");
52
+ expect(out.schemaVersion).toBe(1);
53
+ });
54
+ test("brief: shaped proposal still includes id+ref+status (via brief→normal upgrade)", () => {
55
+ const result = { schemaVersion: 1, ok: true, ref: "lesson:rg-over-grep", proposal };
56
+ const out = shapeProposalProducerOutput(result, "brief");
57
+ const p = out.proposal;
58
+ expect(p.id).toBe("uuid-1");
59
+ expect(p.ref).toBe("lesson:rg-over-grep");
60
+ expect(p.status).toBe("pending");
61
+ });
62
+ });
63
+ describe("reflect/propose failure envelope contract", () => {
64
+ test("non_zero_exit: required failure fields present", () => {
65
+ const failure = {
66
+ schemaVersion: 1,
67
+ ok: false,
68
+ reason: "non_zero_exit",
69
+ error: "exited with code 7",
70
+ ref: "lesson:rg-over-grep",
71
+ exitCode: 7,
72
+ stdout: "out",
73
+ stderr: "err",
74
+ };
75
+ const out = shapeProposalProducerOutput(failure, "normal");
76
+ expect(out.ok).toBe(false);
77
+ expect(out.reason).toBe("non_zero_exit");
78
+ expect(out.error).toBe("exited with code 7");
79
+ expect(out.ref).toBe("lesson:rg-over-grep");
80
+ expect(out.exitCode).toBe(7);
81
+ // stdio only at full
82
+ expect(out).not.toHaveProperty("stdout");
83
+ expect(out).not.toHaveProperty("stderr");
84
+ });
85
+ test("spawn_failed: exitCode null is preserved", () => {
86
+ const failure = {
87
+ schemaVersion: 1,
88
+ ok: false,
89
+ reason: "spawn_failed",
90
+ error: "ENOENT: command not found",
91
+ exitCode: null,
92
+ };
93
+ const out = shapeProposalProducerOutput(failure, "normal");
94
+ expect(out.ok).toBe(false);
95
+ expect(out.reason).toBe("spawn_failed");
96
+ expect(out.exitCode).toBeNull();
97
+ });
98
+ test("parse_error: ref optional", () => {
99
+ const failure = {
100
+ schemaVersion: 1,
101
+ ok: false,
102
+ reason: "parse_error",
103
+ error: "agent stdout was not valid JSON",
104
+ exitCode: 0,
105
+ };
106
+ const out = shapeProposalProducerOutput(failure, "normal");
107
+ expect(out.reason).toBe("parse_error");
108
+ expect(out).not.toHaveProperty("ref");
109
+ });
110
+ test("timeout: timeout reason discriminant", () => {
111
+ const failure = {
112
+ schemaVersion: 1,
113
+ ok: false,
114
+ reason: "timeout",
115
+ error: "timed out after 100ms",
116
+ exitCode: 143,
117
+ };
118
+ const out = shapeProposalProducerOutput(failure, "full");
119
+ expect(out.reason).toBe("timeout");
120
+ expect(out.schemaVersion).toBe(1);
121
+ });
122
+ test("propose-specific failure: type+name appear when set on the result", () => {
123
+ // propose surfaces `type` and `name` in failure envelopes (the input args),
124
+ // separate from the agent-side `ref`. shapeProposalProducerOutput threads
125
+ // both fields through unconditionally when present.
126
+ const failure = {
127
+ schemaVersion: 1,
128
+ ok: false,
129
+ reason: "non_zero_exit",
130
+ error: "agent failed",
131
+ type: "skill",
132
+ name: "hello",
133
+ exitCode: 3,
134
+ };
135
+ const out = shapeProposalProducerOutput(failure, "normal");
136
+ expect(out.type).toBe("skill");
137
+ expect(out.name).toBe("hello");
138
+ });
139
+ });
@@ -0,0 +1,46 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ const repoRoot = path.resolve(import.meta.dir, "..", "..");
4
+ export const SPEC_PATH = path.join(repoRoot, "docs", "technical", "v1-architecture-spec.md");
5
+ export const CLI_DOC_PATH = path.join(repoRoot, "docs", "cli.md");
6
+ export const CONFIG_DOC_PATH = path.join(repoRoot, "docs", "configuration.md");
7
+ export const MIGRATION_PATH = path.join(repoRoot, "docs", "migration", "v1.md");
8
+ export function readDoc(p) {
9
+ return fs.readFileSync(p, "utf8");
10
+ }
11
+ /**
12
+ * Extract a section by its heading line (e.g. "## 9. Locked contracts for v1").
13
+ * Returns an empty string if the heading is not present.
14
+ *
15
+ * Used by contract tests to scope their assertions to a single spec
16
+ * section so unrelated edits elsewhere in the doc don't cause false
17
+ * positives.
18
+ */
19
+ export function extractSection(doc, heading) {
20
+ const start = doc.indexOf(heading);
21
+ if (start < 0)
22
+ return "";
23
+ const depthMatch = heading.match(/^#+/);
24
+ const depth = depthMatch ? depthMatch[0].length : 2;
25
+ // Stop only on a heading at the SAME depth or shallower, OUTSIDE any
26
+ // fenced code block. Markdown headings inside ```...``` blocks are not
27
+ // real headings and must not terminate a section. We stream the doc line
28
+ // by line tracking fence state.
29
+ const lines = doc.slice(start + heading.length).split("\n");
30
+ const stopRe = new RegExp(`^#{1,${depth}}\\s`);
31
+ let inFence = false;
32
+ let consumed = 0;
33
+ // Skip the rest of the heading line itself.
34
+ consumed += (lines.shift() ?? "").length + 1;
35
+ for (const line of lines) {
36
+ const fenceMatch = /^(```+|~~~+)/.test(line.trimStart());
37
+ if (fenceMatch) {
38
+ inFence = !inFence;
39
+ }
40
+ else if (!inFence && stopRe.test(line)) {
41
+ return doc.slice(start, start + heading.length + consumed);
42
+ }
43
+ consumed += line.length + 1;
44
+ }
45
+ return doc.slice(start);
46
+ }
@@ -0,0 +1,228 @@
1
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { akmDistill } from "../../src/commands/distill";
6
+ import { akmPropose } from "../../src/commands/propose";
7
+ import { akmReflect } from "../../src/commands/reflect";
8
+ import { readEvents } from "../../src/core/events";
9
+ import { extractSection, readDoc, SPEC_PATH } from "./spec-helpers";
10
+ // Pins v1 spec §11 — Proposal queue (Planned for v1).
11
+ const REQUIRED_PROPOSAL_FIELDS = ["id", "ref", "status", "source", "sourceRun", "createdAt", "updatedAt"];
12
+ const REQUIRED_PROPOSAL_COMMANDS = ["list", "show", "diff", "accept", "reject"];
13
+ const REQUIRED_EVENTS = ["propose_invoked", "reflect_invoked", "distill_invoked", "promoted", "rejected"];
14
+ describe("v1 spec §11 — proposal queue", () => {
15
+ const spec = readDoc(SPEC_PATH);
16
+ const section = extractSection(spec, "## 11. Proposal queue");
17
+ test("§11 exists and is marked Planned for v1", () => {
18
+ expect(section).not.toBe("");
19
+ expect(section).toContain("Planned for v1");
20
+ });
21
+ test("§11.1 names the per-id proposal directory layout as the durable store", () => {
22
+ // Storage is one directory per proposal under <stashRoot>/.akm/proposals/<id>/
23
+ // containing a single proposal.json (queue state, not asset state).
24
+ expect(section).toContain(".akm/proposals/<id>/");
25
+ expect(section).toContain("proposal.json");
26
+ });
27
+ test("§11.1 declares each required proposal field", () => {
28
+ for (const field of REQUIRED_PROPOSAL_FIELDS) {
29
+ expect(section).toContain(`\`${field}\``);
30
+ }
31
+ });
32
+ test("§11.1 declares pending/accepted/rejected statuses + archive-by-move", () => {
33
+ expect(section).toContain("`pending`");
34
+ expect(section).toContain("`accepted`");
35
+ expect(section).toContain("`rejected`");
36
+ // Archival is a directory move, not a separate status (see §11.1 prose).
37
+ expect(section).toMatch(/archive\/<id>\/|archive-by-move|moved to.*archive/i);
38
+ });
39
+ test("§11.2 lists every proposal subcommand", () => {
40
+ for (const cmd of REQUIRED_PROPOSAL_COMMANDS) {
41
+ expect(section).toContain(`akm proposal ${cmd}`);
42
+ }
43
+ });
44
+ test("§11.2 says `accept` validates BEFORE promoting", () => {
45
+ const flat = section.replace(/\s+/g, " ");
46
+ expect(flat).toMatch(/validation .*\*\*before\*\* promoting/i);
47
+ });
48
+ test("§11.2 says `accept` promotes via writeAssetToSource()", () => {
49
+ // The locked rule is "all asset writes funnel through writeAssetToSource".
50
+ // The proposal queue is the only legal path that bypasses it for queue
51
+ // state — promotion must hand back to the single dispatch point.
52
+ expect(section).toContain("writeAssetToSource()");
53
+ });
54
+ test("§11.1 says multiple proposals per `ref` coexist", () => {
55
+ // The id is per-proposal; the ref isn't unique. The queue must hold N
56
+ // proposals for the same target ref without filesystem collisions.
57
+ // Directory-per-id is the mechanism the spec calls out for this.
58
+ expect(section).toMatch(/multiple proposals.*for the same `ref`|coexist for the same `ref`/i);
59
+ });
60
+ test("§11.2 names a `--reason` flag on `reject`", () => {
61
+ expect(section).toMatch(/akm proposal reject.*--reason/);
62
+ });
63
+ test("§11.3 declares every locked event name", () => {
64
+ for (const event of REQUIRED_EVENTS) {
65
+ expect(section).toContain(`\`${event}\``);
66
+ }
67
+ });
68
+ test("§11.3 says other plugins cannot reuse these event names", () => {
69
+ expect(section).toMatch(/cannot reuse these names/i);
70
+ });
71
+ test("§11 stops before §12 (helper boundary check)", () => {
72
+ // Defensive: extractSection() returns to EOF if no sibling stop
73
+ // heading exists. Pin the section terminus so a missing §12 heading
74
+ // (or a renamed one) trips this test instead of silently spilling
75
+ // §12+§13+§14 content into the §11 assertions above.
76
+ expect(section).not.toContain("## 12.");
77
+ expect(section).not.toContain("## 13.");
78
+ expect(section).not.toContain("## 14.");
79
+ });
80
+ });
81
+ // ── #284 GAP-MED 4: event metadata shape ─────────────────────────────────────
82
+ //
83
+ // Locks the metadata payload of the producer events so observers (audit,
84
+ // dashboards) can rely on consistent keys.
85
+ const tempDirs = [];
86
+ const savedEnv = {
87
+ AKM_STASH_DIR: process.env.AKM_STASH_DIR,
88
+ XDG_CACHE_HOME: process.env.XDG_CACHE_HOME,
89
+ XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME,
90
+ };
91
+ function makeTempDir(prefix) {
92
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
93
+ tempDirs.push(dir);
94
+ return dir;
95
+ }
96
+ function makeStashDir() {
97
+ const stash = makeTempDir("akm-events-meta-stash-");
98
+ for (const sub of ["lessons", "skills", "memories"]) {
99
+ fs.mkdirSync(path.join(stash, sub), { recursive: true });
100
+ }
101
+ return stash;
102
+ }
103
+ function makeProfile() {
104
+ return {
105
+ name: "fake-agent",
106
+ bin: "fake-agent",
107
+ args: [],
108
+ stdio: "captured",
109
+ envPassthrough: ["PATH"],
110
+ parseOutput: "text",
111
+ };
112
+ }
113
+ function asReadableStream(text) {
114
+ const bytes = new TextEncoder().encode(text);
115
+ return new ReadableStream({
116
+ start(controller) {
117
+ controller.enqueue(bytes);
118
+ controller.close();
119
+ },
120
+ });
121
+ }
122
+ function fakeSpawn(stdout, exitCode) {
123
+ return () => {
124
+ const proc = {
125
+ exitCode,
126
+ exited: Promise.resolve(exitCode),
127
+ stdout: asReadableStream(stdout),
128
+ stderr: asReadableStream(""),
129
+ stdin: null,
130
+ kill: () => undefined,
131
+ };
132
+ return proc;
133
+ };
134
+ }
135
+ const VALID_LESSON_PAYLOAD = JSON.stringify({
136
+ ref: "lesson:rg",
137
+ content: "---\ndescription: Use rg\nwhen_to_use: large repos\n---\n\nUse rg.\n",
138
+ });
139
+ const VALID_SKILL_PAYLOAD = JSON.stringify({
140
+ ref: "skill:hello",
141
+ content: "---\ndescription: hi\nwhen_to_use: greeting\n---\n\nHi.\n",
142
+ });
143
+ beforeEach(() => {
144
+ process.env.XDG_CACHE_HOME = makeTempDir("akm-events-meta-cache-");
145
+ process.env.XDG_CONFIG_HOME = makeTempDir("akm-events-meta-config-");
146
+ });
147
+ afterEach(() => {
148
+ if (savedEnv.AKM_STASH_DIR === undefined)
149
+ delete process.env.AKM_STASH_DIR;
150
+ else
151
+ process.env.AKM_STASH_DIR = savedEnv.AKM_STASH_DIR;
152
+ if (savedEnv.XDG_CACHE_HOME === undefined)
153
+ delete process.env.XDG_CACHE_HOME;
154
+ else
155
+ process.env.XDG_CACHE_HOME = savedEnv.XDG_CACHE_HOME;
156
+ if (savedEnv.XDG_CONFIG_HOME === undefined)
157
+ delete process.env.XDG_CONFIG_HOME;
158
+ else
159
+ process.env.XDG_CONFIG_HOME = savedEnv.XDG_CONFIG_HOME;
160
+ for (const dir of tempDirs.splice(0)) {
161
+ fs.rmSync(dir, { recursive: true, force: true });
162
+ }
163
+ });
164
+ describe("§11 event metadata shape (runtime)", () => {
165
+ test("reflect_invoked carries `task` + optional `profile` in metadata", async () => {
166
+ const stash = makeStashDir();
167
+ await akmReflect({
168
+ ref: "lesson:rg",
169
+ task: "focus on perf",
170
+ profile: "claude",
171
+ stashDir: stash,
172
+ agentProfile: makeProfile(),
173
+ runAgentOptions: { spawn: fakeSpawn(VALID_LESSON_PAYLOAD, 0) },
174
+ });
175
+ const { events } = readEvents({ type: "reflect_invoked" });
176
+ expect(events.length).toBe(1);
177
+ const md = (events[0].metadata ?? {});
178
+ expect(md.task).toBe("focus on perf");
179
+ expect(md.profile).toBe("claude");
180
+ expect(events[0].ref).toBe("lesson:rg");
181
+ });
182
+ test("propose_invoked carries `type`+`name`+`task` in metadata", async () => {
183
+ const stash = makeStashDir();
184
+ await akmPropose({
185
+ type: "skill",
186
+ name: "hello",
187
+ task: "say hi",
188
+ stashDir: stash,
189
+ agentProfile: makeProfile(),
190
+ runAgentOptions: { spawn: fakeSpawn(VALID_SKILL_PAYLOAD, 0) },
191
+ });
192
+ const { events } = readEvents({ type: "propose_invoked" });
193
+ expect(events.length).toBe(1);
194
+ const md = (events[0].metadata ?? {});
195
+ expect(md.type).toBe("skill");
196
+ expect(md.name).toBe("hello");
197
+ expect(md.task).toBe("say hi");
198
+ expect(events[0].ref).toBe("skill:hello");
199
+ });
200
+ test("distill_invoked metadata includes `outcome` (queued|skipped|validation_failed)", async () => {
201
+ const stash = makeStashDir();
202
+ const config = {
203
+ stashDir: stash,
204
+ sources: [{ type: "filesystem", name: "stash", path: stash, writable: true }],
205
+ defaultWriteTarget: "stash",
206
+ llm: {
207
+ endpoint: "http://localhost:11434/v1/chat/completions",
208
+ model: "test-model",
209
+ features: { feedback_distillation: true },
210
+ },
211
+ };
212
+ await akmDistill({
213
+ ref: "skill:deploy",
214
+ config,
215
+ stashDir: stash,
216
+ chat: async () => "---\ndescription: x\nwhen_to_use: y\n---\n\nbody.\n",
217
+ lookupFn: async () => null,
218
+ readEventsFn: (() => ({ events: [], nextOffset: 0 })),
219
+ });
220
+ const { events } = readEvents({ type: "distill_invoked" });
221
+ expect(events.length).toBe(1);
222
+ const md = (events[0].metadata ?? {});
223
+ expect(["queued", "skipped", "validation_failed"]).toContain(md.outcome);
224
+ // `proposalId` only stamped on the queued path
225
+ if (md.outcome === "queued")
226
+ expect(typeof md.proposalId).toBe("string");
227
+ });
228
+ });
@@ -0,0 +1,56 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { CONFIG_DOC_PATH, extractSection, readDoc, SPEC_PATH } from "./spec-helpers";
3
+ // Pins v1 spec §12 — Agent CLI integration (Planned for v1).
4
+ const BUILT_IN_PROFILES = ["opencode", "claude", "codex", "gemini", "aider"];
5
+ const SPAWN_FAILURE_REASONS = ["timeout", "spawn_failed", "non_zero_exit", "parse_error"];
6
+ describe("v1 spec §12 — agent CLI integration", () => {
7
+ const spec = readDoc(SPEC_PATH);
8
+ const section = extractSection(spec, "## 12. Agent CLI integration");
9
+ test("§12 exists and is marked Planned for v1", () => {
10
+ expect(section).not.toBe("");
11
+ expect(section).toContain("Planned for v1");
12
+ });
13
+ test("§12.1 lists every built-in profile", () => {
14
+ for (const p of BUILT_IN_PROFILES) {
15
+ expect(section).toContain(`\`${p}\``);
16
+ }
17
+ });
18
+ test("§12.1 declares the AgentProfile shape", () => {
19
+ expect(section).toMatch(/interface AgentProfile/);
20
+ expect(section).toMatch(/readonly bin: string/);
21
+ expect(section).toMatch(/readonly args: readonly string\[\]/);
22
+ expect(section).toMatch(/captured.*interactive/s);
23
+ });
24
+ test("§12.2 names every spawn-wrapper failure reason", () => {
25
+ for (const r of SPAWN_FAILURE_REASONS) {
26
+ expect(section).toContain(`"${r}"`);
27
+ }
28
+ });
29
+ test("§12.4 declares reflect/propose write only to the proposal queue", () => {
30
+ expect(section).toMatch(/write\s*\*\*only\*\*\s*to the proposal queue/i);
31
+ });
32
+ test("§12 stops before §13 (helper boundary check)", () => {
33
+ // Defensive: extractSection() returns to EOF if no sibling stop
34
+ // heading exists. Pin the section terminus so a missing §13 heading
35
+ // (or a renamed one) trips this test instead of silently spilling
36
+ // §13+§14 content into the §12 assertions above.
37
+ expect(section).not.toContain("## 13.");
38
+ expect(section).not.toContain("## 14.");
39
+ });
40
+ });
41
+ describe("v1 spec §12 — configuration.md mirrors the agent block", () => {
42
+ const config = readDoc(CONFIG_DOC_PATH);
43
+ const block = extractSection(config, "## `agent.*` block");
44
+ test("configuration.md has the agent block section", () => {
45
+ expect(block).not.toBe("");
46
+ });
47
+ test("configuration.md declares the three top-level agent keys", () => {
48
+ expect(block).toContain("`agent.default`");
49
+ expect(block).toContain("`agent.timeoutMs`");
50
+ expect(block).toContain("`agent.profiles[<name>]`");
51
+ });
52
+ test("configuration.md says missing `agent` block raises ConfigError with hint", () => {
53
+ expect(block).toMatch(/ConfigError/);
54
+ expect(block).toMatch(/hint/i);
55
+ });
56
+ });
@@ -0,0 +1,34 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { ASSET_SPECS, TYPE_DIRS } from "../../src/core/asset-spec";
3
+ import { extractSection, readDoc, SPEC_PATH } from "./spec-helpers";
4
+ // Pins v1 spec §13 — Lesson asset type (Planned for v1).
5
+ describe("v1 spec §13 — lesson asset type", () => {
6
+ const spec = readDoc(SPEC_PATH);
7
+ const section = extractSection(spec, "## 13. Lesson asset type");
8
+ test("§13 exists and is marked Planned for v1", () => {
9
+ expect(section).not.toBe("");
10
+ expect(section).toContain("Planned for v1");
11
+ });
12
+ test("§13.1 declares `description` and `when_to_use` are required", () => {
13
+ expect(section).toMatch(/description:\s*required/);
14
+ expect(section).toMatch(/when_to_use:\s*required/);
15
+ });
16
+ test("§13.2 stores lessons under `lessons/`", () => {
17
+ expect(section).toContain("`lessons/<name>.md`");
18
+ });
19
+ test("§13.3 routes distill output through the proposal queue", () => {
20
+ expect(section).toMatch(/akm distill/);
21
+ expect(section).toMatch(/akm proposal accept/);
22
+ });
23
+ test("`lesson` is registered as a well-known asset type at runtime", () => {
24
+ expect(ASSET_SPECS.lesson).toBeDefined();
25
+ expect(TYPE_DIRS.lesson).toBe("lessons");
26
+ });
27
+ test("§13 stops before §14 (helper boundary check)", () => {
28
+ // Defensive: extractSection() returns to EOF if no sibling stop
29
+ // heading exists. Pin the section terminus so a missing §14 heading
30
+ // (or a renamed one) trips this test instead of silently spilling
31
+ // §14 content into the §13 assertions above.
32
+ expect(section).not.toContain("## 14.");
33
+ });
34
+ });
@@ -0,0 +1,94 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { isLlmFeatureEnabled, tryLlmFeature } from "../../src/llm/feature-gate";
3
+ import { CONFIG_DOC_PATH, extractSection, readDoc, SPEC_PATH } from "./spec-helpers";
4
+ // Pins v1 spec §14 — `llm.features.*` (Planned for v1).
5
+ //
6
+ // The locked feature keys cannot be renamed after v1.0. New keys may be
7
+ // added; these must not move. Spec §14 retains the historical phantom keys
8
+ // (`tag_dedup`, `memory_consolidation`, `embedding_fallback_score`) so the
9
+ // spec text continues to compile, but they are not in the runtime schema or
10
+ // in user-facing configuration.md (issue #284 phantom-flag cleanup).
11
+ const LOCKED_FEATURE_KEYS = ["curate_rerank", "feedback_distillation", "memory_inference", "graph_extraction"];
12
+ describe("v1 spec §14 — llm.features.*", () => {
13
+ const spec = readDoc(SPEC_PATH);
14
+ const section = extractSection(spec, "## 14. `llm.features.*`");
15
+ test("§14 exists and is marked Planned for v1", () => {
16
+ expect(section).not.toBe("");
17
+ expect(section).toContain("Planned for v1");
18
+ });
19
+ test("§14.1 declares every locked feature key", () => {
20
+ for (const k of LOCKED_FEATURE_KEYS) {
21
+ expect(section).toContain(`\`${k}\``);
22
+ }
23
+ });
24
+ test("§14.1 declares all defaults are false", () => {
25
+ expect(section).toMatch(/defaults are\s*`false`|all defaults are\s*`false`|defaults\s*`false`/i);
26
+ });
27
+ test("§14.2 defines mandatory failure-mode rules", () => {
28
+ expect(section).toMatch(/check the feature flag before/i);
29
+ expect(section).toMatch(/hard timeout/i);
30
+ expect(section).toMatch(/never\s*\*\*\s*mutate state on failure/i);
31
+ });
32
+ test("§14.4 codifies the statelessness invariant", () => {
33
+ expect(section).toMatch(/holds no state across calls/i);
34
+ expect(section).toMatch(/no streaming sessions/i);
35
+ });
36
+ test("§14.5 routes distill output through the proposal queue", () => {
37
+ const flat = section.replace(/\s+/g, " ");
38
+ expect(flat).toMatch(/`lesson` \*\*proposal\*\*/i);
39
+ expect(section).toContain("distill_invoked");
40
+ });
41
+ test("§14 documents orthogonality between llm.features.* and index.<pass>.llm", () => {
42
+ expect(section).toMatch(/orthogonal/i);
43
+ expect(section).toMatch(/llm\.features\.<key>/);
44
+ expect(section).toMatch(/index\.<pass>\.llm/);
45
+ });
46
+ test("§14 stops before §15 (helper boundary check)", () => {
47
+ // Defensive: extractSection() returns to EOF if no sibling stop
48
+ // heading exists. Pin the section terminus so a missing §15 heading
49
+ // (or a renamed one) trips this test instead of silently spilling
50
+ // §15+ content into the §14 assertions above.
51
+ expect(section).not.toContain("## 15.");
52
+ expect(section).not.toContain("## Appendix");
53
+ });
54
+ });
55
+ describe("v1 spec §14 — configuration.md mirrors the feature gates", () => {
56
+ const config = readDoc(CONFIG_DOC_PATH);
57
+ const block = extractSection(config, "## `llm.features.*` map");
58
+ test("configuration.md has the llm.features section", () => {
59
+ expect(block).not.toBe("");
60
+ });
61
+ test("configuration.md lists every locked feature key", () => {
62
+ for (const k of LOCKED_FEATURE_KEYS) {
63
+ expect(block).toContain(k);
64
+ }
65
+ });
66
+ test("configuration.md says unknown llm.features keys are warn-and-ignore", () => {
67
+ expect(block).toMatch(/Unknown keys.*warn-and-ignore/i);
68
+ });
69
+ });
70
+ describe("v1 spec §14 — runtime gate seam", () => {
71
+ // The graceful-fallback contract says: disabled gate returns the fallback
72
+ // without ever calling fn; throws are swallowed and return fallback. We
73
+ // pin the seam shape here so renames trigger the contract test.
74
+ test("isLlmFeatureEnabled is exported and pure", () => {
75
+ expect(typeof isLlmFeatureEnabled).toBe("function");
76
+ expect(isLlmFeatureEnabled(undefined, "curate_rerank")).toBe(false);
77
+ });
78
+ test("tryLlmFeature returns fallback when the gate is disabled (no fn call)", async () => {
79
+ let called = false;
80
+ const result = await tryLlmFeature("curate_rerank", undefined, () => {
81
+ called = true;
82
+ return "ran";
83
+ }, "fallback");
84
+ expect(result).toBe("fallback");
85
+ expect(called).toBe(false);
86
+ });
87
+ test("tryLlmFeature swallows throws and returns fallback when enabled", async () => {
88
+ const config = { llm: { features: { curate_rerank: true } } };
89
+ const result = await tryLlmFeature("curate_rerank", config, () => {
90
+ throw new Error("boom");
91
+ }, "fallback");
92
+ expect(result).toBe("fallback");
93
+ });
94
+ });
@@ -0,0 +1,39 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { ASSET_SPECS } from "../../src/core/asset-spec";
3
+ import { isAssetType } from "../../src/core/common";
4
+ import { extractSection, readDoc, SPEC_PATH } from "./spec-helpers";
5
+ // Pins v1 spec §4.1 — Asset type rules (open set).
6
+ //
7
+ // These tests are intentionally about the *rule*, not the specific list of
8
+ // well-known types. The closed-set list can grow without breaking the
9
+ // contract; what cannot change is that types are an open string set and
10
+ // that the renderer registry is the authority.
11
+ describe("v1 spec §4.1 — asset type rules (open set)", () => {
12
+ const spec = readDoc(SPEC_PATH);
13
+ const section = extractSection(spec, "### 4.1 Asset type rules (open set)");
14
+ test("§4.1 declares the open set rule in the spec", () => {
15
+ expect(section).not.toBe("");
16
+ expect(section).toContain("open string");
17
+ // Renderer registry is named as the authority for well-known types.
18
+ expect(section).toMatch(/renderer/i);
19
+ });
20
+ test("§4.1 names every well-known type that has a renderer today", () => {
21
+ // Every type that ships with an ASSET_SPECS entry today must be named in
22
+ // the well-known list. Adding a new type is fine; silently dropping one
23
+ // is not.
24
+ for (const type of Object.keys(ASSET_SPECS)) {
25
+ expect(section).toContain(`\`${type}\``);
26
+ }
27
+ });
28
+ test("§4.1 names `lesson` as a planned-for-v1 well-known type", () => {
29
+ expect(section).toContain("`lesson`");
30
+ });
31
+ test("isAssetType() accepts arbitrary strings — open set in code", () => {
32
+ // The spec says the type is an open string. The runtime validator must
33
+ // not reject unknown types as part of ref parsing. We only assert the
34
+ // function returns the expected boolean shape; specific well-known
35
+ // values are allowed but not required to be the only true cases.
36
+ expect(typeof isAssetType("skill")).toBe("boolean");
37
+ expect(typeof isAssetType("definitely-not-a-real-type")).toBe("boolean");
38
+ });
39
+ });