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.
- package/dist/{src/cli.js → cli.js} +100 -16
- package/dist/{src/commands → commands}/config-cli.js +42 -0
- package/dist/{src/commands → commands}/history.js +78 -7
- package/dist/{src/commands → commands}/registry-search.js +69 -6
- package/dist/{src/commands → commands}/search.js +30 -3
- package/dist/{src/commands → commands}/show.js +29 -0
- package/dist/{src/commands → commands}/source-add.js +5 -1
- package/dist/{src/commands → commands}/source-manage.js +7 -1
- package/dist/{src/core → core}/config.js +28 -0
- package/dist/{src/indexer → indexer}/db-search.js +1 -0
- package/dist/{src/indexer → indexer}/indexer.js +16 -2
- package/dist/{src/indexer → indexer}/matchers.js +1 -1
- package/dist/{src/indexer → indexer}/search-source.js +4 -2
- package/dist/{src/integrations → integrations}/agent/profiles.js +1 -1
- package/dist/{src/integrations → integrations}/agent/spawn.js +67 -16
- package/dist/{src/integrations → integrations}/github.js +9 -3
- package/dist/{src/llm → llm}/embedders/remote.js +37 -3
- package/dist/{src/output → output}/cli-hints.js +15 -2
- package/dist/{src/output → output}/renderers.js +3 -1
- package/dist/{src/output → output}/shapes.js +8 -1
- package/dist/{src/output → output}/text.js +156 -3
- package/dist/{src/registry → registry}/build-index.js +5 -4
- package/dist/{src/registry → registry}/providers/static-index.js +3 -1
- package/dist/{src/setup → setup}/setup.js +9 -0
- package/dist/{src/wiki → wiki}/wiki.js +54 -6
- package/dist/{src/workflows → workflows}/runs.js +37 -3
- package/package.json +8 -8
- package/dist/tests/add-website-source.test.js +0 -119
- package/dist/tests/agent/agent-config-loader.test.js +0 -70
- package/dist/tests/agent/agent-config.test.js +0 -221
- package/dist/tests/agent/agent-detect.test.js +0 -100
- package/dist/tests/agent/agent-spawn.test.js +0 -234
- package/dist/tests/agent-output.test.js +0 -186
- package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
- package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
- package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
- package/dist/tests/asset-ref.test.js +0 -192
- package/dist/tests/asset-registry.test.js +0 -103
- package/dist/tests/asset-spec.test.js +0 -241
- package/dist/tests/bench/attribution.test.js +0 -995
- package/dist/tests/bench/cleanup-sigint.test.js +0 -83
- package/dist/tests/bench/cleanup.js +0 -203
- package/dist/tests/bench/cleanup.test.js +0 -166
- package/dist/tests/bench/cli.js +0 -683
- package/dist/tests/bench/cli.test.js +0 -177
- package/dist/tests/bench/compare.test.js +0 -556
- package/dist/tests/bench/corpus.js +0 -314
- package/dist/tests/bench/corpus.test.js +0 -258
- package/dist/tests/bench/driver.js +0 -346
- package/dist/tests/bench/driver.test.js +0 -443
- package/dist/tests/bench/evolve-metrics.js +0 -179
- package/dist/tests/bench/evolve-metrics.test.js +0 -187
- package/dist/tests/bench/evolve.js +0 -580
- package/dist/tests/bench/evolve.test.js +0 -616
- package/dist/tests/bench/failure-modes.test.js +0 -300
- package/dist/tests/bench/feedback-integrity.test.js +0 -456
- package/dist/tests/bench/leakage.test.js +0 -125
- package/dist/tests/bench/learning-curve.test.js +0 -133
- package/dist/tests/bench/metrics.js +0 -2319
- package/dist/tests/bench/metrics.test.js +0 -1144
- package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
- package/dist/tests/bench/report.js +0 -1821
- package/dist/tests/bench/report.test.js +0 -989
- package/dist/tests/bench/runner.js +0 -536
- package/dist/tests/bench/runner.test.js +0 -958
- package/dist/tests/bench/search-bridge.test.js +0 -331
- package/dist/tests/bench/tmp.js +0 -41
- package/dist/tests/bench/trajectory.js +0 -116
- package/dist/tests/bench/trajectory.test.js +0 -127
- package/dist/tests/bench/verifier.js +0 -109
- package/dist/tests/bench/verifier.test.js +0 -118
- package/dist/tests/bench/workflow-evaluator.js +0 -557
- package/dist/tests/bench/workflow-evaluator.test.js +0 -421
- package/dist/tests/bench/workflow-spec.js +0 -358
- package/dist/tests/bench/workflow-spec.test.js +0 -363
- package/dist/tests/bench/workflow-trace.js +0 -438
- package/dist/tests/bench/workflow-trace.test.js +0 -254
- package/dist/tests/benchmark-search-quality.js +0 -536
- package/dist/tests/benchmark-suite.js +0 -1441
- package/dist/tests/capture-cli.test.js +0 -112
- package/dist/tests/cli-errors.test.js +0 -203
- package/dist/tests/commands/events.test.js +0 -370
- package/dist/tests/commands/history.test.js +0 -223
- package/dist/tests/commands/import.test.js +0 -103
- package/dist/tests/commands/proposal-cli.test.js +0 -209
- package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
- package/dist/tests/commands/remember.test.js +0 -97
- package/dist/tests/commands/scope-flags.test.js +0 -300
- package/dist/tests/commands/search.test.js +0 -537
- package/dist/tests/commands/show-indexer-parity.test.js +0 -117
- package/dist/tests/commands/show.test.js +0 -294
- package/dist/tests/common.test.js +0 -266
- package/dist/tests/completions.test.js +0 -142
- package/dist/tests/config-cli.test.js +0 -193
- package/dist/tests/config-llm-features.test.js +0 -139
- package/dist/tests/config.test.js +0 -544
- package/dist/tests/contracts/migration-baseline.test.js +0 -43
- package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
- package/dist/tests/contracts/spec-helpers.js +0 -46
- package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
- package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
- package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
- package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
- package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
- package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
- package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
- package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
- package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
- package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
- package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
- package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
- package/dist/tests/core/write-source.test.js +0 -366
- package/dist/tests/curate-command.test.js +0 -87
- package/dist/tests/db-scoring.test.js +0 -201
- package/dist/tests/db.test.js +0 -654
- package/dist/tests/distill-cli-flag.test.js +0 -208
- package/dist/tests/distill.test.js +0 -515
- package/dist/tests/docker-install.test.js +0 -120
- package/dist/tests/e2e.test.js +0 -1398
- package/dist/tests/embedder.test.js +0 -340
- package/dist/tests/embedding-model-config.test.js +0 -379
- package/dist/tests/feedback-command.test.js +0 -172
- package/dist/tests/file-context.test.js +0 -552
- package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
- package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
- package/dist/tests/fixtures/stashes/load.js +0 -166
- package/dist/tests/fixtures/stashes/load.test.js +0 -88
- package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
- package/dist/tests/frontmatter.test.js +0 -190
- package/dist/tests/fts-field-weighting.test.js +0 -254
- package/dist/tests/fuzzy-search.test.js +0 -230
- package/dist/tests/git-provider-clone.test.js +0 -45
- package/dist/tests/github.test.js +0 -161
- package/dist/tests/graph-boost-ranking.test.js +0 -305
- package/dist/tests/graph-extraction.test.js +0 -282
- package/dist/tests/helpers/usage-events.js +0 -8
- package/dist/tests/index-pass-llm.test.js +0 -161
- package/dist/tests/indexer.test.js +0 -559
- package/dist/tests/info-command.test.js +0 -166
- package/dist/tests/init.test.js +0 -69
- package/dist/tests/install-script.test.js +0 -246
- package/dist/tests/integration/agent-real-profile.test.js +0 -94
- package/dist/tests/issue-36-repro.test.js +0 -304
- package/dist/tests/issues-191-194.test.js +0 -160
- package/dist/tests/lesson-lint.test.js +0 -111
- package/dist/tests/llm-client.test.js +0 -115
- package/dist/tests/llm-feature-gate.test.js +0 -151
- package/dist/tests/llm.test.js +0 -139
- package/dist/tests/lockfile.test.js +0 -216
- package/dist/tests/manifest.test.js +0 -205
- package/dist/tests/markdown.test.js +0 -126
- package/dist/tests/matchers-unit.test.js +0 -189
- package/dist/tests/memory-inference.test.js +0 -299
- package/dist/tests/merge-scoring.test.js +0 -136
- package/dist/tests/metadata.test.js +0 -313
- package/dist/tests/migration-help.test.js +0 -89
- package/dist/tests/origin-resolve.test.js +0 -124
- package/dist/tests/output-baseline.test.js +0 -217
- package/dist/tests/output-shapes-unit.test.js +0 -476
- package/dist/tests/parallel-search.test.js +0 -272
- package/dist/tests/parameter-metadata.test.js +0 -365
- package/dist/tests/paths.test.js +0 -177
- package/dist/tests/progressive-disclosure.test.js +0 -280
- package/dist/tests/proposals.test.js +0 -279
- package/dist/tests/proposed-quality.test.js +0 -271
- package/dist/tests/provider-registry.test.js +0 -32
- package/dist/tests/ranking-regression.test.js +0 -548
- package/dist/tests/reflect-propose.test.js +0 -455
- package/dist/tests/registry-build-index.test.js +0 -378
- package/dist/tests/registry-cli.test.js +0 -290
- package/dist/tests/registry-index-v2.test.js +0 -430
- package/dist/tests/registry-install.test.js +0 -728
- package/dist/tests/registry-providers/parity.test.js +0 -189
- package/dist/tests/registry-providers/skills-sh.test.js +0 -309
- package/dist/tests/registry-providers/static-index.test.js +0 -204
- package/dist/tests/registry-resolve.test.js +0 -126
- package/dist/tests/registry-search.test.js +0 -723
- package/dist/tests/remember-frontmatter.test.js +0 -380
- package/dist/tests/remember-unit.test.js +0 -123
- package/dist/tests/ripgrep-install.test.js +0 -251
- package/dist/tests/ripgrep-resolve.test.js +0 -108
- package/dist/tests/ripgrep.test.js +0 -163
- package/dist/tests/save-command.test.js +0 -94
- package/dist/tests/save-trust-qa-fixes.test.js +0 -270
- package/dist/tests/scoring-pipeline.test.js +0 -648
- package/dist/tests/search-include-proposed-cli.test.js +0 -118
- package/dist/tests/self-update.test.js +0 -442
- package/dist/tests/semantic-search-e2e.test.js +0 -512
- package/dist/tests/semantic-status.test.js +0 -471
- package/dist/tests/setup-run.integration.js +0 -877
- package/dist/tests/setup-wizard.test.js +0 -198
- package/dist/tests/setup.test.js +0 -131
- package/dist/tests/source-add.test.js +0 -11
- package/dist/tests/source-clone.test.js +0 -254
- package/dist/tests/source-manage.test.js +0 -366
- package/dist/tests/source-providers/filesystem.test.js +0 -82
- package/dist/tests/source-providers/git.test.js +0 -252
- package/dist/tests/source-providers/website.test.js +0 -128
- package/dist/tests/source-qa-fixes.test.js +0 -268
- package/dist/tests/source-registry.test.js +0 -350
- package/dist/tests/source-resolve.test.js +0 -100
- package/dist/tests/source-source.test.js +0 -221
- package/dist/tests/source.test.js +0 -533
- package/dist/tests/tar-utils-scan.test.js +0 -73
- package/dist/tests/toggle-components.test.js +0 -73
- package/dist/tests/usage-telemetry.test.js +0 -265
- package/dist/tests/utility-scoring.test.js +0 -558
- package/dist/tests/vault-load-error.test.js +0 -78
- package/dist/tests/vault-qa-fixes.test.js +0 -194
- package/dist/tests/vault.test.js +0 -429
- package/dist/tests/vector-search.test.js +0 -608
- package/dist/tests/walker.test.js +0 -252
- package/dist/tests/wave2-cluster-bc.test.js +0 -228
- package/dist/tests/wave2-cluster-d.test.js +0 -180
- package/dist/tests/wave2-cluster-e.test.js +0 -179
- package/dist/tests/wiki-qa-fixes.test.js +0 -270
- package/dist/tests/wiki.test.js +0 -529
- package/dist/tests/workflow-cli.test.js +0 -271
- package/dist/tests/workflow-markdown.test.js +0 -171
- package/dist/tests/workflow-path-escape.test.js +0 -132
- package/dist/tests/workflow-qa-fixes.test.js +0 -377
- package/dist/tests/workflows/indexer-rejection.test.js +0 -213
- /package/dist/{src/commands → commands}/completions.js +0 -0
- /package/dist/{src/commands → commands}/curate.js +0 -0
- /package/dist/{src/commands → commands}/distill.js +0 -0
- /package/dist/{src/commands → commands}/events.js +0 -0
- /package/dist/{src/commands → commands}/info.js +0 -0
- /package/dist/{src/commands → commands}/init.js +0 -0
- /package/dist/{src/commands → commands}/install-audit.js +0 -0
- /package/dist/{src/commands → commands}/installed-stashes.js +0 -0
- /package/dist/{src/commands → commands}/migration-help.js +0 -0
- /package/dist/{src/commands → commands}/proposal.js +0 -0
- /package/dist/{src/commands → commands}/propose.js +0 -0
- /package/dist/{src/commands → commands}/reflect.js +0 -0
- /package/dist/{src/commands → commands}/remember.js +0 -0
- /package/dist/{src/commands → commands}/self-update.js +0 -0
- /package/dist/{src/commands → commands}/source-clone.js +0 -0
- /package/dist/{src/commands → commands}/vault.js +0 -0
- /package/dist/{src/core → core}/asset-ref.js +0 -0
- /package/dist/{src/core → core}/asset-registry.js +0 -0
- /package/dist/{src/core → core}/asset-spec.js +0 -0
- /package/dist/{src/core → core}/common.js +0 -0
- /package/dist/{src/core → core}/errors.js +0 -0
- /package/dist/{src/core → core}/events.js +0 -0
- /package/dist/{src/core → core}/frontmatter.js +0 -0
- /package/dist/{src/core → core}/lesson-lint.js +0 -0
- /package/dist/{src/core → core}/markdown.js +0 -0
- /package/dist/{src/core → core}/paths.js +0 -0
- /package/dist/{src/core → core}/proposals.js +0 -0
- /package/dist/{src/core → core}/warn.js +0 -0
- /package/dist/{src/core → core}/write-source.js +0 -0
- /package/dist/{src/indexer → indexer}/db.js +0 -0
- /package/dist/{src/indexer → indexer}/file-context.js +0 -0
- /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
- /package/dist/{src/indexer → indexer}/graph-extraction.js +0 -0
- /package/dist/{src/indexer → indexer}/manifest.js +0 -0
- /package/dist/{src/indexer → indexer}/memory-inference.js +0 -0
- /package/dist/{src/indexer → indexer}/metadata.js +0 -0
- /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
- /package/dist/{src/indexer → indexer}/semantic-status.js +0 -0
- /package/dist/{src/indexer → indexer}/usage-events.js +0 -0
- /package/dist/{src/indexer → indexer}/walker.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/config.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/detect.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/index.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
- /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
- /package/dist/{src/llm → llm}/client.js +0 -0
- /package/dist/{src/llm → llm}/embedder.js +0 -0
- /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
- /package/dist/{src/llm → llm}/embedders/local.js +0 -0
- /package/dist/{src/llm → llm}/embedders/types.js +0 -0
- /package/dist/{src/llm → llm}/feature-gate.js +0 -0
- /package/dist/{src/llm → llm}/graph-extract.js +0 -0
- /package/dist/{src/llm → llm}/index-passes.js +0 -0
- /package/dist/{src/llm → llm}/memory-infer.js +0 -0
- /package/dist/{src/llm → llm}/metadata-enhance.js +0 -0
- /package/dist/{src/output → output}/context.js +0 -0
- /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
- /package/dist/{src/registry → registry}/factory.js +0 -0
- /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
- /package/dist/{src/registry → registry}/providers/index.js +0 -0
- /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
- /package/dist/{src/registry → registry}/providers/types.js +0 -0
- /package/dist/{src/registry → registry}/resolve.js +0 -0
- /package/dist/{src/registry → registry}/types.js +0 -0
- /package/dist/{src/setup → setup}/detect.js +0 -0
- /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
- /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
- /package/dist/{src/setup → setup}/steps.js +0 -0
- /package/dist/{src/sources → sources}/include.js +0 -0
- /package/dist/{src/sources → sources}/provider-factory.js +0 -0
- /package/dist/{src/sources → sources}/provider.js +0 -0
- /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
- /package/dist/{src/sources → sources}/providers/git.js +0 -0
- /package/dist/{src/sources → sources}/providers/index.js +0 -0
- /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
- /package/dist/{src/sources → sources}/providers/npm.js +0 -0
- /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
- /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
- /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
- /package/dist/{src/sources → sources}/providers/website.js +0 -0
- /package/dist/{src/sources → sources}/resolve.js +0 -0
- /package/dist/{src/sources → sources}/types.js +0 -0
- /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
- /package/dist/{src/version.js → version.js} +0 -0
- /package/dist/{src/workflows → workflows}/authoring.js +0 -0
- /package/dist/{src/workflows → workflows}/cli.js +0 -0
- /package/dist/{src/workflows → workflows}/db.js +0 -0
- /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
- /package/dist/{src/workflows → workflows}/parser.js +0 -0
- /package/dist/{src/workflows → workflows}/renderer.js +0 -0
- /package/dist/{src/workflows → workflows}/schema.js +0 -0
- /package/dist/{src/workflows → workflows}/validator.js +0 -0
|
@@ -1,995 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for per-asset attribution (spec §6.5).
|
|
3
|
-
*
|
|
4
|
-
* Coverage:
|
|
5
|
-
* • `extractAssetLoads` — parses both events.jsonl event objects and
|
|
6
|
-
* verifierStdout substrings (literal `akm show` and tool-call JSON).
|
|
7
|
-
* • `computePerAssetAttribution` — counts pass/fail loads, computes pass
|
|
8
|
-
* rate, sorts by load count then pass rate then ref.
|
|
9
|
-
* • `runMaskedCorpus` — picks top-N, masks each asset from the source
|
|
10
|
-
* fixture, computes marginal contribution. Cost accounting verified
|
|
11
|
-
* against the injected runUtility callable. Source fixture is untouched.
|
|
12
|
-
* • CLI `attribute --top` clamping when top exceeds asset count.
|
|
13
|
-
*/
|
|
14
|
-
import { describe, expect, test } from "bun:test";
|
|
15
|
-
import fs from "node:fs";
|
|
16
|
-
import path from "node:path";
|
|
17
|
-
import { runAttributeCli } from "./cli";
|
|
18
|
-
import { computePerAssetAttribution, extractAssetLoads, runMaskedCorpus, } from "./metrics";
|
|
19
|
-
import { renderAttributionTable } from "./report";
|
|
20
|
-
import { benchMkdtemp, benchTmpRoot } from "./tmp";
|
|
21
|
-
function makeRun(overrides = {}) {
|
|
22
|
-
return {
|
|
23
|
-
schemaVersion: 1,
|
|
24
|
-
taskId: "t",
|
|
25
|
-
arm: "akm",
|
|
26
|
-
seed: 0,
|
|
27
|
-
model: "m",
|
|
28
|
-
outcome: "pass",
|
|
29
|
-
tokens: { input: 0, output: 0 },
|
|
30
|
-
wallclockMs: 0,
|
|
31
|
-
trajectory: { correctAssetLoaded: null, feedbackRecorded: null },
|
|
32
|
-
events: [],
|
|
33
|
-
verifierStdout: "",
|
|
34
|
-
verifierExitCode: 0,
|
|
35
|
-
assetsLoaded: [],
|
|
36
|
-
...overrides,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function makeReport(akmRuns) {
|
|
40
|
-
return {
|
|
41
|
-
timestamp: "2026-04-27T00:00:00Z",
|
|
42
|
-
branch: "test",
|
|
43
|
-
commit: "abc",
|
|
44
|
-
model: "m",
|
|
45
|
-
corpus: { domains: 1, tasks: 1, slice: "all", seedsPerArm: akmRuns.length },
|
|
46
|
-
aggregateNoakm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
47
|
-
aggregateAkm: {
|
|
48
|
-
passRate: akmRuns.filter((r) => r.outcome === "pass").length / Math.max(1, akmRuns.length),
|
|
49
|
-
tokensPerPass: null,
|
|
50
|
-
wallclockMs: 0,
|
|
51
|
-
},
|
|
52
|
-
aggregateDelta: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
53
|
-
trajectoryAkm: { correctAssetLoaded: null, feedbackRecorded: 0 },
|
|
54
|
-
failureModes: { byLabel: {}, byTask: {} },
|
|
55
|
-
tasks: [],
|
|
56
|
-
warnings: [],
|
|
57
|
-
akmRuns,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
describe("extractAssetLoads", () => {
|
|
61
|
-
test("parses literal `akm show <ref>` from verifierStdout", () => {
|
|
62
|
-
const r = makeRun({ verifierStdout: "tool: akm show skill:docker-homelab\nresult: ok\n" });
|
|
63
|
-
expect(extractAssetLoads(r)).toEqual(["skill:docker-homelab"]);
|
|
64
|
-
});
|
|
65
|
-
test('parses tool-call JSON form `args:["show","<ref>"]`', () => {
|
|
66
|
-
const r = makeRun({
|
|
67
|
-
verifierStdout: '{"command":"akm","args":["show","skill:az-cli"]} done',
|
|
68
|
-
});
|
|
69
|
-
expect(extractAssetLoads(r)).toEqual(["skill:az-cli"]);
|
|
70
|
-
});
|
|
71
|
-
test("dedupes refs and preserves first-seen order", () => {
|
|
72
|
-
const r = makeRun({
|
|
73
|
-
verifierStdout: "akm show skill:foo\nakm show skill:bar\nakm show skill:foo\n",
|
|
74
|
-
});
|
|
75
|
-
expect(extractAssetLoads(r)).toEqual(["skill:foo", "skill:bar"]);
|
|
76
|
-
});
|
|
77
|
-
test("parses ref from events.jsonl `show` event", () => {
|
|
78
|
-
const r = makeRun({
|
|
79
|
-
events: [
|
|
80
|
-
{
|
|
81
|
-
schemaVersion: 1,
|
|
82
|
-
id: 0,
|
|
83
|
-
ts: "2026-04-27T00:00:00Z",
|
|
84
|
-
eventType: "show",
|
|
85
|
-
ref: "skill:from-event",
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
});
|
|
89
|
-
expect(extractAssetLoads(r)).toEqual(["skill:from-event"]);
|
|
90
|
-
});
|
|
91
|
-
test("merges events + stdout sources, dedupes across sources", () => {
|
|
92
|
-
const r = makeRun({
|
|
93
|
-
events: [
|
|
94
|
-
{
|
|
95
|
-
schemaVersion: 1,
|
|
96
|
-
id: 0,
|
|
97
|
-
ts: "2026-04-27T00:00:00Z",
|
|
98
|
-
eventType: "show",
|
|
99
|
-
ref: "skill:shared",
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
verifierStdout: "akm show skill:shared\nakm show skill:only-stdout\n",
|
|
103
|
-
});
|
|
104
|
-
expect(extractAssetLoads(r)).toEqual(["skill:shared", "skill:only-stdout"]);
|
|
105
|
-
});
|
|
106
|
-
test("returns empty array when no `akm show` invocations are present", () => {
|
|
107
|
-
const r = makeRun({ verifierStdout: "agent: I will not search\n" });
|
|
108
|
-
expect(extractAssetLoads(r)).toEqual([]);
|
|
109
|
-
});
|
|
110
|
-
test("supports origin-prefixed refs (`team//skill:foo`)", () => {
|
|
111
|
-
const r = makeRun({ verifierStdout: "akm show team//skill:foo\n" });
|
|
112
|
-
expect(extractAssetLoads(r)).toEqual(["team//skill:foo"]);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe("computePerAssetAttribution", () => {
|
|
116
|
-
test("counts pass/fail loads and computes pass rate", () => {
|
|
117
|
-
const runs = [
|
|
118
|
-
// skill:a: 2 pass, 1 fail → 0.667
|
|
119
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:a"] }),
|
|
120
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:a"] }),
|
|
121
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:a"] }),
|
|
122
|
-
// skill:b: 0 pass, 2 fail → 0
|
|
123
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:b"] }),
|
|
124
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:b"] }),
|
|
125
|
-
// skill:c: 1 pass, 0 fail → 1.0
|
|
126
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:c"] }),
|
|
127
|
-
];
|
|
128
|
-
const attr = computePerAssetAttribution(makeReport(runs));
|
|
129
|
-
expect(attr.totalAkmRuns).toBe(6);
|
|
130
|
-
const a = attr.rows.find((r) => r.assetRef === "skill:a");
|
|
131
|
-
expect(a).toMatchObject({ loadCount: 3, loadCountPassing: 2, loadCountFailing: 1 });
|
|
132
|
-
expect(a?.loadPassRate).toBeCloseTo(2 / 3, 5);
|
|
133
|
-
const b = attr.rows.find((r) => r.assetRef === "skill:b");
|
|
134
|
-
expect(b?.loadPassRate).toBe(0);
|
|
135
|
-
const c = attr.rows.find((r) => r.assetRef === "skill:c");
|
|
136
|
-
expect(c?.loadPassRate).toBe(1);
|
|
137
|
-
});
|
|
138
|
-
test("orders rows by load count desc, pass rate desc, ref asc", () => {
|
|
139
|
-
const runs = [
|
|
140
|
-
// skill:high-load-fail — 4 loads, all fail
|
|
141
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:high-load-fail"] }),
|
|
142
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:high-load-fail"] }),
|
|
143
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:high-load-fail"] }),
|
|
144
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:high-load-fail"] }),
|
|
145
|
-
// skill:high-load-pass — 4 loads, all pass (same count, higher pass_rate → first)
|
|
146
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:high-load-pass"] }),
|
|
147
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:high-load-pass"] }),
|
|
148
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:high-load-pass"] }),
|
|
149
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:high-load-pass"] }),
|
|
150
|
-
// skill:low-load — 1 load, pass
|
|
151
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:low-load"] }),
|
|
152
|
-
];
|
|
153
|
-
const attr = computePerAssetAttribution(makeReport(runs));
|
|
154
|
-
expect(attr.rows.map((r) => r.assetRef)).toEqual([
|
|
155
|
-
"skill:high-load-pass", // count=4, rate=1
|
|
156
|
-
"skill:high-load-fail", // count=4, rate=0
|
|
157
|
-
"skill:low-load", // count=1
|
|
158
|
-
]);
|
|
159
|
-
});
|
|
160
|
-
test("returns empty rows when no assets were loaded", () => {
|
|
161
|
-
const runs = [makeRun({ outcome: "pass", assetsLoaded: [] })];
|
|
162
|
-
const attr = computePerAssetAttribution(makeReport(runs));
|
|
163
|
-
expect(attr.rows).toEqual([]);
|
|
164
|
-
expect(attr.totalAkmRuns).toBe(1);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe("renderAttributionTable", () => {
|
|
168
|
-
test("highlights well-used-and-working vs well-used-and-not-working", () => {
|
|
169
|
-
const attr = {
|
|
170
|
-
totalAkmRuns: 10,
|
|
171
|
-
rows: [
|
|
172
|
-
{ assetRef: "skill:works", loadCount: 8, loadCountPassing: 7, loadCountFailing: 1, loadPassRate: 7 / 8 },
|
|
173
|
-
{ assetRef: "skill:broken", loadCount: 6, loadCountPassing: 1, loadCountFailing: 5, loadPassRate: 1 / 6 },
|
|
174
|
-
{ assetRef: "skill:rare", loadCount: 1, loadCountPassing: 1, loadCountFailing: 0, loadPassRate: 1 },
|
|
175
|
-
],
|
|
176
|
-
};
|
|
177
|
-
const md = renderAttributionTable(attr);
|
|
178
|
-
expect(md).toContain("Well-used and working");
|
|
179
|
-
expect(md).toContain("`skill:works`");
|
|
180
|
-
expect(md).toContain("Well-used and NOT working");
|
|
181
|
-
expect(md).toContain("`skill:broken`");
|
|
182
|
-
// skill:rare is below the high-load cutoff so should NOT appear in the working callout (only in the table).
|
|
183
|
-
const workingSection = md.split("Well-used and working")[1]?.split("Well-used and NOT working")[0] ?? "";
|
|
184
|
-
expect(workingSection).not.toContain("`skill:rare`");
|
|
185
|
-
});
|
|
186
|
-
test("renders empty-state message when no rows", () => {
|
|
187
|
-
const md = renderAttributionTable({ totalAkmRuns: 0, rows: [] });
|
|
188
|
-
expect(md).toContain("No assets were loaded");
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
describe("runMaskedCorpus", () => {
|
|
192
|
-
function makeFixturesRoot() {
|
|
193
|
-
const root = benchMkdtemp("akm-bench-attr-fixtures-");
|
|
194
|
-
// fixture A: two assets in one .stash.json
|
|
195
|
-
const fixA = path.join(root, "fixtureA");
|
|
196
|
-
fs.mkdirSync(path.join(fixA, "skills"), { recursive: true });
|
|
197
|
-
fs.writeFileSync(path.join(fixA, "MANIFEST.json"), JSON.stringify({ name: "fixtureA", description: "x", purpose: "x", assets: { skill: 2 }, consumers: [] }));
|
|
198
|
-
fs.writeFileSync(path.join(fixA, "skills", ".stash.json"), JSON.stringify({
|
|
199
|
-
entries: [
|
|
200
|
-
{ name: "alpha", type: "skill", filename: "alpha.md" },
|
|
201
|
-
{ name: "beta", type: "skill", filename: "beta.md" },
|
|
202
|
-
],
|
|
203
|
-
}));
|
|
204
|
-
fs.writeFileSync(path.join(fixA, "skills", "alpha.md"), "# alpha");
|
|
205
|
-
fs.writeFileSync(path.join(fixA, "skills", "beta.md"), "# beta");
|
|
206
|
-
return root;
|
|
207
|
-
}
|
|
208
|
-
function fakeTask(overrides = {}) {
|
|
209
|
-
return {
|
|
210
|
-
id: "fake/t",
|
|
211
|
-
title: "t",
|
|
212
|
-
domain: "fake",
|
|
213
|
-
difficulty: "easy",
|
|
214
|
-
stash: "fixtureA",
|
|
215
|
-
verifier: "regex",
|
|
216
|
-
expectedMatch: "ok",
|
|
217
|
-
budget: { tokens: 100, wallMs: 1000 },
|
|
218
|
-
taskDir: "/tmp",
|
|
219
|
-
...overrides,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
test("masks top-N assets, calls runUtility once per asset, leaves source fixture intact", async () => {
|
|
223
|
-
const fixturesRoot = makeFixturesRoot();
|
|
224
|
-
const sourceContents = fs.readFileSync(path.join(fixturesRoot, "fixtureA", "skills", "alpha.md"), "utf8");
|
|
225
|
-
const baseRuns = [
|
|
226
|
-
// alpha: 3 pass, 1 fail → load_count 4
|
|
227
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
228
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
229
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
230
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:alpha"] }),
|
|
231
|
-
// beta: 1 pass, 1 fail → load_count 2
|
|
232
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:beta"] }),
|
|
233
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:beta"] }),
|
|
234
|
-
];
|
|
235
|
-
const baseReport = makeReport(baseRuns);
|
|
236
|
-
baseReport.taskMetadata = [fakeTask()];
|
|
237
|
-
let callCount = 0;
|
|
238
|
-
const seenStashDirs = [];
|
|
239
|
-
const seenStashFieldUnchanged = [];
|
|
240
|
-
const runUtility = async (options) => {
|
|
241
|
-
callCount += 1;
|
|
242
|
-
// Issue #251: masked re-runs receive the tmp dir through the explicit
|
|
243
|
-
// `stashDirOverride` field, NEVER by mutating `task.stash`. Assert
|
|
244
|
-
// both sides of the contract here.
|
|
245
|
-
const task = options.tasks[0];
|
|
246
|
-
seenStashDirs.push(task?.stashDirOverride ?? "");
|
|
247
|
-
seenStashFieldUnchanged.push(task?.stash === "fixtureA");
|
|
248
|
-
// Simulate that masking alpha drops the pass rate, masking beta does nothing.
|
|
249
|
-
const stashDir = task?.stashDirOverride ?? "";
|
|
250
|
-
const alphaMissing = !fs.existsSync(path.join(stashDir, "skills", "alpha.md"));
|
|
251
|
-
const passRate = alphaMissing ? 0.25 : 0.6;
|
|
252
|
-
return {
|
|
253
|
-
...baseReport,
|
|
254
|
-
aggregateAkm: { passRate, tokensPerPass: null, wallclockMs: 0 },
|
|
255
|
-
akmRuns: [],
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
const result = await runMaskedCorpus({
|
|
259
|
-
baseReport,
|
|
260
|
-
topN: 5, // > 2 assets, should clamp
|
|
261
|
-
runUtility,
|
|
262
|
-
baseOptions: { arms: ["noakm", "akm"], model: "m", seedsPerArm: 1 },
|
|
263
|
-
fixturesRoot,
|
|
264
|
-
});
|
|
265
|
-
// Only 2 unique assets exist in the base report → topN clamped to 2.
|
|
266
|
-
expect(result.runsPerformed).toBe(2);
|
|
267
|
-
expect(callCount).toBe(2);
|
|
268
|
-
expect(result.attributions.length).toBe(2);
|
|
269
|
-
// Asset ranking: alpha first (load_count 4), beta second.
|
|
270
|
-
const alpha = result.attributions[0];
|
|
271
|
-
expect(alpha?.assetRef).toBe("skill:alpha");
|
|
272
|
-
expect(alpha?.basePassRate).toBeCloseTo(4 / 6, 5);
|
|
273
|
-
expect(alpha?.maskedPassRate).toBe(0.25);
|
|
274
|
-
expect(alpha?.marginalContribution).toBeCloseTo(4 / 6 - 0.25, 5);
|
|
275
|
-
const beta = result.attributions[1];
|
|
276
|
-
expect(beta?.assetRef).toBe("skill:beta");
|
|
277
|
-
expect(beta?.maskedPassRate).toBe(0.6);
|
|
278
|
-
// Source fixture content untouched.
|
|
279
|
-
const sourceContentsAfter = fs.readFileSync(path.join(fixturesRoot, "fixtureA", "skills", "alpha.md"), "utf8");
|
|
280
|
-
expect(sourceContentsAfter).toBe(sourceContents);
|
|
281
|
-
// Source .stash.json still has both entries.
|
|
282
|
-
const stashJsonAfter = JSON.parse(fs.readFileSync(path.join(fixturesRoot, "fixtureA", "skills", ".stash.json"), "utf8"));
|
|
283
|
-
expect(stashJsonAfter.entries.length).toBe(2);
|
|
284
|
-
// The two stash dirs the runner saw should be different tmp dirs (not the source).
|
|
285
|
-
expect(new Set(seenStashDirs).size).toBe(2);
|
|
286
|
-
for (const d of seenStashDirs) {
|
|
287
|
-
expect(d.startsWith(benchTmpRoot())).toBe(true);
|
|
288
|
-
}
|
|
289
|
-
// Issue #251: the original `task.stash` field was NEVER mutated.
|
|
290
|
-
expect(seenStashFieldUnchanged.every(Boolean)).toBe(true);
|
|
291
|
-
// The masking strategy + masked refs are surfaced on the result envelope.
|
|
292
|
-
expect(result.maskingStrategy).toBe("leave-one-out");
|
|
293
|
-
expect(result.maskedRefs).toEqual(["skill:alpha", "skill:beta"]);
|
|
294
|
-
fs.rmSync(fixturesRoot, { recursive: true, force: true });
|
|
295
|
-
});
|
|
296
|
-
test("issue #251: regression — runner uses stashDirOverride, NOT __no-stash__ placeholder", async () => {
|
|
297
|
-
// Bug under fix: when runMaskedCorpus mutated `task.stash` and called
|
|
298
|
-
// runUtility with `materialiseStash: false`, the runner was falling back
|
|
299
|
-
// to `path.join(task.taskDir, "__no-stash__")` for the AKM-arm stashDir,
|
|
300
|
-
// because the runner only consulted `task.stash` to call
|
|
301
|
-
// `loadFixtureStash` (which it skipped) — there was no path that
|
|
302
|
-
// forwarded the masked tmp dir to the agent.
|
|
303
|
-
//
|
|
304
|
-
// This test would FAIL before #251: the masked re-run would see the
|
|
305
|
-
// `__no-stash__` placeholder, `alpha.md` would never appear missing, and
|
|
306
|
-
// the marginal contribution would be 0 (false negative).
|
|
307
|
-
const fixturesRoot = makeFixturesRoot();
|
|
308
|
-
const baseRuns = [
|
|
309
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
310
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
311
|
-
];
|
|
312
|
-
const baseReport = makeReport(baseRuns);
|
|
313
|
-
baseReport.taskMetadata = [fakeTask({ taskDir: "/some/task/dir" })];
|
|
314
|
-
let observedStashDir;
|
|
315
|
-
let observedExistedDuringRun = false;
|
|
316
|
-
let observedAlphaMissing = false;
|
|
317
|
-
let observedBetaPresent = false;
|
|
318
|
-
let observedTaskStashUnchanged = false;
|
|
319
|
-
const result = await runMaskedCorpus({
|
|
320
|
-
baseReport,
|
|
321
|
-
topN: 1,
|
|
322
|
-
runUtility: async (options) => {
|
|
323
|
-
const task = options.tasks[0];
|
|
324
|
-
observedStashDir = task?.stashDirOverride;
|
|
325
|
-
// The runner-equivalent resolution we are guarding: if the override
|
|
326
|
-
// is missing, the bug would have us fall back to `taskDir/__no-stash__`.
|
|
327
|
-
// Capture state INSIDE the runUtility callback because the tmp dir is
|
|
328
|
-
// reaped in `runMaskedCorpus`'s `finally` after this returns.
|
|
329
|
-
if (observedStashDir) {
|
|
330
|
-
observedExistedDuringRun = fs.existsSync(observedStashDir);
|
|
331
|
-
observedAlphaMissing = !fs.existsSync(path.join(observedStashDir, "skills", "alpha.md"));
|
|
332
|
-
observedBetaPresent = fs.existsSync(path.join(observedStashDir, "skills", "beta.md"));
|
|
333
|
-
}
|
|
334
|
-
observedTaskStashUnchanged = task?.stash === "fixtureA";
|
|
335
|
-
return {
|
|
336
|
-
...baseReport,
|
|
337
|
-
aggregateAkm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
338
|
-
akmRuns: [],
|
|
339
|
-
};
|
|
340
|
-
},
|
|
341
|
-
baseOptions: { arms: ["akm"], model: "m", seedsPerArm: 1 },
|
|
342
|
-
fixturesRoot,
|
|
343
|
-
});
|
|
344
|
-
expect(result.runsPerformed).toBe(1);
|
|
345
|
-
// The override MUST be set — that is the whole fix.
|
|
346
|
-
expect(observedStashDir).toBeDefined();
|
|
347
|
-
// It must NOT be the `__no-stash__` placeholder the buggy fallback used.
|
|
348
|
-
expect(observedStashDir?.endsWith("__no-stash__")).toBe(false);
|
|
349
|
-
// While the run was active, the override pointed at a real tmp dir with
|
|
350
|
-
// the masked asset removed and the unmasked asset still present.
|
|
351
|
-
expect(observedExistedDuringRun).toBe(true);
|
|
352
|
-
expect(observedAlphaMissing).toBe(true);
|
|
353
|
-
expect(observedBetaPresent).toBe(true);
|
|
354
|
-
// The stash (fixture name) field was NEVER mutated.
|
|
355
|
-
expect(observedTaskStashUnchanged).toBe(true);
|
|
356
|
-
// After the run, the tmp dir is reaped (cleanup contract).
|
|
357
|
-
expect(observedStashDir && fs.existsSync(observedStashDir)).toBe(false);
|
|
358
|
-
fs.rmSync(fixturesRoot, { recursive: true, force: true });
|
|
359
|
-
});
|
|
360
|
-
test("issue #251: source fixture sentinel survives masked-corpus run", async () => {
|
|
361
|
-
// Sentinel-file smoke test (review addendum #251): plant a known file
|
|
362
|
-
// inside the source fixture stash, run a masked-corpus pass, then assert
|
|
363
|
-
// the sentinel is byte-identical. Guards against a recurrence of #243's
|
|
364
|
-
// operator-config-exposure pattern.
|
|
365
|
-
const fixturesRoot = makeFixturesRoot();
|
|
366
|
-
const sentinelPath = path.join(fixturesRoot, "fixtureA", "skills", "__sentinel_251__");
|
|
367
|
-
const sentinelBody = `do-not-touch-${Date.now()}`;
|
|
368
|
-
fs.writeFileSync(sentinelPath, sentinelBody);
|
|
369
|
-
const baseRuns = [
|
|
370
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
371
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:beta"] }),
|
|
372
|
-
];
|
|
373
|
-
const baseReport = makeReport(baseRuns);
|
|
374
|
-
baseReport.taskMetadata = [fakeTask()];
|
|
375
|
-
await runMaskedCorpus({
|
|
376
|
-
baseReport,
|
|
377
|
-
topN: 2,
|
|
378
|
-
runUtility: async () => ({
|
|
379
|
-
...baseReport,
|
|
380
|
-
aggregateAkm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
381
|
-
akmRuns: [],
|
|
382
|
-
}),
|
|
383
|
-
baseOptions: { arms: ["akm"], model: "m", seedsPerArm: 1 },
|
|
384
|
-
fixturesRoot,
|
|
385
|
-
});
|
|
386
|
-
// Sentinel survives unchanged.
|
|
387
|
-
expect(fs.existsSync(sentinelPath)).toBe(true);
|
|
388
|
-
expect(fs.readFileSync(sentinelPath, "utf8")).toBe(sentinelBody);
|
|
389
|
-
// The masked entry's source-fixture content is untouched.
|
|
390
|
-
expect(fs.existsSync(path.join(fixturesRoot, "fixtureA", "skills", "alpha.md"))).toBe(true);
|
|
391
|
-
expect(fs.readFileSync(path.join(fixturesRoot, "fixtureA", "skills", "alpha.md"), "utf8")).toBe("# alpha");
|
|
392
|
-
fs.rmSync(fixturesRoot, { recursive: true, force: true });
|
|
393
|
-
});
|
|
394
|
-
test("issue #251: tmp masked stash dirs are cleaned up after success AND failure", async () => {
|
|
395
|
-
// Cleanup contract from acceptance criteria: try/finally guarantees the
|
|
396
|
-
// tmp dirs are reaped whether the injected runner returns normally or
|
|
397
|
-
// throws. Capture observed dirs from inside the injected runner; after
|
|
398
|
-
// the await they must NOT exist.
|
|
399
|
-
const fixturesRoot = makeFixturesRoot();
|
|
400
|
-
const baseRuns = [
|
|
401
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
402
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:beta"] }),
|
|
403
|
-
];
|
|
404
|
-
const baseReport = makeReport(baseRuns);
|
|
405
|
-
baseReport.taskMetadata = [fakeTask()];
|
|
406
|
-
// Success path.
|
|
407
|
-
const successDirs = [];
|
|
408
|
-
await runMaskedCorpus({
|
|
409
|
-
baseReport,
|
|
410
|
-
topN: 2,
|
|
411
|
-
runUtility: async (options) => {
|
|
412
|
-
const dir = options.tasks[0]?.stashDirOverride;
|
|
413
|
-
if (dir)
|
|
414
|
-
successDirs.push(dir);
|
|
415
|
-
return {
|
|
416
|
-
...baseReport,
|
|
417
|
-
aggregateAkm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
418
|
-
akmRuns: [],
|
|
419
|
-
};
|
|
420
|
-
},
|
|
421
|
-
baseOptions: { arms: ["akm"], model: "m", seedsPerArm: 1 },
|
|
422
|
-
fixturesRoot,
|
|
423
|
-
});
|
|
424
|
-
expect(successDirs.length).toBe(2);
|
|
425
|
-
for (const d of successDirs) {
|
|
426
|
-
expect(fs.existsSync(d)).toBe(false);
|
|
427
|
-
}
|
|
428
|
-
// Failure path: the injected runner throws on the second call.
|
|
429
|
-
const failureDirs = [];
|
|
430
|
-
let calls = 0;
|
|
431
|
-
await expect(runMaskedCorpus({
|
|
432
|
-
baseReport,
|
|
433
|
-
topN: 2,
|
|
434
|
-
runUtility: async (options) => {
|
|
435
|
-
calls += 1;
|
|
436
|
-
const dir = options.tasks[0]?.stashDirOverride;
|
|
437
|
-
if (dir)
|
|
438
|
-
failureDirs.push(dir);
|
|
439
|
-
if (calls === 2)
|
|
440
|
-
throw new Error("simulated runner failure");
|
|
441
|
-
return {
|
|
442
|
-
...baseReport,
|
|
443
|
-
aggregateAkm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
444
|
-
akmRuns: [],
|
|
445
|
-
};
|
|
446
|
-
},
|
|
447
|
-
baseOptions: { arms: ["akm"], model: "m", seedsPerArm: 1 },
|
|
448
|
-
fixturesRoot,
|
|
449
|
-
})).rejects.toThrow("simulated runner failure");
|
|
450
|
-
// Both tmp dirs created so far are reaped (the second call's dir is
|
|
451
|
-
// created in the try-block before the throw, and the finally-block
|
|
452
|
-
// cleans it up).
|
|
453
|
-
for (const d of failureDirs) {
|
|
454
|
-
expect(fs.existsSync(d)).toBe(false);
|
|
455
|
-
}
|
|
456
|
-
fs.rmSync(fixturesRoot, { recursive: true, force: true });
|
|
457
|
-
});
|
|
458
|
-
test("rejects path-traversal asset refs without deleting anything outside the tmp stash", async () => {
|
|
459
|
-
const fixturesRoot = makeFixturesRoot();
|
|
460
|
-
// A sentinel file outside the fixtures tree — if the masker honoured the
|
|
461
|
-
// hostile `..`-laden ref, the deletion target would be computed via
|
|
462
|
-
// `path.join(fixturesRoot/fixtureA/skills/, "..", "..", "..", "sentinel")`
|
|
463
|
-
// and the sentinel would disappear. The validation must block that.
|
|
464
|
-
const sentinelDir = benchMkdtemp("akm-bench-sentinel-");
|
|
465
|
-
const sentinelFile = path.join(sentinelDir, "sentinel.txt");
|
|
466
|
-
fs.writeFileSync(sentinelFile, "do-not-delete");
|
|
467
|
-
const baseRuns = [
|
|
468
|
-
// Hostile ref: name contains `..` segments. Constructed by hand to
|
|
469
|
-
// simulate a prompt-injected agent emitting `akm show "skill:../../../etc"`.
|
|
470
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:../../../etc"] }),
|
|
471
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:../../../etc"] }),
|
|
472
|
-
];
|
|
473
|
-
const baseReport = makeReport(baseRuns);
|
|
474
|
-
baseReport.taskMetadata = [fakeTask()];
|
|
475
|
-
let callCount = 0;
|
|
476
|
-
const result = await runMaskedCorpus({
|
|
477
|
-
baseReport,
|
|
478
|
-
topN: 1,
|
|
479
|
-
runUtility: async () => {
|
|
480
|
-
callCount += 1;
|
|
481
|
-
return {
|
|
482
|
-
...baseReport,
|
|
483
|
-
aggregateAkm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
484
|
-
};
|
|
485
|
-
},
|
|
486
|
-
baseOptions: { arms: ["akm"], model: "m", seedsPerArm: 1 },
|
|
487
|
-
fixturesRoot,
|
|
488
|
-
});
|
|
489
|
-
// The masker rejects the hostile ref → null → runMaskedCorpus falls back
|
|
490
|
-
// to the original fixture name. The runner is still called (we want the
|
|
491
|
-
// accounting to be honest), but no rmSync is performed against any path
|
|
492
|
-
// resolved from the hostile name.
|
|
493
|
-
expect(result.runsPerformed).toBe(1);
|
|
494
|
-
expect(callCount).toBe(1);
|
|
495
|
-
// Sentinel survives.
|
|
496
|
-
expect(fs.existsSync(sentinelFile)).toBe(true);
|
|
497
|
-
expect(fs.readFileSync(sentinelFile, "utf8")).toBe("do-not-delete");
|
|
498
|
-
// Source fixture files survive.
|
|
499
|
-
expect(fs.existsSync(path.join(fixturesRoot, "fixtureA", "skills", "alpha.md"))).toBe(true);
|
|
500
|
-
expect(fs.existsSync(path.join(fixturesRoot, "fixtureA", "skills", "beta.md"))).toBe(true);
|
|
501
|
-
fs.rmSync(sentinelDir, { recursive: true, force: true });
|
|
502
|
-
fs.rmSync(fixturesRoot, { recursive: true, force: true });
|
|
503
|
-
});
|
|
504
|
-
test("rejects absolute-path asset refs without escaping the tmp stash", async () => {
|
|
505
|
-
const fixturesRoot = makeFixturesRoot();
|
|
506
|
-
const sentinelDir = benchMkdtemp("akm-bench-sentinel-abs-");
|
|
507
|
-
const sentinelFile = path.join(sentinelDir, "sentinel.txt");
|
|
508
|
-
fs.writeFileSync(sentinelFile, "do-not-delete");
|
|
509
|
-
const baseRuns = [
|
|
510
|
-
// Hostile ref: name is an absolute POSIX path.
|
|
511
|
-
makeRun({ outcome: "pass", assetsLoaded: [`skill:${sentinelDir}`] }),
|
|
512
|
-
makeRun({ outcome: "pass", assetsLoaded: [`skill:${sentinelDir}`] }),
|
|
513
|
-
];
|
|
514
|
-
const baseReport = makeReport(baseRuns);
|
|
515
|
-
baseReport.taskMetadata = [fakeTask()];
|
|
516
|
-
let callCount = 0;
|
|
517
|
-
const result = await runMaskedCorpus({
|
|
518
|
-
baseReport,
|
|
519
|
-
topN: 1,
|
|
520
|
-
runUtility: async () => {
|
|
521
|
-
callCount += 1;
|
|
522
|
-
return {
|
|
523
|
-
...baseReport,
|
|
524
|
-
aggregateAkm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
525
|
-
};
|
|
526
|
-
},
|
|
527
|
-
baseOptions: { arms: ["akm"], model: "m", seedsPerArm: 1 },
|
|
528
|
-
fixturesRoot,
|
|
529
|
-
});
|
|
530
|
-
expect(result.runsPerformed).toBe(1);
|
|
531
|
-
expect(callCount).toBe(1);
|
|
532
|
-
expect(fs.existsSync(sentinelFile)).toBe(true);
|
|
533
|
-
expect(fs.readFileSync(sentinelFile, "utf8")).toBe("do-not-delete");
|
|
534
|
-
expect(fs.existsSync(sentinelDir)).toBe(true);
|
|
535
|
-
fs.rmSync(sentinelDir, { recursive: true, force: true });
|
|
536
|
-
fs.rmSync(fixturesRoot, { recursive: true, force: true });
|
|
537
|
-
});
|
|
538
|
-
test("cost accounting: runs N times when N <= asset count", async () => {
|
|
539
|
-
const fixturesRoot = makeFixturesRoot();
|
|
540
|
-
const baseRuns = [
|
|
541
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
542
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:beta"] }),
|
|
543
|
-
];
|
|
544
|
-
const baseReport = makeReport(baseRuns);
|
|
545
|
-
baseReport.taskMetadata = [fakeTask()];
|
|
546
|
-
let callCount = 0;
|
|
547
|
-
const result = await runMaskedCorpus({
|
|
548
|
-
baseReport,
|
|
549
|
-
topN: 1,
|
|
550
|
-
runUtility: async () => {
|
|
551
|
-
callCount += 1;
|
|
552
|
-
return {
|
|
553
|
-
...baseReport,
|
|
554
|
-
aggregateAkm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
555
|
-
};
|
|
556
|
-
},
|
|
557
|
-
baseOptions: { arms: ["akm"], model: "m", seedsPerArm: 1 },
|
|
558
|
-
fixturesRoot,
|
|
559
|
-
});
|
|
560
|
-
expect(result.runsPerformed).toBe(1);
|
|
561
|
-
expect(callCount).toBe(1);
|
|
562
|
-
expect(result.attributions.length).toBe(1);
|
|
563
|
-
fs.rmSync(fixturesRoot, { recursive: true, force: true });
|
|
564
|
-
});
|
|
565
|
-
});
|
|
566
|
-
describe("bench attribute --top clamping", () => {
|
|
567
|
-
test("clamps --top when fewer assets exist", async () => {
|
|
568
|
-
// Write a §13.3 envelope to disk with only 2 perAsset rows.
|
|
569
|
-
const tmp = benchMkdtemp("akm-bench-attr-cli-");
|
|
570
|
-
const fixturesRoot = path.join(tmp, "stashes");
|
|
571
|
-
fs.mkdirSync(fixturesRoot, { recursive: true });
|
|
572
|
-
// Two-asset fixture so the masked re-runs find their assets to remove.
|
|
573
|
-
const fixDir = path.join(fixturesRoot, "tiny");
|
|
574
|
-
fs.mkdirSync(path.join(fixDir, "skills"), { recursive: true });
|
|
575
|
-
fs.writeFileSync(path.join(fixDir, "MANIFEST.json"), JSON.stringify({ name: "tiny", description: "x", purpose: "x", assets: { skill: 2 }, consumers: [] }));
|
|
576
|
-
fs.writeFileSync(path.join(fixDir, "skills", ".stash.json"), JSON.stringify({
|
|
577
|
-
entries: [
|
|
578
|
-
{ name: "alpha", type: "skill", filename: "alpha.md" },
|
|
579
|
-
{ name: "beta", type: "skill", filename: "beta.md" },
|
|
580
|
-
],
|
|
581
|
-
}));
|
|
582
|
-
fs.writeFileSync(path.join(fixDir, "skills", "alpha.md"), "# alpha");
|
|
583
|
-
fs.writeFileSync(path.join(fixDir, "skills", "beta.md"), "# beta");
|
|
584
|
-
const envelope = {
|
|
585
|
-
schemaVersion: 1,
|
|
586
|
-
track: "utility",
|
|
587
|
-
branch: "test",
|
|
588
|
-
commit: "abc",
|
|
589
|
-
timestamp: "2026-04-27T00:00:00Z",
|
|
590
|
-
agent: { harness: "opencode", model: "test-model" },
|
|
591
|
-
corpus: { domains: 1, tasks: 1, slice: "all", seedsPerArm: 1 },
|
|
592
|
-
aggregate: {
|
|
593
|
-
noakm: { pass_rate: 0, tokens_per_pass: null, wallclock_ms: 0 },
|
|
594
|
-
akm: { pass_rate: 0.5, tokens_per_pass: null, wallclock_ms: 0 },
|
|
595
|
-
delta: { pass_rate: 0.5, tokens_per_pass: null, wallclock_ms: 0 },
|
|
596
|
-
},
|
|
597
|
-
trajectory: { akm: { correct_asset_loaded: null, feedback_recorded: 0 } },
|
|
598
|
-
tasks: [],
|
|
599
|
-
warnings: [],
|
|
600
|
-
perAsset: {
|
|
601
|
-
total_akm_runs: 4,
|
|
602
|
-
rows: [
|
|
603
|
-
{
|
|
604
|
-
asset_ref: "skill:alpha",
|
|
605
|
-
load_count: 2,
|
|
606
|
-
load_count_passing: 1,
|
|
607
|
-
load_count_failing: 1,
|
|
608
|
-
load_pass_rate: 0.5,
|
|
609
|
-
},
|
|
610
|
-
{ asset_ref: "skill:beta", load_count: 1, load_count_passing: 1, load_count_failing: 0, load_pass_rate: 1 },
|
|
611
|
-
],
|
|
612
|
-
},
|
|
613
|
-
};
|
|
614
|
-
const basePath = path.join(tmp, "run.json");
|
|
615
|
-
fs.writeFileSync(basePath, JSON.stringify(envelope));
|
|
616
|
-
let calls = 0;
|
|
617
|
-
const result = await runAttributeCli({
|
|
618
|
-
basePath,
|
|
619
|
-
topN: 5, // > 2 → clamp to 2
|
|
620
|
-
json: true,
|
|
621
|
-
runUtility: async () => {
|
|
622
|
-
calls += 1;
|
|
623
|
-
return {
|
|
624
|
-
timestamp: "2026-04-27T00:00:00Z",
|
|
625
|
-
branch: "test",
|
|
626
|
-
commit: "abc",
|
|
627
|
-
model: "test-model",
|
|
628
|
-
corpus: { domains: 1, tasks: 0, slice: "all", seedsPerArm: 1 },
|
|
629
|
-
aggregateNoakm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
630
|
-
aggregateAkm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
631
|
-
aggregateDelta: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
632
|
-
trajectoryAkm: { correctAssetLoaded: null, feedbackRecorded: 0 },
|
|
633
|
-
failureModes: { byLabel: {}, byTask: {} },
|
|
634
|
-
tasks: [],
|
|
635
|
-
warnings: [],
|
|
636
|
-
};
|
|
637
|
-
},
|
|
638
|
-
fixturesRoot,
|
|
639
|
-
});
|
|
640
|
-
expect(result.exitCode).toBe(0);
|
|
641
|
-
const json = JSON.parse(result.stdout);
|
|
642
|
-
expect(json.runsPerformed).toBe(2);
|
|
643
|
-
expect(json.maskingStrategy).toBe("leave-one-out");
|
|
644
|
-
expect(json.attributions.length).toBe(2);
|
|
645
|
-
expect(calls).toBe(2);
|
|
646
|
-
fs.rmSync(tmp, { recursive: true, force: true });
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
|
-
describe("runMaskedCorpus marginal_contribution arithmetic", () => {
|
|
650
|
-
// Distinct from the clamp test in `bench attribute --top clamping`, which
|
|
651
|
-
// uses passRate 0 for every masked re-run and so cannot detect a sign
|
|
652
|
-
// error in the marginal-contribution arithmetic. Here we engineer a base
|
|
653
|
-
// pass_rate of 0.8 and two distinct masked pass_rates (0.4 and 0.5) and
|
|
654
|
-
// assert the resulting marginal_contribution = base - masked, with the
|
|
655
|
-
// correct sign and magnitude per masked asset.
|
|
656
|
-
function makeMarginalFixturesRoot() {
|
|
657
|
-
const root = benchMkdtemp("akm-bench-attr-marginal-fixtures-");
|
|
658
|
-
const fixDir = path.join(root, "fixtureMarginal");
|
|
659
|
-
fs.mkdirSync(path.join(fixDir, "skills"), { recursive: true });
|
|
660
|
-
fs.writeFileSync(path.join(fixDir, "MANIFEST.json"), JSON.stringify({ name: "fixtureMarginal", description: "x", purpose: "x", assets: { skill: 2 }, consumers: [] }));
|
|
661
|
-
fs.writeFileSync(path.join(fixDir, "skills", ".stash.json"), JSON.stringify({
|
|
662
|
-
entries: [
|
|
663
|
-
{ name: "alpha", type: "skill", filename: "alpha.md" },
|
|
664
|
-
{ name: "beta", type: "skill", filename: "beta.md" },
|
|
665
|
-
],
|
|
666
|
-
}));
|
|
667
|
-
fs.writeFileSync(path.join(fixDir, "skills", "alpha.md"), "# alpha");
|
|
668
|
-
fs.writeFileSync(path.join(fixDir, "skills", "beta.md"), "# beta");
|
|
669
|
-
return root;
|
|
670
|
-
}
|
|
671
|
-
test("computes marginal_contribution = basePassRate - maskedPassRate per asset", async () => {
|
|
672
|
-
const fixturesRoot = makeMarginalFixturesRoot();
|
|
673
|
-
const baseRuns = [
|
|
674
|
-
// alpha: 4 pass, 0 fail → load_count 4
|
|
675
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
676
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
677
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
678
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha"] }),
|
|
679
|
-
// beta: 1 pass, 1 fail → load_count 2
|
|
680
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:beta"] }),
|
|
681
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:beta"] }),
|
|
682
|
-
];
|
|
683
|
-
const baseReport = {
|
|
684
|
-
timestamp: "2026-04-27T00:00:00Z",
|
|
685
|
-
branch: "test",
|
|
686
|
-
commit: "abc",
|
|
687
|
-
model: "m",
|
|
688
|
-
corpus: { domains: 1, tasks: 1, slice: "all", seedsPerArm: baseRuns.length },
|
|
689
|
-
aggregateNoakm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
690
|
-
// Engineered base pass rate distinct from the masked rates so the
|
|
691
|
-
// arithmetic is observable.
|
|
692
|
-
aggregateAkm: { passRate: 0.8, tokensPerPass: null, wallclockMs: 0 },
|
|
693
|
-
aggregateDelta: { passRate: 0.8, tokensPerPass: null, wallclockMs: 0 },
|
|
694
|
-
trajectoryAkm: { correctAssetLoaded: null, feedbackRecorded: 0 },
|
|
695
|
-
failureModes: { byLabel: {}, byTask: {} },
|
|
696
|
-
tasks: [],
|
|
697
|
-
warnings: [],
|
|
698
|
-
akmRuns: baseRuns,
|
|
699
|
-
taskMetadata: [
|
|
700
|
-
{
|
|
701
|
-
id: "fake/t",
|
|
702
|
-
title: "t",
|
|
703
|
-
domain: "fake",
|
|
704
|
-
difficulty: "easy",
|
|
705
|
-
stash: "fixtureMarginal",
|
|
706
|
-
verifier: "regex",
|
|
707
|
-
expectedMatch: "ok",
|
|
708
|
-
budget: { tokens: 100, wallMs: 1000 },
|
|
709
|
-
taskDir: "/tmp",
|
|
710
|
-
},
|
|
711
|
-
],
|
|
712
|
-
};
|
|
713
|
-
// Map masked-asset → simulated pass rate. The injected runner inspects
|
|
714
|
-
// the on-disk masked stash to detect which asset is missing.
|
|
715
|
-
const maskedPassRates = {
|
|
716
|
-
"skill:alpha": 0.4,
|
|
717
|
-
"skill:beta": 0.5,
|
|
718
|
-
};
|
|
719
|
-
const result = await runMaskedCorpus({
|
|
720
|
-
baseReport,
|
|
721
|
-
topN: 2,
|
|
722
|
-
runUtility: async (options) => {
|
|
723
|
-
// Issue #251: read the masked tmp dir from the explicit
|
|
724
|
-
// `stashDirOverride` field — the original `task.stash` (fixture
|
|
725
|
-
// name) is intentionally unchanged.
|
|
726
|
-
const stashDir = options.tasks[0]?.stashDirOverride ?? "";
|
|
727
|
-
const alphaMissing = !fs.existsSync(path.join(stashDir, "skills", "alpha.md"));
|
|
728
|
-
const betaMissing = !fs.existsSync(path.join(stashDir, "skills", "beta.md"));
|
|
729
|
-
const masked = alphaMissing ? "skill:alpha" : betaMissing ? "skill:beta" : "none";
|
|
730
|
-
const passRate = maskedPassRates[masked] ?? 0;
|
|
731
|
-
return {
|
|
732
|
-
...baseReport,
|
|
733
|
-
aggregateAkm: { passRate, tokensPerPass: null, wallclockMs: 0 },
|
|
734
|
-
akmRuns: [],
|
|
735
|
-
};
|
|
736
|
-
},
|
|
737
|
-
baseOptions: { arms: ["akm"], model: "m", seedsPerArm: 1 },
|
|
738
|
-
fixturesRoot,
|
|
739
|
-
});
|
|
740
|
-
expect(result.runsPerformed).toBe(2);
|
|
741
|
-
expect(result.attributions.length).toBe(2);
|
|
742
|
-
const alpha = result.attributions.find((a) => a.assetRef === "skill:alpha");
|
|
743
|
-
const beta = result.attributions.find((a) => a.assetRef === "skill:beta");
|
|
744
|
-
// Both rows carry the engineered base pass rate.
|
|
745
|
-
expect(alpha?.basePassRate).toBeCloseTo(0.8, 5);
|
|
746
|
-
expect(beta?.basePassRate).toBeCloseTo(0.8, 5);
|
|
747
|
-
// Masked pass rates are the runner-injected values, distinguished per
|
|
748
|
-
// asset (this is the property the vacuous 0 → 0 → 0 fixture above
|
|
749
|
-
// could not exercise).
|
|
750
|
-
expect(alpha?.maskedPassRate).toBeCloseTo(0.4, 5);
|
|
751
|
-
expect(beta?.maskedPassRate).toBeCloseTo(0.5, 5);
|
|
752
|
-
// Marginal contribution = base - masked. Positive sign means masking
|
|
753
|
-
// hurt — the asset was helping. Both must be non-zero.
|
|
754
|
-
expect(alpha?.marginalContribution).toBeCloseTo(0.4, 5);
|
|
755
|
-
expect(beta?.marginalContribution).toBeCloseTo(0.3, 5);
|
|
756
|
-
expect(alpha?.marginalContribution).not.toBe(0);
|
|
757
|
-
expect(beta?.marginalContribution).not.toBe(0);
|
|
758
|
-
fs.rmSync(fixturesRoot, { recursive: true, force: true });
|
|
759
|
-
});
|
|
760
|
-
});
|
|
761
|
-
// ── #249 round-trip: persisted runs[] → attribute → compute paths ──────────
|
|
762
|
-
describe("bench attribute prefers persisted runs[] (#249)", () => {
|
|
763
|
-
test("hydrates persisted runs[] and feeds them to runMaskedCorpus", async () => {
|
|
764
|
-
const tmp = benchMkdtemp("akm-bench-attr-runs-");
|
|
765
|
-
const fixturesRoot = path.join(tmp, "stashes");
|
|
766
|
-
fs.mkdirSync(fixturesRoot, { recursive: true });
|
|
767
|
-
const fixDir = path.join(fixturesRoot, "tiny");
|
|
768
|
-
fs.mkdirSync(path.join(fixDir, "skills"), { recursive: true });
|
|
769
|
-
fs.writeFileSync(path.join(fixDir, "MANIFEST.json"), JSON.stringify({ name: "tiny", description: "x", purpose: "x", assets: { skill: 2 }, consumers: [] }));
|
|
770
|
-
fs.writeFileSync(path.join(fixDir, "skills", ".stash.json"), JSON.stringify({
|
|
771
|
-
entries: [
|
|
772
|
-
{ name: "alpha", type: "skill", filename: "alpha.md" },
|
|
773
|
-
{ name: "beta", type: "skill", filename: "beta.md" },
|
|
774
|
-
],
|
|
775
|
-
}));
|
|
776
|
-
fs.writeFileSync(path.join(fixDir, "skills", "alpha.md"), "# alpha");
|
|
777
|
-
fs.writeFileSync(path.join(fixDir, "skills", "beta.md"), "# beta");
|
|
778
|
-
// Build a §13.3 envelope WITH a persisted runs[] array. The compact rows
|
|
779
|
-
// mirror what the runner would have emitted — both arms, multiple seeds.
|
|
780
|
-
const envelope = {
|
|
781
|
-
schemaVersion: 1,
|
|
782
|
-
track: "utility",
|
|
783
|
-
branch: "test",
|
|
784
|
-
commit: "abc",
|
|
785
|
-
timestamp: "2026-04-27T00:00:00Z",
|
|
786
|
-
agent: { harness: "opencode", model: "test-model" },
|
|
787
|
-
corpus: { domains: 1, tasks: 1, slice: "all", seedsPerArm: 2 },
|
|
788
|
-
aggregate: {
|
|
789
|
-
noakm: { pass_rate: 0, tokens_per_pass: null, wallclock_ms: 0 },
|
|
790
|
-
akm: { pass_rate: 0.5, tokens_per_pass: null, wallclock_ms: 0 },
|
|
791
|
-
delta: { pass_rate: 0.5, tokens_per_pass: null, wallclock_ms: 0 },
|
|
792
|
-
},
|
|
793
|
-
trajectory: { akm: { correct_asset_loaded: null, feedback_recorded: 0 } },
|
|
794
|
-
tasks: [],
|
|
795
|
-
warnings: [],
|
|
796
|
-
runs: [
|
|
797
|
-
// noakm — should be filtered out of attribution.
|
|
798
|
-
{
|
|
799
|
-
task_id: "t",
|
|
800
|
-
arm: "noakm",
|
|
801
|
-
seed: 0,
|
|
802
|
-
model: "test-model",
|
|
803
|
-
outcome: "fail",
|
|
804
|
-
tokens: { input: 0, output: 0 },
|
|
805
|
-
wallclock_ms: 0,
|
|
806
|
-
verifier_exit_code: 1,
|
|
807
|
-
trajectory: { correct_asset_loaded: null, feedback_recorded: null },
|
|
808
|
-
assets_loaded: [],
|
|
809
|
-
failure_mode: null,
|
|
810
|
-
},
|
|
811
|
-
// akm — alpha:1pass+1fail, beta:1pass.
|
|
812
|
-
{
|
|
813
|
-
task_id: "t",
|
|
814
|
-
arm: "akm",
|
|
815
|
-
seed: 0,
|
|
816
|
-
model: "test-model",
|
|
817
|
-
outcome: "pass",
|
|
818
|
-
tokens: { input: 1, output: 2 },
|
|
819
|
-
wallclock_ms: 100,
|
|
820
|
-
verifier_exit_code: 0,
|
|
821
|
-
trajectory: { correct_asset_loaded: true, feedback_recorded: false },
|
|
822
|
-
assets_loaded: ["skill:alpha", "skill:beta"],
|
|
823
|
-
failure_mode: null,
|
|
824
|
-
},
|
|
825
|
-
{
|
|
826
|
-
task_id: "t",
|
|
827
|
-
arm: "akm",
|
|
828
|
-
seed: 1,
|
|
829
|
-
model: "test-model",
|
|
830
|
-
outcome: "fail",
|
|
831
|
-
tokens: { input: 3, output: 4 },
|
|
832
|
-
wallclock_ms: 110,
|
|
833
|
-
verifier_exit_code: 1,
|
|
834
|
-
trajectory: { correct_asset_loaded: false, feedback_recorded: false },
|
|
835
|
-
assets_loaded: ["skill:alpha"],
|
|
836
|
-
failure_mode: "wrong_asset",
|
|
837
|
-
},
|
|
838
|
-
],
|
|
839
|
-
// perAsset is also present (older path) — but the persisted runs[]
|
|
840
|
-
// should take precedence.
|
|
841
|
-
perAsset: {
|
|
842
|
-
total_akm_runs: 2,
|
|
843
|
-
rows: [
|
|
844
|
-
{
|
|
845
|
-
asset_ref: "skill:alpha",
|
|
846
|
-
load_count: 2,
|
|
847
|
-
load_count_passing: 1,
|
|
848
|
-
load_count_failing: 1,
|
|
849
|
-
load_pass_rate: 0.5,
|
|
850
|
-
},
|
|
851
|
-
{
|
|
852
|
-
asset_ref: "skill:beta",
|
|
853
|
-
load_count: 1,
|
|
854
|
-
load_count_passing: 1,
|
|
855
|
-
load_count_failing: 0,
|
|
856
|
-
load_pass_rate: 1,
|
|
857
|
-
},
|
|
858
|
-
],
|
|
859
|
-
},
|
|
860
|
-
};
|
|
861
|
-
const basePath = path.join(tmp, "run.json");
|
|
862
|
-
fs.writeFileSync(basePath, JSON.stringify(envelope));
|
|
863
|
-
let observedAkmAssetsLoaded = [];
|
|
864
|
-
const result = await runAttributeCli({
|
|
865
|
-
basePath,
|
|
866
|
-
topN: 2,
|
|
867
|
-
json: true,
|
|
868
|
-
runUtility: async (options) => {
|
|
869
|
-
// Capture the akmRuns the masked runner sees so we can prove the
|
|
870
|
-
// hydrated runs[] flowed through unchanged.
|
|
871
|
-
observedAkmAssetsLoaded = options.tasks.map((t) => [t.id]);
|
|
872
|
-
return {
|
|
873
|
-
timestamp: "2026-04-27T00:00:00Z",
|
|
874
|
-
branch: "test",
|
|
875
|
-
commit: "abc",
|
|
876
|
-
model: "test-model",
|
|
877
|
-
corpus: { domains: 1, tasks: 1, slice: "all", seedsPerArm: 2 },
|
|
878
|
-
aggregateNoakm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
879
|
-
aggregateAkm: { passRate: 0.25, tokensPerPass: null, wallclockMs: 0 },
|
|
880
|
-
aggregateDelta: { passRate: 0.25, tokensPerPass: null, wallclockMs: 0 },
|
|
881
|
-
trajectoryAkm: { correctAssetLoaded: null, feedbackRecorded: 0 },
|
|
882
|
-
failureModes: { byLabel: {}, byTask: {} },
|
|
883
|
-
tasks: [],
|
|
884
|
-
warnings: [],
|
|
885
|
-
};
|
|
886
|
-
},
|
|
887
|
-
fixturesRoot,
|
|
888
|
-
});
|
|
889
|
-
expect(result.exitCode).toBe(0);
|
|
890
|
-
const json = JSON.parse(result.stdout);
|
|
891
|
-
// 2 attributions = 2 distinct loaded assets, both came from the persisted
|
|
892
|
-
// runs[] (alpha + beta). The noakm row is excluded.
|
|
893
|
-
expect(json.attributions.length).toBe(2);
|
|
894
|
-
expect(observedAkmAssetsLoaded.length).toBeGreaterThan(0);
|
|
895
|
-
fs.rmSync(tmp, { recursive: true, force: true });
|
|
896
|
-
});
|
|
897
|
-
test("falls back to perAsset synthesis when runs[] is absent (legacy report)", async () => {
|
|
898
|
-
const tmp = benchMkdtemp("akm-bench-attr-legacy-");
|
|
899
|
-
const fixturesRoot = path.join(tmp, "stashes");
|
|
900
|
-
fs.mkdirSync(fixturesRoot, { recursive: true });
|
|
901
|
-
const fixDir = path.join(fixturesRoot, "tiny");
|
|
902
|
-
fs.mkdirSync(path.join(fixDir, "skills"), { recursive: true });
|
|
903
|
-
fs.writeFileSync(path.join(fixDir, "MANIFEST.json"), JSON.stringify({ name: "tiny", description: "x", purpose: "x", assets: { skill: 1 }, consumers: [] }));
|
|
904
|
-
fs.writeFileSync(path.join(fixDir, "skills", ".stash.json"), JSON.stringify({ entries: [{ name: "alpha", type: "skill", filename: "alpha.md" }] }));
|
|
905
|
-
fs.writeFileSync(path.join(fixDir, "skills", "alpha.md"), "# alpha");
|
|
906
|
-
// Legacy envelope: NO runs[] key.
|
|
907
|
-
const envelope = {
|
|
908
|
-
schemaVersion: 1,
|
|
909
|
-
track: "utility",
|
|
910
|
-
branch: "test",
|
|
911
|
-
commit: "abc",
|
|
912
|
-
timestamp: "2026-04-27T00:00:00Z",
|
|
913
|
-
agent: { harness: "opencode", model: "test-model" },
|
|
914
|
-
corpus: { domains: 1, tasks: 0, slice: "all", seedsPerArm: 1 },
|
|
915
|
-
aggregate: {
|
|
916
|
-
noakm: { pass_rate: 0, tokens_per_pass: null, wallclock_ms: 0 },
|
|
917
|
-
akm: { pass_rate: 0.5, tokens_per_pass: null, wallclock_ms: 0 },
|
|
918
|
-
delta: { pass_rate: 0.5, tokens_per_pass: null, wallclock_ms: 0 },
|
|
919
|
-
},
|
|
920
|
-
trajectory: { akm: { correct_asset_loaded: null, feedback_recorded: 0 } },
|
|
921
|
-
tasks: [],
|
|
922
|
-
warnings: [],
|
|
923
|
-
perAsset: {
|
|
924
|
-
total_akm_runs: 2,
|
|
925
|
-
rows: [
|
|
926
|
-
{
|
|
927
|
-
asset_ref: "skill:alpha",
|
|
928
|
-
load_count: 2,
|
|
929
|
-
load_count_passing: 1,
|
|
930
|
-
load_count_failing: 1,
|
|
931
|
-
load_pass_rate: 0.5,
|
|
932
|
-
},
|
|
933
|
-
],
|
|
934
|
-
},
|
|
935
|
-
};
|
|
936
|
-
const basePath = path.join(tmp, "run.json");
|
|
937
|
-
fs.writeFileSync(basePath, JSON.stringify(envelope));
|
|
938
|
-
let calls = 0;
|
|
939
|
-
const result = await runAttributeCli({
|
|
940
|
-
basePath,
|
|
941
|
-
topN: 5,
|
|
942
|
-
json: true,
|
|
943
|
-
runUtility: async () => {
|
|
944
|
-
calls += 1;
|
|
945
|
-
return {
|
|
946
|
-
timestamp: "2026-04-27T00:00:00Z",
|
|
947
|
-
branch: "test",
|
|
948
|
-
commit: "abc",
|
|
949
|
-
model: "test-model",
|
|
950
|
-
corpus: { domains: 1, tasks: 0, slice: "all", seedsPerArm: 1 },
|
|
951
|
-
aggregateNoakm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
952
|
-
aggregateAkm: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
953
|
-
aggregateDelta: { passRate: 0, tokensPerPass: null, wallclockMs: 0 },
|
|
954
|
-
trajectoryAkm: { correctAssetLoaded: null, feedbackRecorded: 0 },
|
|
955
|
-
failureModes: { byLabel: {}, byTask: {} },
|
|
956
|
-
tasks: [],
|
|
957
|
-
warnings: [],
|
|
958
|
-
};
|
|
959
|
-
},
|
|
960
|
-
fixturesRoot,
|
|
961
|
-
});
|
|
962
|
-
expect(result.exitCode).toBe(0);
|
|
963
|
-
const json = JSON.parse(result.stdout);
|
|
964
|
-
// Legacy path still works: clamps to 1 attribution row from perAsset.
|
|
965
|
-
expect(json.runsPerformed).toBe(1);
|
|
966
|
-
expect(json.attributions.length).toBe(1);
|
|
967
|
-
expect(calls).toBe(1);
|
|
968
|
-
fs.rmSync(tmp, { recursive: true, force: true });
|
|
969
|
-
});
|
|
970
|
-
});
|
|
971
|
-
// ── #249 metrics-level round-trip: aggregate from runs[] + reduce parity ───
|
|
972
|
-
describe("aggregateRunsForReport + rehydrate round-trip (#249)", () => {
|
|
973
|
-
test("recomputes computePerAssetAttribution identically from persisted rows", async () => {
|
|
974
|
-
const { aggregateRunsForReport, rehydrateRunFromSerialized, computePerAssetAttribution: cpa, } = await import("./metrics");
|
|
975
|
-
const original = [
|
|
976
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:alpha", "skill:beta"] }),
|
|
977
|
-
makeRun({ outcome: "fail", assetsLoaded: ["skill:alpha"], verifierStdout: "junk" }),
|
|
978
|
-
makeRun({ outcome: "pass", assetsLoaded: ["skill:beta"] }),
|
|
979
|
-
];
|
|
980
|
-
const reportBefore = makeReport(original);
|
|
981
|
-
const before = cpa(reportBefore);
|
|
982
|
-
// Round-trip through compact persisted rows.
|
|
983
|
-
const rows = aggregateRunsForReport(original);
|
|
984
|
-
const hydrated = rows.map(rehydrateRunFromSerialized);
|
|
985
|
-
const reportAfter = makeReport(hydrated);
|
|
986
|
-
const after = cpa(reportAfter);
|
|
987
|
-
expect(after.totalAkmRuns).toBe(before.totalAkmRuns);
|
|
988
|
-
expect(after.rows.length).toBe(before.rows.length);
|
|
989
|
-
for (let i = 0; i < before.rows.length; i++) {
|
|
990
|
-
expect(after.rows[i]?.assetRef).toBe(before.rows[i]?.assetRef);
|
|
991
|
-
expect(after.rows[i]?.loadCount).toBe(before.rows[i]?.loadCount);
|
|
992
|
-
expect(after.rows[i]?.loadPassRate).toBe(before.rows[i]?.loadPassRate);
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
});
|