akm-cli 0.7.0-rc1 → 0.7.1

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 (314) hide show
  1. package/dist/{src/cli.js → cli.js} +100 -16
  2. package/dist/{src/commands → commands}/config-cli.js +42 -0
  3. package/dist/{src/commands → commands}/history.js +78 -7
  4. package/dist/{src/commands → commands}/registry-search.js +69 -6
  5. package/dist/{src/commands → commands}/search.js +30 -3
  6. package/dist/{src/commands → commands}/show.js +29 -0
  7. package/dist/{src/commands → commands}/source-add.js +5 -1
  8. package/dist/{src/commands → commands}/source-manage.js +7 -1
  9. package/dist/{src/core → core}/config.js +28 -0
  10. package/dist/{src/indexer → indexer}/db-search.js +1 -0
  11. package/dist/{src/indexer → indexer}/indexer.js +16 -2
  12. package/dist/{src/indexer → indexer}/matchers.js +1 -1
  13. package/dist/{src/indexer → indexer}/search-source.js +4 -2
  14. package/dist/{src/integrations → integrations}/agent/profiles.js +1 -1
  15. package/dist/{src/integrations → integrations}/agent/spawn.js +67 -16
  16. package/dist/{src/integrations → integrations}/github.js +9 -3
  17. package/dist/{src/llm → llm}/embedders/remote.js +37 -3
  18. package/dist/{src/output → output}/cli-hints.js +15 -2
  19. package/dist/{src/output → output}/renderers.js +3 -1
  20. package/dist/{src/output → output}/shapes.js +8 -1
  21. package/dist/{src/output → output}/text.js +156 -3
  22. package/dist/{src/registry → registry}/build-index.js +5 -4
  23. package/dist/{src/registry → registry}/providers/static-index.js +3 -1
  24. package/dist/{src/setup → setup}/setup.js +9 -0
  25. package/dist/{src/wiki → wiki}/wiki.js +54 -6
  26. package/dist/{src/workflows → workflows}/runs.js +37 -3
  27. package/package.json +8 -8
  28. package/dist/tests/add-website-source.test.js +0 -119
  29. package/dist/tests/agent/agent-config-loader.test.js +0 -70
  30. package/dist/tests/agent/agent-config.test.js +0 -221
  31. package/dist/tests/agent/agent-detect.test.js +0 -100
  32. package/dist/tests/agent/agent-spawn.test.js +0 -234
  33. package/dist/tests/agent-output.test.js +0 -186
  34. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
  35. package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
  36. package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
  37. package/dist/tests/asset-ref.test.js +0 -192
  38. package/dist/tests/asset-registry.test.js +0 -103
  39. package/dist/tests/asset-spec.test.js +0 -241
  40. package/dist/tests/bench/attribution.test.js +0 -995
  41. package/dist/tests/bench/cleanup-sigint.test.js +0 -83
  42. package/dist/tests/bench/cleanup.js +0 -203
  43. package/dist/tests/bench/cleanup.test.js +0 -166
  44. package/dist/tests/bench/cli.js +0 -683
  45. package/dist/tests/bench/cli.test.js +0 -177
  46. package/dist/tests/bench/compare.test.js +0 -556
  47. package/dist/tests/bench/corpus.js +0 -314
  48. package/dist/tests/bench/corpus.test.js +0 -258
  49. package/dist/tests/bench/driver.js +0 -346
  50. package/dist/tests/bench/driver.test.js +0 -443
  51. package/dist/tests/bench/evolve-metrics.js +0 -179
  52. package/dist/tests/bench/evolve-metrics.test.js +0 -187
  53. package/dist/tests/bench/evolve.js +0 -580
  54. package/dist/tests/bench/evolve.test.js +0 -616
  55. package/dist/tests/bench/failure-modes.test.js +0 -300
  56. package/dist/tests/bench/feedback-integrity.test.js +0 -456
  57. package/dist/tests/bench/leakage.test.js +0 -125
  58. package/dist/tests/bench/learning-curve.test.js +0 -133
  59. package/dist/tests/bench/metrics.js +0 -2319
  60. package/dist/tests/bench/metrics.test.js +0 -1144
  61. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
  62. package/dist/tests/bench/report.js +0 -1821
  63. package/dist/tests/bench/report.test.js +0 -989
  64. package/dist/tests/bench/runner.js +0 -536
  65. package/dist/tests/bench/runner.test.js +0 -958
  66. package/dist/tests/bench/search-bridge.test.js +0 -331
  67. package/dist/tests/bench/tmp.js +0 -41
  68. package/dist/tests/bench/trajectory.js +0 -116
  69. package/dist/tests/bench/trajectory.test.js +0 -127
  70. package/dist/tests/bench/verifier.js +0 -109
  71. package/dist/tests/bench/verifier.test.js +0 -118
  72. package/dist/tests/bench/workflow-evaluator.js +0 -557
  73. package/dist/tests/bench/workflow-evaluator.test.js +0 -421
  74. package/dist/tests/bench/workflow-spec.js +0 -358
  75. package/dist/tests/bench/workflow-spec.test.js +0 -363
  76. package/dist/tests/bench/workflow-trace.js +0 -438
  77. package/dist/tests/bench/workflow-trace.test.js +0 -254
  78. package/dist/tests/benchmark-search-quality.js +0 -536
  79. package/dist/tests/benchmark-suite.js +0 -1441
  80. package/dist/tests/capture-cli.test.js +0 -112
  81. package/dist/tests/cli-errors.test.js +0 -203
  82. package/dist/tests/commands/events.test.js +0 -370
  83. package/dist/tests/commands/history.test.js +0 -223
  84. package/dist/tests/commands/import.test.js +0 -103
  85. package/dist/tests/commands/proposal-cli.test.js +0 -209
  86. package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
  87. package/dist/tests/commands/remember.test.js +0 -97
  88. package/dist/tests/commands/scope-flags.test.js +0 -300
  89. package/dist/tests/commands/search.test.js +0 -537
  90. package/dist/tests/commands/show-indexer-parity.test.js +0 -117
  91. package/dist/tests/commands/show.test.js +0 -294
  92. package/dist/tests/common.test.js +0 -266
  93. package/dist/tests/completions.test.js +0 -142
  94. package/dist/tests/config-cli.test.js +0 -193
  95. package/dist/tests/config-llm-features.test.js +0 -139
  96. package/dist/tests/config.test.js +0 -544
  97. package/dist/tests/contracts/migration-baseline.test.js +0 -43
  98. package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
  99. package/dist/tests/contracts/spec-helpers.js +0 -46
  100. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
  101. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
  102. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
  103. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
  104. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
  105. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
  106. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
  107. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
  108. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
  109. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
  110. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
  111. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
  112. package/dist/tests/core/write-source.test.js +0 -366
  113. package/dist/tests/curate-command.test.js +0 -87
  114. package/dist/tests/db-scoring.test.js +0 -201
  115. package/dist/tests/db.test.js +0 -654
  116. package/dist/tests/distill-cli-flag.test.js +0 -208
  117. package/dist/tests/distill.test.js +0 -515
  118. package/dist/tests/docker-install.test.js +0 -120
  119. package/dist/tests/e2e.test.js +0 -1398
  120. package/dist/tests/embedder.test.js +0 -340
  121. package/dist/tests/embedding-model-config.test.js +0 -379
  122. package/dist/tests/feedback-command.test.js +0 -172
  123. package/dist/tests/file-context.test.js +0 -552
  124. package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
  125. package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
  126. package/dist/tests/fixtures/stashes/load.js +0 -166
  127. package/dist/tests/fixtures/stashes/load.test.js +0 -88
  128. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
  129. package/dist/tests/frontmatter.test.js +0 -190
  130. package/dist/tests/fts-field-weighting.test.js +0 -254
  131. package/dist/tests/fuzzy-search.test.js +0 -230
  132. package/dist/tests/git-provider-clone.test.js +0 -45
  133. package/dist/tests/github.test.js +0 -161
  134. package/dist/tests/graph-boost-ranking.test.js +0 -305
  135. package/dist/tests/graph-extraction.test.js +0 -282
  136. package/dist/tests/helpers/usage-events.js +0 -8
  137. package/dist/tests/index-pass-llm.test.js +0 -161
  138. package/dist/tests/indexer.test.js +0 -559
  139. package/dist/tests/info-command.test.js +0 -166
  140. package/dist/tests/init.test.js +0 -69
  141. package/dist/tests/install-script.test.js +0 -246
  142. package/dist/tests/integration/agent-real-profile.test.js +0 -94
  143. package/dist/tests/issue-36-repro.test.js +0 -304
  144. package/dist/tests/issues-191-194.test.js +0 -160
  145. package/dist/tests/lesson-lint.test.js +0 -111
  146. package/dist/tests/llm-client.test.js +0 -115
  147. package/dist/tests/llm-feature-gate.test.js +0 -151
  148. package/dist/tests/llm.test.js +0 -139
  149. package/dist/tests/lockfile.test.js +0 -216
  150. package/dist/tests/manifest.test.js +0 -205
  151. package/dist/tests/markdown.test.js +0 -126
  152. package/dist/tests/matchers-unit.test.js +0 -189
  153. package/dist/tests/memory-inference.test.js +0 -299
  154. package/dist/tests/merge-scoring.test.js +0 -136
  155. package/dist/tests/metadata.test.js +0 -313
  156. package/dist/tests/migration-help.test.js +0 -89
  157. package/dist/tests/origin-resolve.test.js +0 -124
  158. package/dist/tests/output-baseline.test.js +0 -217
  159. package/dist/tests/output-shapes-unit.test.js +0 -476
  160. package/dist/tests/parallel-search.test.js +0 -272
  161. package/dist/tests/parameter-metadata.test.js +0 -365
  162. package/dist/tests/paths.test.js +0 -177
  163. package/dist/tests/progressive-disclosure.test.js +0 -280
  164. package/dist/tests/proposals.test.js +0 -279
  165. package/dist/tests/proposed-quality.test.js +0 -271
  166. package/dist/tests/provider-registry.test.js +0 -32
  167. package/dist/tests/ranking-regression.test.js +0 -548
  168. package/dist/tests/reflect-propose.test.js +0 -455
  169. package/dist/tests/registry-build-index.test.js +0 -378
  170. package/dist/tests/registry-cli.test.js +0 -290
  171. package/dist/tests/registry-index-v2.test.js +0 -430
  172. package/dist/tests/registry-install.test.js +0 -728
  173. package/dist/tests/registry-providers/parity.test.js +0 -189
  174. package/dist/tests/registry-providers/skills-sh.test.js +0 -309
  175. package/dist/tests/registry-providers/static-index.test.js +0 -204
  176. package/dist/tests/registry-resolve.test.js +0 -126
  177. package/dist/tests/registry-search.test.js +0 -723
  178. package/dist/tests/remember-frontmatter.test.js +0 -380
  179. package/dist/tests/remember-unit.test.js +0 -123
  180. package/dist/tests/ripgrep-install.test.js +0 -251
  181. package/dist/tests/ripgrep-resolve.test.js +0 -108
  182. package/dist/tests/ripgrep.test.js +0 -163
  183. package/dist/tests/save-command.test.js +0 -94
  184. package/dist/tests/save-trust-qa-fixes.test.js +0 -270
  185. package/dist/tests/scoring-pipeline.test.js +0 -648
  186. package/dist/tests/search-include-proposed-cli.test.js +0 -118
  187. package/dist/tests/self-update.test.js +0 -442
  188. package/dist/tests/semantic-search-e2e.test.js +0 -512
  189. package/dist/tests/semantic-status.test.js +0 -471
  190. package/dist/tests/setup-run.integration.js +0 -877
  191. package/dist/tests/setup-wizard.test.js +0 -198
  192. package/dist/tests/setup.test.js +0 -131
  193. package/dist/tests/source-add.test.js +0 -11
  194. package/dist/tests/source-clone.test.js +0 -254
  195. package/dist/tests/source-manage.test.js +0 -366
  196. package/dist/tests/source-providers/filesystem.test.js +0 -82
  197. package/dist/tests/source-providers/git.test.js +0 -252
  198. package/dist/tests/source-providers/website.test.js +0 -128
  199. package/dist/tests/source-qa-fixes.test.js +0 -268
  200. package/dist/tests/source-registry.test.js +0 -350
  201. package/dist/tests/source-resolve.test.js +0 -100
  202. package/dist/tests/source-source.test.js +0 -221
  203. package/dist/tests/source.test.js +0 -533
  204. package/dist/tests/tar-utils-scan.test.js +0 -73
  205. package/dist/tests/toggle-components.test.js +0 -73
  206. package/dist/tests/usage-telemetry.test.js +0 -265
  207. package/dist/tests/utility-scoring.test.js +0 -558
  208. package/dist/tests/vault-load-error.test.js +0 -78
  209. package/dist/tests/vault-qa-fixes.test.js +0 -194
  210. package/dist/tests/vault.test.js +0 -429
  211. package/dist/tests/vector-search.test.js +0 -608
  212. package/dist/tests/walker.test.js +0 -252
  213. package/dist/tests/wave2-cluster-bc.test.js +0 -228
  214. package/dist/tests/wave2-cluster-d.test.js +0 -180
  215. package/dist/tests/wave2-cluster-e.test.js +0 -179
  216. package/dist/tests/wiki-qa-fixes.test.js +0 -270
  217. package/dist/tests/wiki.test.js +0 -529
  218. package/dist/tests/workflow-cli.test.js +0 -271
  219. package/dist/tests/workflow-markdown.test.js +0 -171
  220. package/dist/tests/workflow-path-escape.test.js +0 -132
  221. package/dist/tests/workflow-qa-fixes.test.js +0 -377
  222. package/dist/tests/workflows/indexer-rejection.test.js +0 -213
  223. /package/dist/{src/commands → commands}/completions.js +0 -0
  224. /package/dist/{src/commands → commands}/curate.js +0 -0
  225. /package/dist/{src/commands → commands}/distill.js +0 -0
  226. /package/dist/{src/commands → commands}/events.js +0 -0
  227. /package/dist/{src/commands → commands}/info.js +0 -0
  228. /package/dist/{src/commands → commands}/init.js +0 -0
  229. /package/dist/{src/commands → commands}/install-audit.js +0 -0
  230. /package/dist/{src/commands → commands}/installed-stashes.js +0 -0
  231. /package/dist/{src/commands → commands}/migration-help.js +0 -0
  232. /package/dist/{src/commands → commands}/proposal.js +0 -0
  233. /package/dist/{src/commands → commands}/propose.js +0 -0
  234. /package/dist/{src/commands → commands}/reflect.js +0 -0
  235. /package/dist/{src/commands → commands}/remember.js +0 -0
  236. /package/dist/{src/commands → commands}/self-update.js +0 -0
  237. /package/dist/{src/commands → commands}/source-clone.js +0 -0
  238. /package/dist/{src/commands → commands}/vault.js +0 -0
  239. /package/dist/{src/core → core}/asset-ref.js +0 -0
  240. /package/dist/{src/core → core}/asset-registry.js +0 -0
  241. /package/dist/{src/core → core}/asset-spec.js +0 -0
  242. /package/dist/{src/core → core}/common.js +0 -0
  243. /package/dist/{src/core → core}/errors.js +0 -0
  244. /package/dist/{src/core → core}/events.js +0 -0
  245. /package/dist/{src/core → core}/frontmatter.js +0 -0
  246. /package/dist/{src/core → core}/lesson-lint.js +0 -0
  247. /package/dist/{src/core → core}/markdown.js +0 -0
  248. /package/dist/{src/core → core}/paths.js +0 -0
  249. /package/dist/{src/core → core}/proposals.js +0 -0
  250. /package/dist/{src/core → core}/warn.js +0 -0
  251. /package/dist/{src/core → core}/write-source.js +0 -0
  252. /package/dist/{src/indexer → indexer}/db.js +0 -0
  253. /package/dist/{src/indexer → indexer}/file-context.js +0 -0
  254. /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
  255. /package/dist/{src/indexer → indexer}/graph-extraction.js +0 -0
  256. /package/dist/{src/indexer → indexer}/manifest.js +0 -0
  257. /package/dist/{src/indexer → indexer}/memory-inference.js +0 -0
  258. /package/dist/{src/indexer → indexer}/metadata.js +0 -0
  259. /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
  260. /package/dist/{src/indexer → indexer}/semantic-status.js +0 -0
  261. /package/dist/{src/indexer → indexer}/usage-events.js +0 -0
  262. /package/dist/{src/indexer → indexer}/walker.js +0 -0
  263. /package/dist/{src/integrations → integrations}/agent/config.js +0 -0
  264. /package/dist/{src/integrations → integrations}/agent/detect.js +0 -0
  265. /package/dist/{src/integrations → integrations}/agent/index.js +0 -0
  266. /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
  267. /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
  268. /package/dist/{src/llm → llm}/client.js +0 -0
  269. /package/dist/{src/llm → llm}/embedder.js +0 -0
  270. /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
  271. /package/dist/{src/llm → llm}/embedders/local.js +0 -0
  272. /package/dist/{src/llm → llm}/embedders/types.js +0 -0
  273. /package/dist/{src/llm → llm}/feature-gate.js +0 -0
  274. /package/dist/{src/llm → llm}/graph-extract.js +0 -0
  275. /package/dist/{src/llm → llm}/index-passes.js +0 -0
  276. /package/dist/{src/llm → llm}/memory-infer.js +0 -0
  277. /package/dist/{src/llm → llm}/metadata-enhance.js +0 -0
  278. /package/dist/{src/output → output}/context.js +0 -0
  279. /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
  280. /package/dist/{src/registry → registry}/factory.js +0 -0
  281. /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
  282. /package/dist/{src/registry → registry}/providers/index.js +0 -0
  283. /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
  284. /package/dist/{src/registry → registry}/providers/types.js +0 -0
  285. /package/dist/{src/registry → registry}/resolve.js +0 -0
  286. /package/dist/{src/registry → registry}/types.js +0 -0
  287. /package/dist/{src/setup → setup}/detect.js +0 -0
  288. /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
  289. /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
  290. /package/dist/{src/setup → setup}/steps.js +0 -0
  291. /package/dist/{src/sources → sources}/include.js +0 -0
  292. /package/dist/{src/sources → sources}/provider-factory.js +0 -0
  293. /package/dist/{src/sources → sources}/provider.js +0 -0
  294. /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
  295. /package/dist/{src/sources → sources}/providers/git.js +0 -0
  296. /package/dist/{src/sources → sources}/providers/index.js +0 -0
  297. /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
  298. /package/dist/{src/sources → sources}/providers/npm.js +0 -0
  299. /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
  300. /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
  301. /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
  302. /package/dist/{src/sources → sources}/providers/website.js +0 -0
  303. /package/dist/{src/sources → sources}/resolve.js +0 -0
  304. /package/dist/{src/sources → sources}/types.js +0 -0
  305. /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
  306. /package/dist/{src/version.js → version.js} +0 -0
  307. /package/dist/{src/workflows → workflows}/authoring.js +0 -0
  308. /package/dist/{src/workflows → workflows}/cli.js +0 -0
  309. /package/dist/{src/workflows → workflows}/db.js +0 -0
  310. /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
  311. /package/dist/{src/workflows → workflows}/parser.js +0 -0
  312. /package/dist/{src/workflows → workflows}/renderer.js +0 -0
  313. /package/dist/{src/workflows → workflows}/schema.js +0 -0
  314. /package/dist/{src/workflows → workflows}/validator.js +0 -0
@@ -1,198 +0,0 @@
1
- /**
2
- * Tests for setup wizard interactive logic:
3
- * - onCancel: Escape on confirmation should stay, not exit
4
- * - stepAddSources: recommended GitHub repos multiselect, cancel returns to menu
5
- */
6
- import { beforeEach, describe, expect, mock, test } from "bun:test";
7
- // ── Mock plumbing ────────────────────────────────────────────────────────────
8
- /** Sentinel returned by mocked prompts when simulating Escape / Ctrl-C. */
9
- const CANCEL = Symbol("clack:cancel");
10
- /** Per-test response queues — shift one value per prompt call. */
11
- const q = {
12
- confirms: [],
13
- selects: [],
14
- texts: [],
15
- multiselects: [],
16
- logged: [],
17
- };
18
- function reset() {
19
- q.confirms.length = 0;
20
- q.selects.length = 0;
21
- q.texts.length = 0;
22
- q.multiselects.length = 0;
23
- q.logged.length = 0;
24
- }
25
- // Must be called **before** any module that imports @clack/prompts is loaded.
26
- mock.module("@clack/prompts", () => ({
27
- isCancel: (v) => v === CANCEL,
28
- cancel: (msg) => {
29
- q.logged.push(`[cancel] ${msg}`);
30
- },
31
- confirm: async () => q.confirms.shift() ?? false,
32
- select: async () => q.selects.shift() ?? "done",
33
- text: async () => q.texts.shift() ?? "",
34
- multiselect: async () => q.multiselects.shift() ?? [],
35
- spinner: () => ({ start: () => { }, stop: () => { } }),
36
- log: {
37
- info: (msg) => {
38
- q.logged.push(msg);
39
- },
40
- success: (msg) => {
41
- q.logged.push(msg);
42
- },
43
- warn: (msg) => {
44
- q.logged.push(msg);
45
- },
46
- step: () => { },
47
- },
48
- intro: () => { },
49
- outro: () => { },
50
- note: (msg, title) => {
51
- q.logged.push(`[note] ${title ?? ""} ${msg}`.trim());
52
- },
53
- }));
54
- // ── onCancel tests ───────────────────────────────────────────────────────────
55
- describe("onCancel – escape handling", () => {
56
- beforeEach(reset);
57
- test("pressing Escape on the exit-confirmation stays in the wizard", async () => {
58
- const { onCancel } = await import("../src/setup/setup");
59
- // Simulate: user already pressed Escape in a prompt (value = CANCEL),
60
- // then presses Escape again on the "Exit the wizard?" confirmation.
61
- q.confirms.push(CANCEL);
62
- const stayed = await onCancel(CANCEL);
63
- expect(stayed).toBe(true);
64
- });
65
- test("choosing No on the exit-confirmation stays in the wizard", async () => {
66
- const { onCancel } = await import("../src/setup/setup");
67
- q.confirms.push(false);
68
- const stayed = await onCancel(CANCEL);
69
- expect(stayed).toBe(true);
70
- });
71
- test("choosing Yes on the exit-confirmation calls bail (exits)", async () => {
72
- const { onCancel } = await import("../src/setup/setup");
73
- q.confirms.push(true);
74
- // bail() calls process.exit — mock it so it throws instead of killing the runner
75
- const originalExit = process.exit;
76
- process.exit = ((code) => {
77
- throw new Error(`EXIT:${code}`);
78
- });
79
- try {
80
- await expect(onCancel(CANCEL)).rejects.toThrow("EXIT:0");
81
- }
82
- finally {
83
- process.exit = originalExit;
84
- }
85
- });
86
- test("non-cancel input is a no-op (returns false)", async () => {
87
- const { onCancel } = await import("../src/setup/setup");
88
- const stayed = await onCancel("normal-value");
89
- expect(stayed).toBe(false);
90
- });
91
- });
92
- // ── stepAddSources tests ───────────────────────────────────────────────────
93
- describe("stepAddSources – recommended GitHub repos", () => {
94
- beforeEach(reset);
95
- test("with no recommended repos configured, the multiselect prompt is skipped", async () => {
96
- const { stepAddSources } = await import("../src/setup/setup");
97
- // No multiselect should be consumed because the recommended-repos array
98
- // is empty. Only the "Add another source?" select should be needed.
99
- q.selects.push("done");
100
- const result = await stepAddSources({ sources: [] });
101
- expect(result).toEqual([]);
102
- // multiselect queue should still be empty (nothing pushed, nothing consumed)
103
- expect(q.multiselects.length).toBe(0);
104
- });
105
- test("preserves an existing git stash that points at the legacy context-hub URL", async () => {
106
- const { stepAddSources } = await import("../src/setup/setup");
107
- const ctxHubUrl = "https://github.com/andrewyng/context-hub";
108
- const cfg = {
109
- sources: [{ type: "git", url: ctxHubUrl, name: "context-hub" }],
110
- };
111
- q.selects.push("done");
112
- const result = await stepAddSources(cfg);
113
- const hub = result.find((s) => s.url === ctxHubUrl);
114
- expect(hub).toBeDefined();
115
- expect(hub?.type).toBe("git");
116
- });
117
- });
118
- describe("semantic search setup", () => {
119
- beforeEach(reset);
120
- test("should list local model and sqlite-vec guidance when describing semantic search assets", async () => {
121
- const { describeSemanticSearchAssets } = await import("../src/setup/setup");
122
- const assets = describeSemanticSearchAssets();
123
- expect(assets[0]).toContain("Local embedding model");
124
- expect(assets[0]).toContain("download");
125
- expect(assets[1]).toContain("sqlite-vec");
126
- });
127
- test("stepSemanticSearch returns disabled when user opts out", async () => {
128
- const { stepSemanticSearch } = await import("../src/setup/setup");
129
- q.confirms.push(false);
130
- const result = await stepSemanticSearch({ semanticSearchMode: "auto" });
131
- expect(result).toEqual({ mode: "off", prepareAssets: false });
132
- });
133
- test("stepSemanticSearch shows assets and allows asset preparation", async () => {
134
- const { stepSemanticSearch } = await import("../src/setup/setup");
135
- q.confirms.push(true, true);
136
- const result = await stepSemanticSearch({ semanticSearchMode: "auto" });
137
- expect(result).toEqual({ mode: "auto", prepareAssets: true });
138
- expect(q.logged.some((entry) => entry.includes("Semantic Search Assets"))).toBe(true);
139
- });
140
- });
141
- describe("stepAddSources – custom GitHub repo", () => {
142
- beforeEach(reset);
143
- test("adds a custom GitHub repo with type 'git'", async () => {
144
- const { stepAddSources } = await import("../src/setup/setup");
145
- // multiselect recommended repos → none
146
- q.multiselects.push([]);
147
- // select "Add another source?" → "github-repo"
148
- q.selects.push("github-repo");
149
- // text: GitHub URL
150
- q.texts.push("https://github.com/owner/repo");
151
- // text: name
152
- q.texts.push("my-repo");
153
- // select → done
154
- q.selects.push("done");
155
- const result = await stepAddSources({ sources: [] });
156
- const repo = result.find((s) => s.url === "https://github.com/owner/repo");
157
- expect(repo).toBeDefined();
158
- expect(repo?.type).toBe("git");
159
- expect(repo?.name).toBe("my-repo");
160
- });
161
- });
162
- describe("stepAddSources – cancel within sub-actions", () => {
163
- beforeEach(reset);
164
- test("pressing Escape on a sub-action text prompt returns to menu", async () => {
165
- const { stepAddSources } = await import("../src/setup/setup");
166
- // multiselect recommended → none
167
- q.multiselects.push([]);
168
- // select → github-repo
169
- q.selects.push("github-repo");
170
- // text: press Escape (cancel) → should return to menu, not re-prompt
171
- q.texts.push(CANCEL);
172
- // back at menu → done
173
- q.selects.push("done");
174
- const result = await stepAddSources({ sources: [] });
175
- // No repo was added because the user cancelled
176
- expect(result).toEqual([]);
177
- });
178
- test("pressing Escape on filesystem path returns to menu", async () => {
179
- const { stepAddSources } = await import("../src/setup/setup");
180
- q.multiselects.push([]);
181
- q.selects.push("filesystem");
182
- q.texts.push(CANCEL); // cancel the path prompt
183
- q.selects.push("done");
184
- const result = await stepAddSources({ sources: [] });
185
- expect(result).toEqual([]);
186
- });
187
- test("pressing Escape on name prompt returns to menu without adding", async () => {
188
- const { stepAddSources } = await import("../src/setup/setup");
189
- q.multiselects.push([]);
190
- q.selects.push("github-repo");
191
- q.texts.push("https://github.com/owner/repo"); // provide URL
192
- q.texts.push(CANCEL); // cancel on name prompt
193
- q.selects.push("done");
194
- const result = await stepAddSources({ sources: [] });
195
- // Repo was NOT added because user cancelled at the name step
196
- expect(result).toEqual([]);
197
- });
198
- });
@@ -1,131 +0,0 @@
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
- // ── detect.ts tests ─────────────────────────────────────────────────────────
6
- describe("detectAgentPlatforms", () => {
7
- let testHome;
8
- const originalHome = process.env.HOME;
9
- beforeEach(() => {
10
- testHome = fs.mkdtempSync(path.join(os.tmpdir(), "akm-detect-"));
11
- process.env.HOME = testHome;
12
- });
13
- afterEach(() => {
14
- process.env.HOME = originalHome;
15
- fs.rmSync(testHome, { recursive: true, force: true });
16
- });
17
- test("returns empty array when no platforms found", async () => {
18
- const { detectAgentPlatforms } = await import("../src/setup/detect");
19
- const result = detectAgentPlatforms();
20
- expect(result).toEqual([]);
21
- });
22
- test("detects .claude directory", async () => {
23
- fs.mkdirSync(path.join(testHome, ".claude"), { recursive: true });
24
- // Re-import to pick up fresh HOME
25
- const { detectAgentPlatforms } = await import("../src/setup/detect");
26
- const result = detectAgentPlatforms();
27
- const claude = result.find((p) => p.name === "Claude Code");
28
- expect(claude).toBeDefined();
29
- expect(claude?.path).toBe(path.join(testHome, ".claude"));
30
- });
31
- test("detects .config/opencode directory", async () => {
32
- fs.mkdirSync(path.join(testHome, ".config", "opencode"), { recursive: true });
33
- const { detectAgentPlatforms } = await import("../src/setup/detect");
34
- const result = detectAgentPlatforms();
35
- const opencode = result.find((p) => p.name === "OpenCode");
36
- expect(opencode).toBeDefined();
37
- expect(opencode?.path).toBe(path.join(testHome, ".config", "opencode"));
38
- });
39
- test("detects multiple platforms", async () => {
40
- fs.mkdirSync(path.join(testHome, ".claude"), { recursive: true });
41
- fs.mkdirSync(path.join(testHome, ".cursor"), { recursive: true });
42
- fs.mkdirSync(path.join(testHome, ".continue"), { recursive: true });
43
- const { detectAgentPlatforms } = await import("../src/setup/detect");
44
- const result = detectAgentPlatforms();
45
- expect(result.length).toBeGreaterThanOrEqual(3);
46
- });
47
- test("ignores files (only detects directories)", async () => {
48
- fs.writeFileSync(path.join(testHome, ".claude"), "not a directory");
49
- const { detectAgentPlatforms } = await import("../src/setup/detect");
50
- const result = detectAgentPlatforms();
51
- const claude = result.find((p) => p.name === "Claude Code");
52
- expect(claude).toBeUndefined();
53
- });
54
- test("returns empty when HOME and USERPROFILE are both unset", async () => {
55
- delete process.env.HOME;
56
- delete process.env.USERPROFILE;
57
- const { detectAgentPlatforms } = await import("../src/setup/detect");
58
- const result = detectAgentPlatforms();
59
- expect(result).toEqual([]);
60
- });
61
- test("falls back to USERPROFILE when HOME is unset (Windows)", async () => {
62
- delete process.env.HOME;
63
- process.env.USERPROFILE = testHome;
64
- fs.mkdirSync(path.join(testHome, ".claude"), { recursive: true });
65
- const { detectAgentPlatforms } = await import("../src/setup/detect");
66
- const result = detectAgentPlatforms();
67
- const claude = result.find((p) => p.name === "Claude Code");
68
- expect(claude).toBeDefined();
69
- expect(claude?.path).toBe(path.join(testHome, ".claude"));
70
- delete process.env.USERPROFILE;
71
- });
72
- });
73
- describe("detectOllama", () => {
74
- let originalFetch;
75
- beforeEach(() => {
76
- originalFetch = globalThis.fetch;
77
- });
78
- afterEach(() => {
79
- globalThis.fetch = originalFetch;
80
- });
81
- test("returns available=true with models from API", async () => {
82
- globalThis.fetch = (async (input) => {
83
- const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
84
- if (url.includes("/api/tags")) {
85
- return new Response(JSON.stringify({
86
- models: [{ name: "llama3.2:latest" }, { name: "nomic-embed-text:latest" }, { name: "codellama:latest" }],
87
- }), { status: 200 });
88
- }
89
- return new Response("", { status: 404 });
90
- });
91
- const { detectOllama } = await import("../src/setup/detect");
92
- const result = await detectOllama();
93
- expect(result.available).toBe(true);
94
- expect(result.models).toContain("llama3.2");
95
- expect(result.models).toContain("nomic-embed-text");
96
- expect(result.models).toContain("codellama");
97
- });
98
- test("strips :latest suffix from model names", async () => {
99
- globalThis.fetch = (async () => {
100
- return new Response(JSON.stringify({
101
- models: [{ name: "llama3.2:latest" }, { name: "phi3:v2" }],
102
- }), { status: 200 });
103
- });
104
- const { detectOllama } = await import("../src/setup/detect");
105
- const result = await detectOllama();
106
- expect(result.models).toContain("llama3.2");
107
- expect(result.models).toContain("phi3:v2");
108
- expect(result.models).not.toContain("llama3.2:latest");
109
- });
110
- test("returns available=false when fetch fails", async () => {
111
- globalThis.fetch = (async () => {
112
- throw new Error("Connection refused");
113
- });
114
- const { detectOllama } = await import("../src/setup/detect");
115
- const result = await detectOllama();
116
- // May still be available=true if `ollama list` CLI works, or false if both fail
117
- // Just verify it doesn't throw
118
- expect(typeof result.available).toBe("boolean");
119
- expect(Array.isArray(result.models)).toBe(true);
120
- });
121
- test("returns sorted model names", async () => {
122
- globalThis.fetch = (async () => {
123
- return new Response(JSON.stringify({
124
- models: [{ name: "zephyr:latest" }, { name: "alpaca:latest" }, { name: "mistral:latest" }],
125
- }), { status: 200 });
126
- });
127
- const { detectOllama } = await import("../src/setup/detect");
128
- const result = await detectOllama();
129
- expect(result.models).toEqual(["alpaca", "mistral", "zephyr"]);
130
- });
131
- });
@@ -1,11 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { shouldAddAsWebsiteUrl } from "../src/commands/source-add";
3
- describe("shouldAddAsWebsiteUrl", () => {
4
- test("treats docs-style URLs as website sources", () => {
5
- expect(shouldAddAsWebsiteUrl("https://docs.example.com/guide")).toBe(true);
6
- });
7
- test("keeps known git hosts on the registry install path", () => {
8
- expect(shouldAddAsWebsiteUrl("https://gitlab.com/acme/project")).toBe(false);
9
- expect(shouldAddAsWebsiteUrl("https://example.com/acme/project.git")).toBe(false);
10
- });
11
- });
@@ -1,254 +0,0 @@
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 { akmClone } from "../src/commands/source-clone";
6
- import { saveConfig } from "../src/core/config";
7
- import { UsageError } from "../src/core/errors";
8
- const originalStashDir = process.env.AKM_STASH_DIR;
9
- const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
10
- const originalXdgCacheHome = process.env.XDG_CACHE_HOME;
11
- let testConfigDir = "";
12
- let testCacheDir = "";
13
- let stashDir = "";
14
- let searchPathDir = "";
15
- function writeFile(filePath, content) {
16
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
17
- fs.writeFileSync(filePath, content);
18
- }
19
- function createStashDir(prefix) {
20
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
21
- for (const sub of ["skills", "commands", "agents", "knowledge", "scripts"]) {
22
- fs.mkdirSync(path.join(dir, sub), { recursive: true });
23
- }
24
- return dir;
25
- }
26
- beforeEach(() => {
27
- testConfigDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-config-"));
28
- testCacheDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-cache-"));
29
- stashDir = createStashDir("akm-clone-working-");
30
- searchPathDir = createStashDir("akm-clone-searchpath-");
31
- process.env.XDG_CONFIG_HOME = testConfigDir;
32
- process.env.XDG_CACHE_HOME = testCacheDir;
33
- process.env.AKM_STASH_DIR = stashDir;
34
- saveConfig({
35
- semanticSearchMode: "off",
36
- sources: [{ type: "filesystem", path: searchPathDir }],
37
- });
38
- });
39
- afterEach(() => {
40
- process.env.AKM_STASH_DIR = originalStashDir ?? undefined;
41
- if (originalXdgConfigHome === undefined)
42
- delete process.env.XDG_CONFIG_HOME;
43
- else
44
- process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
45
- if (originalXdgCacheHome === undefined)
46
- delete process.env.XDG_CACHE_HOME;
47
- else
48
- process.env.XDG_CACHE_HOME = originalXdgCacheHome;
49
- for (const dir of [testConfigDir, testCacheDir, stashDir, searchPathDir]) {
50
- if (dir)
51
- fs.rmSync(dir, { recursive: true, force: true });
52
- }
53
- });
54
- describe("akmClone", () => {
55
- test("clones a script from search path to primary stash", async () => {
56
- writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "#!/bin/bash\necho deploy\n");
57
- const result = await akmClone({ sourceRef: "script:deploy.sh" });
58
- expect(result.destination.ref).toContain("script:deploy.sh");
59
- expect(result.overwritten).toBe(false);
60
- expect(fs.existsSync(path.join(stashDir, "scripts", "deploy.sh"))).toBe(true);
61
- expect(fs.readFileSync(path.join(stashDir, "scripts", "deploy.sh"), "utf8")).toBe("#!/bin/bash\necho deploy\n");
62
- });
63
- test("clones a skill directory", async () => {
64
- writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Review Skill\n");
65
- writeFile(path.join(searchPathDir, "skills", "review", "helper.md"), "# Helper\n");
66
- const result = await akmClone({ sourceRef: "skill:review" });
67
- expect(result.overwritten).toBe(false);
68
- expect(fs.existsSync(path.join(stashDir, "skills", "review", "SKILL.md"))).toBe(true);
69
- expect(fs.existsSync(path.join(stashDir, "skills", "review", "helper.md"))).toBe(true);
70
- });
71
- test("clones with a new name", async () => {
72
- writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo deploy\n");
73
- const result = await akmClone({ sourceRef: "script:deploy.sh", newName: "my-deploy.sh" });
74
- expect(fs.existsSync(path.join(stashDir, "scripts", "my-deploy.sh"))).toBe(true);
75
- expect(result.destination.ref).toContain("my-deploy.sh");
76
- });
77
- test("throws when asset already exists without --force", async () => {
78
- writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo original\n");
79
- writeFile(path.join(stashDir, "scripts", "deploy.sh"), "echo existing\n");
80
- await expect(akmClone({ sourceRef: `${searchPathDir}//script:deploy.sh` })).rejects.toThrow("already exists");
81
- });
82
- test("overwrites with --force", async () => {
83
- writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo updated\n");
84
- writeFile(path.join(stashDir, "scripts", "deploy.sh"), "echo old\n");
85
- const result = await akmClone({ sourceRef: `${searchPathDir}//script:deploy.sh`, force: true });
86
- expect(result.overwritten).toBe(true);
87
- expect(fs.readFileSync(path.join(stashDir, "scripts", "deploy.sh"), "utf8")).toBe("echo updated\n");
88
- });
89
- test("force overwrite removes stale files from skill directory", async () => {
90
- // Source skill has only SKILL.md
91
- writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Updated\n");
92
- // Existing working skill has an extra file
93
- writeFile(path.join(stashDir, "skills", "review", "SKILL.md"), "# Old\n");
94
- writeFile(path.join(stashDir, "skills", "review", "stale.md"), "# Stale\n");
95
- await akmClone({ sourceRef: `${searchPathDir}//skill:review`, force: true });
96
- expect(fs.existsSync(path.join(stashDir, "skills", "review", "SKILL.md"))).toBe(true);
97
- expect(fs.existsSync(path.join(stashDir, "skills", "review", "stale.md"))).toBe(false);
98
- });
99
- test("throws when source asset not found", async () => {
100
- await expect(akmClone({ sourceRef: "script:nonexistent.sh" })).rejects.toThrow();
101
- });
102
- test("clones from working stash to itself with new name", async () => {
103
- writeFile(path.join(stashDir, "scripts", "original.sh"), "echo original\n");
104
- const _result = await akmClone({ sourceRef: "script:original.sh", newName: "copy.sh" });
105
- expect(fs.existsSync(path.join(stashDir, "scripts", "copy.sh"))).toBe(true);
106
- });
107
- test("throws when self-cloning a script without rename", async () => {
108
- writeFile(path.join(stashDir, "scripts", "deploy.sh"), "echo deploy\n");
109
- await expect(akmClone({ sourceRef: "script:deploy.sh" })).rejects.toThrow("same path");
110
- // Verify the file was not destroyed
111
- expect(fs.readFileSync(path.join(stashDir, "scripts", "deploy.sh"), "utf8")).toBe("echo deploy\n");
112
- });
113
- test("throws when self-cloning a skill without rename", async () => {
114
- writeFile(path.join(stashDir, "skills", "review", "SKILL.md"), "# Review\n");
115
- await expect(akmClone({ sourceRef: "skill:review" })).rejects.toThrow("same path");
116
- // Verify the skill was not destroyed
117
- expect(fs.existsSync(path.join(stashDir, "skills", "review", "SKILL.md"))).toBe(true);
118
- });
119
- describe("newName validation", () => {
120
- beforeEach(() => {
121
- writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo deploy\n");
122
- writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Review\n");
123
- });
124
- test("throws on empty string newName", async () => {
125
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "" })).rejects.toThrow(UsageError);
126
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "" })).rejects.toThrow(/empty/);
127
- });
128
- test("throws on '.' as newName", async () => {
129
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "." })).rejects.toThrow(UsageError);
130
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "." })).rejects.toThrow(/Unsafe/);
131
- });
132
- test("throws on '..' as newName", async () => {
133
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: ".." })).rejects.toThrow(UsageError);
134
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: ".." })).rejects.toThrow(/Unsafe/);
135
- });
136
- test("throws on path-traversal newName", async () => {
137
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "../escape.sh" })).rejects.toThrow(UsageError);
138
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "../escape.sh" })).rejects.toThrow(/Unsafe/);
139
- });
140
- test("throws on absolute path as newName", async () => {
141
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "/etc/evil.sh" })).rejects.toThrow(UsageError);
142
- await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "/etc/evil.sh" })).rejects.toThrow(/Unsafe/);
143
- });
144
- test("empty newName does not wipe the type directory for skills", async () => {
145
- writeFile(path.join(stashDir, "skills", "existing", "SKILL.md"), "# Existing\n");
146
- await expect(akmClone({ sourceRef: "skill:review", newName: "", force: true })).rejects.toThrow(UsageError);
147
- // Existing skill must be untouched
148
- expect(fs.existsSync(path.join(stashDir, "skills", "existing", "SKILL.md"))).toBe(true);
149
- });
150
- });
151
- });
152
- describe("akmClone --dest", () => {
153
- let customDest;
154
- beforeEach(() => {
155
- customDest = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-dest-"));
156
- });
157
- afterEach(() => {
158
- if (customDest)
159
- fs.rmSync(customDest, { recursive: true, force: true });
160
- });
161
- test("clones script to custom destination preserving type dir structure", async () => {
162
- writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "#!/bin/bash\necho deploy\n");
163
- const result = await akmClone({ sourceRef: "script:deploy.sh", dest: customDest });
164
- expect(result.destination.path).toBe(path.join(customDest, "scripts", "deploy.sh"));
165
- expect(fs.existsSync(path.join(customDest, "scripts", "deploy.sh"))).toBe(true);
166
- expect(fs.readFileSync(path.join(customDest, "scripts", "deploy.sh"), "utf8")).toBe("#!/bin/bash\necho deploy\n");
167
- // Working stash should NOT have the file
168
- expect(fs.existsSync(path.join(stashDir, "scripts", "deploy.sh"))).toBe(false);
169
- });
170
- test("clones skill directory to custom destination", async () => {
171
- writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Review Skill\n");
172
- writeFile(path.join(searchPathDir, "skills", "review", "helper.md"), "# Helper\n");
173
- const result = await akmClone({ sourceRef: "skill:review", dest: customDest });
174
- expect(fs.existsSync(path.join(customDest, "skills", "review", "SKILL.md"))).toBe(true);
175
- expect(fs.existsSync(path.join(customDest, "skills", "review", "helper.md"))).toBe(true);
176
- expect(result.overwritten).toBe(false);
177
- });
178
- test("--dest does not require a working stash", async () => {
179
- writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo deploy\n");
180
- // Point AKM_STASH_DIR to a non-existent directory to simulate no working stash
181
- process.env.AKM_STASH_DIR = path.join(os.tmpdir(), `nonexistent-stash-${Date.now()}`);
182
- const result = await akmClone({
183
- sourceRef: `${searchPathDir}//script:deploy.sh`,
184
- dest: customDest,
185
- });
186
- expect(fs.existsSync(path.join(customDest, "scripts", "deploy.sh"))).toBe(true);
187
- expect(result.destination.path).toBe(path.join(customDest, "scripts", "deploy.sh"));
188
- });
189
- test("--dest with --force overwrites at custom destination", async () => {
190
- writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo updated\n");
191
- writeFile(path.join(customDest, "scripts", "deploy.sh"), "echo old\n");
192
- const result = await akmClone({
193
- sourceRef: `${searchPathDir}//script:deploy.sh`,
194
- force: true,
195
- dest: customDest,
196
- });
197
- expect(result.overwritten).toBe(true);
198
- expect(fs.readFileSync(path.join(customDest, "scripts", "deploy.sh"), "utf8")).toBe("echo updated\n");
199
- });
200
- test("throws when asset exists at --dest without --force", async () => {
201
- writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo new\n");
202
- writeFile(path.join(customDest, "scripts", "deploy.sh"), "echo existing\n");
203
- await expect(akmClone({ sourceRef: `${searchPathDir}//script:deploy.sh`, dest: customDest })).rejects.toThrow("already exists at destination");
204
- });
205
- });
206
- describe("akmClone remote", () => {
207
- let remoteFixtureDir;
208
- beforeEach(() => {
209
- // Create a fixture directory that simulates a remote package
210
- remoteFixtureDir = createStashDir("akm-clone-remote-fixture-");
211
- writeFile(path.join(remoteFixtureDir, "scripts", "remote-tool.sh"), "#!/bin/bash\necho remote\n");
212
- writeFile(path.join(remoteFixtureDir, "skills", "remote-skill", "SKILL.md"), "# Remote Skill\n");
213
- });
214
- afterEach(() => {
215
- if (remoteFixtureDir)
216
- fs.rmSync(remoteFixtureDir, { recursive: true, force: true });
217
- });
218
- test("clones a script from a remote origin via installRegistryRef", async () => {
219
- // Use bare path as origin — not in stashes, so isRemoteOrigin returns true
220
- const result = await akmClone({
221
- sourceRef: `${remoteFixtureDir}//script:remote-tool.sh`,
222
- });
223
- expect(result.remoteFetched).toBeDefined();
224
- expect(result.remoteFetched?.origin).toBe(remoteFixtureDir);
225
- expect(fs.existsSync(path.join(stashDir, "scripts", "remote-tool.sh"))).toBe(true);
226
- expect(fs.readFileSync(path.join(stashDir, "scripts", "remote-tool.sh"), "utf8")).toBe("#!/bin/bash\necho remote\n");
227
- });
228
- test("returns remoteFetched metadata", async () => {
229
- const result = await akmClone({
230
- sourceRef: `${remoteFixtureDir}//script:remote-tool.sh`,
231
- });
232
- expect(result.remoteFetched).toBeDefined();
233
- expect(result.remoteFetched?.stashRoot).toBeTruthy();
234
- expect(result.remoteFetched?.cacheDir).toBeTruthy();
235
- });
236
- test("throws when remote fetch succeeds but asset not found in package", async () => {
237
- await expect(akmClone({ sourceRef: `${remoteFixtureDir}//script:nonexistent.sh` })).rejects.toThrow("not found");
238
- });
239
- test("clones from remote origin to custom destination", async () => {
240
- const customDest = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-remote-dest-"));
241
- try {
242
- const result = await akmClone({
243
- sourceRef: `${remoteFixtureDir}//script:remote-tool.sh`,
244
- dest: customDest,
245
- });
246
- expect(result.remoteFetched).toBeDefined();
247
- expect(fs.existsSync(path.join(customDest, "scripts", "remote-tool.sh"))).toBe(true);
248
- expect(result.destination.path).toBe(path.join(customDest, "scripts", "remote-tool.sh"));
249
- }
250
- finally {
251
- fs.rmSync(customDest, { recursive: true, force: true });
252
- }
253
- });
254
- });