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,1038 +0,0 @@
1
- /**
2
- * Unit tests for the JSON + markdown report renderers.
3
- */
4
- import { describe, expect, test } from "bun:test";
5
- import fs from "node:fs";
6
- import { formatTrajBool, renderJsonReport, renderMarkdownSummary, renderUtilityReport, resolveGitBranch, resolveGitCommit, serializeRunForReport, } from "./report";
7
- import { benchMkdtemp } from "./tmp";
8
- const sample = {
9
- timestamp: "2026-04-27T12:00:00Z",
10
- branch: "feature/akm-bench",
11
- commit: "deadbeef",
12
- model: "anthropic/claude-opus-4-7",
13
- track: "utility",
14
- arms: {
15
- noakm: {
16
- passRate: 0.4,
17
- tokensPerPass: 18000,
18
- wallclockMs: 41000,
19
- budgetExceeded: 0,
20
- runsWithMeasuredTokens: 4,
21
- },
22
- akm: {
23
- passRate: 0.7,
24
- tokensPerPass: 14000,
25
- wallclockMs: 36000,
26
- budgetExceeded: 1,
27
- runsWithMeasuredTokens: 7,
28
- },
29
- },
30
- };
31
- describe("renderJsonReport", () => {
32
- test("stamps timestamp, branch, commit, and model", () => {
33
- const json = renderJsonReport(sample);
34
- const parsed = JSON.parse(json);
35
- expect(parsed.schemaVersion).toBe(1);
36
- expect(parsed.timestamp).toBe(sample.timestamp);
37
- expect(parsed.branch).toBe(sample.branch);
38
- expect(parsed.commit).toBe(sample.commit);
39
- expect(parsed.track).toBe("utility");
40
- expect(parsed.agent.harness).toBe("opencode");
41
- expect(parsed.agent.model).toBe(sample.model);
42
- });
43
- test("includes arm aggregates verbatim", () => {
44
- const json = renderJsonReport(sample);
45
- const parsed = JSON.parse(json);
46
- expect(parsed.aggregate.noakm.passRate).toBeCloseTo(0.4);
47
- expect(parsed.aggregate.akm.passRate).toBeCloseTo(0.7);
48
- });
49
- });
50
- describe("renderMarkdownSummary", () => {
51
- test("produces a roughly 5-line summary with the model + arm rows", () => {
52
- const md = renderMarkdownSummary(sample);
53
- const lines = md.split("\n");
54
- expect(lines.length).toBeGreaterThanOrEqual(4);
55
- expect(lines.length).toBeLessThanOrEqual(8);
56
- expect(md).toContain(sample.model);
57
- expect(md).toContain("noakm");
58
- expect(md).toContain("akm");
59
- expect(md).toContain("pass_rate=");
60
- });
61
- });
62
- // ── Utility-track report (§13.3) ───────────────────────────────────────────
63
- function pt(passRate, tokens, wall, count = 5) {
64
- const passes = Math.round(passRate * count);
65
- return {
66
- passRate,
67
- passAt1: passes > 0 ? 1 : 0,
68
- tokensPerPass: tokens,
69
- tokensPerRun: tokens,
70
- wallclockMs: wall,
71
- passRateStdev: 0,
72
- budgetExceededCount: 0,
73
- harnessErrorCount: 0,
74
- count,
75
- runsWithMeasuredTokens: count,
76
- };
77
- }
78
- const utilSample = {
79
- timestamp: "2026-04-27T12:00:00Z",
80
- branch: "release/0.7.0",
81
- commit: "deadbee",
82
- model: "anthropic/claude-opus-4-7",
83
- corpus: { domains: 3, tasks: 2, slice: "all", seedsPerArm: 5 },
84
- aggregateNoakm: { passRate: 0.4, tokensPerPass: 18000, tokensPerRun: null, wallclockMs: 41000 },
85
- aggregateAkm: { passRate: 0.7, tokensPerPass: 14000, tokensPerRun: null, wallclockMs: 36000 },
86
- aggregateDelta: { passRate: 0.3, tokensPerPass: -4000, tokensPerRun: null, wallclockMs: -5000 },
87
- trajectoryAkm: { correctAssetLoaded: 0.78, feedbackRecorded: 0.65 },
88
- failureModes: { byLabel: {}, byTask: {} },
89
- tasks: [
90
- {
91
- id: "domain-a/task-1",
92
- noakm: pt(0.4, 20000, 40000),
93
- akm: pt(0.8, 13000, 35000),
94
- delta: { passRate: 0.4, tokensPerPass: -7000, tokensPerRun: null, wallclockMs: -5000 },
95
- },
96
- {
97
- id: "domain-b/task-2",
98
- noakm: pt(0.4, null, 42000),
99
- akm: pt(0.6, 15000, 37000),
100
- delta: { passRate: 0.2, tokensPerPass: null, tokensPerRun: null, wallclockMs: -5000 },
101
- },
102
- ],
103
- warnings: [],
104
- };
105
- describe("renderUtilityReport JSON corpus identity (#250)", () => {
106
- test("emits selectedTaskIds, taskCorpusHash, fixtures, fixtureContentHash when present", () => {
107
- const stamped = {
108
- ...utilSample,
109
- corpus: {
110
- ...utilSample.corpus,
111
- selectedTaskIds: ["domain-a/task-1", "domain-b/task-2"],
112
- taskCorpusHash: "deadbeef".repeat(8),
113
- fixtures: { "fixture-a": "aa".repeat(32), "fixture-b": "bb".repeat(32) },
114
- fixtureContentHash: "ff".repeat(32),
115
- },
116
- };
117
- const { json } = renderUtilityReport(stamped);
118
- const corpus = json.corpus;
119
- expect(corpus.selectedTaskIds).toEqual(["domain-a/task-1", "domain-b/task-2"]);
120
- expect(corpus.taskCorpusHash).toBe("deadbeef".repeat(8));
121
- expect(corpus.fixtureContentHash).toBe("ff".repeat(32));
122
- expect(corpus.fixtures).toEqual({ "fixture-a": "aa".repeat(32), "fixture-b": "bb".repeat(32) });
123
- });
124
- test("legacy reports without identity stamps still render (#250 backward compat)", () => {
125
- const { json } = renderUtilityReport(utilSample);
126
- const corpus = json.corpus;
127
- // The four #250 keys are absent on legacy inputs and the renderer does
128
- // not synthesise placeholders.
129
- expect(corpus.taskCorpusHash).toBeUndefined();
130
- expect(corpus.fixtureContentHash).toBeUndefined();
131
- });
132
- });
133
- describe("renderUtilityReport JSON", () => {
134
- test("conforms to the §13.3 shape", () => {
135
- const { json } = renderUtilityReport(utilSample);
136
- const obj = json;
137
- expect(obj.schemaVersion).toBe(1);
138
- expect(obj.track).toBe("utility");
139
- expect(obj.branch).toBe("release/0.7.0");
140
- expect(obj.commit).toBe("deadbee");
141
- expect(obj.timestamp).toBe("2026-04-27T12:00:00Z");
142
- expect(obj.agent.harness).toBe("opencode");
143
- expect(obj.agent.model).toBe("anthropic/claude-opus-4-7");
144
- const corpus = obj.corpus;
145
- expect(corpus.domains).toBe(3);
146
- expect(corpus.tasks).toBe(2);
147
- expect(corpus.slice).toBe("all");
148
- expect(corpus.seedsPerArm).toBe(5);
149
- const aggregate = obj.aggregate;
150
- expect(aggregate.noakm.pass_rate).toBeCloseTo(0.4);
151
- expect(aggregate.akm.tokens_per_pass).toBe(14000);
152
- expect(aggregate.delta.pass_rate).toBeCloseTo(0.3);
153
- expect(aggregate.delta.wallclock_ms).toBeCloseTo(-5000);
154
- const trajectory = obj.trajectory;
155
- expect(trajectory.akm.correct_asset_loaded).toBeCloseTo(0.78);
156
- expect(trajectory.akm.feedback_recorded).toBeCloseTo(0.65);
157
- const tasks = obj.tasks;
158
- expect(tasks.length).toBe(2);
159
- expect(tasks[0]?.id).toBe("domain-a/task-1");
160
- expect((tasks[0]?.akm).pass_rate).toBeCloseTo(0.8);
161
- expect((tasks[1]?.delta).tokens_per_pass).toBeNull();
162
- expect(obj.warnings).toEqual([]);
163
- });
164
- });
165
- describe("renderUtilityReport markdown", () => {
166
- test("contains the expected sections", () => {
167
- const { markdown } = renderUtilityReport(utilSample);
168
- expect(markdown).toContain("# akm-bench utility");
169
- expect(markdown).toContain("anthropic/claude-opus-4-7");
170
- expect(markdown).toContain("release/0.7.0");
171
- expect(markdown).toContain("## Aggregate");
172
- expect(markdown).toContain("## Trajectory (akm)");
173
- expect(markdown).toContain("## Per-task pass rates");
174
- expect(markdown).toContain("domain-a/task-1");
175
- expect(markdown).toContain("domain-b/task-2");
176
- expect(markdown).toContain("correct_asset_loaded: 78.0%");
177
- expect(markdown).toContain("feedback_recorded: 65.0%");
178
- });
179
- test("delta row shows signed values", () => {
180
- const { markdown } = renderUtilityReport(utilSample);
181
- expect(markdown).toContain("**delta**");
182
- expect(markdown).toContain("+0.30");
183
- expect(markdown).toContain("-4000");
184
- expect(markdown).toContain("-5000");
185
- });
186
- test("is byte-stable across reruns with identical input", () => {
187
- const a = renderUtilityReport(utilSample).markdown;
188
- const b = renderUtilityReport(utilSample).markdown;
189
- expect(a).toBe(b);
190
- });
191
- test("renders warnings section when warnings are present", () => {
192
- const withWarn = { ...utilSample, warnings: ["stash xyz failed to load"] };
193
- const { markdown } = renderUtilityReport(withWarn);
194
- expect(markdown).toContain("## Warnings");
195
- expect(markdown).toContain("stash xyz failed to load");
196
- });
197
- });
198
- // ── Compact runs[] serialisation (#249) ───────────────────────────────────
199
- function makeRun(overrides = {}) {
200
- const base = {
201
- schemaVersion: 1,
202
- taskId: "domain-a/task-1",
203
- arm: "akm",
204
- seed: 0,
205
- model: "anthropic/claude-opus-4-7",
206
- outcome: "pass",
207
- tokens: { input: 1234, output: 5678 },
208
- wallclockMs: 4200,
209
- trajectory: { correctAssetLoaded: true, feedbackRecorded: false },
210
- events: [
211
- // events[] MUST be filtered out of the persisted row.
212
- { id: 0, ts: "2026-04-27T12:00:00Z", kind: "noop" },
213
- ],
214
- verifierStdout: "x".repeat(1024 * 1024),
215
- verifierExitCode: 0,
216
- assetsLoaded: ["skill:foo"],
217
- failureMode: null,
218
- };
219
- return { ...base, ...overrides };
220
- }
221
- describe("serializeRunForReport", () => {
222
- test("omits events[] and verifierStdout, keeps the compact field set", () => {
223
- const row = serializeRunForReport(makeRun());
224
- expect(row).toEqual({
225
- task_id: "domain-a/task-1",
226
- arm: "akm",
227
- seed: 0,
228
- model: "anthropic/claude-opus-4-7",
229
- outcome: "pass",
230
- tokens: { input: 1234, output: 5678 },
231
- wallclock_ms: 4200,
232
- verifier_exit_code: 0,
233
- trajectory: { correct_asset_loaded: true, feedback_recorded: false },
234
- assets_loaded: ["skill:foo"],
235
- failure_mode: null,
236
- });
237
- // No events / stdout leakage even when the source carries large data.
238
- expect(Object.keys(row)).not.toContain("events");
239
- expect(Object.keys(row)).not.toContain("verifierStdout");
240
- expect(Object.keys(row)).not.toContain("verifier_stdout");
241
- });
242
- test("passes unknown token-shape keys through (token-shape seam for #252)", () => {
243
- // Simulate a future RunResult.tokens that grows a `measurement` field.
244
- const futureRun = makeRun({
245
- tokens: { input: 10, output: 20, measurement: "parsed" },
246
- });
247
- const row = serializeRunForReport(futureRun);
248
- expect(row.tokens).toEqual({ input: 10, output: 20, measurement: "parsed" });
249
- });
250
- test("propagates failure_mode label when present", () => {
251
- const run = makeRun({ outcome: "fail", failureMode: "wrong_asset" });
252
- const row = serializeRunForReport(run);
253
- expect(row.outcome).toBe("fail");
254
- expect(row.failure_mode).toBe("wrong_asset");
255
- });
256
- });
257
- // ── formatTrajBool (M3) ───────────────────────────────────────────────────
258
- describe("formatTrajBool", () => {
259
- test("null → '—' (harness error, no trajectory data)", () => {
260
- expect(formatTrajBool(null)).toBe("—");
261
- });
262
- test("false → '✗' (agent ran, behaviour not observed)", () => {
263
- expect(formatTrajBool(false)).toBe("✗");
264
- });
265
- test("true → '✓' (behaviour confirmed)", () => {
266
- expect(formatTrajBool(true)).toBe("✓");
267
- });
268
- });
269
- describe("renderUtilityReport per-run trajectory table (M3)", () => {
270
- test("markdown includes per-run table when allRuns has akm runs", () => {
271
- const allRuns = [
272
- makeRun({
273
- taskId: "domain-a/task-1",
274
- arm: "akm",
275
- seed: 0,
276
- trajectory: { correctAssetLoaded: true, feedbackRecorded: false },
277
- }),
278
- makeRun({
279
- taskId: "domain-a/task-1",
280
- arm: "akm",
281
- seed: 1,
282
- trajectory: { correctAssetLoaded: null, feedbackRecorded: null },
283
- }),
284
- // noakm run should be excluded from the table
285
- makeRun({
286
- taskId: "domain-a/task-1",
287
- arm: "noakm",
288
- seed: 0,
289
- trajectory: { correctAssetLoaded: false, feedbackRecorded: false },
290
- }),
291
- ];
292
- const report = { ...utilSample, allRuns };
293
- const { markdown } = renderUtilityReport(report);
294
- expect(markdown).toContain("| task | seed | correct_asset_loaded | feedback_recorded |");
295
- expect(markdown).toContain("domain-a/task-1 | 0 | ✓ | ✗");
296
- expect(markdown).toContain("domain-a/task-1 | 1 | — | —");
297
- // noakm run must NOT appear in the akm-only trajectory table
298
- // (the table is gated on arm === "akm")
299
- });
300
- test("markdown has no per-run trajectory table when allRuns is absent", () => {
301
- const { markdown } = renderUtilityReport(utilSample);
302
- expect(markdown).not.toContain("| task | seed | correct_asset_loaded | feedback_recorded |");
303
- });
304
- });
305
- describe("renderUtilityReport runs[] persistence (#249)", () => {
306
- test("emits one row per (task, arm, seed) when allRuns is supplied", () => {
307
- const allRuns = [
308
- makeRun({ taskId: "domain-a/task-1", arm: "noakm", seed: 0 }),
309
- makeRun({ taskId: "domain-a/task-1", arm: "noakm", seed: 1 }),
310
- makeRun({ taskId: "domain-a/task-1", arm: "akm", seed: 0 }),
311
- makeRun({ taskId: "domain-a/task-1", arm: "akm", seed: 1, outcome: "fail" }),
312
- ];
313
- const report = { ...utilSample, allRuns };
314
- const { json } = renderUtilityReport(report);
315
- const obj = json;
316
- const runs = obj.runs;
317
- expect(Array.isArray(runs)).toBe(true);
318
- expect(runs.length).toBe(4);
319
- // Order matches the runner's deterministic emission order.
320
- expect(runs[0]?.arm).toBe("noakm");
321
- expect(runs[2]?.arm).toBe("akm");
322
- expect(runs[3]?.outcome).toBe("fail");
323
- // verifier stdout / events MUST be absent.
324
- for (const r of runs) {
325
- expect(Object.keys(r)).not.toContain("events");
326
- expect(Object.keys(r)).not.toContain("verifierStdout");
327
- }
328
- });
329
- test("omits the runs key entirely when allRuns is not supplied (legacy shape)", () => {
330
- const { json } = renderUtilityReport(utilSample);
331
- const obj = json;
332
- expect("runs" in obj).toBe(false);
333
- });
334
- });
335
- describe("token-measurement surface (issue #252)", () => {
336
- function fakeRun(overrides) {
337
- return {
338
- schemaVersion: 1,
339
- taskId: "t",
340
- arm: "akm",
341
- seed: 0,
342
- model: "m",
343
- outcome: "pass",
344
- tokens: { input: 0, output: 0 },
345
- tokenMeasurement: "parsed",
346
- wallclockMs: 0,
347
- trajectory: { correctAssetLoaded: null, feedbackRecorded: null },
348
- events: [],
349
- verifierStdout: "",
350
- verifierExitCode: 0,
351
- assetsLoaded: [],
352
- ...overrides,
353
- };
354
- }
355
- test("JSON envelope has token_measurement coverage block + warning when any run is missing", () => {
356
- const akmRuns = [
357
- fakeRun({ seed: 0, tokenMeasurement: "parsed", tokens: { input: 100, output: 50 } }),
358
- fakeRun({ seed: 1, tokenMeasurement: "missing" }),
359
- fakeRun({ seed: 2, tokenMeasurement: "unsupported" }),
360
- ];
361
- const sampleWithRuns = { ...utilSample, akmRuns };
362
- const { json, markdown } = renderUtilityReport(sampleWithRuns);
363
- const obj = json;
364
- const tm = obj.token_measurement;
365
- expect(tm.total_runs).toBe(3);
366
- expect(tm.runs_with_measured_tokens).toBe(1);
367
- expect(tm.runs_missing_measurement).toBe(1);
368
- expect(tm.runs_unsupported_measurement).toBe(1);
369
- expect(tm.coverage).toBeCloseTo(1 / 3);
370
- expect(tm.reliable).toBe(false);
371
- const warnings = obj.warnings;
372
- expect(warnings.length).toBe(1);
373
- expect(warnings[0]).toContain("token measurement unreliable");
374
- expect(markdown).toContain("## Token measurement (akm)");
375
- expect(markdown).toContain("unreliable");
376
- expect(markdown).toContain("## Warnings");
377
- expect(markdown).toContain("token measurement unreliable");
378
- });
379
- test("JSON envelope marks reliable=true and emits no warning when every run is parsed", () => {
380
- const akmRuns = [
381
- fakeRun({ seed: 0, tokenMeasurement: "parsed", tokens: { input: 100, output: 50 } }),
382
- fakeRun({ seed: 1, tokenMeasurement: "parsed", tokens: { input: 200, output: 75 } }),
383
- ];
384
- const sampleWithRuns = { ...utilSample, akmRuns };
385
- const { json, markdown } = renderUtilityReport(sampleWithRuns);
386
- const obj = json;
387
- const tm = obj.token_measurement;
388
- expect(tm.total_runs).toBe(2);
389
- expect(tm.runs_with_measured_tokens).toBe(2);
390
- expect(tm.coverage).toBeCloseTo(1);
391
- expect(tm.reliable).toBe(true);
392
- expect(obj.warnings).toEqual([]);
393
- expect(markdown).toContain("reliable");
394
- expect(markdown).not.toContain("token measurement unreliable");
395
- });
396
- test("coverage is null and section is skipped when no akm runs are attached", () => {
397
- const { json, markdown } = renderUtilityReport(utilSample);
398
- const obj = json;
399
- const tm = obj.token_measurement;
400
- expect(tm.total_runs).toBe(0);
401
- expect(tm.coverage).toBeNull();
402
- expect(tm.reliable).toBe(false);
403
- expect(markdown).not.toContain("## Token measurement");
404
- });
405
- });
406
- describe("renderUtilityReport negative-transfer (#260)", () => {
407
- test("JSON envelope carries zeros and empty arrays when no regressions exist", () => {
408
- const { json, markdown } = renderUtilityReport(utilSample);
409
- const obj = json;
410
- expect(obj.negative_transfer_count).toBe(0);
411
- expect(obj.negative_transfer_severity).toBe(0);
412
- expect(obj.top_regressed_tasks).toEqual([]);
413
- // Markdown stays QUIET — emits the literal "none" sentinel.
414
- expect(markdown).toContain("## Negative transfer");
415
- expect(markdown).toContain("none");
416
- expect(markdown).not.toContain("### Top regressed tasks");
417
- });
418
- test("JSON envelope groups two domains and surfaces a single regression", () => {
419
- const sample = {
420
- ...utilSample,
421
- tasks: [
422
- {
423
- id: "domain-a/task-1",
424
- noakm: pt(0.4, 20000, 40000),
425
- akm: pt(0.8, 13000, 35000),
426
- delta: { passRate: 0.4, tokensPerPass: -7000, tokensPerRun: null, wallclockMs: -5000 },
427
- },
428
- {
429
- id: "domain-b/task-2",
430
- noakm: pt(0.6, 20000, 40000),
431
- akm: pt(0.2, 25000, 38000),
432
- delta: { passRate: -0.4, tokensPerPass: 5000, tokensPerRun: null, wallclockMs: -2000 },
433
- },
434
- ],
435
- };
436
- const { json } = renderUtilityReport(sample);
437
- const obj = json;
438
- expect(obj.negative_transfer_count).toBe(1);
439
- expect(obj.negative_transfer_severity).toBeCloseTo(0.4);
440
- const top = obj.top_regressed_tasks;
441
- expect(top).toHaveLength(1);
442
- expect(top[0]?.task_id).toBe("domain-b/task-2");
443
- expect(top[0]?.domain).toBe("domain-b");
444
- expect(top[0]?.delta).toBeCloseTo(-0.4);
445
- expect(top[0]?.severity).toBeCloseTo(0.4);
446
- const domains = obj.domain_level_deltas;
447
- expect(domains).toHaveLength(2);
448
- expect(domains.map((d) => d.domain)).toEqual(["domain-a", "domain-b"]);
449
- const domB = domains.find((d) => d.domain === "domain-b");
450
- expect(domB?.regression_count).toBe(1);
451
- expect(domB?.pass_rate_delta).toBeCloseTo(-0.4);
452
- });
453
- test("markdown renders the regressed-task table and domain table when regressions exist", () => {
454
- const akmRuns = [
455
- {
456
- schemaVersion: 1,
457
- taskId: "domain-b/task-2",
458
- arm: "akm",
459
- seed: 0,
460
- model: "m",
461
- outcome: "fail",
462
- tokens: { input: 0, output: 0 },
463
- wallclockMs: 0,
464
- trajectory: { correctAssetLoaded: null, feedbackRecorded: null },
465
- events: [],
466
- verifierStdout: "",
467
- verifierExitCode: 1,
468
- assetsLoaded: ["skill:bad-guidance", "knowledge:context"],
469
- },
470
- {
471
- schemaVersion: 1,
472
- taskId: "domain-b/task-2",
473
- arm: "akm",
474
- seed: 1,
475
- model: "m",
476
- outcome: "fail",
477
- tokens: { input: 0, output: 0 },
478
- wallclockMs: 0,
479
- trajectory: { correctAssetLoaded: null, feedbackRecorded: null },
480
- events: [],
481
- verifierStdout: "",
482
- verifierExitCode: 1,
483
- assetsLoaded: ["skill:bad-guidance"],
484
- },
485
- ];
486
- const sample = {
487
- ...utilSample,
488
- tasks: [
489
- {
490
- id: "domain-a/task-1",
491
- noakm: pt(0.4, 20000, 40000),
492
- akm: pt(0.8, 13000, 35000),
493
- delta: { passRate: 0.4, tokensPerPass: -7000, tokensPerRun: null, wallclockMs: -5000 },
494
- },
495
- {
496
- id: "domain-b/task-2",
497
- noakm: pt(0.6, 20000, 40000),
498
- akm: pt(0.2, 25000, 38000),
499
- delta: { passRate: -0.4, tokensPerPass: 5000, tokensPerRun: null, wallclockMs: -2000 },
500
- },
501
- ],
502
- akmRuns,
503
- };
504
- const { json, markdown } = renderUtilityReport(sample);
505
- expect(markdown).toContain("## Negative transfer");
506
- expect(markdown).toContain("count=1");
507
- expect(markdown).toContain("### Top regressed tasks");
508
- expect(markdown).toContain("domain-b/task-2");
509
- expect(markdown).toContain("### Domain-level deltas");
510
- expect(markdown).toContain("### Asset regression candidates");
511
- expect(markdown).toContain("skill:bad-guidance");
512
- const obj = json;
513
- const candidates = obj.asset_regression_candidates;
514
- expect(candidates.length).toBeGreaterThan(0);
515
- const bad = candidates.find((c) => c.asset_ref === "skill:bad-guidance");
516
- expect(bad?.regressed_task_count).toBe(1);
517
- expect(bad?.total_load_count).toBe(2);
518
- });
519
- });
520
- describe("git resolvers", () => {
521
- test("resolveGitBranch + resolveGitCommit return non-empty strings in this repo", () => {
522
- // The bench worktree IS a git repo; these MUST succeed.
523
- const branch = resolveGitBranch();
524
- const commit = resolveGitCommit();
525
- expect(typeof branch).toBe("string");
526
- expect(branch.length).toBeGreaterThan(0);
527
- expect(typeof commit).toBe("string");
528
- expect(commit.length).toBeGreaterThan(0);
529
- });
530
- test("falls back to 'unknown' outside a git repo", () => {
531
- const tmp = benchMkdtemp("bench-nogit-");
532
- try {
533
- expect(resolveGitBranch(tmp)).toBe("unknown");
534
- expect(resolveGitCommit(tmp)).toBe("unknown");
535
- }
536
- finally {
537
- fs.rmSync(tmp, { recursive: true, force: true });
538
- }
539
- });
540
- });
541
- // ── Corpus-coverage block (#262) ───────────────────────────────────────────
542
- describe("renderUtilityReport corpus_coverage (#262)", () => {
543
- test("JSON envelope always carries a corpus_coverage block, zero-valued when no tags", () => {
544
- const { json } = renderUtilityReport(utilSample);
545
- const obj = json;
546
- const cov = obj.corpus_coverage;
547
- expect(cov).toBeDefined();
548
- const coverage = cov.coverage;
549
- expect(coverage.totalTasks).toBe(0);
550
- expect(cov.by_memory_ability).toEqual([]);
551
- expect(cov.by_task_family).toEqual([]);
552
- });
553
- test("JSON envelope groups tasks by memory_ability when taskMetadata is plumbed", () => {
554
- const sample = {
555
- ...utilSample,
556
- taskMetadata: [
557
- {
558
- id: "domain-a/task-1",
559
- title: "t1",
560
- domain: "domain-a",
561
- difficulty: "easy",
562
- stash: "minimal",
563
- verifier: "regex",
564
- budget: { tokens: 1, wallMs: 1 },
565
- taskDir: "/tmp",
566
- memoryAbility: "procedural_lookup",
567
- taskFamily: "domain-a/family-1",
568
- },
569
- {
570
- id: "domain-b/task-2",
571
- title: "t2",
572
- domain: "domain-b",
573
- difficulty: "easy",
574
- stash: "minimal",
575
- verifier: "regex",
576
- budget: { tokens: 1, wallMs: 1 },
577
- taskDir: "/tmp",
578
- memoryAbility: "procedural_lookup",
579
- taskFamily: "domain-b/family-2",
580
- },
581
- ],
582
- };
583
- const { json, markdown } = renderUtilityReport(sample);
584
- const obj = json;
585
- const cov = obj.corpus_coverage;
586
- const coverage = cov.coverage;
587
- expect(coverage.totalTasks).toBe(2);
588
- expect(coverage.memoryAbilityCounts.procedural_lookup).toBe(2);
589
- expect(coverage.memoryAbilityCounts.abstention).toBe(0);
590
- const byAbility = cov.by_memory_ability;
591
- expect(byAbility).toHaveLength(1);
592
- expect(byAbility[0]?.category).toBe("procedural_lookup");
593
- expect(byAbility[0]?.task_count).toBe(2);
594
- expect(markdown).toContain("## Corpus coverage");
595
- expect(markdown).toContain("procedural_lookup");
596
- });
597
- test("markdown corpus-coverage section is omitted when no tasks carry memory_ability", () => {
598
- const { markdown } = renderUtilityReport(utilSample);
599
- expect(markdown).not.toContain("## Corpus coverage");
600
- });
601
- });
602
- // ── Workflow compliance (#257) ─────────────────────────────────────────────
603
- describe("renderUtilityReport workflow compliance (#257)", () => {
604
- function makeCheck(overrides = {}) {
605
- const base = {
606
- schemaVersion: 1,
607
- workflowId: "wf-1",
608
- taskId: "domain-a/task-1",
609
- arm: "akm",
610
- seed: 0,
611
- status: "pass",
612
- score: 1,
613
- requiredPassed: 3,
614
- requiredTotal: 3,
615
- violations: [],
616
- evidence: {
617
- matchedEvents: 3,
618
- feedbackRecorded: true,
619
- goldAssetLoaded: true,
620
- traceTruncated: false,
621
- },
622
- };
623
- return { ...base, ...overrides };
624
- }
625
- test("emits an empty workflow object and skips the markdown section when no checks were collected", () => {
626
- const { json, markdown } = renderUtilityReport(utilSample);
627
- const obj = json;
628
- const wf = obj.workflow;
629
- expect(wf).toBeDefined();
630
- expect(wf.total_checks).toBe(0);
631
- expect(wf.applicable_checks).toBe(0);
632
- expect(wf.overall_compliance).toBe(0);
633
- expect(wf.violation_count).toBe(0);
634
- expect(wf.by_workflow).toEqual({});
635
- expect(wf.top_violations).toEqual([]);
636
- expect(wf.cross_tab).toEqual([]);
637
- expect(markdown).not.toContain("## Workflow compliance");
638
- });
639
- test("aggregates pass/partial/fail counts and surfaces top violations with evidence", () => {
640
- const checks = [
641
- makeCheck({
642
- workflowId: "wf-1",
643
- taskId: "domain-a/task-1",
644
- seed: 0,
645
- status: "pass",
646
- score: 1,
647
- }),
648
- makeCheck({
649
- workflowId: "wf-1",
650
- taskId: "domain-a/task-1",
651
- seed: 1,
652
- status: "partial",
653
- score: 0.5,
654
- requiredPassed: 1,
655
- requiredTotal: 2,
656
- violations: [
657
- { code: "missing_required_event", message: "expected akm_search", expected: "akm_search x1", observed: "0" },
658
- ],
659
- }),
660
- makeCheck({
661
- workflowId: "wf-2",
662
- taskId: "domain-b/task-2",
663
- seed: 0,
664
- status: "fail",
665
- score: 0,
666
- requiredPassed: 0,
667
- requiredTotal: 1,
668
- violations: [
669
- { code: "missing_required_event", message: "expected akm_search again", observed: "0" },
670
- { code: "wrong_feedback_polarity", message: "negative expected", expected: "negative" },
671
- ],
672
- }),
673
- ];
674
- // Tag task outcomes so the cross-tab populates pass/fail rows.
675
- checks[0].taskOutcome = "pass";
676
- checks[1].taskOutcome = "pass";
677
- checks[2].taskOutcome = "fail";
678
- const sample = { ...utilSample, workflowChecks: checks };
679
- const { json, markdown } = renderUtilityReport(sample);
680
- const obj = json;
681
- const wf = obj.workflow;
682
- expect(wf.total_checks).toBe(3);
683
- expect(wf.applicable_checks).toBe(3);
684
- expect(wf.strict_pass_rate).toBeCloseTo(1 / 3);
685
- expect(wf.partial_pass_rate).toBeCloseTo(1 / 3);
686
- expect(wf.fail_rate).toBeCloseTo(1 / 3);
687
- expect(wf.violation_count).toBe(3);
688
- // overall_compliance is mean(score): (1 + 0.5 + 0) / 3 ≈ 0.5
689
- expect(wf.overall_compliance).toBeCloseTo(0.5);
690
- const byWorkflow = wf.by_workflow;
691
- expect(byWorkflow["wf-1"]).toBeDefined();
692
- expect(byWorkflow["wf-1"].count).toBe(2);
693
- expect(byWorkflow["wf-1"].pass_rate).toBeCloseTo(0.5);
694
- expect(byWorkflow["wf-1"].partial_rate).toBeCloseTo(0.5);
695
- expect(byWorkflow["wf-2"].count).toBe(1);
696
- expect(byWorkflow["wf-2"].fail_rate).toBeCloseTo(1);
697
- const topVio = wf.top_violations;
698
- // missing_required_event appears twice → ranked first
699
- expect(topVio[0]?.code).toBe("missing_required_event");
700
- expect(topVio[0]?.count).toBe(2);
701
- const evidence = topVio[0]?.evidence;
702
- expect(evidence.length).toBeGreaterThan(0);
703
- // Evidence pointers identify (task, seed, workflow_id).
704
- expect(evidence[0]?.task_id).toBeDefined();
705
- expect(evidence[0]?.seed).toBeDefined();
706
- expect(evidence[0]?.workflow_id).toBeDefined();
707
- const crossTab = wf.cross_tab;
708
- const passRow = crossTab.find((r) => r.task_outcome === "pass");
709
- const failRow = crossTab.find((r) => r.task_outcome === "fail");
710
- expect(passRow).toBeDefined();
711
- expect(failRow).toBeDefined();
712
- // task pass run with pass + partial workflow checks → worst-status reduction = "partial"
713
- expect(passRow?.partial).toBe(1);
714
- // task fail run with fail workflow check → fail bucket
715
- expect(failRow?.fail).toBe(1);
716
- expect(markdown).toContain("## Workflow compliance");
717
- expect(markdown).toContain("overall_compliance=0.50");
718
- expect(markdown).toContain("### By workflow");
719
- expect(markdown).toContain("wf-1");
720
- expect(markdown).toContain("wf-2");
721
- expect(markdown).toContain("### Top violations");
722
- expect(markdown).toContain("missing_required_event");
723
- expect(markdown).toContain("### Violation evidence");
724
- expect(markdown).toContain("### Task outcome × workflow outcome");
725
- });
726
- test("not_applicable checks are excluded from rate denominators but show up in by_workflow.count", () => {
727
- const checks = [
728
- makeCheck({ workflowId: "wf-applies", status: "pass", score: 1 }),
729
- makeCheck({ workflowId: "wf-skips", status: "not_applicable", score: 0 }),
730
- ];
731
- const sample = { ...utilSample, workflowChecks: checks };
732
- const { json, markdown } = renderUtilityReport(sample);
733
- const obj = json;
734
- const wf = obj.workflow;
735
- expect(wf.total_checks).toBe(2);
736
- expect(wf.applicable_checks).toBe(1);
737
- expect(wf.strict_pass_rate).toBeCloseTo(1);
738
- const byWorkflow = wf.by_workflow;
739
- expect(byWorkflow["wf-skips"].count).toBe(1);
740
- expect(byWorkflow["wf-skips"].pass_rate).toBe(0);
741
- // Markdown still emits the section because at least one check is applicable.
742
- expect(markdown).toContain("## Workflow compliance");
743
- });
744
- test("when every check is not_applicable, markdown surfaces the loaded-but-no-match sentence", () => {
745
- const checks = [
746
- makeCheck({ workflowId: "wf-a", status: "not_applicable", score: 0 }),
747
- makeCheck({ workflowId: "wf-b", status: "not_applicable", score: 0 }),
748
- ];
749
- const sample = { ...utilSample, workflowChecks: checks };
750
- const { json, markdown } = renderUtilityReport(sample);
751
- const obj = json;
752
- const wf = obj.workflow;
753
- expect(wf.total_checks).toBe(2);
754
- expect(wf.applicable_checks).toBe(0);
755
- expect(markdown).toContain("## Workflow compliance");
756
- expect(markdown).toContain("No workflow specs applied");
757
- });
758
- test("harness_error checks are bucketed as fail and counted against compliance", () => {
759
- const checks = [
760
- makeCheck({ workflowId: "wf-1", status: "harness_error", score: 0 }),
761
- ];
762
- const sample = { ...utilSample, workflowChecks: checks };
763
- const { json } = renderUtilityReport(sample);
764
- const obj = json;
765
- const wf = obj.workflow;
766
- expect(wf.applicable_checks).toBe(1);
767
- expect(wf.fail_rate).toBeCloseTo(1);
768
- });
769
- test("multiple specs across multiple tasks aggregate per-spec deterministically", () => {
770
- const checks = [
771
- makeCheck({ workflowId: "wf-a", taskId: "t1", seed: 0, status: "pass", score: 1 }),
772
- makeCheck({
773
- workflowId: "wf-a",
774
- taskId: "t1",
775
- seed: 1,
776
- status: "fail",
777
- score: 0,
778
- violations: [{ code: "forbidden_event", message: "x" }],
779
- }),
780
- makeCheck({
781
- workflowId: "wf-b",
782
- taskId: "t2",
783
- seed: 0,
784
- status: "partial",
785
- score: 0.5,
786
- violations: [{ code: "wrong_order", message: "y" }],
787
- }),
788
- ];
789
- const sample = { ...utilSample, workflowChecks: checks };
790
- const { markdown } = renderUtilityReport(sample);
791
- // Specs are listed alphabetically.
792
- const aIdx = markdown.indexOf("| wf-a ");
793
- const bIdx = markdown.indexOf("| wf-b ");
794
- expect(aIdx).toBeGreaterThan(0);
795
- expect(bIdx).toBeGreaterThan(aIdx);
796
- });
797
- test("markdown is byte-stable across reruns for the workflow section", () => {
798
- const checks = [
799
- makeCheck({
800
- workflowId: "wf-1",
801
- status: "partial",
802
- score: 0.5,
803
- violations: [{ code: "missing_required_event", message: "x" }],
804
- }),
805
- ];
806
- const sample = { ...utilSample, workflowChecks: checks };
807
- const a = renderUtilityReport(sample).markdown;
808
- const b = renderUtilityReport(sample).markdown;
809
- expect(a).toBe(b);
810
- });
811
- // ── Reliability sub-block (#258) ────────────────────────────────────────
812
- test("workflow.reliability is present and zeroed when no checks were collected", () => {
813
- const { json } = renderUtilityReport(utilSample);
814
- const obj = json;
815
- const wf = obj.workflow;
816
- const reliability = wf.reliability;
817
- expect(reliability).toBeDefined();
818
- expect(reliability.by_workflow).toEqual({});
819
- const corpus = reliability.corpus;
820
- expect(corpus.pass_at_k).toBe(0);
821
- expect(corpus.pass_all_k).toBe(0);
822
- expect(corpus.groups).toBe(0);
823
- });
824
- test("workflow.reliability surfaces pass@k and pass^k per workflow + corpus", () => {
825
- // wf-flaky: t1 has 1 pass + 1 fail (anyPass=1, allPass=0)
826
- // wf-solid: t2 has 2 pass (anyPass=1, allPass=1)
827
- const checks = [
828
- makeCheck({ workflowId: "wf-flaky", taskId: "t1", seed: 0, status: "pass", score: 1 }),
829
- makeCheck({ workflowId: "wf-flaky", taskId: "t1", seed: 1, status: "fail", score: 0 }),
830
- makeCheck({ workflowId: "wf-solid", taskId: "t2", seed: 0, status: "pass", score: 1 }),
831
- makeCheck({ workflowId: "wf-solid", taskId: "t2", seed: 1, status: "pass", score: 1 }),
832
- ];
833
- const sample = { ...utilSample, workflowChecks: checks };
834
- const { json, markdown } = renderUtilityReport(sample);
835
- const obj = json;
836
- const wf = obj.workflow;
837
- const reliability = wf.reliability;
838
- const byWorkflow = reliability.by_workflow;
839
- expect(byWorkflow["wf-flaky"].pass_at_k).toBeCloseTo(1);
840
- expect(byWorkflow["wf-flaky"].pass_all_k).toBe(0);
841
- expect(byWorkflow["wf-solid"].pass_at_k).toBe(1);
842
- expect(byWorkflow["wf-solid"].pass_all_k).toBe(1);
843
- const corpus = reliability.corpus;
844
- expect(corpus.groups).toBe(2);
845
- expect(corpus.pass_at_k).toBeCloseTo(1);
846
- expect(corpus.pass_all_k).toBeCloseTo(0.5);
847
- expect(markdown).toContain("### Reliability (pass@k / pass^k)");
848
- expect(markdown).toContain("| wf-flaky |");
849
- expect(markdown).toContain("| wf-solid |");
850
- expect(markdown).toContain("Inconsistent workflows");
851
- // wf-flaky should be flagged: pass@k=1 vs pass^k=0 (gap=1).
852
- expect(markdown).toContain("`wf-flaky`");
853
- // wf-solid should NOT be in the inconsistent list.
854
- const inconsistentSection = markdown.split("Inconsistent workflows")[1] ?? "";
855
- expect(inconsistentSection).not.toContain("`wf-solid`");
856
- });
857
- test("reliability is omitted from markdown when no group is applicable", () => {
858
- const checks = [
859
- makeCheck({ workflowId: "wf-skips", status: "not_applicable", score: 0 }),
860
- ];
861
- const sample = { ...utilSample, workflowChecks: checks };
862
- const { markdown } = renderUtilityReport(sample);
863
- expect(markdown).not.toContain("### Reliability (pass@k / pass^k)");
864
- });
865
- test("reliability handles all-pass corpus without flagging inconsistency", () => {
866
- const checks = [
867
- makeCheck({ workflowId: "wf-1", taskId: "t1", seed: 0, status: "pass", score: 1 }),
868
- makeCheck({ workflowId: "wf-1", taskId: "t1", seed: 1, status: "pass", score: 1 }),
869
- ];
870
- const sample = { ...utilSample, workflowChecks: checks };
871
- const { json, markdown } = renderUtilityReport(sample);
872
- const obj = json;
873
- const wf = obj.workflow;
874
- const reliability = wf.reliability;
875
- const corpus = reliability.corpus;
876
- expect(corpus.pass_at_k).toBe(1);
877
- expect(corpus.pass_all_k).toBe(1);
878
- expect(markdown).toContain("### Reliability (pass@k / pass^k)");
879
- expect(markdown).not.toContain("Inconsistent workflows");
880
- });
881
- test("reliability handles none-pass corpus (zeroed but section still rendered)", () => {
882
- const checks = [
883
- makeCheck({ workflowId: "wf-1", taskId: "t1", seed: 0, status: "fail", score: 0 }),
884
- makeCheck({ workflowId: "wf-1", taskId: "t1", seed: 1, status: "fail", score: 0 }),
885
- ];
886
- const sample = { ...utilSample, workflowChecks: checks };
887
- const { json, markdown } = renderUtilityReport(sample);
888
- const obj = json;
889
- const wf = obj.workflow;
890
- const reliability = wf.reliability;
891
- const corpus = reliability.corpus;
892
- expect(corpus.pass_at_k).toBe(0);
893
- expect(corpus.pass_all_k).toBe(0);
894
- expect(corpus.groups).toBe(1);
895
- expect(markdown).toContain("### Reliability (pass@k / pass^k)");
896
- // pass@k=0 fails the floor → no inconsistency callout.
897
- expect(markdown).not.toContain("Inconsistent workflows");
898
- });
899
- test("reliability tolerates mixed partial/fail (partial counts as non-pass for pass^k)", () => {
900
- const checks = [
901
- makeCheck({ workflowId: "wf-1", taskId: "t1", seed: 0, status: "pass", score: 1 }),
902
- makeCheck({ workflowId: "wf-1", taskId: "t1", seed: 1, status: "partial", score: 0.5 }),
903
- makeCheck({ workflowId: "wf-1", taskId: "t1", seed: 2, status: "fail", score: 0 }),
904
- ];
905
- const sample = { ...utilSample, workflowChecks: checks };
906
- const { json } = renderUtilityReport(sample);
907
- const obj = json;
908
- const wf = obj.workflow;
909
- const reliability = wf.reliability;
910
- const byWorkflow = reliability.by_workflow;
911
- expect(byWorkflow["wf-1"].pass_at_k).toBe(1); // 1 of 1 task has any pass
912
- expect(byWorkflow["wf-1"].pass_all_k).toBe(0); // not all 3 seeds are pass
913
- expect(byWorkflow["wf-1"].k).toBe(3);
914
- });
915
- });
916
- // ── AKM overhead block (#263) ──────────────────────────────────────────────
917
- describe("akm_overhead block (#263)", () => {
918
- function fakeRun(overrides) {
919
- return {
920
- schemaVersion: 1,
921
- taskId: "t",
922
- arm: "akm",
923
- seed: 0,
924
- model: "m",
925
- outcome: "pass",
926
- tokens: { input: 0, output: 0 },
927
- tokenMeasurement: "parsed",
928
- wallclockMs: 0,
929
- trajectory: { correctAssetLoaded: null, feedbackRecorded: null },
930
- events: [],
931
- verifierStdout: "",
932
- verifierExitCode: 0,
933
- assetsLoaded: [],
934
- ...overrides,
935
- };
936
- }
937
- test("emits empty/zero envelope when no akm runs are attached", () => {
938
- const { json, markdown } = renderUtilityReport(utilSample);
939
- const obj = json;
940
- expect("akm_overhead" in obj).toBe(true);
941
- const ov = obj.akm_overhead;
942
- expect(ov.aggregate.total_runs).toBe(0);
943
- expect(ov.aggregate.tool_calls_per_success).toBeNull();
944
- expect(ov.aggregate.cost_per_success).toBeNull();
945
- expect(ov.per_run).toEqual([]);
946
- // Markdown section is gated on having akm runs to summarise.
947
- expect(markdown).not.toContain("## AKM overhead");
948
- });
949
- test("populates per-run rows + aggregate from akmRuns + taskMetadata", () => {
950
- const akmRuns = [
951
- fakeRun({
952
- taskId: "domain-a/task-1",
953
- seed: 0,
954
- outcome: "pass",
955
- tokens: { input: 100, output: 50 },
956
- events: [
957
- {
958
- schemaVersion: 1,
959
- id: 0,
960
- ts: "2026-04-27T10:00:00.000Z",
961
- eventType: "search",
962
- },
963
- {
964
- schemaVersion: 1,
965
- id: 1,
966
- ts: "2026-04-27T10:00:00.500Z",
967
- eventType: "show",
968
- ref: "skill:gold",
969
- },
970
- ],
971
- }),
972
- ];
973
- const taskMetadata = [
974
- {
975
- id: "domain-a/task-1",
976
- title: "T1",
977
- domain: "domain-a",
978
- difficulty: "easy",
979
- stash: "fixture-a",
980
- verifier: "regex",
981
- budget: { tokens: 1000, wallMs: 1000 },
982
- taskDir: "/tmp/ignored",
983
- goldRef: "skill:gold",
984
- expectedTransferFrom: [],
985
- },
986
- ];
987
- const sampleWithRuns = { ...utilSample, akmRuns, taskMetadata };
988
- const { json, markdown } = renderUtilityReport(sampleWithRuns);
989
- const obj = json;
990
- const ov = obj.akm_overhead;
991
- const perRun = ov.per_run;
992
- expect(perRun).toHaveLength(1);
993
- expect(perRun[0].search_count).toBe(1);
994
- expect(perRun[0].show_count).toBe(1);
995
- expect(perRun[0].assets_loaded_count).toBe(1);
996
- expect(perRun[0].irrelevant_assets_loaded_count).toBe(0);
997
- expect(perRun[0].time_to_first_correct_asset_ms).toBe(500);
998
- expect(perRun[0].context_bytes_loaded).toBeNull();
999
- expect(perRun[0].asset_bytes_loaded).toBeNull();
1000
- const agg = ov.aggregate;
1001
- expect(agg.total_runs).toBe(1);
1002
- expect(agg.passing_runs).toBe(1);
1003
- expect(agg.tool_calls_per_success).toBe(2);
1004
- expect(agg.cost_per_success).toBe(150);
1005
- expect(agg.mean_context_bytes_loaded).toBeNull();
1006
- expect(markdown).toContain("## AKM overhead");
1007
- expect(markdown).toContain("tool_calls_per_success");
1008
- expect(markdown).toContain("context_bytes_loaded: n/a");
1009
- });
1010
- test("excessive AKM calls produce high tool_calls_per_success in markdown", () => {
1011
- const akmRuns = [
1012
- fakeRun({
1013
- taskId: "domain-a/task-1",
1014
- outcome: "fail",
1015
- events: [
1016
- { schemaVersion: 1, id: 0, ts: "2026-04-27T10:00:00.000Z", eventType: "search" },
1017
- { schemaVersion: 1, id: 1, ts: "2026-04-27T10:00:00.001Z", eventType: "search" },
1018
- { schemaVersion: 1, id: 2, ts: "2026-04-27T10:00:00.002Z", eventType: "show", ref: "skill:wrong" },
1019
- ],
1020
- }),
1021
- fakeRun({
1022
- taskId: "domain-a/task-1",
1023
- seed: 1,
1024
- outcome: "pass",
1025
- tokens: { input: 1, output: 1 },
1026
- events: [{ schemaVersion: 1, id: 0, ts: "2026-04-27T10:00:00.000Z", eventType: "search" }],
1027
- }),
1028
- ];
1029
- const sampleWithRuns = { ...utilSample, akmRuns };
1030
- const { json } = renderUtilityReport(sampleWithRuns);
1031
- const obj = json;
1032
- const ov = obj.akm_overhead;
1033
- const agg = ov.aggregate;
1034
- expect(agg.total_tool_calls).toBe(4);
1035
- expect(agg.passing_runs).toBe(1);
1036
- expect(agg.tool_calls_per_success).toBe(4);
1037
- });
1038
- });