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