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,616 +0,0 @@
1
- /**
2
- * Unit tests for the evolve runner (Track B, #243).
3
- *
4
- * Every external interaction is mocked via injected fakes:
5
- * • `spawn` — fake SpawnFn forwarded to runOne; produces deterministic
6
- * stdout per arm so the runner's outcome classification is testable.
7
- * • `akmCli` — fake AkmCliFn that records every call and returns scripted
8
- * stdout/stderr/exit codes for `feedback` / `distill` / `reflect` /
9
- * `proposal *` / `index`.
10
- * • `materialiseStash: false` — runUtility never touches the on-disk
11
- * fixture directory.
12
- */
13
- import { afterAll, beforeAll, describe, expect, test } from "bun:test";
14
- import fs from "node:fs";
15
- import path from "node:path";
16
- import { buildSyntheticPrompt, runEvolve } from "./evolve";
17
- import { computeLongitudinalMetrics, computeProposalQualityMetrics } from "./metrics";
18
- import { benchMkdtemp } from "./tmp";
19
- function asReadableStream(text) {
20
- const bytes = new TextEncoder().encode(text);
21
- return new ReadableStream({
22
- start(controller) {
23
- controller.enqueue(bytes);
24
- controller.close();
25
- },
26
- });
27
- }
28
- /**
29
- * Build a fake spawn that drives the agent harness deterministically.
30
- * The fake always emits `ok` on agent runs; per-task pass/fail is controlled
31
- * by setting `expectedMatch` on the task: `"ok"` to pass, anything else
32
- * (e.g. `"WONT_MATCH"`) to fail. This bypasses the verifier-spawn path
33
- * because our fake tasks all use `verifier: "regex"`.
34
- */
35
- function buildFakeSpawn(opts) {
36
- return (_cmd, options) => {
37
- if (opts.observed) {
38
- opts.observed.arms.push(options.env?.BENCH_EVOLVE_ARM ?? (options.env?.AKM_STASH_DIR ? "akm" : "noakm"));
39
- opts.observed.cwd.push(options.cwd);
40
- }
41
- const proc = {
42
- exitCode: 0,
43
- exited: Promise.resolve(0),
44
- stdout: asReadableStream("ok"),
45
- stderr: asReadableStream(""),
46
- stdin: null,
47
- kill() { },
48
- };
49
- return proc;
50
- };
51
- }
52
- /**
53
- * Build a fake akmCli that records calls and returns scripted responses.
54
- * `proposalQueue` is the list of proposals returned by `proposal list`.
55
- * `lintByProposal` controls lint outcomes for `proposal show`.
56
- */
57
- function buildFakeAkmCli(opts) {
58
- return async (args, _cwd, env) => {
59
- if (opts.observed) {
60
- opts.observed.calls.push(args);
61
- opts.observed.envSeen.push({ ...env });
62
- }
63
- if (args[0] === "feedback")
64
- return { exitCode: 0, stdout: "", stderr: "" };
65
- if (args[0] === "distill")
66
- return { exitCode: 0, stdout: "", stderr: "" };
67
- if (args[0] === "reflect")
68
- return { exitCode: 0, stdout: "", stderr: "" };
69
- if (args[0] === "index")
70
- return { exitCode: 0, stdout: "", stderr: "" };
71
- if (args[0] === "proposal" && args[1] === "list") {
72
- const queue = opts.proposalQueue ?? [];
73
- return {
74
- exitCode: 0,
75
- stdout: JSON.stringify(queue.map((p) => ({ id: p.id, target_ref: p.targetRef, kind: p.kind ?? "lesson" }))),
76
- stderr: "",
77
- };
78
- }
79
- if (args[0] === "proposal" && args[1] === "show") {
80
- const id = args[2];
81
- const lint = opts.lintByProposal?.[id] ?? { lintPass: true };
82
- const payload = {
83
- id,
84
- lint_pass: lint.lintPass,
85
- lint: lint.lintPass ? { pass: true, issues: [] } : { pass: false, issues: [lint.message ?? "lint error"] },
86
- };
87
- return { exitCode: 0, stdout: JSON.stringify(payload), stderr: "" };
88
- }
89
- if (args[0] === "proposal" && args[1] === "accept")
90
- return { exitCode: 0, stdout: "", stderr: "" };
91
- if (args[0] === "proposal" && args[1] === "reject")
92
- return { exitCode: 0, stdout: "", stderr: "" };
93
- return { exitCode: 0, stdout: "", stderr: "" };
94
- };
95
- }
96
- function fakeTask(taskDir, overrides = {}) {
97
- return {
98
- id: "fake-d/task-a",
99
- title: "Fake A",
100
- domain: "fake-d",
101
- difficulty: "easy",
102
- stash: "minimal",
103
- verifier: "regex",
104
- expectedMatch: "ok",
105
- budget: { tokens: 1000, wallMs: 5000 },
106
- taskDir,
107
- slice: "train",
108
- goldRef: "skill:fake-a",
109
- ...overrides,
110
- };
111
- }
112
- describe("runEvolve — Phase 1 feedback", () => {
113
- let workspaceRoot;
114
- let taskDir;
115
- beforeAll(() => {
116
- workspaceRoot = benchMkdtemp("bench-evolve-test-");
117
- taskDir = path.join(workspaceRoot, "task");
118
- fs.mkdirSync(taskDir, { recursive: true });
119
- });
120
- afterAll(() => {
121
- fs.rmSync(workspaceRoot, { recursive: true, force: true });
122
- });
123
- test("records --positive feedback on pass and --negative on fail", async () => {
124
- const observed = { calls: [], envSeen: [] };
125
- // Two train tasks: one passes (expectedMatch=ok matches "ok" stdout), one fails.
126
- const tasks = [
127
- fakeTask(taskDir, { id: "fake-d/pass", goldRef: "skill:passing", slice: "train", expectedMatch: "ok" }),
128
- fakeTask(taskDir, { id: "fake-d/fail", goldRef: "skill:failing", slice: "train", expectedMatch: "WONT" }),
129
- fakeTask(taskDir, { id: "fake-d/eval", goldRef: "skill:eval-target", slice: "eval", expectedMatch: "ok" }),
130
- ];
131
- const spawn = buildFakeSpawn({});
132
- const akmCli = buildFakeAkmCli({ observed });
133
- const report = await runEvolve({
134
- tasks,
135
- model: "test-model",
136
- seedsPerArm: 2,
137
- spawn,
138
- akmCli,
139
- materialiseStash: false,
140
- timestamp: "2026-04-27T00:00:00Z",
141
- branch: "test",
142
- commit: "abc",
143
- });
144
- // Verify feedback events exist.
145
- const feedbackCalls = observed.calls.filter((c) => c[0] === "feedback");
146
- expect(feedbackCalls.length).toBeGreaterThan(0);
147
- // Each train (passing) seed -> --positive; each train (failing) seed -> --negative.
148
- const positives = feedbackCalls.filter((c) => c[2] === "--positive");
149
- const negatives = feedbackCalls.filter((c) => c[2] === "--negative");
150
- expect(positives.length).toBe(2); // pass task × 2 seeds
151
- expect(negatives.length).toBe(2); // fail task × 2 seeds
152
- // The feedback log should match.
153
- const positiveLog = report.feedbackLog.filter((e) => e.signal === "positive");
154
- expect(positiveLog.length).toBe(2);
155
- expect(positiveLog[0].goldRef).toBe("skill:passing");
156
- });
157
- });
158
- describe("runEvolve — Phase 2 threshold + proposal lifecycle", () => {
159
- let workspaceRoot;
160
- let taskDir;
161
- beforeAll(() => {
162
- workspaceRoot = benchMkdtemp("bench-evolve-phase2-");
163
- taskDir = path.join(workspaceRoot, "task");
164
- fs.mkdirSync(taskDir, { recursive: true });
165
- });
166
- afterAll(() => {
167
- fs.rmSync(workspaceRoot, { recursive: true, force: true });
168
- });
169
- test("threshold gates distill+reflect", async () => {
170
- const observed = { calls: [], envSeen: [] };
171
- const tasks = [
172
- fakeTask(taskDir, { id: "fake-d/loser", goldRef: "skill:loser", slice: "train", expectedMatch: "WONT" }),
173
- fakeTask(taskDir, { id: "fake-d/winner", goldRef: "skill:winner", slice: "train", expectedMatch: "ok" }),
174
- fakeTask(taskDir, { id: "fake-d/eval", goldRef: "skill:eval-only", slice: "eval", expectedMatch: "ok" }),
175
- ];
176
- const spawn = buildFakeSpawn({});
177
- const akmCli = buildFakeAkmCli({ observed, proposalQueue: [] });
178
- await runEvolve({
179
- tasks,
180
- model: "test-model",
181
- seedsPerArm: 3,
182
- spawn,
183
- akmCli,
184
- materialiseStash: false,
185
- negativeThreshold: { absoluteCount: 2, ratio: 0.5 },
186
- });
187
- const distillCalls = observed.calls.filter((c) => c[0] === "distill");
188
- const reflectCalls = observed.calls.filter((c) => c[0] === "reflect");
189
- // Loser crosses threshold; winner does not.
190
- expect(distillCalls.map((c) => c[1])).toEqual(["skill:loser"]);
191
- expect(reflectCalls.map((c) => c[1])).toEqual(["skill:loser"]);
192
- });
193
- test("lint_pass=true → accept, lint_pass=false → reject", async () => {
194
- const observed = { calls: [], envSeen: [] };
195
- const tasks = [
196
- fakeTask(taskDir, { id: "fake-d/loser", goldRef: "skill:loser", slice: "train", expectedMatch: "WONT" }),
197
- fakeTask(taskDir, { id: "fake-d/eval", goldRef: "skill:eval-only", slice: "eval", expectedMatch: "ok" }),
198
- ];
199
- const spawn = buildFakeSpawn({});
200
- const akmCli = buildFakeAkmCli({
201
- observed,
202
- proposalQueue: [
203
- { id: "p-good", targetRef: "skill:loser", kind: "lesson" },
204
- { id: "p-bad", targetRef: "skill:loser", kind: "revision" },
205
- ],
206
- lintByProposal: {
207
- "p-good": { lintPass: true },
208
- "p-bad": { lintPass: false, message: "missing description" },
209
- },
210
- });
211
- const report = await runEvolve({
212
- tasks,
213
- model: "test-model",
214
- seedsPerArm: 2,
215
- spawn,
216
- akmCli,
217
- materialiseStash: false,
218
- });
219
- const accepted = observed.calls.find((c) => c[0] === "proposal" && c[1] === "accept" && c[2] === "p-good");
220
- const rejected = observed.calls.find((c) => c[0] === "proposal" && c[1] === "reject" && c[2] === "p-bad");
221
- expect(accepted).toBeDefined();
222
- expect(rejected).toBeDefined();
223
- expect(report.proposalLog.find((e) => e.proposalId === "p-good")?.decision).toBe("accept");
224
- expect(report.proposalLog.find((e) => e.proposalId === "p-bad")?.decision).toBe("reject");
225
- expect(report.proposals.totalProposals).toBe(2);
226
- expect(report.proposals.totalAccepted).toBe(1);
227
- expect(report.proposals.acceptanceRate).toBe(0.5);
228
- });
229
- test("rebuilds index after Phase 2", async () => {
230
- const observed = { calls: [], envSeen: [] };
231
- const tasks = [fakeTask(taskDir, { id: "fake-d/eval-only", slice: "eval", expectedMatch: "ok" })];
232
- const spawn = buildFakeSpawn({});
233
- const akmCli = buildFakeAkmCli({ observed });
234
- await runEvolve({ tasks, model: "test-model", seedsPerArm: 1, spawn, akmCli, materialiseStash: false });
235
- expect(observed.calls.some((c) => c[0] === "index")).toBe(true);
236
- });
237
- });
238
- describe("runEvolve — Phase 3 three-arm execution", () => {
239
- let workspaceRoot;
240
- let taskDir;
241
- beforeAll(() => {
242
- workspaceRoot = benchMkdtemp("bench-evolve-phase3-");
243
- taskDir = path.join(workspaceRoot, "task");
244
- fs.mkdirSync(taskDir, { recursive: true });
245
- });
246
- afterAll(() => {
247
- fs.rmSync(workspaceRoot, { recursive: true, force: true });
248
- });
249
- test("produces pre / post / synthetic arm reports", async () => {
250
- const tasks = [
251
- fakeTask(taskDir, { id: "fake-d/eval-task", slice: "eval", goldRef: "skill:t", expectedMatch: "ok" }),
252
- fakeTask(taskDir, { id: "fake-d/train-task", slice: "train", goldRef: "skill:tr", expectedMatch: "ok" }),
253
- ];
254
- const spawn = buildFakeSpawn({});
255
- const akmCli = buildFakeAkmCli({});
256
- const report = await runEvolve({
257
- tasks,
258
- model: "test-model",
259
- seedsPerArm: 2,
260
- spawn,
261
- akmCli,
262
- materialiseStash: false,
263
- });
264
- expect(report.arms.pre.tasks.length).toBe(1); // eval-only
265
- expect(report.arms.post.tasks.length).toBe(1);
266
- expect(report.arms.synthetic.tasks.length).toBe(1);
267
- });
268
- test("synthetic arm receives no AKM_STASH_DIR via spawn wrapper", async () => {
269
- const observed = { arms: [], cwd: [] };
270
- const tasks = [fakeTask(taskDir, { id: "fake-d/eval-x", slice: "eval", goldRef: "skill:x", expectedMatch: "ok" })];
271
- const spawn = buildFakeSpawn({ observed });
272
- const akmCli = buildFakeAkmCli({});
273
- await runEvolve({
274
- tasks,
275
- model: "test-model",
276
- seedsPerArm: 1,
277
- spawn,
278
- akmCli,
279
- materialiseStash: false,
280
- });
281
- // Among the spawn arms, we expect to see the literal "synthetic" tag.
282
- expect(observed.arms).toContain("synthetic");
283
- });
284
- test("buildSyntheticPrompt mentions Bring Your Own Skills", () => {
285
- const text = buildSyntheticPrompt("docker-homelab/x");
286
- expect(text).toContain("Bring Your Own Skills");
287
- expect(text).toContain("scratchpad");
288
- });
289
- test("synthetic arm forwards buildSyntheticPrompt(task) into the agent spawn (#267)", async () => {
290
- // Capture every agent cmd; runAgent appends the prompt as its trailing
291
- // arg. Phase 3's synthetic arm should now ship the BYOS scratchpad
292
- // prompt instead of the driver default.
293
- const capturedSyntheticPrompts = [];
294
- const spawn = (cmd, options) => {
295
- const isAgent = cmd[0] === "opencode";
296
- if (isAgent && options.env?.BENCH_EVOLVE_SCRATCHPAD === "1") {
297
- // Trailing token is the prompt.
298
- capturedSyntheticPrompts.push(cmd[cmd.length - 1] ?? "");
299
- }
300
- return {
301
- exitCode: 0,
302
- exited: Promise.resolve(0),
303
- stdout: asReadableStream("ok"),
304
- stderr: asReadableStream(""),
305
- stdin: null,
306
- kill() { },
307
- };
308
- };
309
- const tasks = [
310
- fakeTask(taskDir, { id: "fake-d/eval-a", slice: "eval", goldRef: "skill:a", expectedMatch: "ok" }),
311
- fakeTask(taskDir, { id: "fake-d/eval-b", slice: "eval", goldRef: "skill:b", expectedMatch: "ok" }),
312
- ];
313
- const akmCli = buildFakeAkmCli({});
314
- await runEvolve({
315
- tasks,
316
- model: "test-model",
317
- seedsPerArm: 1,
318
- spawn,
319
- akmCli,
320
- materialiseStash: false,
321
- });
322
- expect(capturedSyntheticPrompts.length).toBe(2);
323
- for (const prompt of capturedSyntheticPrompts) {
324
- expect(prompt).toContain("Bring Your Own Skills");
325
- expect(prompt).toContain("scratchpad");
326
- }
327
- // Per-task ids landed in their respective prompts.
328
- expect(capturedSyntheticPrompts.some((p) => p.includes("fake-d/eval-a"))).toBe(true);
329
- expect(capturedSyntheticPrompts.some((p) => p.includes("fake-d/eval-b"))).toBe(true);
330
- });
331
- });
332
- describe("runEvolve — leakage prevention (§7.4)", () => {
333
- let workspaceRoot;
334
- let taskDir;
335
- beforeAll(() => {
336
- workspaceRoot = benchMkdtemp("bench-evolve-leak-");
337
- taskDir = path.join(workspaceRoot, "task");
338
- fs.mkdirSync(taskDir, { recursive: true });
339
- });
340
- afterAll(() => {
341
- fs.rmSync(workspaceRoot, { recursive: true, force: true });
342
- });
343
- test("invokes distill with --exclude-feedback-from when ref is also an eval-slice gold ref (#267)", async () => {
344
- const observed = { calls: [], envSeen: [] };
345
- // The same `skill:shared` is the gold ref for BOTH a failing train task
346
- // AND an eval task. Distill is now invoked WITH the exclusion flag;
347
- // distill itself filters the leaked feedback out of the prompt.
348
- const tasks = [
349
- fakeTask(taskDir, { id: "fake-d/train-shared", goldRef: "skill:shared", slice: "train", expectedMatch: "WONT" }),
350
- fakeTask(taskDir, { id: "fake-d/eval-shared", goldRef: "skill:shared", slice: "eval", expectedMatch: "ok" }),
351
- ];
352
- const spawn = buildFakeSpawn({});
353
- const akmCli = buildFakeAkmCli({ observed });
354
- const report = await runEvolve({
355
- tasks,
356
- model: "test-model",
357
- seedsPerArm: 3,
358
- spawn,
359
- akmCli,
360
- materialiseStash: false,
361
- });
362
- const distillCalls = observed.calls.filter((c) => c[0] === "distill");
363
- // Distill now runs even on shared refs — but with the exclusion flag.
364
- expect(distillCalls.length).toBe(1);
365
- const flagIdx = distillCalls[0]?.indexOf("--exclude-feedback-from") ?? -1;
366
- expect(flagIdx).toBeGreaterThan(-1);
367
- expect(distillCalls[0]?.[flagIdx + 1]).toBe("skill:shared");
368
- // Per-ref leakage info note replaces the old "skipped" warning.
369
- expect(report.warnings.some((w) => w.includes("filtered eval-slice gold-ref feedback"))).toBe(true);
370
- // Env var fallback is also threaded through for harnesses that drop flags.
371
- const distillEnv = observed.envSeen.find((env) => env.AKM_DISTILL_EXCLUDE_FEEDBACK_FROM !== undefined);
372
- expect(distillEnv?.AKM_DISTILL_EXCLUDE_FEEDBACK_FROM).toBe("skill:shared");
373
- });
374
- test("does not emit the deprecated '--exclude-gold-ref' generic warning (#267)", async () => {
375
- const observed = { calls: [], envSeen: [] };
376
- // Three distinct failing-train refs all cross threshold. The old runner
377
- // would emit a generic "distill ignores the env hint" warning once;
378
- // with #267 the filter is real, so that line MUST NOT appear.
379
- const tasks = [
380
- fakeTask(taskDir, { id: "fake-d/loser-a", goldRef: "skill:loser-a", slice: "train", expectedMatch: "WONT" }),
381
- fakeTask(taskDir, { id: "fake-d/loser-b", goldRef: "skill:loser-b", slice: "train", expectedMatch: "WONT" }),
382
- fakeTask(taskDir, { id: "fake-d/loser-c", goldRef: "skill:loser-c", slice: "train", expectedMatch: "WONT" }),
383
- fakeTask(taskDir, { id: "fake-d/eval", goldRef: "skill:eval-target", slice: "eval", expectedMatch: "ok" }),
384
- ];
385
- const spawn = buildFakeSpawn({});
386
- const akmCli = buildFakeAkmCli({ observed });
387
- const report = await runEvolve({
388
- tasks,
389
- model: "test-model",
390
- seedsPerArm: 3,
391
- spawn,
392
- akmCli,
393
- materialiseStash: false,
394
- });
395
- const generic = report.warnings.filter((w) => w.includes("distill/reflect cannot today filter their own LLM input"));
396
- expect(generic.length).toBe(0);
397
- // We did still evolve all three refs, each carrying the exclusion flag.
398
- const distillCalls = observed.calls.filter((c) => c[0] === "distill");
399
- expect(distillCalls.length).toBe(3);
400
- for (const call of distillCalls) {
401
- const idx = call.indexOf("--exclude-feedback-from");
402
- expect(idx).toBeGreaterThan(-1);
403
- expect(call[idx + 1]).toBe("skill:eval-target");
404
- }
405
- });
406
- });
407
- describe("runEvolve — Phase 1 fault tolerance", () => {
408
- let workspaceRoot;
409
- let taskDir;
410
- beforeAll(() => {
411
- workspaceRoot = benchMkdtemp("bench-evolve-faulty-");
412
- taskDir = path.join(workspaceRoot, "task");
413
- fs.mkdirSync(taskDir, { recursive: true });
414
- });
415
- afterAll(() => {
416
- fs.rmSync(workspaceRoot, { recursive: true, force: true });
417
- });
418
- test("a throwing akmCli on one feedback ref does not halt Phase 2", async () => {
419
- const observed = { calls: [], envSeen: [] };
420
- // Two failing train tasks. The akmCli throws on `feedback skill:bomb`
421
- // but otherwise behaves normally. Phase 2 should still proceed and
422
- // distill the surviving refs.
423
- const tasks = [
424
- fakeTask(taskDir, { id: "fake-d/bomb", goldRef: "skill:bomb", slice: "train", expectedMatch: "WONT" }),
425
- fakeTask(taskDir, { id: "fake-d/loser", goldRef: "skill:loser", slice: "train", expectedMatch: "WONT" }),
426
- fakeTask(taskDir, { id: "fake-d/eval", goldRef: "skill:eval-target", slice: "eval", expectedMatch: "ok" }),
427
- ];
428
- const spawn = buildFakeSpawn({});
429
- const inner = buildFakeAkmCli({ observed });
430
- const akmCli = async (args, cwd, env) => {
431
- if (args[0] === "feedback" && args[1] === "skill:bomb") {
432
- throw new Error("subprocess crashed");
433
- }
434
- return inner(args, cwd, env);
435
- };
436
- const report = await runEvolve({
437
- tasks,
438
- model: "test-model",
439
- seedsPerArm: 2,
440
- spawn,
441
- akmCli,
442
- materialiseStash: false,
443
- negativeThreshold: { absoluteCount: 2, ratio: 0.5 },
444
- });
445
- // The throwing ref produced a warning of the documented shape.
446
- expect(report.warnings.some((w) => w.includes("phase1.feedback_dispatch_failed: skill:bomb"))).toBe(true);
447
- // Phase 2 still ran for the surviving ref (skill:loser crosses threshold).
448
- const distillCalls = observed.calls.filter((c) => c[0] === "distill");
449
- expect(distillCalls.map((c) => c[1])).toContain("skill:loser");
450
- // The throwing entries are still in feedbackLog (with ok:false).
451
- const bombEntries = report.feedbackLog.filter((e) => e.goldRef === "skill:bomb");
452
- expect(bombEntries.length).toBe(2);
453
- expect(bombEntries.every((e) => e.ok === false)).toBe(true);
454
- });
455
- });
456
- describe("runEvolve — operator stash sandboxing", () => {
457
- let workspaceRoot;
458
- let taskDir;
459
- beforeAll(() => {
460
- workspaceRoot = benchMkdtemp("bench-evolve-sandbox-");
461
- taskDir = path.join(workspaceRoot, "task");
462
- fs.mkdirSync(taskDir, { recursive: true });
463
- });
464
- afterAll(() => {
465
- fs.rmSync(workspaceRoot, { recursive: true, force: true });
466
- });
467
- test("does not mutate process.env.AKM_STASH_DIR", async () => {
468
- const sentinel = "/tmp/sentinel-operator-stash-must-not-change";
469
- const before = process.env.AKM_STASH_DIR;
470
- process.env.AKM_STASH_DIR = sentinel;
471
- try {
472
- const tasks = [
473
- fakeTask(taskDir, { id: "fake-d/loser", goldRef: "skill:loser", slice: "train", expectedMatch: "WONT" }),
474
- fakeTask(taskDir, { id: "fake-d/eval", goldRef: "skill:eval-target", slice: "eval", expectedMatch: "ok" }),
475
- ];
476
- const spawn = buildFakeSpawn({});
477
- const akmCli = buildFakeAkmCli({});
478
- await runEvolve({
479
- tasks,
480
- model: "test-model",
481
- seedsPerArm: 2,
482
- spawn,
483
- akmCli,
484
- materialiseStash: false,
485
- });
486
- expect(process.env.AKM_STASH_DIR).toBe(sentinel);
487
- }
488
- finally {
489
- if (before === undefined)
490
- delete process.env.AKM_STASH_DIR;
491
- else
492
- process.env.AKM_STASH_DIR = before;
493
- }
494
- });
495
- test("akmCli env never carries the operator's AKM_STASH_DIR (materialiseStash:false strips it)", async () => {
496
- const sentinel = "/tmp/sentinel-operator-stash-leak-test";
497
- const before = process.env.AKM_STASH_DIR;
498
- process.env.AKM_STASH_DIR = sentinel;
499
- try {
500
- const observed = { calls: [], envSeen: [] };
501
- const tasks = [
502
- fakeTask(taskDir, { id: "fake-d/loser", goldRef: "skill:loser", slice: "train", expectedMatch: "WONT" }),
503
- fakeTask(taskDir, { id: "fake-d/eval", goldRef: "skill:eval-target", slice: "eval", expectedMatch: "ok" }),
504
- ];
505
- const spawn = buildFakeSpawn({});
506
- const akmCli = buildFakeAkmCli({ observed });
507
- await runEvolve({
508
- tasks,
509
- model: "test-model",
510
- seedsPerArm: 2,
511
- spawn,
512
- akmCli,
513
- materialiseStash: false,
514
- });
515
- // Every recorded env passed to the fake akmCli must NOT carry the
516
- // operator's sentinel value — the runEvolve sandbox strips it.
517
- for (const env of observed.envSeen) {
518
- expect(env.AKM_STASH_DIR).not.toBe(sentinel);
519
- }
520
- }
521
- finally {
522
- if (before === undefined)
523
- delete process.env.AKM_STASH_DIR;
524
- else
525
- process.env.AKM_STASH_DIR = before;
526
- }
527
- });
528
- });
529
- describe("computeLongitudinalMetrics", () => {
530
- // Build a minimal §13.3-shape report with a single task and prescribed pass rate.
531
- function makeReport(taskId, akmPassRate, opts = {}) {
532
- const seedsPerArm = opts.seedsPerArm ?? 5;
533
- const akm = {
534
- passRate: akmPassRate,
535
- passAt1: 0,
536
- tokensPerPass: null,
537
- wallclockMs: 0,
538
- passRateStdev: 0,
539
- budgetExceededCount: 0,
540
- harnessErrorCount: 0,
541
- count: seedsPerArm,
542
- runsWithMeasuredTokens: 0,
543
- };
544
- const noakm = { ...akm, passRate: 0 };
545
- return {
546
- timestamp: "t",
547
- branch: "b",
548
- commit: "c",
549
- model: "m",
550
- corpus: { domains: 1, tasks: 1, slice: "eval", seedsPerArm },
551
- aggregateNoakm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
552
- aggregateAkm: { passRate: akmPassRate, tokensPerPass: null, wallclockMs: 0 },
553
- aggregateDelta: { passRate: akmPassRate, tokensPerPass: null, wallclockMs: 0 },
554
- trajectoryAkm: { correctAssetLoaded: null, feedbackRecorded: 0 },
555
- failureModes: opts.failureMode
556
- ? {
557
- byLabel: { [opts.failureMode]: 1 },
558
- byTask: { [taskId]: { [opts.failureMode]: 1 } },
559
- }
560
- : { byLabel: {}, byTask: {} },
561
- tasks: [{ id: taskId, noakm, akm, delta: { passRate: akmPassRate, tokensPerPass: null, wallclockMs: 0 } }],
562
- warnings: [],
563
- };
564
- }
565
- test("computes improvement_slope, over_synthetic_lift, degradation_count", () => {
566
- const pre = makeReport("t", 0.4);
567
- const post = makeReport("t", 0.7);
568
- const synthetic = makeReport("t", 0.2);
569
- const longi = computeLongitudinalMetrics(pre, post, synthetic);
570
- expect(longi.improvementSlope).toBeCloseTo(0.3, 2);
571
- expect(longi.overSyntheticLift).toBeCloseTo(0.5, 2);
572
- expect(longi.degradationCount).toBe(0);
573
- });
574
- test("flags degradations with > 1 seed drop", () => {
575
- const pre = makeReport("t", 0.8, { seedsPerArm: 5 });
576
- // 1/5 = 0.2 — drop of 0.4 is way above threshold.
577
- const post = makeReport("t", 0.4, { seedsPerArm: 5, failureMode: "search_no_gold" });
578
- const synthetic = makeReport("t", 0.5);
579
- const longi = computeLongitudinalMetrics(pre, post, synthetic);
580
- expect(longi.degradationCount).toBe(1);
581
- expect(longi.degradations[0].failureMode).toBe("search_no_gold");
582
- });
583
- test("does NOT flag a 0.1 drop with seedsPerArm=5 (within 1-seed threshold)", () => {
584
- const pre = makeReport("t", 0.6, { seedsPerArm: 5 });
585
- const post = makeReport("t", 0.5, { seedsPerArm: 5 });
586
- const synthetic = makeReport("t", 0.5);
587
- const longi = computeLongitudinalMetrics(pre, post, synthetic);
588
- // 1/5 = 0.2; drop of 0.1 is below threshold. No degradation.
589
- expect(longi.degradationCount).toBe(0);
590
- });
591
- });
592
- describe("computeProposalQualityMetrics", () => {
593
- test("aggregates accepted / lint_pass / total per asset", () => {
594
- const log = [
595
- { proposalId: "p1", assetRef: "skill:a", kind: "lesson", lintPass: true, decision: "accept" },
596
- { proposalId: "p2", assetRef: "skill:a", kind: "revision", lintPass: false, decision: "reject" },
597
- { proposalId: "p3", assetRef: "skill:b", kind: "lesson", lintPass: true, decision: "accept" },
598
- ];
599
- const m = computeProposalQualityMetrics(log);
600
- expect(m.totalProposals).toBe(3);
601
- expect(m.totalAccepted).toBe(2);
602
- expect(m.acceptanceRate).toBeCloseTo(2 / 3, 2);
603
- expect(m.lintPassRate).toBeCloseTo(2 / 3, 2);
604
- const a = m.rows.find((r) => r.assetRef === "skill:a");
605
- expect(a?.proposalCount).toBe(2);
606
- expect(a?.acceptedCount).toBe(1);
607
- expect(a?.lintPassCount).toBe(1);
608
- });
609
- test("zero-proposal log yields zeroes (no NaN)", () => {
610
- const m = computeProposalQualityMetrics([]);
611
- expect(m.totalProposals).toBe(0);
612
- expect(m.acceptanceRate).toBe(0);
613
- expect(m.lintPassRate).toBe(0);
614
- expect(m.rows.length).toBe(0);
615
- });
616
- });