akm-cli 0.7.0 → 0.7.2

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 (332) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/{src/cli.js → cli.js} +22 -8
  3. package/dist/{src/commands → commands}/installed-stashes.js +1 -1
  4. package/dist/{src/commands → commands}/source-add.js +1 -1
  5. package/dist/{src/core → core}/common.js +16 -1
  6. package/dist/{src/core → core}/config.js +5 -2
  7. package/dist/{src/indexer → indexer}/db-search.js +16 -1
  8. package/dist/{src/indexer → indexer}/graph-extraction.js +5 -3
  9. package/dist/{src/indexer → indexer}/indexer.js +27 -11
  10. package/dist/{src/indexer → indexer}/memory-inference.js +47 -58
  11. package/dist/{src/indexer → indexer}/search-source.js +1 -1
  12. package/dist/{src/llm → llm}/client.js +61 -1
  13. package/dist/{src/llm → llm}/embedder.js +8 -5
  14. package/dist/{src/llm → llm}/embedders/local.js +8 -2
  15. package/dist/{src/llm → llm}/embedders/remote.js +4 -2
  16. package/dist/{src/llm → llm}/graph-extract.js +4 -4
  17. package/dist/llm/memory-infer.js +114 -0
  18. package/dist/{src/llm → llm}/metadata-enhance.js +2 -2
  19. package/dist/{src/output → output}/cli-hints.js +2 -0
  20. package/dist/{src/setup → setup}/setup.js +30 -20
  21. package/dist/sources/providers/website.js +27 -0
  22. package/dist/{src/sources/providers/website.js → sources/website-ingest.js} +38 -51
  23. package/docs/README.md +7 -0
  24. package/docs/migration/release-notes/0.7.0.md +14 -0
  25. package/package.json +11 -8
  26. package/dist/src/llm/memory-infer.js +0 -86
  27. package/dist/tests/add-website-source.test.js +0 -119
  28. package/dist/tests/agent/agent-config-loader.test.js +0 -70
  29. package/dist/tests/agent/agent-config.test.js +0 -221
  30. package/dist/tests/agent/agent-detect.test.js +0 -100
  31. package/dist/tests/agent/agent-spawn.test.js +0 -234
  32. package/dist/tests/agent-output.test.js +0 -186
  33. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
  34. package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
  35. package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
  36. package/dist/tests/asset-ref.test.js +0 -192
  37. package/dist/tests/asset-registry.test.js +0 -103
  38. package/dist/tests/asset-spec.test.js +0 -241
  39. package/dist/tests/bench/attribution.test.js +0 -996
  40. package/dist/tests/bench/cleanup-sigint.test.js +0 -83
  41. package/dist/tests/bench/cleanup.js +0 -234
  42. package/dist/tests/bench/cleanup.test.js +0 -166
  43. package/dist/tests/bench/cli.js +0 -1018
  44. package/dist/tests/bench/cli.test.js +0 -445
  45. package/dist/tests/bench/compare.test.js +0 -556
  46. package/dist/tests/bench/corpus.js +0 -317
  47. package/dist/tests/bench/corpus.test.js +0 -258
  48. package/dist/tests/bench/doctor.js +0 -525
  49. package/dist/tests/bench/driver.js +0 -401
  50. package/dist/tests/bench/driver.test.js +0 -584
  51. package/dist/tests/bench/environment.js +0 -233
  52. package/dist/tests/bench/environment.test.js +0 -199
  53. package/dist/tests/bench/evolve-metrics.js +0 -179
  54. package/dist/tests/bench/evolve-metrics.test.js +0 -187
  55. package/dist/tests/bench/evolve.js +0 -647
  56. package/dist/tests/bench/evolve.test.js +0 -624
  57. package/dist/tests/bench/failure-modes.test.js +0 -349
  58. package/dist/tests/bench/feedback-integrity.test.js +0 -457
  59. package/dist/tests/bench/leakage.test.js +0 -228
  60. package/dist/tests/bench/learning-curve.test.js +0 -134
  61. package/dist/tests/bench/metrics.js +0 -2395
  62. package/dist/tests/bench/metrics.test.js +0 -1150
  63. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
  64. package/dist/tests/bench/opencode-config.js +0 -194
  65. package/dist/tests/bench/opencode-config.test.js +0 -370
  66. package/dist/tests/bench/report.js +0 -1885
  67. package/dist/tests/bench/report.test.js +0 -1038
  68. package/dist/tests/bench/run-config.js +0 -355
  69. package/dist/tests/bench/run-config.test.js +0 -298
  70. package/dist/tests/bench/run-curate-test.js +0 -32
  71. package/dist/tests/bench/run-failing-tasks.js +0 -56
  72. package/dist/tests/bench/run-full-bench.js +0 -51
  73. package/dist/tests/bench/run-items36-targeted.js +0 -69
  74. package/dist/tests/bench/run-nano-quick.js +0 -42
  75. package/dist/tests/bench/run-waveg-targeted.js +0 -62
  76. package/dist/tests/bench/runner.js +0 -699
  77. package/dist/tests/bench/runner.test.js +0 -958
  78. package/dist/tests/bench/search-bridge.test.js +0 -331
  79. package/dist/tests/bench/tmp.js +0 -131
  80. package/dist/tests/bench/trajectory.js +0 -116
  81. package/dist/tests/bench/trajectory.test.js +0 -127
  82. package/dist/tests/bench/verifier.js +0 -114
  83. package/dist/tests/bench/verifier.test.js +0 -118
  84. package/dist/tests/bench/workflow-evaluator.js +0 -557
  85. package/dist/tests/bench/workflow-evaluator.test.js +0 -421
  86. package/dist/tests/bench/workflow-spec.js +0 -345
  87. package/dist/tests/bench/workflow-spec.test.js +0 -363
  88. package/dist/tests/bench/workflow-trace.js +0 -472
  89. package/dist/tests/bench/workflow-trace.test.js +0 -254
  90. package/dist/tests/benchmark-search-quality.js +0 -536
  91. package/dist/tests/benchmark-suite.js +0 -1441
  92. package/dist/tests/capture-cli.test.js +0 -112
  93. package/dist/tests/cli-errors.test.js +0 -204
  94. package/dist/tests/commands/events.test.js +0 -370
  95. package/dist/tests/commands/history.test.js +0 -418
  96. package/dist/tests/commands/import.test.js +0 -103
  97. package/dist/tests/commands/proposal-cli.test.js +0 -209
  98. package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
  99. package/dist/tests/commands/remember.test.js +0 -97
  100. package/dist/tests/commands/scope-flags.test.js +0 -300
  101. package/dist/tests/commands/search.test.js +0 -537
  102. package/dist/tests/commands/show-indexer-parity.test.js +0 -117
  103. package/dist/tests/commands/show.test.js +0 -294
  104. package/dist/tests/common.test.js +0 -266
  105. package/dist/tests/completions.test.js +0 -142
  106. package/dist/tests/config-cli.test.js +0 -193
  107. package/dist/tests/config-llm-features.test.js +0 -139
  108. package/dist/tests/config.test.js +0 -569
  109. package/dist/tests/contracts/migration-baseline.test.js +0 -43
  110. package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
  111. package/dist/tests/contracts/spec-helpers.js +0 -46
  112. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
  113. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
  114. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
  115. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
  116. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
  117. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
  118. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
  119. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
  120. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
  121. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
  122. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
  123. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
  124. package/dist/tests/core/write-source.test.js +0 -366
  125. package/dist/tests/curate-command.test.js +0 -87
  126. package/dist/tests/db-scoring.test.js +0 -201
  127. package/dist/tests/db.test.js +0 -654
  128. package/dist/tests/distill-cli-flag.test.js +0 -208
  129. package/dist/tests/distill.test.js +0 -515
  130. package/dist/tests/docker-install.test.js +0 -120
  131. package/dist/tests/e2e.test.js +0 -1419
  132. package/dist/tests/embedder.test.js +0 -340
  133. package/dist/tests/embedding-model-config.test.js +0 -379
  134. package/dist/tests/feedback-command.test.js +0 -172
  135. package/dist/tests/file-context.test.js +0 -552
  136. package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
  137. package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
  138. package/dist/tests/fixtures/stashes/load.js +0 -166
  139. package/dist/tests/fixtures/stashes/load.test.js +0 -97
  140. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
  141. package/dist/tests/frontmatter.test.js +0 -190
  142. package/dist/tests/fts-field-weighting.test.js +0 -254
  143. package/dist/tests/fuzzy-search.test.js +0 -230
  144. package/dist/tests/git-provider-clone.test.js +0 -45
  145. package/dist/tests/github.test.js +0 -161
  146. package/dist/tests/graph-boost-ranking.test.js +0 -305
  147. package/dist/tests/graph-extraction.test.js +0 -282
  148. package/dist/tests/helpers/usage-events.js +0 -8
  149. package/dist/tests/index-pass-llm.test.js +0 -161
  150. package/dist/tests/indexer.test.js +0 -570
  151. package/dist/tests/info-command.test.js +0 -166
  152. package/dist/tests/init.test.js +0 -69
  153. package/dist/tests/install-script.test.js +0 -246
  154. package/dist/tests/integration/agent-real-profile.test.js +0 -94
  155. package/dist/tests/issue-36-repro.test.js +0 -304
  156. package/dist/tests/issues-191-194.test.js +0 -160
  157. package/dist/tests/lesson-lint.test.js +0 -111
  158. package/dist/tests/llm-client.test.js +0 -115
  159. package/dist/tests/llm-feature-gate.test.js +0 -151
  160. package/dist/tests/llm.test.js +0 -139
  161. package/dist/tests/lockfile.test.js +0 -216
  162. package/dist/tests/manifest.test.js +0 -205
  163. package/dist/tests/markdown.test.js +0 -126
  164. package/dist/tests/matchers-unit.test.js +0 -189
  165. package/dist/tests/memory-inference.test.js +0 -299
  166. package/dist/tests/merge-scoring.test.js +0 -136
  167. package/dist/tests/metadata.test.js +0 -313
  168. package/dist/tests/migration-help.test.js +0 -89
  169. package/dist/tests/origin-resolve.test.js +0 -124
  170. package/dist/tests/output-baseline.test.js +0 -218
  171. package/dist/tests/output-shapes-unit.test.js +0 -478
  172. package/dist/tests/parallel-search.test.js +0 -272
  173. package/dist/tests/parameter-metadata.test.js +0 -365
  174. package/dist/tests/paths.test.js +0 -177
  175. package/dist/tests/progressive-disclosure.test.js +0 -280
  176. package/dist/tests/proposals.test.js +0 -279
  177. package/dist/tests/proposed-quality.test.js +0 -271
  178. package/dist/tests/provider-registry.test.js +0 -32
  179. package/dist/tests/ranking-regression.test.js +0 -548
  180. package/dist/tests/reflect-propose.test.js +0 -455
  181. package/dist/tests/registry-build-index.test.js +0 -394
  182. package/dist/tests/registry-cli.test.js +0 -290
  183. package/dist/tests/registry-index-v2.test.js +0 -430
  184. package/dist/tests/registry-install.test.js +0 -728
  185. package/dist/tests/registry-providers/parity.test.js +0 -189
  186. package/dist/tests/registry-providers/skills-sh.test.js +0 -309
  187. package/dist/tests/registry-providers/static-index.test.js +0 -238
  188. package/dist/tests/registry-resolve.test.js +0 -126
  189. package/dist/tests/registry-search.test.js +0 -923
  190. package/dist/tests/remember-frontmatter.test.js +0 -378
  191. package/dist/tests/remember-unit.test.js +0 -123
  192. package/dist/tests/ripgrep-install.test.js +0 -251
  193. package/dist/tests/ripgrep-resolve.test.js +0 -108
  194. package/dist/tests/ripgrep.test.js +0 -163
  195. package/dist/tests/save-command.test.js +0 -94
  196. package/dist/tests/save-trust-qa-fixes.test.js +0 -270
  197. package/dist/tests/scoring-pipeline.test.js +0 -648
  198. package/dist/tests/search-include-proposed-cli.test.js +0 -118
  199. package/dist/tests/self-update.test.js +0 -442
  200. package/dist/tests/semantic-search-e2e.test.js +0 -512
  201. package/dist/tests/semantic-status.test.js +0 -471
  202. package/dist/tests/setup-run.integration.js +0 -877
  203. package/dist/tests/setup-wizard.test.js +0 -198
  204. package/dist/tests/setup.test.js +0 -131
  205. package/dist/tests/source-add.test.js +0 -11
  206. package/dist/tests/source-clone.test.js +0 -254
  207. package/dist/tests/source-manage.test.js +0 -366
  208. package/dist/tests/source-providers/filesystem.test.js +0 -82
  209. package/dist/tests/source-providers/git.test.js +0 -252
  210. package/dist/tests/source-providers/website.test.js +0 -128
  211. package/dist/tests/source-qa-fixes.test.js +0 -286
  212. package/dist/tests/source-registry.test.js +0 -350
  213. package/dist/tests/source-resolve.test.js +0 -100
  214. package/dist/tests/source-source.test.js +0 -281
  215. package/dist/tests/source.test.js +0 -533
  216. package/dist/tests/tar-utils-scan.test.js +0 -73
  217. package/dist/tests/toggle-components.test.js +0 -73
  218. package/dist/tests/usage-telemetry.test.js +0 -265
  219. package/dist/tests/utility-scoring.test.js +0 -558
  220. package/dist/tests/vault-load-error.test.js +0 -78
  221. package/dist/tests/vault-qa-fixes.test.js +0 -194
  222. package/dist/tests/vault.test.js +0 -429
  223. package/dist/tests/vector-search.test.js +0 -608
  224. package/dist/tests/walker.test.js +0 -252
  225. package/dist/tests/wave2-cluster-bc.test.js +0 -228
  226. package/dist/tests/wave2-cluster-d.test.js +0 -180
  227. package/dist/tests/wave2-cluster-e.test.js +0 -179
  228. package/dist/tests/wiki-qa-fixes.test.js +0 -270
  229. package/dist/tests/wiki.test.js +0 -529
  230. package/dist/tests/workflow-cli.test.js +0 -271
  231. package/dist/tests/workflow-markdown.test.js +0 -171
  232. package/dist/tests/workflow-path-escape.test.js +0 -132
  233. package/dist/tests/workflow-qa-fixes.test.js +0 -395
  234. package/dist/tests/workflows/indexer-rejection.test.js +0 -213
  235. /package/dist/{src/commands → commands}/completions.js +0 -0
  236. /package/dist/{src/commands → commands}/config-cli.js +0 -0
  237. /package/dist/{src/commands → commands}/curate.js +0 -0
  238. /package/dist/{src/commands → commands}/distill.js +0 -0
  239. /package/dist/{src/commands → commands}/events.js +0 -0
  240. /package/dist/{src/commands → commands}/history.js +0 -0
  241. /package/dist/{src/commands → commands}/info.js +0 -0
  242. /package/dist/{src/commands → commands}/init.js +0 -0
  243. /package/dist/{src/commands → commands}/install-audit.js +0 -0
  244. /package/dist/{src/commands → commands}/migration-help.js +0 -0
  245. /package/dist/{src/commands → commands}/proposal.js +0 -0
  246. /package/dist/{src/commands → commands}/propose.js +0 -0
  247. /package/dist/{src/commands → commands}/reflect.js +0 -0
  248. /package/dist/{src/commands → commands}/registry-search.js +0 -0
  249. /package/dist/{src/commands → commands}/remember.js +0 -0
  250. /package/dist/{src/commands → commands}/search.js +0 -0
  251. /package/dist/{src/commands → commands}/self-update.js +0 -0
  252. /package/dist/{src/commands → commands}/show.js +0 -0
  253. /package/dist/{src/commands → commands}/source-clone.js +0 -0
  254. /package/dist/{src/commands → commands}/source-manage.js +0 -0
  255. /package/dist/{src/commands → commands}/vault.js +0 -0
  256. /package/dist/{src/core → core}/asset-ref.js +0 -0
  257. /package/dist/{src/core → core}/asset-registry.js +0 -0
  258. /package/dist/{src/core → core}/asset-spec.js +0 -0
  259. /package/dist/{src/core → core}/errors.js +0 -0
  260. /package/dist/{src/core → core}/events.js +0 -0
  261. /package/dist/{src/core → core}/frontmatter.js +0 -0
  262. /package/dist/{src/core → core}/lesson-lint.js +0 -0
  263. /package/dist/{src/core → core}/markdown.js +0 -0
  264. /package/dist/{src/core → core}/paths.js +0 -0
  265. /package/dist/{src/core → core}/proposals.js +0 -0
  266. /package/dist/{src/core → core}/warn.js +0 -0
  267. /package/dist/{src/core → core}/write-source.js +0 -0
  268. /package/dist/{src/indexer → indexer}/db.js +0 -0
  269. /package/dist/{src/indexer → indexer}/file-context.js +0 -0
  270. /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
  271. /package/dist/{src/indexer → indexer}/manifest.js +0 -0
  272. /package/dist/{src/indexer → indexer}/matchers.js +0 -0
  273. /package/dist/{src/indexer → indexer}/metadata.js +0 -0
  274. /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
  275. /package/dist/{src/indexer → indexer}/semantic-status.js +0 -0
  276. /package/dist/{src/indexer → indexer}/usage-events.js +0 -0
  277. /package/dist/{src/indexer → indexer}/walker.js +0 -0
  278. /package/dist/{src/integrations → integrations}/agent/config.js +0 -0
  279. /package/dist/{src/integrations → integrations}/agent/detect.js +0 -0
  280. /package/dist/{src/integrations → integrations}/agent/index.js +0 -0
  281. /package/dist/{src/integrations → integrations}/agent/profiles.js +0 -0
  282. /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
  283. /package/dist/{src/integrations → integrations}/agent/spawn.js +0 -0
  284. /package/dist/{src/integrations → integrations}/github.js +0 -0
  285. /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
  286. /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
  287. /package/dist/{src/llm → llm}/embedders/types.js +0 -0
  288. /package/dist/{src/llm → llm}/feature-gate.js +0 -0
  289. /package/dist/{src/llm → llm}/index-passes.js +0 -0
  290. /package/dist/{src/output → output}/context.js +0 -0
  291. /package/dist/{src/output → output}/renderers.js +0 -0
  292. /package/dist/{src/output → output}/shapes.js +0 -0
  293. /package/dist/{src/output → output}/text.js +0 -0
  294. /package/dist/{src/registry → registry}/build-index.js +0 -0
  295. /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
  296. /package/dist/{src/registry → registry}/factory.js +0 -0
  297. /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
  298. /package/dist/{src/registry → registry}/providers/index.js +0 -0
  299. /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
  300. /package/dist/{src/registry → registry}/providers/static-index.js +0 -0
  301. /package/dist/{src/registry → registry}/providers/types.js +0 -0
  302. /package/dist/{src/registry → registry}/resolve.js +0 -0
  303. /package/dist/{src/registry → registry}/types.js +0 -0
  304. /package/dist/{src/setup → setup}/detect.js +0 -0
  305. /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
  306. /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
  307. /package/dist/{src/setup → setup}/steps.js +0 -0
  308. /package/dist/{src/sources → sources}/include.js +0 -0
  309. /package/dist/{src/sources → sources}/provider-factory.js +0 -0
  310. /package/dist/{src/sources → sources}/provider.js +0 -0
  311. /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
  312. /package/dist/{src/sources → sources}/providers/git.js +0 -0
  313. /package/dist/{src/sources → sources}/providers/index.js +0 -0
  314. /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
  315. /package/dist/{src/sources → sources}/providers/npm.js +0 -0
  316. /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
  317. /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
  318. /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
  319. /package/dist/{src/sources → sources}/resolve.js +0 -0
  320. /package/dist/{src/sources → sources}/types.js +0 -0
  321. /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
  322. /package/dist/{src/version.js → version.js} +0 -0
  323. /package/dist/{src/wiki → wiki}/wiki.js +0 -0
  324. /package/dist/{src/workflows → workflows}/authoring.js +0 -0
  325. /package/dist/{src/workflows → workflows}/cli.js +0 -0
  326. /package/dist/{src/workflows → workflows}/db.js +0 -0
  327. /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
  328. /package/dist/{src/workflows → workflows}/parser.js +0 -0
  329. /package/dist/{src/workflows → workflows}/renderer.js +0 -0
  330. /package/dist/{src/workflows → workflows}/runs.js +0 -0
  331. /package/dist/{src/workflows → workflows}/schema.js +0 -0
  332. /package/dist/{src/workflows → workflows}/validator.js +0 -0
@@ -1,252 +0,0 @@
1
- import { afterAll, afterEach, describe, expect, test } from "bun:test";
2
- import { spawnSync } from "node:child_process";
3
- import fs from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import { walkStash, walkStashFlat } from "../src/indexer/walker";
7
- const createdTmpDirs = [];
8
- function tmpDir() {
9
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-walker-"));
10
- createdTmpDirs.push(dir);
11
- return dir;
12
- }
13
- afterAll(() => {
14
- for (const dir of createdTmpDirs) {
15
- fs.rmSync(dir, { recursive: true, force: true });
16
- }
17
- });
18
- function writeFile(filePath, content = "") {
19
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
20
- fs.writeFileSync(filePath, content);
21
- }
22
- describe("walkStash", () => {
23
- test("returns empty array for non-existent directory", () => {
24
- expect(walkStash("/nonexistent/path", "script")).toEqual([]);
25
- });
26
- test("returns empty array for empty directory", () => {
27
- const dir = tmpDir();
28
- expect(walkStash(dir, "script")).toEqual([]);
29
- });
30
- test("groups script files by parent directory", () => {
31
- const root = tmpDir();
32
- writeFile(path.join(root, "docker", "build.sh"), "echo build\n");
33
- writeFile(path.join(root, "docker", "compose.sh"), "echo compose\n");
34
- writeFile(path.join(root, "git", "diff.ts"), "console.log('diff')\n");
35
- const groups = walkStash(root, "script");
36
- expect(groups).toHaveLength(2);
37
- const dockerGroup = groups.find((g) => g.dirPath.endsWith("docker"));
38
- const gitGroup = groups.find((g) => g.dirPath.endsWith("git"));
39
- expect(dockerGroup).toBeDefined();
40
- expect(dockerGroup?.files).toHaveLength(2);
41
- expect(gitGroup).toBeDefined();
42
- expect(gitGroup?.files).toHaveLength(1);
43
- });
44
- test("skips .stash.json files", () => {
45
- const root = tmpDir();
46
- writeFile(path.join(root, "group", "run.sh"), "echo hi\n");
47
- writeFile(path.join(root, "group", ".stash.json"), '{"entries":[]}');
48
- const groups = walkStash(root, "script");
49
- expect(groups).toHaveLength(1);
50
- const files = groups[0].files;
51
- expect(files).toHaveLength(1);
52
- expect(files[0]).toContain("run.sh");
53
- });
54
- test("only includes relevant files for script type", () => {
55
- const root = tmpDir();
56
- writeFile(path.join(root, "group", "run.sh"), "echo hi\n");
57
- writeFile(path.join(root, "group", "README.md"), "ignore\n");
58
- writeFile(path.join(root, "group", "data.json"), "{}");
59
- const groups = walkStash(root, "script");
60
- expect(groups).toHaveLength(1);
61
- expect(groups[0].files).toHaveLength(1);
62
- });
63
- test("only includes SKILL.md for skill type", () => {
64
- const root = tmpDir();
65
- writeFile(path.join(root, "review", "SKILL.md"), "# Review\n");
66
- writeFile(path.join(root, "review", "README.md"), "ignore\n");
67
- writeFile(path.join(root, "refactor", "SKILL.md"), "# Refactor\n");
68
- const groups = walkStash(root, "skill");
69
- expect(groups).toHaveLength(2);
70
- for (const group of groups) {
71
- expect(group.files).toHaveLength(1);
72
- expect(group.files[0]).toContain("SKILL.md");
73
- }
74
- });
75
- test("only includes .md for command type", () => {
76
- const root = tmpDir();
77
- writeFile(path.join(root, "release.md"), "release\n");
78
- writeFile(path.join(root, "setup.sh"), "echo setup\n");
79
- const groups = walkStash(root, "command");
80
- expect(groups).toHaveLength(1);
81
- expect(groups[0].files).toHaveLength(1);
82
- expect(groups[0].files[0]).toContain("release.md");
83
- });
84
- test("walks nested directories", () => {
85
- const root = tmpDir();
86
- writeFile(path.join(root, "a", "b", "c", "deep.sh"), "echo deep\n");
87
- const groups = walkStash(root, "script");
88
- expect(groups).toHaveLength(1);
89
- expect(groups[0].files[0]).toContain("deep.sh");
90
- });
91
- test("includes files from root level", () => {
92
- const root = tmpDir();
93
- writeFile(path.join(root, "deploy.sh"), "echo deploy\n");
94
- const groups = walkStash(root, "script");
95
- expect(groups).toHaveLength(1);
96
- expect(groups[0].dirPath).toBe(root);
97
- });
98
- test("handles knowledge type (.md files)", () => {
99
- const root = tmpDir();
100
- writeFile(path.join(root, "guide.md"), "# Guide\n");
101
- writeFile(path.join(root, "reference.md"), "# Reference\n");
102
- writeFile(path.join(root, "data.json"), "{}");
103
- const groups = walkStash(root, "knowledge");
104
- expect(groups).toHaveLength(1);
105
- expect(groups[0].files).toHaveLength(2);
106
- });
107
- });
108
- describe("walkStashFlat", () => {
109
- test("returns FileContext objects (not plain paths)", () => {
110
- const root = tmpDir();
111
- writeFile(path.join(root, "scripts", "build.sh"), "echo build\n");
112
- const results = walkStashFlat(root);
113
- expect(results).toHaveLength(1);
114
- const ctx = results[0];
115
- expect(typeof ctx.absPath).toBe("string");
116
- expect(typeof ctx.relPath).toBe("string");
117
- expect(typeof ctx.ext).toBe("string");
118
- expect(typeof ctx.fileName).toBe("string");
119
- expect(typeof ctx.stashRoot).toBe("string");
120
- expect(typeof ctx.content).toBe("function");
121
- expect(typeof ctx.frontmatter).toBe("function");
122
- expect(typeof ctx.stat).toBe("function");
123
- });
124
- test("walks across all asset type directories", () => {
125
- const root = tmpDir();
126
- writeFile(path.join(root, "scripts", "build.sh"), "echo build\n");
127
- writeFile(path.join(root, "agents", "helper.md"), "# Helper\n");
128
- writeFile(path.join(root, "knowledge", "guide.md"), "# Guide\n");
129
- writeFile(path.join(root, "scripts", "deploy.py"), "print('deploy')\n");
130
- const results = walkStashFlat(root);
131
- expect(results).toHaveLength(4);
132
- const fileNames = results.map((r) => r.fileName).sort();
133
- expect(fileNames).toEqual(["build.sh", "deploy.py", "guide.md", "helper.md"]);
134
- });
135
- test("does not filter by asset type", () => {
136
- const root = tmpDir();
137
- writeFile(path.join(root, "data.json"), '{"key":"value"}');
138
- writeFile(path.join(root, "script.py"), "print('hi')\n");
139
- const results = walkStashFlat(root);
140
- expect(results).toHaveLength(2);
141
- const fileNames = results.map((r) => r.fileName).sort();
142
- expect(fileNames).toEqual(["data.json", "script.py"]);
143
- });
144
- test("skips directories starting with dot", () => {
145
- const root = tmpDir();
146
- writeFile(path.join(root, ".hidden", "file.txt"), "secret\n");
147
- writeFile(path.join(root, "visible", "file.txt"), "public\n");
148
- const results = walkStashFlat(root);
149
- expect(results).toHaveLength(1);
150
- expect(results[0].fileName).toBe("file.txt");
151
- expect(results[0].absPath).toContain("visible");
152
- });
153
- test("preserves stashRoot on all FileContext results", () => {
154
- const root = tmpDir();
155
- writeFile(path.join(root, "a", "one.sh"), "echo one\n");
156
- writeFile(path.join(root, "b", "two.md"), "# Two\n");
157
- writeFile(path.join(root, "c", "three.py"), "print(3)\n");
158
- const results = walkStashFlat(root);
159
- expect(results).toHaveLength(3);
160
- for (const ctx of results) {
161
- expect(ctx.stashRoot).toBe(root);
162
- }
163
- });
164
- test("git walk stays scoped to the stash root subtree", () => {
165
- const repoRoot = tmpDir();
166
- const stashRoot = path.join(repoRoot, "stash");
167
- writeFile(path.join(repoRoot, "outside.txt"), "outside\n");
168
- writeFile(path.join(stashRoot, "scripts", "build.sh"), "echo build\n");
169
- const gitInit = spawnSync("git", ["init"], { cwd: repoRoot, encoding: "utf8" });
170
- expect(gitInit.status).toBe(0);
171
- const results = walkStashFlat(stashRoot);
172
- expect(results).toHaveLength(1);
173
- expect(results[0]?.relPath).toBe("scripts/build.sh");
174
- expect(results[0]?.absPath.startsWith(stashRoot)).toBe(true);
175
- });
176
- });
177
- // ── T6: isInsideGitRepo in nested repo ───────────────────────────────────────
178
- //
179
- // Gap: isInsideGitRepo() walks up the directory tree looking for .git. In a
180
- // nested git repo (e.g. a stash directory inside a monorepo worktree), it
181
- // should find the nearest .git — but creating nested repos in CI is fragile
182
- // and platform-dependent, so this gap is intentionally left untested here.
183
- // If regression is suspected, test manually by creating a nested git init
184
- // inside an existing repo and verifying walkStashFlat still uses the git walker.
185
- // ── R4.3: symlink escape ─────────────────────────────────────────────────────
186
- //
187
- // walkStashFlat (manual fallback) must skip symlinks that point outside the
188
- // stash root so that malicious or accidental symlinks cannot leak files from
189
- // the host filesystem into search results.
190
- describe("walkStashFlat — symlink escape", () => {
191
- // Track extra files created outside tmpDir() so we can clean them up.
192
- const extraFiles = [];
193
- afterEach(() => {
194
- for (const f of extraFiles.splice(0)) {
195
- try {
196
- fs.rmSync(f, { force: true });
197
- }
198
- catch {
199
- // best-effort
200
- }
201
- }
202
- });
203
- test("symlink pointing outside stash root is NOT included in results", () => {
204
- // Create a stash root that is NOT inside a git repo so the manual walker
205
- // is used (the git walker relies on git ls-files which won't list a
206
- // symlink that targets an untracked file outside the repo).
207
- const stashRoot = tmpDir();
208
- const skillsDir = path.join(stashRoot, "skills");
209
- fs.mkdirSync(skillsDir, { recursive: true });
210
- // Create a real file OUTSIDE the stash root
211
- const outsideFile = path.join(os.tmpdir(), `akm-symlink-target-${process.pid}-${Date.now()}.md`);
212
- fs.writeFileSync(outsideFile, "# Secret content outside stash\n");
213
- extraFiles.push(outsideFile);
214
- // Create a symlink inside the stash that points to the outside file
215
- const symlinkPath = path.join(skillsDir, "escaped.md");
216
- fs.symlinkSync(outsideFile, symlinkPath);
217
- // Also create a legitimate file so we can confirm the walker still works
218
- writeFile(path.join(skillsDir, "legitimate.md"), "# Legit\n");
219
- const results = walkStashFlat(stashRoot);
220
- const resultPaths = results.map((r) => r.absPath);
221
- // The symlink must NOT appear in results
222
- expect(resultPaths).not.toContain(symlinkPath);
223
- // Confirm the outside target is also not reached through the symlink
224
- expect(resultPaths).not.toContain(outsideFile);
225
- // The legitimate file should still be found
226
- expect(resultPaths.some((p) => p.endsWith("legitimate.md"))).toBe(true);
227
- // Cleanup the symlink (tmpDir cleanup handles the rest)
228
- fs.rmSync(symlinkPath, { force: true });
229
- });
230
- test("symlink pointing to a directory outside stash root is also skipped", () => {
231
- const stashRoot = tmpDir();
232
- const knowledgeDir = path.join(stashRoot, "knowledge");
233
- fs.mkdirSync(knowledgeDir, { recursive: true });
234
- // Create a directory OUTSIDE the stash with a file inside
235
- const outsideDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-symlink-dir-target-"));
236
- extraFiles.push(outsideDir);
237
- fs.writeFileSync(path.join(outsideDir, "secret.md"), "# Outside dir secret\n");
238
- // Symlink the outside directory into the stash
239
- const symlinkDir = path.join(knowledgeDir, "escaped-dir");
240
- fs.symlinkSync(outsideDir, symlinkDir);
241
- // Create a legitimate file to confirm walker still functions
242
- writeFile(path.join(knowledgeDir, "real.md"), "# Real\n");
243
- const results = walkStashFlat(stashRoot);
244
- const resultPaths = results.map((r) => r.absPath);
245
- // No file from inside the outside dir must appear
246
- expect(resultPaths.some((p) => p.startsWith(outsideDir))).toBe(false);
247
- // The legitimate file should still be found
248
- expect(resultPaths.some((p) => p.endsWith("real.md"))).toBe(true);
249
- // Cleanup the symlink
250
- fs.rmSync(symlinkDir, { force: true });
251
- });
252
- });
@@ -1,228 +0,0 @@
1
- /**
2
- * Wave-2 QA fixes tests — Cluster B (#21, #36) and Cluster C (#6, #14, #24).
3
- *
4
- * Cluster B: defaultWriteTarget and llm/embedding subkey support in config-cli.
5
- * Cluster C: empty-query guards + minScore floor for semantic-only hits.
6
- */
7
- import { describe, expect, test } from "bun:test";
8
- import { getConfigValue, listConfig, parseConfigValue, setConfigValue, unsetConfigValue, } from "../src/commands/config-cli";
9
- // ── Cluster B: #21 defaultWriteTarget ────────────────────────────────────────
10
- describe("config-cli: defaultWriteTarget (#21)", () => {
11
- const base = { semanticSearchMode: "auto" };
12
- test("parseConfigValue returns defaultWriteTarget", () => {
13
- expect(parseConfigValue("defaultWriteTarget", "my-stash")).toEqual({
14
- defaultWriteTarget: "my-stash",
15
- });
16
- });
17
- test("parseConfigValue rejects empty defaultWriteTarget", () => {
18
- expect(() => parseConfigValue("defaultWriteTarget", "")).toThrow();
19
- });
20
- test("getConfigValue returns null when not set", () => {
21
- expect(getConfigValue(base, "defaultWriteTarget")).toBeNull();
22
- });
23
- test("getConfigValue returns the set value", () => {
24
- const config = { ...base, defaultWriteTarget: "my-stash" };
25
- expect(getConfigValue(config, "defaultWriteTarget")).toBe("my-stash");
26
- });
27
- test("setConfigValue sets defaultWriteTarget — no sources configured", () => {
28
- const result = setConfigValue(base, "defaultWriteTarget", "any-name");
29
- expect(result.defaultWriteTarget).toBe("any-name");
30
- });
31
- test("setConfigValue validates name against sources when sources[] is non-empty", () => {
32
- const config = {
33
- ...base,
34
- sources: [{ type: "filesystem", path: "/tmp/stash", name: "primary" }],
35
- };
36
- expect(() => setConfigValue(config, "defaultWriteTarget", "unknown-stash")).toThrow(/Unknown source name/);
37
- });
38
- test("setConfigValue accepts a valid source name", () => {
39
- const config = {
40
- ...base,
41
- sources: [{ type: "filesystem", path: "/tmp/stash", name: "primary" }],
42
- };
43
- const result = setConfigValue(config, "defaultWriteTarget", "primary");
44
- expect(result.defaultWriteTarget).toBe("primary");
45
- });
46
- test("unsetConfigValue clears defaultWriteTarget", () => {
47
- const config = { ...base, defaultWriteTarget: "primary" };
48
- const result = unsetConfigValue(config, "defaultWriteTarget");
49
- expect(result.defaultWriteTarget).toBeUndefined();
50
- });
51
- test("listConfig includes defaultWriteTarget when set", () => {
52
- const config = { ...base, defaultWriteTarget: "primary" };
53
- const listed = listConfig(config);
54
- expect(listed.defaultWriteTarget).toBe("primary");
55
- });
56
- test("listConfig omits defaultWriteTarget when not set", () => {
57
- const listed = listConfig(base);
58
- expect(listed.defaultWriteTarget).toBeUndefined();
59
- });
60
- });
61
- // ── Cluster B: #36 llm/embedding subkey support ───────────────────────────────
62
- describe("config-cli: llm.* and embedding.* subkeys (#36)", () => {
63
- const base = { semanticSearchMode: "auto" };
64
- // ── parseConfigValue ──────────────────────────────────────────────────────
65
- test("parseConfigValue handles llm.endpoint", () => {
66
- const result = parseConfigValue("llm.endpoint", "http://localhost:11434/v1/chat/completions");
67
- expect(result.llm?.endpoint).toBe("http://localhost:11434/v1/chat/completions");
68
- });
69
- test("parseConfigValue handles llm.model", () => {
70
- const result = parseConfigValue("llm.model", "llama3.2");
71
- expect(result.llm?.model).toBe("llama3.2");
72
- });
73
- test("parseConfigValue handles llm.apiKey", () => {
74
- const result = parseConfigValue("llm.apiKey", "sk-test");
75
- expect(result.llm?.apiKey).toBe("sk-test");
76
- });
77
- test("parseConfigValue handles embedding.endpoint", () => {
78
- const result = parseConfigValue("embedding.endpoint", "http://localhost:11434/v1/embeddings");
79
- expect(result.embedding?.endpoint).toBe("http://localhost:11434/v1/embeddings");
80
- });
81
- test("parseConfigValue handles embedding.model", () => {
82
- const result = parseConfigValue("embedding.model", "nomic-embed-text");
83
- expect(result.embedding?.model).toBe("nomic-embed-text");
84
- });
85
- test("parseConfigValue handles embedding.apiKey", () => {
86
- const result = parseConfigValue("embedding.apiKey", "sk-embed");
87
- expect(result.embedding?.apiKey).toBe("sk-embed");
88
- });
89
- test("parseConfigValue rejects empty llm.endpoint", () => {
90
- expect(() => parseConfigValue("llm.endpoint", "")).toThrow();
91
- });
92
- // ── getConfigValue ────────────────────────────────────────────────────────
93
- test("getConfigValue: llm.endpoint returns null when llm not set", () => {
94
- expect(getConfigValue(base, "llm.endpoint")).toBeNull();
95
- });
96
- test("getConfigValue: llm.endpoint returns value when set", () => {
97
- const config = {
98
- ...base,
99
- llm: { endpoint: "http://localhost/v1", model: "llama3.2" },
100
- };
101
- expect(getConfigValue(config, "llm.endpoint")).toBe("http://localhost/v1");
102
- expect(getConfigValue(config, "llm.model")).toBe("llama3.2");
103
- expect(getConfigValue(config, "llm.apiKey")).toBeNull();
104
- });
105
- test("getConfigValue: embedding subkeys work", () => {
106
- const config = {
107
- ...base,
108
- embedding: { endpoint: "http://localhost/emb", model: "bge-small" },
109
- };
110
- expect(getConfigValue(config, "embedding.endpoint")).toBe("http://localhost/emb");
111
- expect(getConfigValue(config, "embedding.model")).toBe("bge-small");
112
- expect(getConfigValue(config, "embedding.apiKey")).toBeNull();
113
- });
114
- // ── setConfigValue with deep merge ────────────────────────────────────────
115
- test("setConfigValue: llm.endpoint preserves sibling model field", () => {
116
- const config = {
117
- ...base,
118
- llm: { endpoint: "http://old/", model: "old-model" },
119
- };
120
- const result = setConfigValue(config, "llm.endpoint", "http://new/");
121
- expect(result.llm?.endpoint).toBe("http://new/");
122
- expect(result.llm?.model).toBe("old-model");
123
- });
124
- test("setConfigValue: llm.model preserves sibling endpoint field", () => {
125
- const config = {
126
- ...base,
127
- llm: { endpoint: "http://localhost/v1", model: "old-model" },
128
- };
129
- const result = setConfigValue(config, "llm.model", "gpt-4o");
130
- expect(result.llm?.model).toBe("gpt-4o");
131
- expect(result.llm?.endpoint).toBe("http://localhost/v1");
132
- });
133
- test("setConfigValue: llm.apiKey merges into existing llm config", () => {
134
- const config = {
135
- ...base,
136
- llm: { endpoint: "http://localhost/v1", model: "llama3.2" },
137
- };
138
- const result = setConfigValue(config, "llm.apiKey", "sk-secret");
139
- expect(result.llm?.apiKey).toBe("sk-secret");
140
- expect(result.llm?.endpoint).toBe("http://localhost/v1");
141
- });
142
- test("setConfigValue: embedding.endpoint works when embedding was undefined", () => {
143
- const result = setConfigValue(base, "embedding.endpoint", "http://localhost/emb");
144
- expect(result.embedding?.endpoint).toBe("http://localhost/emb");
145
- expect(result.embedding?.model).toBe("");
146
- });
147
- // ── unsetConfigValue ──────────────────────────────────────────────────────
148
- test("unsetConfigValue: llm.endpoint sets endpoint to empty string", () => {
149
- const config = {
150
- ...base,
151
- llm: { endpoint: "http://localhost/v1", model: "llama3.2" },
152
- };
153
- const result = unsetConfigValue(config, "llm.endpoint");
154
- expect(result.llm?.endpoint).toBe("");
155
- expect(result.llm?.model).toBe("llama3.2");
156
- });
157
- test("unsetConfigValue: llm.apiKey removes the key", () => {
158
- const config = {
159
- ...base,
160
- llm: { endpoint: "http://localhost/v1", model: "llama3.2", apiKey: "sk-secret" },
161
- };
162
- const result = unsetConfigValue(config, "llm.apiKey");
163
- expect(result.llm?.apiKey).toBeUndefined();
164
- expect(result.llm?.endpoint).toBe("http://localhost/v1");
165
- });
166
- test("unsetConfigValue: embedding.apiKey removes the key", () => {
167
- const config = {
168
- ...base,
169
- embedding: { endpoint: "http://localhost/emb", model: "bge-small", apiKey: "sk-embed" },
170
- };
171
- const result = unsetConfigValue(config, "embedding.apiKey");
172
- expect(result.embedding?.apiKey).toBeUndefined();
173
- expect(result.embedding?.endpoint).toBe("http://localhost/emb");
174
- });
175
- });
176
- // ── Cluster C: #14 empty query guard ────────────────────────────────────────
177
- describe("search empty-query guard (#14, #24)", () => {
178
- // Note: The empty-query guard for `akmSearch` lives in the CLI layer (src/cli.ts),
179
- // not in `akmSearch` itself (which accepts empty queries for programmatic list-all).
180
- // The guard for `akmCurate` IS in the function itself since curation always
181
- // requires a meaningful query.
182
- test("akmCurate throws UsageError for empty string query", async () => {
183
- const { akmCurate } = await import("../src/commands/curate");
184
- await expect(akmCurate({ query: "" })).rejects.toThrow(/query is required/i);
185
- });
186
- test("akmCurate throws UsageError for whitespace-only query", async () => {
187
- const { akmCurate } = await import("../src/commands/curate");
188
- await expect(akmCurate({ query: " " })).rejects.toThrow(/query is required/i);
189
- });
190
- test("akmCurate UsageError has MISSING_REQUIRED_ARGUMENT code", async () => {
191
- const { akmCurate } = await import("../src/commands/curate");
192
- const { UsageError } = await import("../src/core/errors");
193
- try {
194
- await akmCurate({ query: "" });
195
- throw new Error("should have thrown");
196
- }
197
- catch (err) {
198
- expect(err).toBeInstanceOf(UsageError);
199
- expect(err.code).toBe("MISSING_REQUIRED_ARGUMENT");
200
- }
201
- });
202
- });
203
- // ── Cluster C: #6 minScore floor ─────────────────────────────────────────────
204
- describe("search.minScore floor in config (#6)", () => {
205
- test("AkmConfig accepts search.minScore", () => {
206
- const config = {
207
- semanticSearchMode: "auto",
208
- search: { minScore: 0.3 },
209
- };
210
- expect(config.search?.minScore).toBe(0.3);
211
- });
212
- test("AkmConfig accepts search.minScore of 0 (disabled)", () => {
213
- const config = {
214
- semanticSearchMode: "auto",
215
- search: { minScore: 0 },
216
- };
217
- expect(config.search?.minScore).toBe(0);
218
- });
219
- test("minScore default is 0.2 in db-search (white-box)", () => {
220
- // Verify the default is what the implementation docs: if search is
221
- // undefined then minScore should be 0.2 (defaulted in db-search.ts).
222
- const config = { semanticSearchMode: "auto" };
223
- expect(config.search?.minScore).toBeUndefined();
224
- // The effective default 0.2 is applied inside searchDatabase; we just
225
- // confirm the config field default is undefined here. An integration test
226
- // would require a live DB with semantic hits, which is out of scope.
227
- });
228
- });
@@ -1,180 +0,0 @@
1
- /**
2
- * Wave-2 QA fixes tests — Cluster D (errors, exit codes, hint text).
3
- *
4
- * #8 — hint field rendered in error output (already working; regression guard).
5
- * #13 — UsageError exits 2, ConfigError exits 78, NotFoundError exits 1.
6
- * #15 — `akm show foo` (malformed ref) throws UsageError/MISSING_REQUIRED_ARGUMENT.
7
- * #16 — `config set sources <bad>` says "sources" not "stashes".
8
- * #27 — clone missing asset: user-facing message, no "Stash type root" leakage.
9
- * #38 — deprecation hints reference real commands.
10
- */
11
- import { describe, expect, test } from "bun:test";
12
- import { parseConfigValue } from "../src/commands/config-cli";
13
- import { parseAssetRef } from "../src/core/asset-ref";
14
- import { ConfigError, NotFoundError, UsageError } from "../src/core/errors";
15
- // ── #15: parseAssetRef — MISSING_REQUIRED_ARGUMENT code ────────────────────
16
- describe("parseAssetRef error codes (#15)", () => {
17
- test("empty ref throws UsageError with MISSING_REQUIRED_ARGUMENT", () => {
18
- try {
19
- parseAssetRef("");
20
- throw new Error("should have thrown");
21
- }
22
- catch (err) {
23
- expect(err).toBeInstanceOf(UsageError);
24
- expect(err.code).toBe("MISSING_REQUIRED_ARGUMENT");
25
- }
26
- });
27
- test("ref without colon throws UsageError with MISSING_REQUIRED_ARGUMENT", () => {
28
- try {
29
- parseAssetRef("foo");
30
- throw new Error("should have thrown");
31
- }
32
- catch (err) {
33
- expect(err).toBeInstanceOf(UsageError);
34
- expect(err.code).toBe("MISSING_REQUIRED_ARGUMENT");
35
- }
36
- });
37
- test("ref with invalid type throws UsageError with MISSING_REQUIRED_ARGUMENT", () => {
38
- try {
39
- parseAssetRef("badtype:name");
40
- throw new Error("should have thrown");
41
- }
42
- catch (err) {
43
- expect(err).toBeInstanceOf(UsageError);
44
- expect(err.code).toBe("MISSING_REQUIRED_ARGUMENT");
45
- }
46
- });
47
- test("valid ref parses correctly", () => {
48
- const ref = parseAssetRef("skill:deploy");
49
- expect(ref.type).toBe("skill");
50
- expect(ref.name).toBe("deploy");
51
- });
52
- test("MISSING_REQUIRED_ARGUMENT has a hint in errors.ts", () => {
53
- const err = new UsageError("test", "MISSING_REQUIRED_ARGUMENT");
54
- expect(err.hint()).toBeDefined();
55
- expect(err.hint()).toMatch(/type:name/);
56
- });
57
- });
58
- // ── #13: exit code classification ────────────────────────────────────────────
59
- describe("error class exit-code classification (#13)", () => {
60
- test("UsageError should be classified as exit 2", () => {
61
- const err = new UsageError("bad input");
62
- // Verify the code exists so callers can distinguish
63
- expect(err.name).toBe("UsageError");
64
- expect(err instanceof UsageError).toBe(true);
65
- });
66
- test("ConfigError should be classified as exit 78", () => {
67
- const err = new ConfigError("config bad");
68
- expect(err.name).toBe("ConfigError");
69
- expect(err instanceof ConfigError).toBe(true);
70
- });
71
- test("NotFoundError should be classified as exit 1 (GENERAL)", () => {
72
- const err = new NotFoundError("not found");
73
- expect(err.name).toBe("NotFoundError");
74
- expect(err instanceof NotFoundError).toBe(true);
75
- });
76
- test("UsageError and ConfigError are distinguishable via instanceof", () => {
77
- const usage = new UsageError("bad");
78
- const config = new ConfigError("bad");
79
- expect(usage instanceof UsageError).toBe(true);
80
- expect(usage instanceof ConfigError).toBe(false);
81
- expect(config instanceof ConfigError).toBe(true);
82
- expect(config instanceof UsageError).toBe(false);
83
- });
84
- });
85
- // ── #8: hint field rendered ───────────────────────────────────────────────────
86
- describe("error hint rendering (#8)", () => {
87
- test("ConfigError with hint: true returns hint", () => {
88
- const err = new ConfigError("bad", "STASH_DIR_NOT_FOUND");
89
- expect(err.hint()).toBeDefined();
90
- expect(err.hint()).toMatch(/akm init/);
91
- });
92
- test("ConfigError with explicit hint returns it", () => {
93
- const err = new ConfigError("bad", "INVALID_CONFIG_FILE", "my custom hint");
94
- expect(err.hint()).toBe("my custom hint");
95
- });
96
- test("UsageError with INVALID_SOURCE_VALUE has a hint", () => {
97
- const err = new UsageError("bad source", "INVALID_SOURCE_VALUE");
98
- expect(err.hint()).toBeDefined();
99
- expect(err.hint()).toContain("stash");
100
- });
101
- test("NotFoundError with ASSET_NOT_FOUND has a canned hint (Wave C #284)", () => {
102
- const err = new NotFoundError("not found");
103
- // Wave C added a default hint for ASSET_NOT_FOUND pointing at search/index.
104
- expect(err.hint()).toContain("akm search");
105
- });
106
- test("NotFoundError with explicit hint returns it", () => {
107
- const err = new NotFoundError("not found", "ASSET_NOT_FOUND", "run akm init");
108
- expect(err.hint()).toBe("run akm init");
109
- });
110
- });
111
- // ── #16: config set sources error message says "sources" ─────────────────────
112
- describe("config-cli parseConfigValue sources error message (#16)", () => {
113
- test("invalid sources value shows 'sources' not 'stashes' in error", () => {
114
- try {
115
- parseConfigValue("sources", "not-json");
116
- throw new Error("should have thrown");
117
- }
118
- catch (err) {
119
- expect(err).toBeInstanceOf(UsageError);
120
- const msg = err.message;
121
- expect(msg).toContain("sources");
122
- expect(msg).not.toContain("stashes");
123
- }
124
- });
125
- test("stashes alias also shows 'sources' in error", () => {
126
- try {
127
- parseConfigValue("stashes", "not-json");
128
- throw new Error("should have thrown");
129
- }
130
- catch (err) {
131
- expect(err).toBeInstanceOf(UsageError);
132
- const msg = err.message;
133
- expect(msg).toContain("sources");
134
- }
135
- });
136
- test("invalid array element shows 'sources[0]' not 'stashes[0]'", () => {
137
- try {
138
- parseConfigValue("sources", "[{}]");
139
- throw new Error("should have thrown");
140
- }
141
- catch (err) {
142
- expect(err).toBeInstanceOf(UsageError);
143
- const msg = err.message;
144
- expect(msg).toContain("sources[0]");
145
- expect(msg).not.toContain("stashes[0]");
146
- }
147
- });
148
- });
149
- // ── #27: source-resolve user-facing error messages ───────────────────────────
150
- describe("source-resolve user-facing errors (#27)", () => {
151
- test("error message does not contain 'Stash type root'", async () => {
152
- // Import the resolver lazily so we don't pull in full DB on every test run.
153
- const { resolveAssetPath } = await import("../src/sources/resolve");
154
- try {
155
- await resolveAssetPath("/tmp/nonexistent-stash-dir-xyz", "skill", "missing-skill");
156
- throw new Error("should have thrown");
157
- }
158
- catch (err) {
159
- expect(err).toBeInstanceOf(NotFoundError);
160
- const msg = err.message;
161
- expect(msg).not.toContain("Stash type root");
162
- // Should contain user-facing wording
163
- expect(msg).toMatch(/Asset not found for ref|not found for ref|not accessible/i);
164
- }
165
- });
166
- test("error hint is set on the not-found error from source-resolve", async () => {
167
- const { resolveAssetPath } = await import("../src/sources/resolve");
168
- try {
169
- await resolveAssetPath("/tmp/nonexistent-stash-dir-xyz", "skill", "missing-skill");
170
- throw new Error("should have thrown");
171
- }
172
- catch (err) {
173
- expect(err).toBeInstanceOf(NotFoundError);
174
- const hint = err.hint();
175
- // Should have an actionable hint
176
- expect(hint).toBeDefined();
177
- expect(hint).toMatch(/akm list|akm index/i);
178
- }
179
- });
180
- });