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