akm-cli 0.7.0 → 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 (327) hide show
  1. package/package.json +8 -8
  2. package/dist/tests/add-website-source.test.js +0 -119
  3. package/dist/tests/agent/agent-config-loader.test.js +0 -70
  4. package/dist/tests/agent/agent-config.test.js +0 -221
  5. package/dist/tests/agent/agent-detect.test.js +0 -100
  6. package/dist/tests/agent/agent-spawn.test.js +0 -234
  7. package/dist/tests/agent-output.test.js +0 -186
  8. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
  9. package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
  10. package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
  11. package/dist/tests/asset-ref.test.js +0 -192
  12. package/dist/tests/asset-registry.test.js +0 -103
  13. package/dist/tests/asset-spec.test.js +0 -241
  14. package/dist/tests/bench/attribution.test.js +0 -996
  15. package/dist/tests/bench/cleanup-sigint.test.js +0 -83
  16. package/dist/tests/bench/cleanup.js +0 -234
  17. package/dist/tests/bench/cleanup.test.js +0 -166
  18. package/dist/tests/bench/cli.js +0 -1018
  19. package/dist/tests/bench/cli.test.js +0 -445
  20. package/dist/tests/bench/compare.test.js +0 -556
  21. package/dist/tests/bench/corpus.js +0 -317
  22. package/dist/tests/bench/corpus.test.js +0 -258
  23. package/dist/tests/bench/doctor.js +0 -525
  24. package/dist/tests/bench/driver.js +0 -401
  25. package/dist/tests/bench/driver.test.js +0 -584
  26. package/dist/tests/bench/environment.js +0 -233
  27. package/dist/tests/bench/environment.test.js +0 -199
  28. package/dist/tests/bench/evolve-metrics.js +0 -179
  29. package/dist/tests/bench/evolve-metrics.test.js +0 -187
  30. package/dist/tests/bench/evolve.js +0 -647
  31. package/dist/tests/bench/evolve.test.js +0 -624
  32. package/dist/tests/bench/failure-modes.test.js +0 -349
  33. package/dist/tests/bench/feedback-integrity.test.js +0 -457
  34. package/dist/tests/bench/leakage.test.js +0 -228
  35. package/dist/tests/bench/learning-curve.test.js +0 -134
  36. package/dist/tests/bench/metrics.js +0 -2395
  37. package/dist/tests/bench/metrics.test.js +0 -1150
  38. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
  39. package/dist/tests/bench/opencode-config.js +0 -194
  40. package/dist/tests/bench/opencode-config.test.js +0 -370
  41. package/dist/tests/bench/report.js +0 -1885
  42. package/dist/tests/bench/report.test.js +0 -1038
  43. package/dist/tests/bench/run-config.js +0 -355
  44. package/dist/tests/bench/run-config.test.js +0 -298
  45. package/dist/tests/bench/run-curate-test.js +0 -32
  46. package/dist/tests/bench/run-failing-tasks.js +0 -56
  47. package/dist/tests/bench/run-full-bench.js +0 -51
  48. package/dist/tests/bench/run-items36-targeted.js +0 -69
  49. package/dist/tests/bench/run-nano-quick.js +0 -42
  50. package/dist/tests/bench/run-waveg-targeted.js +0 -62
  51. package/dist/tests/bench/runner.js +0 -699
  52. package/dist/tests/bench/runner.test.js +0 -958
  53. package/dist/tests/bench/search-bridge.test.js +0 -331
  54. package/dist/tests/bench/tmp.js +0 -131
  55. package/dist/tests/bench/trajectory.js +0 -116
  56. package/dist/tests/bench/trajectory.test.js +0 -127
  57. package/dist/tests/bench/verifier.js +0 -114
  58. package/dist/tests/bench/verifier.test.js +0 -118
  59. package/dist/tests/bench/workflow-evaluator.js +0 -557
  60. package/dist/tests/bench/workflow-evaluator.test.js +0 -421
  61. package/dist/tests/bench/workflow-spec.js +0 -345
  62. package/dist/tests/bench/workflow-spec.test.js +0 -363
  63. package/dist/tests/bench/workflow-trace.js +0 -472
  64. package/dist/tests/bench/workflow-trace.test.js +0 -254
  65. package/dist/tests/benchmark-search-quality.js +0 -536
  66. package/dist/tests/benchmark-suite.js +0 -1441
  67. package/dist/tests/capture-cli.test.js +0 -112
  68. package/dist/tests/cli-errors.test.js +0 -204
  69. package/dist/tests/commands/events.test.js +0 -370
  70. package/dist/tests/commands/history.test.js +0 -418
  71. package/dist/tests/commands/import.test.js +0 -103
  72. package/dist/tests/commands/proposal-cli.test.js +0 -209
  73. package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
  74. package/dist/tests/commands/remember.test.js +0 -97
  75. package/dist/tests/commands/scope-flags.test.js +0 -300
  76. package/dist/tests/commands/search.test.js +0 -537
  77. package/dist/tests/commands/show-indexer-parity.test.js +0 -117
  78. package/dist/tests/commands/show.test.js +0 -294
  79. package/dist/tests/common.test.js +0 -266
  80. package/dist/tests/completions.test.js +0 -142
  81. package/dist/tests/config-cli.test.js +0 -193
  82. package/dist/tests/config-llm-features.test.js +0 -139
  83. package/dist/tests/config.test.js +0 -569
  84. package/dist/tests/contracts/migration-baseline.test.js +0 -43
  85. package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
  86. package/dist/tests/contracts/spec-helpers.js +0 -46
  87. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
  88. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
  89. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
  90. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
  91. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
  92. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
  93. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
  94. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
  95. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
  96. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
  97. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
  98. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
  99. package/dist/tests/core/write-source.test.js +0 -366
  100. package/dist/tests/curate-command.test.js +0 -87
  101. package/dist/tests/db-scoring.test.js +0 -201
  102. package/dist/tests/db.test.js +0 -654
  103. package/dist/tests/distill-cli-flag.test.js +0 -208
  104. package/dist/tests/distill.test.js +0 -515
  105. package/dist/tests/docker-install.test.js +0 -120
  106. package/dist/tests/e2e.test.js +0 -1419
  107. package/dist/tests/embedder.test.js +0 -340
  108. package/dist/tests/embedding-model-config.test.js +0 -379
  109. package/dist/tests/feedback-command.test.js +0 -172
  110. package/dist/tests/file-context.test.js +0 -552
  111. package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
  112. package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
  113. package/dist/tests/fixtures/stashes/load.js +0 -166
  114. package/dist/tests/fixtures/stashes/load.test.js +0 -97
  115. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
  116. package/dist/tests/frontmatter.test.js +0 -190
  117. package/dist/tests/fts-field-weighting.test.js +0 -254
  118. package/dist/tests/fuzzy-search.test.js +0 -230
  119. package/dist/tests/git-provider-clone.test.js +0 -45
  120. package/dist/tests/github.test.js +0 -161
  121. package/dist/tests/graph-boost-ranking.test.js +0 -305
  122. package/dist/tests/graph-extraction.test.js +0 -282
  123. package/dist/tests/helpers/usage-events.js +0 -8
  124. package/dist/tests/index-pass-llm.test.js +0 -161
  125. package/dist/tests/indexer.test.js +0 -570
  126. package/dist/tests/info-command.test.js +0 -166
  127. package/dist/tests/init.test.js +0 -69
  128. package/dist/tests/install-script.test.js +0 -246
  129. package/dist/tests/integration/agent-real-profile.test.js +0 -94
  130. package/dist/tests/issue-36-repro.test.js +0 -304
  131. package/dist/tests/issues-191-194.test.js +0 -160
  132. package/dist/tests/lesson-lint.test.js +0 -111
  133. package/dist/tests/llm-client.test.js +0 -115
  134. package/dist/tests/llm-feature-gate.test.js +0 -151
  135. package/dist/tests/llm.test.js +0 -139
  136. package/dist/tests/lockfile.test.js +0 -216
  137. package/dist/tests/manifest.test.js +0 -205
  138. package/dist/tests/markdown.test.js +0 -126
  139. package/dist/tests/matchers-unit.test.js +0 -189
  140. package/dist/tests/memory-inference.test.js +0 -299
  141. package/dist/tests/merge-scoring.test.js +0 -136
  142. package/dist/tests/metadata.test.js +0 -313
  143. package/dist/tests/migration-help.test.js +0 -89
  144. package/dist/tests/origin-resolve.test.js +0 -124
  145. package/dist/tests/output-baseline.test.js +0 -218
  146. package/dist/tests/output-shapes-unit.test.js +0 -478
  147. package/dist/tests/parallel-search.test.js +0 -272
  148. package/dist/tests/parameter-metadata.test.js +0 -365
  149. package/dist/tests/paths.test.js +0 -177
  150. package/dist/tests/progressive-disclosure.test.js +0 -280
  151. package/dist/tests/proposals.test.js +0 -279
  152. package/dist/tests/proposed-quality.test.js +0 -271
  153. package/dist/tests/provider-registry.test.js +0 -32
  154. package/dist/tests/ranking-regression.test.js +0 -548
  155. package/dist/tests/reflect-propose.test.js +0 -455
  156. package/dist/tests/registry-build-index.test.js +0 -394
  157. package/dist/tests/registry-cli.test.js +0 -290
  158. package/dist/tests/registry-index-v2.test.js +0 -430
  159. package/dist/tests/registry-install.test.js +0 -728
  160. package/dist/tests/registry-providers/parity.test.js +0 -189
  161. package/dist/tests/registry-providers/skills-sh.test.js +0 -309
  162. package/dist/tests/registry-providers/static-index.test.js +0 -238
  163. package/dist/tests/registry-resolve.test.js +0 -126
  164. package/dist/tests/registry-search.test.js +0 -923
  165. package/dist/tests/remember-frontmatter.test.js +0 -378
  166. package/dist/tests/remember-unit.test.js +0 -123
  167. package/dist/tests/ripgrep-install.test.js +0 -251
  168. package/dist/tests/ripgrep-resolve.test.js +0 -108
  169. package/dist/tests/ripgrep.test.js +0 -163
  170. package/dist/tests/save-command.test.js +0 -94
  171. package/dist/tests/save-trust-qa-fixes.test.js +0 -270
  172. package/dist/tests/scoring-pipeline.test.js +0 -648
  173. package/dist/tests/search-include-proposed-cli.test.js +0 -118
  174. package/dist/tests/self-update.test.js +0 -442
  175. package/dist/tests/semantic-search-e2e.test.js +0 -512
  176. package/dist/tests/semantic-status.test.js +0 -471
  177. package/dist/tests/setup-run.integration.js +0 -877
  178. package/dist/tests/setup-wizard.test.js +0 -198
  179. package/dist/tests/setup.test.js +0 -131
  180. package/dist/tests/source-add.test.js +0 -11
  181. package/dist/tests/source-clone.test.js +0 -254
  182. package/dist/tests/source-manage.test.js +0 -366
  183. package/dist/tests/source-providers/filesystem.test.js +0 -82
  184. package/dist/tests/source-providers/git.test.js +0 -252
  185. package/dist/tests/source-providers/website.test.js +0 -128
  186. package/dist/tests/source-qa-fixes.test.js +0 -286
  187. package/dist/tests/source-registry.test.js +0 -350
  188. package/dist/tests/source-resolve.test.js +0 -100
  189. package/dist/tests/source-source.test.js +0 -281
  190. package/dist/tests/source.test.js +0 -533
  191. package/dist/tests/tar-utils-scan.test.js +0 -73
  192. package/dist/tests/toggle-components.test.js +0 -73
  193. package/dist/tests/usage-telemetry.test.js +0 -265
  194. package/dist/tests/utility-scoring.test.js +0 -558
  195. package/dist/tests/vault-load-error.test.js +0 -78
  196. package/dist/tests/vault-qa-fixes.test.js +0 -194
  197. package/dist/tests/vault.test.js +0 -429
  198. package/dist/tests/vector-search.test.js +0 -608
  199. package/dist/tests/walker.test.js +0 -252
  200. package/dist/tests/wave2-cluster-bc.test.js +0 -228
  201. package/dist/tests/wave2-cluster-d.test.js +0 -180
  202. package/dist/tests/wave2-cluster-e.test.js +0 -179
  203. package/dist/tests/wiki-qa-fixes.test.js +0 -270
  204. package/dist/tests/wiki.test.js +0 -529
  205. package/dist/tests/workflow-cli.test.js +0 -271
  206. package/dist/tests/workflow-markdown.test.js +0 -171
  207. package/dist/tests/workflow-path-escape.test.js +0 -132
  208. package/dist/tests/workflow-qa-fixes.test.js +0 -395
  209. package/dist/tests/workflows/indexer-rejection.test.js +0 -213
  210. /package/dist/{src/cli.js → cli.js} +0 -0
  211. /package/dist/{src/commands → commands}/completions.js +0 -0
  212. /package/dist/{src/commands → commands}/config-cli.js +0 -0
  213. /package/dist/{src/commands → commands}/curate.js +0 -0
  214. /package/dist/{src/commands → commands}/distill.js +0 -0
  215. /package/dist/{src/commands → commands}/events.js +0 -0
  216. /package/dist/{src/commands → commands}/history.js +0 -0
  217. /package/dist/{src/commands → commands}/info.js +0 -0
  218. /package/dist/{src/commands → commands}/init.js +0 -0
  219. /package/dist/{src/commands → commands}/install-audit.js +0 -0
  220. /package/dist/{src/commands → commands}/installed-stashes.js +0 -0
  221. /package/dist/{src/commands → commands}/migration-help.js +0 -0
  222. /package/dist/{src/commands → commands}/proposal.js +0 -0
  223. /package/dist/{src/commands → commands}/propose.js +0 -0
  224. /package/dist/{src/commands → commands}/reflect.js +0 -0
  225. /package/dist/{src/commands → commands}/registry-search.js +0 -0
  226. /package/dist/{src/commands → commands}/remember.js +0 -0
  227. /package/dist/{src/commands → commands}/search.js +0 -0
  228. /package/dist/{src/commands → commands}/self-update.js +0 -0
  229. /package/dist/{src/commands → commands}/show.js +0 -0
  230. /package/dist/{src/commands → commands}/source-add.js +0 -0
  231. /package/dist/{src/commands → commands}/source-clone.js +0 -0
  232. /package/dist/{src/commands → commands}/source-manage.js +0 -0
  233. /package/dist/{src/commands → commands}/vault.js +0 -0
  234. /package/dist/{src/core → core}/asset-ref.js +0 -0
  235. /package/dist/{src/core → core}/asset-registry.js +0 -0
  236. /package/dist/{src/core → core}/asset-spec.js +0 -0
  237. /package/dist/{src/core → core}/common.js +0 -0
  238. /package/dist/{src/core → core}/config.js +0 -0
  239. /package/dist/{src/core → core}/errors.js +0 -0
  240. /package/dist/{src/core → core}/events.js +0 -0
  241. /package/dist/{src/core → core}/frontmatter.js +0 -0
  242. /package/dist/{src/core → core}/lesson-lint.js +0 -0
  243. /package/dist/{src/core → core}/markdown.js +0 -0
  244. /package/dist/{src/core → core}/paths.js +0 -0
  245. /package/dist/{src/core → core}/proposals.js +0 -0
  246. /package/dist/{src/core → core}/warn.js +0 -0
  247. /package/dist/{src/core → core}/write-source.js +0 -0
  248. /package/dist/{src/indexer → indexer}/db-search.js +0 -0
  249. /package/dist/{src/indexer → indexer}/db.js +0 -0
  250. /package/dist/{src/indexer → indexer}/file-context.js +0 -0
  251. /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
  252. /package/dist/{src/indexer → indexer}/graph-extraction.js +0 -0
  253. /package/dist/{src/indexer → indexer}/indexer.js +0 -0
  254. /package/dist/{src/indexer → indexer}/manifest.js +0 -0
  255. /package/dist/{src/indexer → indexer}/matchers.js +0 -0
  256. /package/dist/{src/indexer → indexer}/memory-inference.js +0 -0
  257. /package/dist/{src/indexer → indexer}/metadata.js +0 -0
  258. /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
  259. /package/dist/{src/indexer → indexer}/search-source.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/profiles.js +0 -0
  267. /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
  268. /package/dist/{src/integrations → integrations}/agent/spawn.js +0 -0
  269. /package/dist/{src/integrations → integrations}/github.js +0 -0
  270. /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
  271. /package/dist/{src/llm → llm}/client.js +0 -0
  272. /package/dist/{src/llm → llm}/embedder.js +0 -0
  273. /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
  274. /package/dist/{src/llm → llm}/embedders/local.js +0 -0
  275. /package/dist/{src/llm → llm}/embedders/remote.js +0 -0
  276. /package/dist/{src/llm → llm}/embedders/types.js +0 -0
  277. /package/dist/{src/llm → llm}/feature-gate.js +0 -0
  278. /package/dist/{src/llm → llm}/graph-extract.js +0 -0
  279. /package/dist/{src/llm → llm}/index-passes.js +0 -0
  280. /package/dist/{src/llm → llm}/memory-infer.js +0 -0
  281. /package/dist/{src/llm → llm}/metadata-enhance.js +0 -0
  282. /package/dist/{src/output → output}/cli-hints.js +0 -0
  283. /package/dist/{src/output → output}/context.js +0 -0
  284. /package/dist/{src/output → output}/renderers.js +0 -0
  285. /package/dist/{src/output → output}/shapes.js +0 -0
  286. /package/dist/{src/output → output}/text.js +0 -0
  287. /package/dist/{src/registry → registry}/build-index.js +0 -0
  288. /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
  289. /package/dist/{src/registry → registry}/factory.js +0 -0
  290. /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
  291. /package/dist/{src/registry → registry}/providers/index.js +0 -0
  292. /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
  293. /package/dist/{src/registry → registry}/providers/static-index.js +0 -0
  294. /package/dist/{src/registry → registry}/providers/types.js +0 -0
  295. /package/dist/{src/registry → registry}/resolve.js +0 -0
  296. /package/dist/{src/registry → registry}/types.js +0 -0
  297. /package/dist/{src/setup → setup}/detect.js +0 -0
  298. /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
  299. /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
  300. /package/dist/{src/setup → setup}/setup.js +0 -0
  301. /package/dist/{src/setup → setup}/steps.js +0 -0
  302. /package/dist/{src/sources → sources}/include.js +0 -0
  303. /package/dist/{src/sources → sources}/provider-factory.js +0 -0
  304. /package/dist/{src/sources → sources}/provider.js +0 -0
  305. /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
  306. /package/dist/{src/sources → sources}/providers/git.js +0 -0
  307. /package/dist/{src/sources → sources}/providers/index.js +0 -0
  308. /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
  309. /package/dist/{src/sources → sources}/providers/npm.js +0 -0
  310. /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
  311. /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
  312. /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
  313. /package/dist/{src/sources → sources}/providers/website.js +0 -0
  314. /package/dist/{src/sources → sources}/resolve.js +0 -0
  315. /package/dist/{src/sources → sources}/types.js +0 -0
  316. /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
  317. /package/dist/{src/version.js → version.js} +0 -0
  318. /package/dist/{src/wiki → wiki}/wiki.js +0 -0
  319. /package/dist/{src/workflows → workflows}/authoring.js +0 -0
  320. /package/dist/{src/workflows → workflows}/cli.js +0 -0
  321. /package/dist/{src/workflows → workflows}/db.js +0 -0
  322. /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
  323. /package/dist/{src/workflows → workflows}/parser.js +0 -0
  324. /package/dist/{src/workflows → workflows}/renderer.js +0 -0
  325. /package/dist/{src/workflows → workflows}/runs.js +0 -0
  326. /package/dist/{src/workflows → workflows}/schema.js +0 -0
  327. /package/dist/{src/workflows → workflows}/validator.js +0 -0
@@ -1,366 +0,0 @@
1
- /**
2
- * Tests for src/core/write-source.ts — the single dispatch point for writes.
3
- *
4
- * Covers the locked v1 contract from spec §2.6 / §2.7 / §5.4 / §10 step 5:
5
- *
6
- * - writable refusal (default-resolution + explicit `writable: false`)
7
- * - plain filesystem write
8
- * - git commit on success
9
- * - git commit + push when `pushOnCommit` is set
10
- * - git delete (commits the deletion)
11
- * - rejection of `writable: true` on website / npm at config load
12
- * - rejection of unsupported `kind` reaching the helper
13
- * - resolveWriteTarget precedence (explicit → defaultWriteTarget → stashDir)
14
- */
15
- import { afterEach, beforeEach, describe, expect, test } from "bun:test";
16
- import { spawnSync } from "node:child_process";
17
- import fs from "node:fs";
18
- import os from "node:os";
19
- import path from "node:path";
20
- import { ConfigError, UsageError } from "../../src/core/errors";
21
- import { assertWritableAllowedForKind, deleteAssetFromSource, resolveWritable, resolveWriteTarget, sanitizeCommitMessage, writeAssetToSource, } from "../../src/core/write-source";
22
- // ── Fixtures ────────────────────────────────────────────────────────────────
23
- const tempDirs = [];
24
- function makeTempDir(prefix) {
25
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
26
- tempDirs.push(dir);
27
- return dir;
28
- }
29
- function initBareGitRepo() {
30
- const remoteDir = makeTempDir("akm-write-remote-");
31
- const workDir = makeTempDir("akm-write-work-");
32
- // Bare remote so `git push` has somewhere to send commits.
33
- let r = spawnSync("git", ["init", "--bare", "--initial-branch=main", remoteDir], { encoding: "utf8" });
34
- if (r.status !== 0)
35
- throw new Error(`git init --bare failed: ${r.stderr}`);
36
- r = spawnSync("git", ["init", "--initial-branch=main", workDir], { encoding: "utf8" });
37
- if (r.status !== 0)
38
- throw new Error(`git init failed: ${r.stderr}`);
39
- // Identity for the working tree — write-source supplies its own at commit
40
- // time, but a remote add + initial push needs *some* config.
41
- spawnSync("git", ["-C", workDir, "config", "user.email", "test@akm.local"], { encoding: "utf8" });
42
- spawnSync("git", ["-C", workDir, "config", "user.name", "akm test"], { encoding: "utf8" });
43
- spawnSync("git", ["-C", workDir, "remote", "add", "origin", remoteDir], { encoding: "utf8" });
44
- // Seed an initial commit so `git push` can fast-forward.
45
- fs.writeFileSync(path.join(workDir, "README.md"), "seed\n");
46
- spawnSync("git", ["-C", workDir, "add", "README.md"], { encoding: "utf8" });
47
- spawnSync("git", ["-C", workDir, "commit", "-m", "seed"], { encoding: "utf8" });
48
- spawnSync("git", ["-C", workDir, "push", "-u", "origin", "main"], { encoding: "utf8" });
49
- return { remoteDir, workDir };
50
- }
51
- afterEach(() => {
52
- while (tempDirs.length > 0) {
53
- const dir = tempDirs.pop();
54
- if (dir)
55
- fs.rmSync(dir, { recursive: true, force: true });
56
- }
57
- });
58
- // ── resolveWritable ─────────────────────────────────────────────────────────
59
- describe("resolveWritable", () => {
60
- test("defaults to true for filesystem", () => {
61
- expect(resolveWritable({ type: "filesystem" })).toBe(true);
62
- });
63
- test("defaults to false for git", () => {
64
- expect(resolveWritable({ type: "git" })).toBe(false);
65
- });
66
- test("defaults to false for website / npm", () => {
67
- expect(resolveWritable({ type: "website" })).toBe(false);
68
- expect(resolveWritable({ type: "npm" })).toBe(false);
69
- });
70
- test("explicit value wins for filesystem", () => {
71
- expect(resolveWritable({ type: "filesystem", writable: false })).toBe(false);
72
- });
73
- test("explicit value wins for git", () => {
74
- expect(resolveWritable({ type: "git", writable: true })).toBe(true);
75
- });
76
- });
77
- // ── assertWritableAllowedForKind ────────────────────────────────────────────
78
- describe("assertWritableAllowedForKind", () => {
79
- test("rejects writable: true on website", () => {
80
- expect(() => assertWritableAllowedForKind({ type: "website", writable: true, name: "docs" })).toThrow(ConfigError);
81
- });
82
- test("rejects writable: true on npm", () => {
83
- expect(() => assertWritableAllowedForKind({ type: "npm", writable: true, name: "pkg" })).toThrow(ConfigError);
84
- });
85
- test("allows writable: true on git", () => {
86
- expect(() => assertWritableAllowedForKind({ type: "git", writable: true })).not.toThrow();
87
- });
88
- test("allows writable: true on filesystem", () => {
89
- expect(() => assertWritableAllowedForKind({ type: "filesystem", writable: true })).not.toThrow();
90
- });
91
- test("ignores absent / false writable on website + npm (no-op)", () => {
92
- expect(() => assertWritableAllowedForKind({ type: "website" })).not.toThrow();
93
- expect(() => assertWritableAllowedForKind({ type: "npm", writable: false })).not.toThrow();
94
- });
95
- });
96
- // ── writeAssetToSource — filesystem ─────────────────────────────────────────
97
- describe("writeAssetToSource — filesystem", () => {
98
- test("writes the asset to the expected on-disk location", async () => {
99
- const dir = makeTempDir("akm-write-fs-");
100
- const source = { kind: "filesystem", name: "mine", path: dir };
101
- const config = { type: "filesystem", path: dir, name: "mine", writable: true };
102
- const result = await writeAssetToSource(source, config, { type: "memory", name: "alpha" }, "hello world");
103
- expect(result.path).toBe(path.join(dir, "memories", "alpha.md"));
104
- expect(result.ref).toBe("memory:alpha");
105
- expect(fs.readFileSync(result.path, "utf8")).toBe("hello world\n");
106
- });
107
- test("creates intermediate directories", async () => {
108
- const dir = makeTempDir("akm-write-fs-nested-");
109
- const source = { kind: "filesystem", name: "mine", path: dir };
110
- const config = { type: "filesystem", path: dir, writable: true };
111
- const result = await writeAssetToSource(source, config, { type: "knowledge", name: "topic/sub" }, "body");
112
- expect(fs.existsSync(result.path)).toBe(true);
113
- expect(result.path.endsWith(path.join("knowledge", "topic", "sub.md"))).toBe(true);
114
- });
115
- test("appends a trailing newline when missing", async () => {
116
- const dir = makeTempDir("akm-write-fs-nl-");
117
- const source = { kind: "filesystem", name: "mine", path: dir };
118
- const config = { type: "filesystem", writable: true };
119
- const result = await writeAssetToSource(source, config, { type: "memory", name: "a" }, "no-newline");
120
- expect(fs.readFileSync(result.path, "utf8")).toBe("no-newline\n");
121
- });
122
- test("preserves an existing trailing newline (no double newline)", async () => {
123
- const dir = makeTempDir("akm-write-fs-nl2-");
124
- const source = { kind: "filesystem", name: "mine", path: dir };
125
- const config = { type: "filesystem", writable: true };
126
- const result = await writeAssetToSource(source, config, { type: "memory", name: "a" }, "with-newline\n");
127
- expect(fs.readFileSync(result.path, "utf8")).toBe("with-newline\n");
128
- });
129
- test("refuses to write when source is not writable", async () => {
130
- const dir = makeTempDir("akm-write-readonly-");
131
- const source = { kind: "filesystem", name: "ro", path: dir };
132
- const config = { type: "filesystem", writable: false };
133
- await expect(writeAssetToSource(source, config, { type: "memory", name: "a" }, "body")).rejects.toThrow(UsageError);
134
- });
135
- test("refuses to write when default-writable would be false (e.g. git default)", async () => {
136
- const dir = makeTempDir("akm-write-default-ro-");
137
- const source = { kind: "git", name: "upstream", path: dir };
138
- const config = { type: "git", url: "https://example.test/x" };
139
- await expect(writeAssetToSource(source, config, { type: "memory", name: "a" }, "body")).rejects.toThrow(UsageError);
140
- });
141
- test("rejects unknown asset types", async () => {
142
- const dir = makeTempDir("akm-write-unknown-");
143
- const source = { kind: "filesystem", name: "mine", path: dir };
144
- const config = { type: "filesystem", writable: true };
145
- await expect(writeAssetToSource(source, config, { type: "totally-not-a-type", name: "a" }, "body")).rejects.toThrow(UsageError);
146
- });
147
- test("rejects path traversal in asset name", async () => {
148
- const dir = makeTempDir("akm-write-traversal-");
149
- const source = { kind: "filesystem", name: "mine", path: dir };
150
- const config = { type: "filesystem", writable: true };
151
- await expect(writeAssetToSource(source, config, { type: "memory", name: "../../escape" }, "body")).rejects.toThrow();
152
- });
153
- });
154
- // ── writeAssetToSource — git ────────────────────────────────────────────────
155
- describe("writeAssetToSource — git", () => {
156
- test("performs a git commit after writing", async () => {
157
- const { workDir } = initBareGitRepo();
158
- const source = { kind: "git", name: "team", path: workDir };
159
- const config = { type: "git", writable: true };
160
- await writeAssetToSource(source, config, { type: "memory", name: "alpha" }, "body");
161
- const log = spawnSync("git", ["-C", workDir, "log", "--format=%s", "-1"], { encoding: "utf8" });
162
- expect(log.stdout.trim()).toBe("Update memory:alpha");
163
- // Working tree should be clean post-commit.
164
- const status = spawnSync("git", ["-C", workDir, "status", "--porcelain"], { encoding: "utf8" });
165
- expect(status.stdout.trim()).toBe("");
166
- });
167
- test("pushes when pushOnCommit option is set", async () => {
168
- const { remoteDir, workDir } = initBareGitRepo();
169
- const source = { kind: "git", name: "team", path: workDir };
170
- const config = {
171
- type: "git",
172
- writable: true,
173
- options: { pushOnCommit: true },
174
- };
175
- await writeAssetToSource(source, config, { type: "memory", name: "pushed" }, "body");
176
- // Confirm the commit landed on the bare remote.
177
- const remoteLog = spawnSync("git", ["--git-dir", remoteDir, "log", "--format=%s", "-1", "main"], {
178
- encoding: "utf8",
179
- });
180
- expect(remoteLog.stdout.trim()).toBe("Update memory:pushed");
181
- });
182
- test("does not push when pushOnCommit is absent", async () => {
183
- const { remoteDir, workDir } = initBareGitRepo();
184
- const source = { kind: "git", name: "team", path: workDir };
185
- const config = { type: "git", writable: true };
186
- await writeAssetToSource(source, config, { type: "memory", name: "local-only" }, "body");
187
- const remoteLog = spawnSync("git", ["--git-dir", remoteDir, "log", "--format=%s", "-1", "main"], {
188
- encoding: "utf8",
189
- });
190
- // Remote still only has the seed commit.
191
- expect(remoteLog.stdout.trim()).toBe("seed");
192
- });
193
- });
194
- // ── deleteAssetFromSource ───────────────────────────────────────────────────
195
- describe("deleteAssetFromSource", () => {
196
- test("removes the asset and commits the removal on git sources", async () => {
197
- const { workDir } = initBareGitRepo();
198
- const source = { kind: "git", name: "team", path: workDir };
199
- const config = { type: "git", writable: true };
200
- await writeAssetToSource(source, config, { type: "memory", name: "doomed" }, "body");
201
- expect(fs.existsSync(path.join(workDir, "memories", "doomed.md"))).toBe(true);
202
- await deleteAssetFromSource(source, config, { type: "memory", name: "doomed" });
203
- expect(fs.existsSync(path.join(workDir, "memories", "doomed.md"))).toBe(false);
204
- const log = spawnSync("git", ["-C", workDir, "log", "--format=%s", "-1"], { encoding: "utf8" });
205
- expect(log.stdout.trim()).toBe("Remove memory:doomed");
206
- });
207
- test("filesystem delete is a plain unlink (no commit)", async () => {
208
- const dir = makeTempDir("akm-delete-fs-");
209
- const source = { kind: "filesystem", name: "mine", path: dir };
210
- const config = { type: "filesystem", writable: true };
211
- await writeAssetToSource(source, config, { type: "memory", name: "ephem" }, "body");
212
- await deleteAssetFromSource(source, config, { type: "memory", name: "ephem" });
213
- expect(fs.existsSync(path.join(dir, "memories", "ephem.md"))).toBe(false);
214
- });
215
- test("throws when the asset does not exist", async () => {
216
- const dir = makeTempDir("akm-delete-missing-");
217
- const source = { kind: "filesystem", name: "mine", path: dir };
218
- const config = { type: "filesystem", writable: true };
219
- await expect(deleteAssetFromSource(source, config, { type: "memory", name: "ghost" })).rejects.toThrow(UsageError);
220
- });
221
- test("refuses to delete from a non-writable source", async () => {
222
- const dir = makeTempDir("akm-delete-ro-");
223
- const source = { kind: "filesystem", name: "ro", path: dir };
224
- const config = { type: "filesystem", writable: false };
225
- await expect(deleteAssetFromSource(source, config, { type: "memory", name: "x" })).rejects.toThrow(UsageError);
226
- });
227
- });
228
- // ── Unknown kind reaching the helper ────────────────────────────────────────
229
- describe("writeAssetToSource — unsupported kinds", () => {
230
- test("rejects unknown source kinds with ConfigError", async () => {
231
- // The config loader would normally catch this, but the helper still
232
- // defends itself in case an external caller bypasses the loader.
233
- const dir = makeTempDir("akm-write-unsup-");
234
- const source = { kind: "website", name: "docs", path: dir };
235
- const config = { type: "website", writable: true };
236
- await expect(writeAssetToSource(source, config, { type: "memory", name: "a" }, "body")).rejects.toThrow(ConfigError);
237
- });
238
- });
239
- // ── resolveWriteTarget ──────────────────────────────────────────────────────
240
- describe("resolveWriteTarget", () => {
241
- let savedEnv;
242
- let savedCfgEnv;
243
- beforeEach(() => {
244
- savedEnv = process.env.AKM_STASH_DIR;
245
- savedCfgEnv = process.env.AKM_CONFIG_DIR;
246
- });
247
- afterEach(() => {
248
- if (savedEnv === undefined)
249
- delete process.env.AKM_STASH_DIR;
250
- else
251
- process.env.AKM_STASH_DIR = savedEnv;
252
- if (savedCfgEnv === undefined)
253
- delete process.env.AKM_CONFIG_DIR;
254
- else
255
- process.env.AKM_CONFIG_DIR = savedCfgEnv;
256
- });
257
- test("explicit --target wins", () => {
258
- const dir = makeTempDir("akm-target-explicit-");
259
- const result = resolveWriteTarget({
260
- semanticSearchMode: "off",
261
- sources: [{ type: "filesystem", path: dir, name: "explicit", writable: true }],
262
- }, "explicit");
263
- expect(result.source.name).toBe("explicit");
264
- expect(result.source.path).toBe(dir);
265
- });
266
- test("falls back to defaultWriteTarget", () => {
267
- const dir = makeTempDir("akm-target-default-");
268
- const result = resolveWriteTarget({
269
- semanticSearchMode: "off",
270
- sources: [{ type: "filesystem", path: dir, name: "default-one", writable: true }],
271
- defaultWriteTarget: "default-one",
272
- });
273
- expect(result.source.name).toBe("default-one");
274
- });
275
- test("falls back to working stashDir when no explicit target / defaultWriteTarget", () => {
276
- const stashDir = makeTempDir("akm-target-stash-");
277
- process.env.AKM_STASH_DIR = stashDir;
278
- const result = resolveWriteTarget({ semanticSearchMode: "off" });
279
- expect(result.source.kind).toBe("filesystem");
280
- expect(result.source.path).toBe(stashDir);
281
- });
282
- test("throws ConfigError when defaultWriteTarget points at a missing source", () => {
283
- expect(() => resolveWriteTarget({
284
- semanticSearchMode: "off",
285
- sources: [{ type: "filesystem", path: "/tmp/akm-missing", name: "exists", writable: true }],
286
- defaultWriteTarget: "ghost",
287
- })).toThrow(ConfigError);
288
- });
289
- test("throws UsageError when --target names a missing source", () => {
290
- expect(() => resolveWriteTarget({
291
- semanticSearchMode: "off",
292
- sources: [{ type: "filesystem", path: "/tmp/akm-other", name: "other", writable: true }],
293
- }, "nope")).toThrow(UsageError);
294
- });
295
- });
296
- // ── sanitizeCommitMessage (issue #270) ──────────────────────────────────────
297
- describe("sanitizeCommitMessage", () => {
298
- test("strips newline injection attempts and collapses to a single line", () => {
299
- // Classic newline-injection payload: forge a Co-Authored-By trailer.
300
- const payload = "Update skill:foo\n\nCo-Authored-By: attacker <evil@example>";
301
- const out = sanitizeCommitMessage(payload);
302
- expect(out.includes("\n")).toBe(false);
303
- expect(out.includes("\r")).toBe(false);
304
- // Content survives, just on one line with whitespace runs collapsed.
305
- expect(out).toBe("Update skill:foo Co-Authored-By: attacker <evil@example>");
306
- });
307
- test("strips carriage returns", () => {
308
- expect(sanitizeCommitMessage("a\rb\r\nc")).toBe("a b c");
309
- });
310
- test("strips NUL bytes", () => {
311
- const out = sanitizeCommitMessage("subject\x00hidden");
312
- expect(out.includes("\x00")).toBe(false);
313
- expect(out).toBe("subjecthidden");
314
- });
315
- test("strips other C0 control characters", () => {
316
- // 0x07 BEL, 0x1B ESC, 0x7F DEL — all become spaces (then collapsed).
317
- expect(sanitizeCommitMessage("a\x07b\x1Bc\x7Fd")).toBe("a b c d");
318
- });
319
- test("clamps to 4096 characters", () => {
320
- const long = "x".repeat(5000);
321
- const out = sanitizeCommitMessage(long);
322
- expect(out.length).toBe(4096);
323
- });
324
- test("returns empty string for empty/whitespace-only input", () => {
325
- expect(sanitizeCommitMessage("")).toBe("");
326
- expect(sanitizeCommitMessage(" \n\r\t ")).toBe("");
327
- });
328
- test("returns empty string for non-string input", () => {
329
- expect(sanitizeCommitMessage(undefined)).toBe("");
330
- expect(sanitizeCommitMessage(null)).toBe("");
331
- });
332
- });
333
- // ── git commit message sanitization end-to-end (issue #270) ─────────────────
334
- describe("writeAssetToSource — commit message sanitization (issue #270)", () => {
335
- test("ref.origin with embedded newline does not produce multi-line commit", async () => {
336
- const { workDir } = initBareGitRepo();
337
- const source = { kind: "git", name: "team", path: workDir };
338
- const config = { type: "git", writable: true };
339
- // Newline-laden origin: an attacker who controls a config entry could
340
- // otherwise smuggle trailers into the commit subject.
341
- const malignOrigin = "team\n\nCo-Authored-By: attacker <evil@example>";
342
- await writeAssetToSource(source, config, { type: "memory", name: "alpha", origin: malignOrigin }, "body");
343
- const fullLog = spawnSync("git", ["-C", workDir, "log", "--format=%B%x00", "-1"], { encoding: "utf8" });
344
- // Trim the NUL terminator we used as a record separator. The remaining
345
- // body must contain no embedded newlines (other than the trailing one git
346
- // always appends to the message).
347
- // biome-ignore lint/suspicious/noControlCharactersInRegex: NUL is the explicit record separator.
348
- const messageBody = fullLog.stdout.replace(/\x00\s*$/, "").replace(/\n$/, "");
349
- expect(messageBody.includes("\n")).toBe(false);
350
- expect(messageBody.includes("Co-Authored-By: attacker")).toBe(true);
351
- // The injected trailer is part of the *subject*, not a real trailer.
352
- expect(messageBody.startsWith("Update team")).toBe(true);
353
- });
354
- test("ref.origin with NUL byte is sanitized (commit succeeds)", async () => {
355
- const { workDir } = initBareGitRepo();
356
- const source = { kind: "git", name: "team", path: workDir };
357
- const config = { type: "git", writable: true };
358
- // A NUL byte in argv would make git reject the commit outright. We strip
359
- // it so the commit succeeds with the rest of the origin intact.
360
- const malignOrigin = "team\x00hidden";
361
- await writeAssetToSource(source, config, { type: "memory", name: "beta", origin: malignOrigin }, "body");
362
- const log = spawnSync("git", ["-C", workDir, "log", "--format=%s", "-1"], { encoding: "utf8" });
363
- expect(log.stdout.includes("\x00")).toBe(false);
364
- expect(log.stdout.trim()).toBe("Update teamhidden//memory:beta");
365
- });
366
- });
@@ -1,87 +0,0 @@
1
- import { 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
- const CLI = path.join(__dirname, "..", "src", "cli.ts");
7
- const tempDirs = [];
8
- function makeTempDir(prefix) {
9
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
10
- tempDirs.push(dir);
11
- return dir;
12
- }
13
- function writeFile(filePath, content) {
14
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
15
- fs.writeFileSync(filePath, content);
16
- }
17
- function runCli(stashDir, args) {
18
- const xdgCache = makeTempDir("akm-curate-cache-");
19
- const xdgConfig = makeTempDir("akm-curate-config-");
20
- const result = spawnSync("bun", [CLI, ...args], {
21
- encoding: "utf8",
22
- timeout: 30_000,
23
- env: {
24
- ...process.env,
25
- AKM_STASH_DIR: stashDir,
26
- XDG_CACHE_HOME: xdgCache,
27
- XDG_CONFIG_HOME: xdgConfig,
28
- },
29
- });
30
- expect(result.status).toBe(0);
31
- return result.stdout.trim();
32
- }
33
- afterEach(() => {
34
- for (const dir of tempDirs.splice(0)) {
35
- fs.rmSync(dir, { recursive: true, force: true });
36
- }
37
- });
38
- describe("curate command", () => {
39
- function makeStash() {
40
- const stashDir = makeTempDir("akm-curate-stash-");
41
- writeFile(path.join(stashDir, "scripts", "deploy.sh"), "#!/usr/bin/env bash\necho deploy\n");
42
- writeFile(path.join(stashDir, "commands", "release.md"), "---\ndescription: Release the app\n---\nnpm version {{version}} && git push --follow-tags\n");
43
- writeFile(path.join(stashDir, "skills", "release-review", "SKILL.md"), "---\ndescription: Review a release plan\n---\n# Release Review\nCheck rollout, rollback, and validation.\n");
44
- writeFile(path.join(stashDir, "knowledge", "release-guide.md"), "# Release Guide\n\nUse this guide to explain the release workflow.\n");
45
- return stashDir;
46
- }
47
- test("returns curated JSON with follow-up commands and previews", () => {
48
- const stashDir = makeStash();
49
- const output = runCli(stashDir, ["curate", "release deploy", "--format=json"]);
50
- const json = JSON.parse(output);
51
- expect(json.query).toBe("release deploy");
52
- expect(json.summary).toContain("Selected");
53
- expect(json.items.length).toBeGreaterThanOrEqual(2);
54
- expect(new Set(json.items.map((item) => item.type)).size).toBeGreaterThanOrEqual(2);
55
- for (const item of json.items) {
56
- if (item.source === "stash") {
57
- expect(typeof item.ref).toBe("string");
58
- expect(String(item.followUp)).toContain("akm show");
59
- expect(typeof item.reason).toBe("string");
60
- }
61
- }
62
- });
63
- test("prefers one strong match per asset type by default", () => {
64
- const stashDir = makeStash();
65
- writeFile(path.join(stashDir, "commands", "release-notes.md"), "---\ndescription: Draft release notes\n---\nWrite release notes for {{version}}\n");
66
- const output = runCli(stashDir, ["curate", "release", "--format=json"]);
67
- const json = JSON.parse(output);
68
- const commandItems = json.items.filter((item) => item.type === "command");
69
- expect(commandItems.length).toBe(1);
70
- });
71
- test("text output includes direct refs and follow-up commands", () => {
72
- const stashDir = makeStash();
73
- const output = runCli(stashDir, ["curate", "release deploy", "--format=text"]);
74
- expect(output).toContain('Curated results for "release deploy"');
75
- expect(output).toContain("[command]");
76
- expect(output).toContain("ref: command:release");
77
- expect(output).toContain("show: akm show command:release");
78
- });
79
- test("returns a tip when no curated results are found", () => {
80
- const stashDir = makeTempDir("akm-curate-empty-stash-");
81
- const output = runCli(stashDir, ["curate", "totally unmatched request", "--format=json"]);
82
- const json = JSON.parse(output);
83
- expect(json.items).toEqual([]);
84
- expect(json.summary).toContain("No curated assets were selected");
85
- expect(json.tip).toContain("No matching");
86
- });
87
- });
@@ -1,201 +0,0 @@
1
- import { afterAll, 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 { closeDatabase, openDatabase, rebuildFts, sanitizeFtsQuery, searchFts, upsertEntry } from "../src/indexer/db";
6
- // ── Temp directory management ───────────────────────────────────────────────
7
- const createdTmpDirs = [];
8
- function tmpDir(label = "db-scoring") {
9
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), `akm-${label}-`));
10
- createdTmpDirs.push(dir);
11
- return dir;
12
- }
13
- function tmpDbPath(label = "db-scoring") {
14
- const dir = tmpDir(label);
15
- return path.join(dir, "test.db");
16
- }
17
- afterAll(() => {
18
- for (const dir of createdTmpDirs) {
19
- fs.rmSync(dir, { recursive: true, force: true });
20
- }
21
- });
22
- // ── Environment isolation ───────────────────────────────────────────────────
23
- const savedEnv = {};
24
- beforeEach(() => {
25
- savedEnv.XDG_CACHE_HOME = process.env.XDG_CACHE_HOME;
26
- savedEnv.XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME;
27
- process.env.XDG_CACHE_HOME = tmpDir("cache");
28
- process.env.XDG_CONFIG_HOME = tmpDir("config");
29
- });
30
- afterEach(() => {
31
- for (const [key, val] of Object.entries(savedEnv)) {
32
- if (val === undefined) {
33
- delete process.env[key];
34
- }
35
- else {
36
- process.env[key] = val;
37
- }
38
- }
39
- });
40
- // ── Helpers ─────────────────────────────────────────────────────────────────
41
- function makeEntry(overrides) {
42
- return {
43
- description: "A test entry",
44
- ...overrides,
45
- };
46
- }
47
- function insertTestEntry(db, key, opts) {
48
- const type = opts?.type ?? "script";
49
- const entry = makeEntry({ name: key, type, description: opts?.description ?? `Description for ${key}` });
50
- return upsertEntry(db, key, opts?.dirPath ?? "/test/dir", opts?.filePath ?? `/test/dir/${key}.ts`, opts?.stashDir ?? "/test/stash", entry, opts?.searchText ?? `${key} ${entry.description}`);
51
- }
52
- // ── Issue #2: sanitizeFtsQuery preserves identifier tokens ──────────────────
53
- describe("sanitizeFtsQuery — identifier preservation (Issue #2)", () => {
54
- test("hyphenated query becomes AND of component tokens", () => {
55
- const result = sanitizeFtsQuery("code-review");
56
- // Hyphens are replaced with spaces — FTS5 treats hyphen as NOT in
57
- // query context. The result is implicit AND: "code review".
58
- expect(result).toContain("code");
59
- expect(result).toContain("review");
60
- // Must NOT use OR join
61
- expect(result).not.toContain(" OR ");
62
- });
63
- test("dotted query becomes AND of component tokens", () => {
64
- const result = sanitizeFtsQuery("k8s.setup");
65
- // Dots cause FTS5 syntax errors; replaced with spaces
66
- expect(result).toContain("k8s");
67
- expect(result).toContain("setup");
68
- expect(result).not.toContain(".");
69
- });
70
- test("preserves underscores in identifiers like deploy_prod", () => {
71
- const result = sanitizeFtsQuery("deploy_prod");
72
- // Underscores are valid in FTS5 queries (unicode61 treats them as
73
- // token separators on both index and query sides)
74
- expect(result).toContain("deploy_prod");
75
- });
76
- test("strips FTS5 syntax characters (quotes, parens, asterisks, colons, carets)", () => {
77
- const result = sanitizeFtsQuery('"hello" (world) test*');
78
- // The dangerous FTS5 syntax chars should be removed
79
- expect(result).not.toContain('"');
80
- expect(result).not.toContain("(");
81
- expect(result).not.toContain(")");
82
- expect(result).not.toContain("*");
83
- // But the actual words should remain
84
- expect(result).toContain("hello");
85
- expect(result).toContain("world");
86
- expect(result).toContain("test");
87
- });
88
- test("strips NEAR operator from query", () => {
89
- // NEAR is a special FTS5 operator that should be neutralized
90
- const result = sanitizeFtsQuery("NEAR foo bar");
91
- expect(result).not.toMatch(/\bNEAR\b/);
92
- expect(result).toContain("foo");
93
- expect(result).toContain("bar");
94
- });
95
- test("uses AND (implicit space-separated) rather than OR", () => {
96
- const result = sanitizeFtsQuery("deploy production");
97
- // Should NOT contain OR — tokens should be AND-joined (space-separated)
98
- expect(result).not.toContain(" OR ");
99
- // Both tokens should be present
100
- expect(result).toContain("deploy");
101
- expect(result).toContain("production");
102
- });
103
- test("returns empty string for empty query", () => {
104
- expect(sanitizeFtsQuery("")).toBe("");
105
- });
106
- test("returns empty string for only-syntax-chars query", () => {
107
- expect(sanitizeFtsQuery('"()*:^{}')).toBe("");
108
- });
109
- test("handles mixed valid and syntax chars", () => {
110
- const result = sanitizeFtsQuery('deploy:prod "code-review"');
111
- expect(result).not.toContain(":");
112
- expect(result).not.toContain('"');
113
- expect(result).toContain("deploy");
114
- expect(result).toContain("prod");
115
- // code-review becomes "code review" (space-separated AND)
116
- expect(result).toContain("code");
117
- expect(result).toContain("review");
118
- });
119
- });
120
- // ── Issue #2: Integration test — hyphenated search through searchFts ────────
121
- describe("searchFts — hyphenated identifier search (Issue #2)", () => {
122
- test("searching for 'code-review' matches entry with code-review in search text", () => {
123
- const db = openDatabase(tmpDbPath());
124
- try {
125
- insertTestEntry(db, "code-review", {
126
- description: "code-review skill for reviewing pull requests",
127
- searchText: "code-review skill for reviewing pull requests",
128
- });
129
- insertTestEntry(db, "deploy-prod", {
130
- description: "deploy-prod deploy to production servers",
131
- searchText: "deploy-prod deploy to production servers",
132
- });
133
- rebuildFts(db);
134
- const results = searchFts(db, "code-review", 10);
135
- expect(results.length).toBeGreaterThanOrEqual(1);
136
- // The code-review entry should be the top result
137
- expect(results[0].entry.name).toBe("code-review");
138
- }
139
- finally {
140
- closeDatabase(db);
141
- }
142
- });
143
- test("AND semantics: multi-word query only matches entries containing all terms", () => {
144
- const db = openDatabase(tmpDbPath());
145
- try {
146
- insertTestEntry(db, "deploy-tool", {
147
- description: "deploy applications to production servers",
148
- searchText: "deploy applications to production servers",
149
- });
150
- insertTestEntry(db, "code-tool", {
151
- description: "code linting and formatting tool",
152
- searchText: "code linting and formatting tool",
153
- });
154
- insertTestEntry(db, "review-tool", {
155
- description: "review pull requests and merge code",
156
- searchText: "review pull requests and merge code",
157
- });
158
- rebuildFts(db);
159
- // With AND semantics, "code review" should NOT match "deploy-tool"
160
- // (which has neither "code" nor "review")
161
- // "review-tool" has both "review" and "code" in its search text
162
- const results = searchFts(db, "code review", 10);
163
- const names = results.map((r) => r.entry.name);
164
- expect(names).not.toContain("deploy-tool");
165
- // review-tool should match (it contains both "code" and "review")
166
- expect(names).toContain("review-tool");
167
- }
168
- finally {
169
- closeDatabase(db);
170
- }
171
- });
172
- });
173
- // ── Issue #9: Single-character queries ──────────────────────────────────────
174
- describe("sanitizeFtsQuery — single-char tokens (Issue #9)", () => {
175
- test("single character token is preserved", () => {
176
- const result = sanitizeFtsQuery("R");
177
- expect(result).toBe("R");
178
- });
179
- test("single character query returns FTS results when content matches", () => {
180
- const db = openDatabase(tmpDbPath());
181
- try {
182
- insertTestEntry(db, "r-lang", {
183
- searchText: "R programming language for statistics",
184
- });
185
- insertTestEntry(db, "python-tool", {
186
- searchText: "Python scripting language",
187
- });
188
- rebuildFts(db);
189
- const results = searchFts(db, "R", 10);
190
- expect(results.length).toBeGreaterThanOrEqual(1);
191
- }
192
- finally {
193
- closeDatabase(db);
194
- }
195
- });
196
- test("mixed single and multi-char tokens are all preserved", () => {
197
- const result = sanitizeFtsQuery("R language");
198
- expect(result).toContain("R");
199
- expect(result).toContain("language");
200
- });
201
- });