skillfit 0.12.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +60 -119
  2. package/README.zh-CN.md +60 -116
  3. package/dist/commands/bench-check-report.js +1 -34
  4. package/dist/commands/bench.js +6 -239
  5. package/dist/commands/eval-preflight-error.js +9 -0
  6. package/dist/commands/eval-preflight.js +4 -11
  7. package/dist/commands/eval-report.js +6 -459
  8. package/dist/commands/install.js +14 -98
  9. package/dist/harness/bench-check.js +277 -0
  10. package/dist/harness/bench-diagnostics.js +34 -0
  11. package/dist/harness/eval-acceptance.js +1 -1
  12. package/dist/harness/eval-audit.js +1 -1
  13. package/dist/harness/eval-manifest.js +456 -0
  14. package/dist/install/constants.js +1 -0
  15. package/dist/install/transaction.js +112 -0
  16. package/docs/README.md +65 -0
  17. package/docs/architecture.md +86 -0
  18. package/docs/archive-delivery.md +83 -0
  19. package/docs/archive-inventory.md +91 -0
  20. package/docs/evaluation-reports.md +1 -1
  21. package/docs/first-real-eval.md +12 -10
  22. package/docs/growth-roadmap-2026-10.md +17 -18
  23. package/docs/package-contents.md +80 -0
  24. package/docs/plans/2026-10-20-archive-replay-verification.json +125 -0
  25. package/docs/plans/2026-10-20-archive-source-verification.json +256 -0
  26. package/docs/plans/2026-10-20-delivery-verification.json +146 -0
  27. package/docs/plans/2026-10-20-docs-architecture-cleanup.md +233 -0
  28. package/docs/plans/2026-10-20-install-transactions-and-archive-delivery.md +233 -0
  29. package/docs/plans/2026-10-21-npm-0.13.0-release.md +74 -0
  30. package/docs/plans/2026-10-21-npm-0.13.1-release.md +38 -0
  31. package/docs/releases/0.12.0-attestation-check.json +22 -0
  32. package/docs/releases/0.12.0-attestations.json +155 -0
  33. package/docs/releases/0.12.0-ci-registry-install.json +90 -0
  34. package/docs/releases/0.12.0-feature-smoke.json +34 -0
  35. package/docs/releases/0.12.0-foundations-smoke.json +1576 -0
  36. package/docs/releases/0.12.0-local-registry-install.json +75 -0
  37. package/docs/releases/0.12.0-preparation-attempt-1.json +22 -0
  38. package/docs/releases/0.12.0-registry-metadata.json +96 -0
  39. package/docs/releases/0.12.0-signatures.txt +6 -0
  40. package/docs/releases/0.12.0-verification.json +99 -0
  41. package/docs/releases/0.12.0.md +14 -0
  42. package/docs/releases/0.13.0-archive-replays.json +266 -0
  43. package/docs/releases/0.13.0-archive-restoration.json +168 -0
  44. package/docs/releases/0.13.0-attestation-check.json +22 -0
  45. package/docs/releases/0.13.0-attestations.json +147 -0
  46. package/docs/releases/0.13.0-ci-registry-install.json +60 -0
  47. package/docs/releases/0.13.0-feature-smoke.json +41 -0
  48. package/docs/releases/0.13.0-feature-smoke.mjs +114 -0
  49. package/docs/releases/0.13.0-foundations-smoke.json +1576 -0
  50. package/docs/releases/0.13.0-local-registry-install.json +40 -0
  51. package/docs/releases/0.13.0-preparation.json +102 -0
  52. package/docs/releases/0.13.0-preview-review.json +16 -0
  53. package/docs/releases/0.13.0-registry-metadata.json +92 -0
  54. package/docs/releases/0.13.0-signatures.txt +12 -0
  55. package/docs/releases/0.13.0-verification.json +136 -0
  56. package/docs/releases/0.13.0.md +112 -0
  57. package/docs/releases/0.13.1-feature-smoke.mjs +116 -0
  58. package/docs/releases/0.13.1-preparation-failure-1.json +25 -0
  59. package/docs/releases/0.13.1-preparation.json +149 -0
  60. package/docs/releases/0.13.1.md +62 -0
  61. package/docs/releases/archive-delivery-smoke.mjs +37 -0
  62. package/docs/releases/release-docs-smoke.mjs +37 -0
  63. package/docs/reproducible-offline-example.md +1 -1
  64. package/evidence/README.md +24 -1
  65. package/evidence/archive-catalog.v1.json +8044 -0
  66. package/evidence/fetch-archives.mjs +211 -0
  67. package/package.json +9 -2
  68. package/skills/skillfit/SKILL.md +20 -6
  69. package/dist/cli.test.js +0 -193
  70. package/dist/commands/bench-calibration.test.js +0 -237
  71. package/dist/commands/bench-check-json.test.js +0 -242
  72. package/dist/commands/bench-manage.test.js +0 -87
  73. package/dist/commands/bench.test.js +0 -1166
  74. package/dist/commands/bundle.test.js +0 -142
  75. package/dist/commands/calibration-cli.test.js +0 -145
  76. package/dist/commands/doctor.test.js +0 -280
  77. package/dist/commands/eval-agent-preflight.test.js +0 -269
  78. package/dist/commands/eval-cli-usage.test.js +0 -75
  79. package/dist/commands/eval-export-modes.test.js +0 -350
  80. package/dist/commands/eval-export.test.js +0 -279
  81. package/dist/commands/eval-interruption.test.js +0 -263
  82. package/dist/commands/eval-preflight.test.js +0 -382
  83. package/dist/commands/eval-report.test.js +0 -367
  84. package/dist/commands/eval.test.js +0 -503
  85. package/dist/commands/evaluation-report.test.js +0 -243
  86. package/dist/commands/install.test.js +0 -555
  87. package/dist/commands/npm-first-run.test.js +0 -74
  88. package/dist/commands/replay-cancellation.test.js +0 -105
  89. package/dist/commands/report.test.js +0 -110
  90. package/dist/commands/setup.test.js +0 -150
  91. package/dist/commands/upstream.test.js +0 -139
  92. package/dist/commands/workflow-entrypoints.test.js +0 -137
  93. package/dist/docs.test.js +0 -154
  94. package/dist/frontmatter.test.js +0 -49
  95. package/dist/harness/bench.test.js +0 -109
  96. package/dist/harness/bundle.test.js +0 -71
  97. package/dist/harness/codex-usage.test.js +0 -87
  98. package/dist/harness/costs.test.js +0 -92
  99. package/dist/harness/eval-budget.test.js +0 -237
  100. package/dist/harness/eval-component.test.js +0 -770
  101. package/dist/harness/eval-efficiency.test.js +0 -56
  102. package/dist/harness/execution-timing.test.js +0 -61
  103. package/dist/harness/executors/api.test.js +0 -175
  104. package/dist/harness/executors/cli.test.js +0 -541
  105. package/dist/harness/executors/mock.test.js +0 -43
  106. package/dist/harness/experiment-session.test.js +0 -317
  107. package/dist/harness/installed-skill.test.js +0 -162
  108. package/dist/harness/interruption.test.js +0 -31
  109. package/dist/harness/judge-accounting.test.js +0 -216
  110. package/dist/harness/judge.test.js +0 -181
  111. package/dist/harness/kimi-usage.test.js +0 -62
  112. package/dist/harness/native-diff.test.js +0 -53
  113. package/dist/harness/oss-lru-cache.test.js +0 -79
  114. package/dist/harness/oss-normalize-url.test.js +0 -64
  115. package/dist/harness/oss-regression-witness.test.js +0 -89
  116. package/dist/harness/oss-skill-followup.test.js +0 -59
  117. package/dist/harness/prompt.test.js +0 -48
  118. package/dist/harness/receipts.test.js +0 -148
  119. package/dist/harness/report.test.js +0 -297
  120. package/dist/harness/runner.test.js +0 -635
  121. package/dist/harness/skill-revision.test.js +0 -148
  122. package/dist/harness/stats.test.js +0 -124
  123. package/dist/harness/target.test.js +0 -60
  124. package/dist/harness/trigger.test.js +0 -261
  125. package/dist/harness/verifier-summary.test.js +0 -99
  126. package/dist/harness/verifier.test.js +0 -128
  127. package/dist/harness/waza-behavior.test.js +0 -139
  128. package/dist/mcp/probe.test.js +0 -139
  129. package/evidence/artifacts/2026-10-12-diagnosing-revision/calibration-records.tar.gz +0 -0
  130. package/evidence/artifacts/2026-10-12-diagnosing-revision/interrupted-records.tar.gz +0 -0
  131. package/evidence/artifacts/2026-10-12-diagnosing-revision/validation-records.tar.gz +0 -0
  132. package/evidence/artifacts/2026-10-12-diagnosing-v2/regression-records.tar.gz +0 -0
  133. package/evidence/artifacts/2026-10-12-diagnosing-v2/transfer-records.tar.gz +0 -0
  134. package/evidence/artifacts/2026-10-12-normalize-url-v2-available/readiness-records.tar.gz +0 -0
  135. package/evidence/artifacts/2026-10-12-normalize-url-v2-comparison/records.tar.gz +0 -0
  136. package/evidence/artifacts/2026-10-12-normalize-url-v2-recovery/records.tar.gz +0 -0
  137. package/evidence/artifacts/2026-10-12-normalize-url-v2-validated/records.tar.gz +0 -0
  138. package/evidence/artifacts/2026-10-13-debugging-completed-development/package.tar.gz +0 -0
  139. package/evidence/artifacts/2026-10-13-debugging-controls-and-sleep-stop/package.tar.gz +0 -0
  140. package/evidence/artifacts/2026-10-13-debugging-development-stops/package.tar.gz +0 -0
  141. package/evidence/artifacts/2026-10-14-debugging-followup-routing-stop/package.tar.gz +0 -0
  142. package/evidence/artifacts/2026-10-14-debugging-independent-validation/package.tar.gz +0 -0
  143. package/evidence/artifacts/2026-10-14-debugging-reading-pilot-and-cost-review/package.tar.gz +0 -0
  144. package/evidence/artifacts/2026-10-14-debugging-spending-stop/package.tar.gz +0 -0
  145. package/evidence/artifacts/2026-10-15-independent-comparison-regression-stop/package.tar.gz +0 -0
  146. package/evidence/artifacts/2026-10-15-native-diff-mechanism/package.tar.gz +0 -0
  147. package/evidence/artifacts/2026-10-15-receiver-mechanism-stop/package.tar.gz +0 -0
@@ -1,1166 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { execFileSync, spawnSync } from 'node:child_process';
3
- import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { join } from 'node:path';
6
- import { fileURLToPath } from 'node:url';
7
- import { test } from 'node:test';
8
- import { loadBench } from '../harness/bench.js';
9
- import { runVerifier } from '../harness/runner.js';
10
- import { parseVerifierSummary } from '../harness/verifier-summary.js';
11
- import { runBenchAdd, runBenchCheck, runBenchInit } from './bench.js';
12
- const PACKAGE_ROOT = fileURLToPath(new URL('../..', import.meta.url));
13
- const BUNDLED_CODE_REVIEW = join(PACKAGE_ROOT, 'benches', 'code-review');
14
- const BUNDLED_DEBUGGING = join(PACKAGE_ROOT, 'benches', 'debugging');
15
- test('contributed-bench CI gate checks every directory and fails if one check fails', (t) => {
16
- const cwd = tmp(t, 'skillfit-contrib-gate-');
17
- mkdirSync(join(cwd, 'benches', 'contrib', 'good'), { recursive: true });
18
- mkdirSync(join(cwd, 'benches', 'contrib', 'broken'), { recursive: true });
19
- mkdirSync(join(cwd, 'dist'), { recursive: true });
20
- writeFileSync(join(cwd, 'dist', 'cli.js'), 'process.stdout.write(process.argv.at(-1)+"\\n");process.exit(process.argv.at(-1).endsWith("broken")?1:0)');
21
- const result = spawnSync(process.execPath, [join(PACKAGE_ROOT, 'scripts', 'check-contrib-benches.mjs')], { cwd, encoding: 'utf8' });
22
- assert.equal(result.status, 1);
23
- assert.match(result.stdout, /Checking contributed bench: /);
24
- assert.match(result.stdout, /broken/);
25
- assert.match(result.stdout, /good/);
26
- });
27
- function tmp(t, prefix) {
28
- const dir = mkdtempSync(join(tmpdir(), prefix));
29
- t.after(() => rmSync(dir, { recursive: true, force: true }));
30
- return dir;
31
- }
32
- function collector() {
33
- const lines = [];
34
- return { lines, log: (msg) => lines.push(msg) };
35
- }
36
- test('runBenchInit dry-run prints the plan and writes nothing', async (t) => {
37
- const cwd = tmp(t, 'skillfit-bench-init-');
38
- const { lines, log } = collector();
39
- const result = await runBenchInit({ cwd, dryRun: true, log });
40
- assert.equal(result, null);
41
- assert.ok(!existsSync(join(cwd, 'skillfit-bench')));
42
- const output = lines.join('\n');
43
- assert.match(output, /Bench scaffold plan \(dry run\)/);
44
- assert.match(output, /\+ bench\.json/);
45
- assert.match(output, /\+ verifiers\/example-task\.mjs/);
46
- });
47
- test('runBenchInit scaffolds a bench that loads and passes bench check', async (t) => {
48
- const cwd = tmp(t, 'skillfit-bench-init-');
49
- const { log } = collector();
50
- const result = await runBenchInit({ cwd, yes: true, log });
51
- assert.ok(result);
52
- assert.equal(result.dir, join(cwd, 'skillfit-bench'));
53
- const bench = loadBench(result.dir);
54
- assert.equal(bench.name, 'skillfit-bench');
55
- assert.equal(bench.tasks.length, 1);
56
- assert.equal(bench.tasks[0]?.verifierKind, undefined, 'default output template is unchanged');
57
- const report = await runBenchCheck({ dir: result.dir, log: () => { } });
58
- assert.equal(report.failures, 0);
59
- assert.ok(report.checks.some((c) => c.status === 'INFO' && c.message.includes('no shouldTrigger label')));
60
- });
61
- test('command starter dry-run writes nothing and invalid kinds fail before writing', async (t) => {
62
- const cwd = tmp(t, 'skillfit-command-init-');
63
- const { lines, log } = collector();
64
- await runBenchInit({ cwd, kind: 'command', dryRun: true, log });
65
- assert.ok(!existsSync(join(cwd, 'skillfit-bench')));
66
- assert.match(lines.join('\n'), /fixtures\/example-task\/index\.js/);
67
- await assert.rejects(() => runBenchInit({ cwd, kind: 'typo', yes: true, log }), /Unknown bench kind/);
68
- assert.ok(!existsSync(join(cwd, 'skillfit-bench')));
69
- });
70
- test('command starter is self-contained, passes offline NOP/oracle gates and previews two calls', async (t) => {
71
- const cwd = tmp(t, 'skillfit-command-init-');
72
- const dir = join(cwd, 'my bench');
73
- const { lines, log } = collector();
74
- await runBenchInit({ dir, kind: 'command', yes: true, log });
75
- const bench = loadBench(dir);
76
- assert.equal(bench.tasks[0]?.verifierKind, 'command');
77
- assert.equal(bench.tasks[0]?.promptTrigger, 'prompts/example-task.trigger.md');
78
- const original = readFileSync(join(dir, 'fixtures/example-task/index.js'), 'utf8');
79
- const report = await runBenchCheck({ dir, log: () => { } });
80
- assert.equal(report.failures, 0, JSON.stringify(report.checks));
81
- assert.equal(report.warnings, 0, JSON.stringify(report.checks));
82
- assert.equal(readFileSync(join(dir, 'fixtures/example-task/index.js'), 'utf8'), original, 'offline check must solve only a disposable copy');
83
- assert.match(lines.join('\n'), /--input workspace --trials 1 --max-calls 2 --dry-run/);
84
- const preview = spawnSync(process.execPath, [join(PACKAGE_ROOT, 'dist/cli.js'),
85
- 'eval', join(PACKAGE_ROOT, 'skills/skillfit'), '--bench', dir, '--agent', 'codex',
86
- '--input', 'workspace', '--trials', '1', '--max-calls', '2', '--dry-run'], { cwd, encoding: 'utf8', timeout: 30_000 });
87
- assert.equal(preview.status, 0, preview.stderr);
88
- assert.match(preview.stdout, /2 planned; ceiling 2/);
89
- assert.match(preview.stdout, /workspace files on disk/);
90
- assert.ok(!existsSync(join(cwd, 'runs')), 'preview must not create a run');
91
- });
92
- test('command starter grades behavior, accepting equivalent repairs and rejecting wrong or incomplete programs', async (t) => {
93
- const cwd = tmp(t, 'skillfit-command-grade-');
94
- const dir = join(cwd, 'bench');
95
- await runBenchInit({ dir, kind: 'command', yes: true, log: () => { } });
96
- const programs = [
97
- { id: 'original', source: 'export const add = (a, b) => a - b;', passed: false },
98
- { id: 'equivalent', source: 'export const add = (left, right) => [left, right].reduce((sum, n) => sum + n, 0);', passed: true },
99
- { id: 'hardcoded', source: 'export const add = () => 5;', passed: false },
100
- { id: 'partial', source: 'export const add = (a, b) => Math.abs(a + b);', passed: false },
101
- { id: 'syntax-error', source: 'export const add = ;', passed: false },
102
- { id: 'early-exit', source: 'process.exit(0);', passed: false },
103
- ];
104
- for (const program of programs)
105
- await t.test(program.id, async () => {
106
- const runDir = join(cwd, `run ${program.id}`);
107
- cpSync(join(dir, 'fixtures/example-task'), runDir, { recursive: true });
108
- writeFileSync(join(runDir, 'index.js'), program.source);
109
- const result = await runVerifier(dir, 'node verifiers/example-task.mjs', runDir);
110
- assert.equal(result.exitCode, program.passed ? 0 : 1, result.output);
111
- const summary = parseVerifierSummary(result.output);
112
- assert.equal(summary?.passed, program.passed);
113
- assert.equal(summary?.checks.length, 4);
114
- assert.equal(summary?.checks[0]?.pass, true);
115
- if (program.id === 'partial') {
116
- assert.equal(summary?.checks[1]?.pass, true);
117
- assert.equal(summary?.checks[2]?.pass, false, 'negative-input failures must stay visible');
118
- }
119
- });
120
- });
121
- test('command starter rejects modified or missing protected tests and package metadata', async (t) => {
122
- const cwd = tmp(t, 'skillfit-command-protected-');
123
- const dir = join(cwd, 'bench');
124
- await runBenchInit({ dir, kind: 'command', yes: true, log: () => { } });
125
- for (const file of ['package.json', 'test.mjs']) {
126
- for (const mutation of ['modify', 'remove'])
127
- await t.test(`${mutation} ${file}`, async () => {
128
- const runDir = join(cwd, `${mutation}-${file}`);
129
- cpSync(join(dir, 'fixtures/example-task'), runDir, { recursive: true });
130
- writeFileSync(join(runDir, 'index.js'), 'export const add = (a, b) => a + b;');
131
- if (mutation === 'remove')
132
- rmSync(join(runDir, file));
133
- else
134
- writeFileSync(join(runDir, file), file === 'package.json' ? '{"type":"module"}' : '// tests removed');
135
- const result = await runVerifier(dir, 'node verifiers/example-task.mjs', runDir);
136
- assert.equal(result.exitCode, 1, result.output);
137
- assert.equal(parseVerifierSummary(result.output)?.checks[0]?.pass, false);
138
- });
139
- }
140
- });
141
- test('bench init CLI validates template kind and keeps existing output untouched', (t) => {
142
- const cwd = tmp(t, 'skillfit-command-cli-');
143
- const cli = join(PACKAGE_ROOT, 'dist/cli.js');
144
- const dir = join(cwd, 'bench');
145
- const invalid = spawnSync(process.execPath, [cli, 'bench', 'init', dir, '--kind', 'typo', '--yes'], { encoding: 'utf8' });
146
- assert.notEqual(invalid.status, 0);
147
- assert.match(invalid.stderr, /Unknown --kind/);
148
- assert.ok(!existsSync(dir));
149
- const misplaced = spawnSync(process.execPath, [cli, 'bench', 'check', dir, '--kind', 'command'], { encoding: 'utf8' });
150
- assert.notEqual(misplaced.status, 0);
151
- assert.match(misplaced.stderr, /--kind applies only to bench init/);
152
- const created = spawnSync(process.execPath, [cli, 'bench', 'init', dir, '--kind', 'command', '--yes'], { encoding: 'utf8' });
153
- assert.equal(created.status, 0, created.stderr);
154
- const manifest = readFileSync(join(dir, 'bench.json'), 'utf8');
155
- const collision = spawnSync(process.execPath, [cli, 'bench', 'init', dir, '--kind', 'command', '--yes'], { encoding: 'utf8' });
156
- assert.notEqual(collision.status, 0);
157
- assert.match(collision.stderr, /not empty/);
158
- assert.equal(readFileSync(join(dir, 'bench.json'), 'utf8'), manifest);
159
- });
160
- test('runBenchInit refuses a non-empty target directory', async (t) => {
161
- const cwd = tmp(t, 'skillfit-bench-init-');
162
- const dir = join(cwd, 'skillfit-bench');
163
- mkdirSync(dir, { recursive: true });
164
- writeFileSync(join(dir, 'occupied.txt'), 'x');
165
- await assert.rejects(() => runBenchInit({ cwd, yes: true, log: () => { } }), /not empty/);
166
- });
167
- test('runBenchInit aborts when the user declines', async (t) => {
168
- const cwd = tmp(t, 'skillfit-bench-init-');
169
- const result = await runBenchInit({ cwd, confirm: () => Promise.resolve(false), log: () => { } });
170
- assert.equal(result, null);
171
- assert.ok(!existsSync(join(cwd, 'skillfit-bench')));
172
- });
173
- // Exercises the real readline path in a child process, because the defect is about stdin closing
174
- // without ever delivering a line — something an injected `confirm` stub cannot reproduce.
175
- test('bench init fails fast when stdin closes without an answer', (t) => {
176
- const cwd = tmp(t, 'skillfit-bench-stdin-');
177
- const result = spawnSync(process.execPath, [join(PACKAGE_ROOT, 'dist', 'cli.js'), 'bench', 'init', join(cwd, 'stdin-probe')], { cwd, encoding: 'utf8', input: '', timeout: 30_000 });
178
- assert.equal(result.signal, null, 'must not hang until the timeout');
179
- assert.notEqual(result.status, 0, 'closed non-TTY stdin must fail, not exit 0 having written nothing');
180
- assert.match(result.stderr, /--yes/);
181
- assert.ok(!existsSync(join(cwd, 'stdin-probe')), 'nothing was written');
182
- });
183
- test('runBenchCheck passes on the bundled code-review bench', async () => {
184
- const { log } = collector();
185
- const report = await runBenchCheck({ dir: BUNDLED_CODE_REVIEW, log });
186
- assert.equal(report.failures, 0);
187
- assert.ok(!report.checks.some((c) => c.message.includes('negative-control')));
188
- // The teaching material must not trip the gates it is teaching. Warnings are asserted, not just
189
- // failures, because a bundled bench that warns is a bundled bench modelling the wrong habit.
190
- assert.equal(report.warnings, 0, report.checks.filter((c) => c.status === 'WARN').map((c) => c.message).join('; '));
191
- assert.ok(report.checks.some((c) => c.status === 'PASS' && c.message.includes('negative controls (40%)')));
192
- });
193
- test('runBenchCheck gates every bundled debugging task with its oracle', async () => {
194
- const { log } = collector();
195
- const report = await runBenchCheck({ dir: BUNDLED_DEBUGGING, log });
196
- assert.equal(report.failures, 0);
197
- const oraclePasses = report.checks.filter((c) => c.status === 'PASS' && c.message.includes('oracle solution passes the verifier'));
198
- assert.equal(oraclePasses.length, 8, 'every task registers an oracle and that oracle solves it');
199
- assert.ok(!report.checks.some((c) => c.message.includes('no oracle')), 'the bundled bench must not trip its own missing-oracle warning');
200
- assert.equal(report.warnings, 0, report.checks.filter((c) => c.status === 'WARN').map((c) => c.message).join('; '));
201
- assert.ok(report.checks.some((c) => c.status === 'PASS' && c.message.includes('negative controls (38%)')));
202
- });
203
- function commandKindBench(t, withOracle) {
204
- const dir = tmp(t, 'skillfit-bench-cmdkind-');
205
- mkdirSync(join(dir, 'fixtures', 't1'), { recursive: true });
206
- mkdirSync(join(dir, 'prompts'), { recursive: true });
207
- mkdirSync(join(dir, 'verifiers'), { recursive: true });
208
- mkdirSync(join(dir, 'ground-truth'), { recursive: true });
209
- writeFileSync(join(dir, 'fixtures', 't1', 'index.txt'), 'x\n');
210
- writeFileSync(join(dir, 'prompts', 't1.md'), 'Do something.\n');
211
- writeFileSync(join(dir, 'verifiers', 'v.mjs'), EXACT_VERIFIER);
212
- writeFileSync(join(dir, 'ground-truth', 'o.mjs'), `import fs from 'node:fs';
213
- import path from 'node:path';
214
- fs.writeFileSync(path.join(process.argv[2], '_output.md'), 'right\\n');
215
- `);
216
- const task = {
217
- id: 't1',
218
- fixture: 'fixtures/t1',
219
- prompt: 'prompts/t1.md',
220
- verifier: 'node verifiers/v.mjs',
221
- verifierKind: 'command',
222
- };
223
- if (withOracle)
224
- task['oracle'] = 'node ground-truth/o.mjs';
225
- writeFileSync(join(dir, 'bench.json'), JSON.stringify({ schemaVersion: 1, tasks: [task] }));
226
- return dir;
227
- }
228
- test('runBenchCheck names the offline coverage a command-kind task actually has', async (t) => {
229
- const gated = await runBenchCheck({ dir: commandKindBench(t, true), log: () => { } });
230
- assert.equal(gated.failures, 0);
231
- const gatedInfo = gated.checks.find((c) => c.message.includes('mock-arm probes not applicable'));
232
- assert.ok(gatedInfo, 'command-kind tasks always report why mock probes were skipped');
233
- assert.match(gatedInfo.message, /offline coverage comes from the oracle and NOP gates/);
234
- const ungated = await runBenchCheck({ dir: commandKindBench(t, false), log: () => { } });
235
- const ungatedInfo = ungated.checks.find((c) => c.message.includes('mock-arm probes not applicable'));
236
- assert.ok(ungatedInfo);
237
- assert.match(ungatedInfo.message, /nothing offline shows this task is solvable/);
238
- });
239
- test('runBenchCheck fails a command-kind task whose verifier cannot be spawned', async (t) => {
240
- const dir = commandKindBench(t, true);
241
- const manifest = JSON.parse(readFileSync(join(dir, 'bench.json'), 'utf8'));
242
- const task = manifest.tasks[0];
243
- assert.ok(task);
244
- task.verifier = 'no-such-verifier-binary verifiers/v.mjs';
245
- writeFileSync(join(dir, 'bench.json'), JSON.stringify(manifest));
246
- const report = await runBenchCheck({ dir, log: () => { } });
247
- assert.ok(report.checks.some((c) => c.status === 'FAIL' && c.message.includes('t1: verifier could not be started')), 'a verifier that never ran is a bench defect and must say so');
248
- assert.ok(!report.checks.some((c) => c.status === 'PASS' && c.message.includes('fails on the untouched fixture')), 'the NOP gate must not read "could not spawn" as the failure it exists to require');
249
- });
250
- // The visible suite IS this task's specification, so it is also the thing an agent can edit to win.
251
- // `bench check` covers the NOP and oracle directions but not tampering, so the cheat gets its own test.
252
- test('the bundled feat-slug verifier rejects a rewritten test suite', async (t) => {
253
- const runDir = tmp(t, 'skillfit-featslug-tamper-');
254
- cpSync(join(BUNDLED_DEBUGGING, 'fixtures', 'feat-slug'), runDir, { recursive: true });
255
- const solve = await runVerifier(BUNDLED_DEBUGGING, 'node ground-truth/oracle-feat-slug.mjs', runDir);
256
- assert.equal(solve.exitCode, 0, 'the oracle must solve the pristine fixture');
257
- const solved = await runVerifier(BUNDLED_DEBUGGING, 'node verifiers/feat-slug.mjs', runDir);
258
- assert.equal(solved.exitCode, 0, 'the reference solution must pass');
259
- // A suite that the correct implementation still satisfies, so only the tamper check can catch it.
260
- writeFileSync(join(runDir, 'test', 'slug.test.mjs'), `import test from 'node:test';
261
- import assert from 'node:assert/strict';
262
- import { slugify } from '../src/slug.mjs';
263
-
264
- test('trivial', () => {
265
- assert.equal(typeof slugify('anything'), 'string');
266
- });
267
- `, 'utf8');
268
- const tampered = await runVerifier(BUNDLED_DEBUGGING, 'node verifiers/feat-slug.mjs', runDir);
269
- assert.notEqual(tampered.exitCode, 0, 'editing the specification is not satisfying it');
270
- assert.match(tampered.output, /visible suite unmodified/);
271
- assert.match(tampered.output, /differs from the fixture copy/);
272
- });
273
- // The two checks this replaced scanned test source text — four `test(` occurrences and a match on
274
- // /negative|maxItems|invalid|reject/i — so empty tests containing the right words scored full marks.
275
- test('the bundled range-parser verifier rejects a keyword-stuffed empty test suite', async (t) => {
276
- const runDir = tmp(t, 'skillfit-rangeparser-game-');
277
- cpSync(join(BUNDLED_DEBUGGING, 'fixtures', 'range-parser'), runDir, { recursive: true });
278
- const solve = await runVerifier(BUNDLED_DEBUGGING, 'node ground-truth/oracle-range-parser.mjs', runDir);
279
- assert.equal(solve.exitCode, 0, 'the oracle must solve the pristine fixture');
280
- const solved = await runVerifier(BUNDLED_DEBUGGING, 'node verifiers/range-parser.mjs', runDir);
281
- assert.equal(solved.exitCode, 0, 'the reference solution must pass');
282
- mkdirSync(join(runDir, 'test'), { recursive: true });
283
- writeFileSync(join(runDir, 'test', 'basic.test.mjs'), `import test from 'node:test';
284
- import assert from 'node:assert/strict';
285
-
286
- test('invalid input handling', () => { assert.ok(true); });
287
- test('negative value handling', () => { assert.ok(true); });
288
- test('maxItems limit', () => { assert.ok(true); });
289
- test('rejects bad segments', () => { assert.ok(true); });
290
- `, 'utf8');
291
- const gamed = await runVerifier(BUNDLED_DEBUGGING, 'node verifiers/range-parser.mjs', runDir);
292
- assert.notEqual(gamed.exitCode, 0, 'a suite that asserts nothing is not a regression test');
293
- assert.match(gamed.output, /red-to-green regression test/);
294
- assert.match(gamed.output, /detects none of the seeded bugs/);
295
- });
296
- test('runBenchCheck fails a bench whose verifier accepts empty output', async (t) => {
297
- const dir = tmp(t, 'skillfit-bench-broken-');
298
- mkdirSync(join(dir, 'fixtures', 't1'), { recursive: true });
299
- mkdirSync(join(dir, 'prompts'), { recursive: true });
300
- mkdirSync(join(dir, 'verifiers'), { recursive: true });
301
- writeFileSync(join(dir, 'fixtures', 't1', 'index.txt'), 'x\n');
302
- writeFileSync(join(dir, 'prompts', 't1.md'), 'Do something.\n');
303
- writeFileSync(join(dir, 'verifiers', 'always.mjs'), 'process.exit(0);\n');
304
- writeFileSync(join(dir, 'bench.json'), JSON.stringify({
305
- schemaVersion: 1,
306
- name: 'broken',
307
- tasks: [{ id: 't1', fixture: 'fixtures/t1', prompt: 'prompts/t1.md', verifier: 'node verifiers/always.mjs' }],
308
- }));
309
- const report = await runBenchCheck({ dir, log: () => { } });
310
- assert.ok(report.failures >= 2);
311
- assert.ok(report.checks.some((c) => c.status === 'FAIL' && c.message.includes('empty output')));
312
- });
313
- test('runBenchCheck fails cleanly on a non-bench directory', async (t) => {
314
- const dir = tmp(t, 'skillfit-bench-none-');
315
- const report = await runBenchCheck({ dir, log: () => { } });
316
- assert.equal(report.failures, 1);
317
- assert.match(report.checks[0]?.message ?? '', /does not load/);
318
- });
319
- function oracleBench(t, verifierSrc, oracleSrc) {
320
- const dir = tmp(t, 'skillfit-bench-oracle-');
321
- mkdirSync(join(dir, 'fixtures', 't1'), { recursive: true });
322
- mkdirSync(join(dir, 'prompts'), { recursive: true });
323
- mkdirSync(join(dir, 'verifiers'), { recursive: true });
324
- mkdirSync(join(dir, 'ground-truth'), { recursive: true });
325
- writeFileSync(join(dir, 'fixtures', 't1', 'index.txt'), 'x\n');
326
- writeFileSync(join(dir, 'prompts', 't1.md'), 'Do something.\n');
327
- writeFileSync(join(dir, 'verifiers', 'v.mjs'), verifierSrc);
328
- writeFileSync(join(dir, 'ground-truth', 'o.mjs'), oracleSrc);
329
- writeFileSync(join(dir, 'bench.json'), JSON.stringify({
330
- schemaVersion: 1,
331
- tasks: [
332
- {
333
- id: 't1',
334
- fixture: 'fixtures/t1',
335
- prompt: 'prompts/t1.md',
336
- verifier: 'node verifiers/v.mjs',
337
- oracle: 'node ground-truth/o.mjs',
338
- },
339
- ],
340
- }));
341
- return dir;
342
- }
343
- const EXACT_VERIFIER = `import fs from 'node:fs';
344
- import path from 'node:path';
345
- let out = '';
346
- try {
347
- out = fs.readFileSync(path.join(process.argv[2], '_output.md'), 'utf8').trim();
348
- } catch {
349
- console.log(JSON.stringify({ passed: false, checks: [{ name: 'answer', pass: false }] }));
350
- process.exit(1);
351
- }
352
- const passed = out === 'right';
353
- console.log(JSON.stringify({ passed, checks: [{ name: 'answer', pass: passed }] }));
354
- process.exit(passed ? 0 : 1);
355
- `;
356
- test('runBenchCheck passes when the oracle aces the verifier', async (t) => {
357
- const oracle = `import fs from 'node:fs';
358
- import path from 'node:path';
359
- fs.writeFileSync(path.join(process.argv[2], '_output.md'), 'right\\n');
360
- `;
361
- const dir = oracleBench(t, EXACT_VERIFIER, oracle);
362
- const report = await runBenchCheck({ dir, log: () => { } });
363
- assert.equal(report.failures, 0);
364
- assert.ok(report.checks.some((c) => c.status === 'PASS' && c.message.includes('oracle solution passes the verifier with full checks')));
365
- });
366
- test('runBenchCheck fails when the oracle does not solve the task', async (t) => {
367
- const oracle = `import fs from 'node:fs';
368
- import path from 'node:path';
369
- fs.writeFileSync(path.join(process.argv[2], '_output.md'), 'wrong\\n');
370
- `;
371
- const dir = oracleBench(t, EXACT_VERIFIER, oracle);
372
- const report = await runBenchCheck({ dir, log: () => { } });
373
- assert.ok(report.checks.some((c) => c.status === 'FAIL' && c.message.includes('oracle solution does not pass the verifier')));
374
- });
375
- test('runBenchCheck fails when the oracle passes the exit code but not every check', async (t) => {
376
- const partialVerifier = `import fs from 'node:fs';
377
- import path from 'node:path';
378
- let out = '';
379
- try {
380
- out = fs.readFileSync(path.join(process.argv[2], '_output.md'), 'utf8');
381
- } catch {
382
- console.log(JSON.stringify({ passed: false }));
383
- process.exit(1);
384
- }
385
- if (out.trim() === '') {
386
- console.log(JSON.stringify({ passed: false }));
387
- process.exit(1);
388
- }
389
- console.log(JSON.stringify({ passed: true, checks: [{ name: 'a', pass: true }, { name: 'b', pass: false }] }));
390
- process.exit(0);
391
- `;
392
- const oracle = `import fs from 'node:fs';
393
- import path from 'node:path';
394
- fs.writeFileSync(path.join(process.argv[2], '_output.md'), 'something\\n');
395
- `;
396
- const dir = oracleBench(t, partialVerifier, oracle);
397
- const report = await runBenchCheck({ dir, log: () => { } });
398
- assert.ok(report.checks.some((c) => c.status === 'FAIL' && c.message.includes('scores 0.50 on its checks')));
399
- });
400
- test('runBenchCheck fails when the oracle command itself errors', async (t) => {
401
- const dir = oracleBench(t, EXACT_VERIFIER, 'process.exit(1);\n');
402
- const report = await runBenchCheck({ dir, log: () => { } });
403
- assert.ok(report.checks.some((c) => c.status === 'FAIL' && c.message.includes('oracle command itself failed')));
404
- });
405
- test('runBenchCheck warns when a task registers no oracle', async (t) => {
406
- const dir = tmp(t, 'skillfit-bench-nooracle-');
407
- mkdirSync(join(dir, 'fixtures', 't1'), { recursive: true });
408
- mkdirSync(join(dir, 'prompts'), { recursive: true });
409
- mkdirSync(join(dir, 'verifiers'), { recursive: true });
410
- writeFileSync(join(dir, 'fixtures', 't1', 'index.txt'), 'x\n');
411
- writeFileSync(join(dir, 'prompts', 't1.md'), 'Do something.\n');
412
- writeFileSync(join(dir, 'verifiers', 'v.mjs'), EXACT_VERIFIER);
413
- writeFileSync(join(dir, 'bench.json'), JSON.stringify({
414
- schemaVersion: 1,
415
- tasks: [
416
- {
417
- id: 't1',
418
- fixture: 'fixtures/t1',
419
- prompt: 'prompts/t1.md',
420
- verifier: 'node verifiers/v.mjs',
421
- },
422
- ],
423
- }));
424
- const report = await runBenchCheck({ dir, log: () => { } });
425
- const warning = report.checks.find((c) => c.status === 'WARN' && c.message.startsWith('t1: no oracle'));
426
- assert.ok(warning, 'expected a WARN for the missing oracle');
427
- assert.match(warning.message, /task winnability is unverified/);
428
- // A missing oracle warns rather than fails: `bench add --freeze` legitimately
429
- // produces oracle-less tasks mid-authoring, and a hard fail would block that flow.
430
- assert.equal(report.failures, 0);
431
- });
432
- test('runBenchCheck does not warn about oracles when every task registers one', async (t) => {
433
- const oracle = `import fs from 'node:fs';
434
- import path from 'node:path';
435
- fs.writeFileSync(path.join(process.argv[2], '_output.md'), 'right\\n');
436
- `;
437
- const dir = oracleBench(t, EXACT_VERIFIER, oracle);
438
- const report = await runBenchCheck({ dir, log: () => { } });
439
- assert.equal(report.failures, 0);
440
- assert.ok(!report.checks.some((c) => c.message.includes('no oracle')), 'a bench with oracles registered must not warn about missing ones');
441
- });
442
- function facetCountBench(t, count) {
443
- const dir = tmp(t, 'skillfit-bench-facets-');
444
- mkdirSync(join(dir, 'fixtures', 't1'), { recursive: true });
445
- mkdirSync(join(dir, 'prompts'), { recursive: true });
446
- mkdirSync(join(dir, 'verifiers'), { recursive: true });
447
- writeFileSync(join(dir, 'fixtures', 't1', 'index.txt'), 'x\n');
448
- writeFileSync(join(dir, 'prompts', 't1.md'), 'Do something.\n');
449
- const names = Array.from({ length: count }, (_, i) => `check-${i + 1}`);
450
- writeFileSync(join(dir, 'verifiers', 'v.mjs'), `import fs from 'node:fs';
451
- import path from 'node:path';
452
- let out = '';
453
- try {
454
- out = fs.readFileSync(path.join(process.argv[2], '_output.md'), 'utf8');
455
- } catch {
456
- out = '';
457
- }
458
- const passed = out.trim() === 'right';
459
- const checks = ${JSON.stringify(names)}.map((name) => ({ name, pass: passed }));
460
- console.log(JSON.stringify({ passed, checks }));
461
- process.exit(passed ? 0 : 1);
462
- `);
463
- writeFileSync(join(dir, 'bench.json'), JSON.stringify({
464
- schemaVersion: 1,
465
- tasks: [
466
- {
467
- id: 't1',
468
- fixture: 'fixtures/t1',
469
- prompt: 'prompts/t1.md',
470
- verifier: 'node verifiers/v.mjs',
471
- },
472
- ],
473
- }));
474
- return dir;
475
- }
476
- function facetGate(report) {
477
- return report.checks.find((c) => c.message.includes('facet check(s)'));
478
- }
479
- test('runBenchCheck warns when the facet-check count falls outside 2–8', async (t) => {
480
- for (const count of [1, 12]) {
481
- const report = await runBenchCheck({ dir: facetCountBench(t, count), log: () => { } });
482
- const gate = facetGate(report);
483
- assert.ok(gate, `expected a facet-count line for ${count} checks`);
484
- assert.equal(gate.status, 'WARN', `${count} checks must warn`);
485
- assert.ok(gate.message.startsWith(`t1: ${count} facet check(s)`), `message should name the count, got: ${gate.message}`);
486
- }
487
- });
488
- test('runBenchCheck passes facet counts at both ends of the 2–8 contract', async (t) => {
489
- for (const count of [2, 8]) {
490
- const report = await runBenchCheck({ dir: facetCountBench(t, count), log: () => { } });
491
- const gate = facetGate(report);
492
- assert.ok(gate, `expected a facet-count line for ${count} checks`);
493
- assert.equal(gate.status, 'PASS', `${count} checks must pass`);
494
- assert.equal(report.failures, 0);
495
- }
496
- });
497
- function triggerLabelBench(t, labeled, negatives) {
498
- const dir = tmp(t, 'skillfit-bench-negatives-');
499
- mkdirSync(join(dir, 'prompts'), { recursive: true });
500
- mkdirSync(join(dir, 'verifiers'), { recursive: true });
501
- writeFileSync(join(dir, 'verifiers', 'v.mjs'), EXACT_VERIFIER);
502
- const tasks = [];
503
- for (let i = 0; i < labeled; i++) {
504
- const id = `task-${i + 1}`;
505
- mkdirSync(join(dir, 'fixtures', id), { recursive: true });
506
- writeFileSync(join(dir, 'fixtures', id, 'index.txt'), 'x\n');
507
- writeFileSync(join(dir, 'prompts', `${id}.md`), `${id} prompt.\n`);
508
- tasks.push({
509
- id,
510
- fixture: `fixtures/${id}`,
511
- prompt: `prompts/${id}.md`,
512
- verifier: 'node verifiers/v.mjs',
513
- shouldTrigger: i >= negatives,
514
- });
515
- }
516
- writeFileSync(join(dir, 'bench.json'), JSON.stringify({ schemaVersion: 1, tasks }));
517
- return dir;
518
- }
519
- function negativeControlLine(report) {
520
- return report.checks.find((c) => c.message.includes('negative controls'));
521
- }
522
- test('runBenchCheck warns when negative controls fall below the 30% target', async (t) => {
523
- const report = await runBenchCheck({ dir: triggerLabelBench(t, 5, 1), log: () => { } });
524
- const line = negativeControlLine(report);
525
- assert.ok(line, 'expected a negative-control line');
526
- assert.equal(line.status, 'WARN', '1/5 = 20% must warn');
527
- assert.match(line.message, /^1\/5 labeled task\(s\) are negative controls \(20%\)/);
528
- assert.match(line.message, /below the 30% target/);
529
- });
530
- test('runBenchCheck passes negative controls at exactly the 30% target', async (t) => {
531
- const report = await runBenchCheck({ dir: triggerLabelBench(t, 10, 3), log: () => { } });
532
- const line = negativeControlLine(report);
533
- assert.ok(line, 'expected a negative-control line');
534
- assert.equal(line.status, 'PASS', '3/10 = 30% is at the target and must not warn');
535
- assert.match(line.message, /^3\/10 labeled task\(s\) are negative controls \(30%\)/);
536
- });
537
- test('runBenchCheck still warns hardest when a labelled bench has no negative controls', async (t) => {
538
- const report = await runBenchCheck({ dir: triggerLabelBench(t, 3, 0), log: () => { } });
539
- assert.ok(report.checks.some((c) => c.status === 'WARN' && c.message.includes('cannot measure false-trigger rate')));
540
- });
541
- function gitRepoWithBug(t) {
542
- const dir = tmp(t, 'skillfit-freeze-src-');
543
- writeFileSync(join(dir, 'add.js'), 'export function add(a, b) {\n return a - b;\n}\n');
544
- writeFileSync(join(dir, 'add.test.js'), `import { test } from 'node:test';\nimport assert from 'node:assert/strict';\nimport { add } from './add.js';\ntest('add works', () => { assert.equal(add(1, 2), 3); });\n`);
545
- writeFileSync(join(dir, 'package.json'), '{ "type": "module" }\n');
546
- execFileSync('git', ['init', '-q'], { cwd: dir });
547
- execFileSync('git', ['config', 'user.email', 't@t'], { cwd: dir });
548
- execFileSync('git', ['config', 'user.name', 't'], { cwd: dir });
549
- execFileSync('git', ['add', '-A'], { cwd: dir });
550
- execFileSync('git', ['commit', '-qm', 'init'], { cwd: dir });
551
- mkdirSync(join(dir, 'node_modules', 'junk'), { recursive: true });
552
- writeFileSync(join(dir, 'node_modules', 'junk', 'big.js'), 'x'.repeat(4096));
553
- writeFileSync(join(dir, 'untracked.txt'), 'not tracked\n');
554
- return dir;
555
- }
556
- function freezeBench(t) {
557
- const cwd = tmp(t, 'skillfit-freeze-bench-');
558
- const dir = join(cwd, 'my-bench');
559
- return runBenchInit({ cwd, dir, yes: true, log: () => { } }).then(() => dir);
560
- }
561
- test('runBenchAdd --freeze captures only git-tracked files and registers the task', async (t) => {
562
- const source = gitRepoWithBug(t);
563
- const benchDir = await freezeBench(t);
564
- const result = await runBenchAdd({
565
- benchDir,
566
- task: 'add-bug',
567
- prompt: 'The add function is broken. Fix it so the tests pass.',
568
- freeze: true,
569
- sourceDir: source,
570
- verifierCmd: 'node --test',
571
- shouldTrigger: true,
572
- yes: true,
573
- log: () => { },
574
- });
575
- assert.ok(result);
576
- const fixture = join(benchDir, 'fixtures', 'add-bug');
577
- assert.ok(existsSync(join(fixture, 'add.js')), 'tracked file captured');
578
- assert.ok(!existsSync(join(fixture, 'untracked.txt')), 'untracked file excluded');
579
- assert.ok(!existsSync(join(fixture, 'node_modules')), 'node_modules excluded');
580
- const bench = loadBench(benchDir);
581
- const task = bench.tasks.find((entry) => entry.id === 'add-bug');
582
- assert.equal(task?.verifierKind, 'command');
583
- assert.equal(task?.shouldTrigger, true);
584
- assert.equal(task?.promptTrigger, 'prompts/add-bug.trigger.md');
585
- assert.ok(existsSync(join(benchDir, 'prompts', 'add-bug.trigger.md')));
586
- assert.ok(existsSync(join(benchDir, 'ground-truth', 'add-bug.md')));
587
- const runDir = mkdtempSync(join(tmpdir(), 'skillfit-freeze-run-'));
588
- t.after(() => rmSync(runDir, { recursive: true, force: true }));
589
- for (const file of ['add.js', 'add.test.js', 'package.json']) {
590
- writeFileSync(join(runDir, file), readFileSync(join(fixture, file)));
591
- }
592
- const failing = spawnSync('node', [join(benchDir, 'verifiers', 'add-bug.mjs'), runDir], {
593
- cwd: benchDir,
594
- encoding: 'utf8',
595
- });
596
- assert.notEqual(failing.status, 0, 'verifier fails while the bug is present');
597
- writeFileSync(join(runDir, 'add.js'), 'export function add(a, b) {\n return a + b;\n}\n');
598
- const passing = spawnSync('node', [join(benchDir, 'verifiers', 'add-bug.mjs'), runDir], {
599
- cwd: benchDir,
600
- encoding: 'utf8',
601
- });
602
- assert.equal(passing.status, 0, 'verifier passes once the fix is in place');
603
- const report = await runBenchCheck({ dir: benchDir, log: () => { } });
604
- assert.equal(report.failures, 0);
605
- });
606
- test('runBenchAdd --freeze supports --expect output verifiers', async (t) => {
607
- const source = gitRepoWithBug(t);
608
- const benchDir = await freezeBench(t);
609
- await runBenchAdd({
610
- benchDir,
611
- task: 'explain-bug',
612
- prompt: 'Explain why add.test.js fails.',
613
- freeze: true,
614
- sourceDir: source,
615
- expect: 'subtracts instead of adds',
616
- yes: true,
617
- log: () => { },
618
- });
619
- const bench = loadBench(benchDir);
620
- const task = bench.tasks.find((entry) => entry.id === 'explain-bug');
621
- assert.equal(task?.verifierKind, 'output');
622
- const runDir = mkdtempSync(join(tmpdir(), 'skillfit-freeze-run-'));
623
- t.after(() => rmSync(runDir, { recursive: true, force: true }));
624
- writeFileSync(join(runDir, '_output.md'), 'The implementation subtracts instead of adds.');
625
- const ok = spawnSync('node', [join(benchDir, 'verifiers', 'explain-bug.mjs'), runDir], {
626
- cwd: benchDir,
627
- encoding: 'utf8',
628
- });
629
- assert.equal(ok.status, 0);
630
- writeFileSync(join(runDir, '_output.md'), 'no idea');
631
- const bad = spawnSync('node', [join(benchDir, 'verifiers', 'explain-bug.mjs'), runDir], {
632
- cwd: benchDir,
633
- encoding: 'utf8',
634
- });
635
- assert.equal(bad.status, 1);
636
- });
637
- function stubDrafter(verifierSrc, oracleSrc) {
638
- return {
639
- describe: () => ({ kind: 'mock', model: 'stub-drafter' }),
640
- run: (_prompt, workdir) => {
641
- writeFileSync(join(workdir, 'verifier.mjs'), verifierSrc);
642
- writeFileSync(join(workdir, 'oracle.mjs'), oracleSrc);
643
- return Promise.resolve({ output: '' });
644
- },
645
- };
646
- }
647
- const DRAFTED_COMMAND_VERIFIER = `import { spawnSync } from 'node:child_process';
648
- const result = spawnSync('node --test', { cwd: process.argv[2], shell: true, encoding: 'utf8' });
649
- const passed = result.status === 0;
650
- console.log(JSON.stringify({ passed, checks: [{ name: 'tests-pass', pass: passed }] }));
651
- process.exit(passed ? 0 : 1);
652
- `;
653
- const DRAFTED_ORACLE = `import fs from 'node:fs';
654
- import path from 'node:path';
655
- fs.writeFileSync(path.join(process.argv[2], 'add.js'), 'export function add(a, b) {\\n return a + b;\\n}\\n');
656
- `;
657
- test('runBenchAdd --freeze --decompose installs a gated draft with its oracle', async (t) => {
658
- const source = gitRepoWithBug(t);
659
- const benchDir = await freezeBench(t);
660
- const result = await runBenchAdd({
661
- benchDir,
662
- task: 'add-bug-drafted',
663
- prompt: 'The add function is broken. Fix it so the tests pass.',
664
- freeze: true,
665
- sourceDir: source,
666
- decompose: true,
667
- runsRoot: tmp(t, 'skillfit-draft-records-'),
668
- verifierKind: 'command',
669
- executor: stubDrafter(DRAFTED_COMMAND_VERIFIER, DRAFTED_ORACLE),
670
- yes: true,
671
- log: () => { },
672
- });
673
- assert.ok(result);
674
- const bench = loadBench(benchDir);
675
- const task = bench.tasks.find((entry) => entry.id === 'add-bug-drafted');
676
- assert.equal(task?.verifierKind, 'command');
677
- assert.equal(task?.oracle, 'node ground-truth/oracle-add-bug-drafted.mjs');
678
- assert.ok(existsSync(join(benchDir, 'ground-truth', 'oracle-add-bug-drafted.mjs')));
679
- assert.match(readFileSync(join(benchDir, 'verifiers', 'add-bug-drafted.mjs'), 'utf8'), /tests-pass/);
680
- const report = await runBenchCheck({ dir: benchDir, log: () => { } });
681
- assert.equal(report.failures, 0);
682
- });
683
- test('runBenchAdd --decompose needs an agent or injected executor', async (t) => {
684
- const source = gitRepoWithBug(t);
685
- const benchDir = await freezeBench(t);
686
- await assert.rejects(() => runBenchAdd({
687
- benchDir,
688
- task: 'x1',
689
- prompt: 'p',
690
- freeze: true,
691
- sourceDir: source,
692
- decompose: true,
693
- runsRoot: tmp(t, 'skillfit-draft-records-'),
694
- yes: true,
695
- log: () => { },
696
- }), /needs an agent/);
697
- });
698
- test('runBenchAdd --decompose rejects a draft that passes the untouched fixture', async (t) => {
699
- const source = gitRepoWithBug(t);
700
- const benchDir = await freezeBench(t);
701
- const laxVerifier = 'console.log(JSON.stringify({ passed: true }));\nprocess.exit(0);\n';
702
- await assert.rejects(() => runBenchAdd({
703
- benchDir,
704
- task: 'x1',
705
- prompt: 'p',
706
- freeze: true,
707
- sourceDir: source,
708
- decompose: true,
709
- runsRoot: tmp(t, 'skillfit-draft-records-'),
710
- executor: stubDrafter(laxVerifier, DRAFTED_ORACLE),
711
- yes: true,
712
- log: () => { },
713
- }), /NOP gate/);
714
- const bench = loadBench(benchDir);
715
- assert.ok(!bench.tasks.some((entry) => entry.id === 'x1'), 'nothing was registered');
716
- });
717
- test('runBenchAdd --decompose rejects a draft whose oracle does not solve the task', async (t) => {
718
- const source = gitRepoWithBug(t);
719
- const benchDir = await freezeBench(t);
720
- const idleOracle = '// does nothing\n';
721
- await assert.rejects(() => runBenchAdd({
722
- benchDir,
723
- task: 'x1',
724
- prompt: 'p',
725
- freeze: true,
726
- sourceDir: source,
727
- decompose: true,
728
- runsRoot: tmp(t, 'skillfit-draft-records-'),
729
- verifierKind: 'command',
730
- executor: stubDrafter(DRAFTED_COMMAND_VERIFIER, idleOracle),
731
- yes: true,
732
- log: () => { },
733
- }), /oracle gate/);
734
- });
735
- test('runBenchAdd --decompose validates flag combinations', async (t) => {
736
- const source = gitRepoWithBug(t);
737
- const benchDir = await freezeBench(t);
738
- const base = {
739
- benchDir,
740
- task: 'x1',
741
- prompt: 'p',
742
- freeze: true,
743
- sourceDir: source,
744
- yes: true,
745
- log: () => { },
746
- };
747
- await assert.rejects(() => runBenchAdd({ ...base, decompose: true, verifierCmd: 'node --test' }), /drafts the verifier/);
748
- await assert.rejects(() => runBenchAdd({ ...base, decompose: true, oracle: 'node ground-truth/o.mjs' }), /own oracle/);
749
- await assert.rejects(() => runBenchAdd({ ...base, freeze: false, fromCommit: 'HEAD', decompose: true }), /only with --freeze/);
750
- });
751
- test('runBenchAdd --decompose dry-run skips the agent and writes nothing', async (t) => {
752
- const source = gitRepoWithBug(t);
753
- const benchDir = await freezeBench(t);
754
- let invoked = false;
755
- const spy = {
756
- describe: () => ({ kind: 'mock', model: 'spy' }),
757
- run: () => {
758
- invoked = true;
759
- return Promise.resolve({ output: '' });
760
- },
761
- };
762
- const result = await runBenchAdd({
763
- benchDir,
764
- task: 'x1',
765
- prompt: 'p',
766
- freeze: true,
767
- sourceDir: source,
768
- decompose: true,
769
- runsRoot: tmp(t, 'skillfit-draft-records-'),
770
- executor: spy,
771
- dryRun: true,
772
- log: () => { },
773
- });
774
- assert.equal(result, null);
775
- assert.equal(invoked, false);
776
- assert.ok(!existsSync(join(benchDir, 'verifiers', 'x1.mjs')));
777
- });
778
- test('runBenchAdd validates flags and rejects duplicates', async (t) => {
779
- const source = gitRepoWithBug(t);
780
- const benchDir = await freezeBench(t);
781
- const base = {
782
- benchDir,
783
- task: 'x1',
784
- prompt: 'p',
785
- freeze: true,
786
- sourceDir: source,
787
- yes: true,
788
- log: () => { },
789
- };
790
- await assert.rejects(() => runBenchAdd({ ...base, verifierCmd: 'a', expect: 'b' }), /not both/);
791
- await assert.rejects(() => runBenchAdd({ ...base }), /needs a verifier/);
792
- await assert.rejects(() => runBenchAdd({ ...base, verifierCmd: 'true', task: 'example-task' }), /already exists/);
793
- await assert.rejects(() => runBenchAdd({ ...base, verifierCmd: 'true', task: 'bad id!' }), /Invalid --task id/);
794
- await assert.rejects(() => runBenchAdd({ ...base, verifierCmd: 'true', prompt: '' }), /needs a task prompt/);
795
- await assert.rejects(() => runBenchAdd({ ...base, verifierCmd: 'true', freeze: false }), /needs an importer/);
796
- });
797
- test('runBenchAdd --freeze dry-run writes nothing', async (t) => {
798
- const source = gitRepoWithBug(t);
799
- const benchDir = await freezeBench(t);
800
- const { lines, log } = collector();
801
- const result = await runBenchAdd({
802
- benchDir,
803
- task: 'add-bug',
804
- prompt: 'Fix add.',
805
- freeze: true,
806
- sourceDir: source,
807
- verifierCmd: 'node --test',
808
- dryRun: true,
809
- log,
810
- });
811
- assert.equal(result, null);
812
- assert.ok(!existsSync(join(benchDir, 'fixtures', 'add-bug')));
813
- assert.match(lines.join('\n'), /dry run/);
814
- // The command string is persisted into a generated verifier and re-run under a shell on every
815
- // later check and eval, so it is disclosed before anything is written.
816
- assert.match(lines.join('\n'), /--verifier-cmd "node --test" is written into verifiers\/add-bug\.mjs/);
817
- assert.match(lines.join('\n'), /re-executed with a shell/);
818
- });
819
- test('runBenchAdd backs up an existing file and rolls back a failed write', async (t) => {
820
- const source = gitRepoWithBug(t);
821
- const benchDir = await freezeBench(t);
822
- const leftover = join(benchDir, 'verifiers', 'add-bug.mjs');
823
- writeFileSync(leftover, 'original verifier\n');
824
- const before = readFileSync(join(benchDir, 'bench.json'), 'utf8');
825
- mkdirSync(join(benchDir, 'prompts', 'blocked.md'));
826
- await assert.rejects(runBenchAdd({
827
- benchDir, task: 'blocked', prompt: 'Fix add.', freeze: true, sourceDir: source,
828
- verifierCmd: 'node --test', yes: true, log: () => { },
829
- }), /non-file/);
830
- assert.equal(readFileSync(join(benchDir, 'bench.json'), 'utf8'), before);
831
- assert.equal(existsSync(join(benchDir, 'fixtures', 'blocked', 'add.js')), false);
832
- rmSync(join(benchDir, 'prompts', 'blocked.md'), { recursive: true, force: true });
833
- await runBenchAdd({
834
- benchDir, task: 'add-bug', prompt: 'Fix add.', freeze: true, sourceDir: source,
835
- verifierCmd: 'node --test', yes: true, log: () => { },
836
- });
837
- assert.equal(readFileSync(leftover + '.skillfit-bak', 'utf8'), 'original verifier\n');
838
- assert.notEqual(readFileSync(leftover, 'utf8'), 'original verifier\n');
839
- });
840
- test('runBenchAdd works in a non-git source directory with explicit file selection', async (t) => {
841
- const source = tmp(t, 'skillfit-freeze-plain-');
842
- writeFileSync(join(source, 'main.js'), 'console.log(1);\n');
843
- mkdirSync(join(source, 'node_modules', 'junk'), { recursive: true });
844
- writeFileSync(join(source, 'node_modules', 'junk', 'x.js'), 'x');
845
- const benchDir = await freezeBench(t);
846
- await runBenchAdd({
847
- benchDir,
848
- task: 'plain',
849
- prompt: 'p',
850
- freeze: true,
851
- sourceDir: source,
852
- include: ['main.js'],
853
- verifierCmd: 'node main.js',
854
- yes: true,
855
- log: () => { },
856
- });
857
- const fixture = join(benchDir, 'fixtures', 'plain');
858
- assert.ok(existsSync(join(fixture, 'main.js')));
859
- assert.ok(!existsSync(join(fixture, 'node_modules')));
860
- assert.ok(!existsSync(join(fixture, '.git')));
861
- });
862
- function gitRepoWithFixHistory(t) {
863
- const repo = tmp(t, 'skillfit-mine-repo-');
864
- mkdirSync(join(repo, 'src'), { recursive: true });
865
- writeFileSync(join(repo, 'src', 'add.js'), 'export function add(a, b) {\n return a - b;\n}\n');
866
- writeFileSync(join(repo, 'package.json'), '{ "type": "module" }\n');
867
- const git = (args) => execFileSync('git', args, { cwd: repo, encoding: 'utf8' }).trim();
868
- git(['init', '-q']);
869
- git(['config', 'user.email', 't@t']);
870
- git(['config', 'user.name', 't']);
871
- git(['add', '-A']);
872
- git(['commit', '-qm', 'initial: buggy add']);
873
- const buggyCommit = git(['rev-parse', 'HEAD']);
874
- mkdirSync(join(repo, 'test'), { recursive: true });
875
- writeFileSync(join(repo, 'test', 'sanity.test.js'), `import { test } from 'node:test';\nimport assert from 'node:assert/strict';\nimport { add } from '../src/add.js';\ntest('add returns a number', () => { assert.equal(typeof add(1, 2), 'number'); });\n`);
876
- git(['add', '-A']);
877
- git(['commit', '-qm', 'test: add sanity check']);
878
- const testOnlyCommit = git(['rev-parse', 'HEAD']);
879
- writeFileSync(join(repo, 'src', 'add.js'), 'export function add(a, b) {\n return a + b;\n}\n');
880
- writeFileSync(join(repo, 'test', 'add-fix.test.js'), `import { test } from 'node:test';\nimport assert from 'node:assert/strict';\nimport { add } from '../src/add.js';\ntest('add sums two numbers', () => { assert.equal(add(1, 2), 3); });\ntest('add handles zero', () => { assert.equal(add(0, 0), 0); });\n`);
881
- git(['add', '-A']);
882
- git(['commit', '-qm', 'fix: add was subtracting instead of adding']);
883
- const fixCommit = git(['rev-parse', 'HEAD']);
884
- return { repo, buggyCommit, testOnlyCommit, fixCommit };
885
- }
886
- test('runBenchAdd --from-commit mines parent fixture + embedded FAIL_TO_PASS verifier', async (t) => {
887
- const { repo, fixCommit } = gitRepoWithFixHistory(t);
888
- const benchDir = await freezeBench(t);
889
- const result = await runBenchAdd({
890
- benchDir,
891
- fromCommit: fixCommit,
892
- sourceDir: repo,
893
- shouldTrigger: true,
894
- yes: true,
895
- log: () => { },
896
- });
897
- assert.ok(result);
898
- assert.match(result.taskId, /^fix-[0-9a-f]{7}$/);
899
- const fixture = join(benchDir, 'fixtures', result.taskId);
900
- assert.match(readFileSync(join(fixture, 'src', 'add.js'), 'utf8'), /return a - b/, 'fixture is the parent (buggy) state');
901
- assert.ok(existsSync(join(fixture, 'package.json')));
902
- assert.ok(existsSync(join(fixture, 'test', 'sanity.test.js')), 'parent tests come along');
903
- assert.ok(!existsSync(join(fixture, 'test', 'add-fix.test.js')), 'the fix tests stay hidden in the verifier');
904
- const bench = loadBench(benchDir);
905
- const task = bench.tasks.find((entry) => entry.id === result.taskId);
906
- assert.equal(task?.verifierKind, 'command');
907
- assert.equal(task?.shouldTrigger, true);
908
- const runDir = mkdtempSync(join(tmpdir(), 'skillfit-mine-run-'));
909
- t.after(() => rmSync(runDir, { recursive: true, force: true }));
910
- writeFileSync(join(runDir, 'package.json'), readFileSync(join(fixture, 'package.json')));
911
- mkdirSync(join(runDir, 'src'), { recursive: true });
912
- writeFileSync(join(runDir, 'src', 'add.js'), readFileSync(join(fixture, 'src', 'add.js')));
913
- const pristine = spawnSync('node', [join(benchDir, 'verifiers', `${result.taskId}.mjs`), runDir], {
914
- cwd: benchDir,
915
- encoding: 'utf8',
916
- });
917
- assert.notEqual(pristine.status, 0, 'embedded fix tests fail on the parent state');
918
- writeFileSync(join(runDir, 'src', 'add.js'), 'export function add(a, b) {\n return a + b;\n}\n');
919
- const fixed = spawnSync('node', [join(benchDir, 'verifiers', `${result.taskId}.mjs`), runDir], {
920
- cwd: benchDir,
921
- encoding: 'utf8',
922
- });
923
- assert.equal(fixed.status, 0, 'embedded fix tests pass once the fix is implemented');
924
- const report = await runBenchCheck({ dir: benchDir, log: () => { } });
925
- assert.equal(report.failures, 0);
926
- });
927
- test('commit import honors an issue prompt without revealing the fix message', async (t) => {
928
- const { repo, fixCommit } = gitRepoWithFixHistory(t);
929
- const issue = 'Addition returns the wrong result. Reproduce and repair it.\n';
930
- const promptFile = join(tmp(t, 'skillfit-issue-prompt-'), 'issue.md');
931
- writeFileSync(promptFile, issue);
932
- for (const promptOptions of [{ prompt: issue }, { promptFile }]) {
933
- const benchDir = await freezeBench(t);
934
- const result = await runBenchAdd({ benchDir, sourceDir: repo, fromCommit: fixCommit,
935
- ...promptOptions, yes: true, log: () => { } });
936
- assert.ok(result);
937
- assert.equal(readFileSync(join(benchDir, 'prompts', `${result.taskId}.md`), 'utf8'), issue);
938
- assert.match(readFileSync(join(benchDir, 'fixtures', result.taskId, 'src/add.js'), 'utf8'), /return a - b/);
939
- assert.ok(!existsSync(join(benchDir, 'fixtures', result.taskId, 'test/add-fix.test.js')));
940
- }
941
- const benchDir = await freezeBench(t);
942
- for (const invalid of [{ prompt: '' }, { prompt: 'x', promptFile }]) {
943
- await assert.rejects(() => runBenchAdd({ benchDir, sourceDir: repo, fromCommit: fixCommit,
944
- ...invalid, yes: true, log: () => { } }), /prompt.*empty|exactly one prompt/);
945
- }
946
- });
947
- test('calibration supports workspace receipts and a dry-run that starts no executor', async (t) => {
948
- const dir = makeCalibBench(t);
949
- const runsRoot = join(tmp(t, 'skillfit-calib-workspace-'), 'runs');
950
- const prompts = [];
951
- const executor = {
952
- describe: () => ({ kind: 'cli', model: 'offline-calibration' }),
953
- run: (prompt) => { prompts.push(prompt); return Promise.resolve({ output: 'ok done' }); },
954
- };
955
- await runBenchCheck({ dir, calibrate: { executor, inputMode: 'workspace', dryRun: true, runsRoot }, log: () => { } });
956
- assert.equal(prompts.length, 0);
957
- assert.ok(!existsSync(runsRoot));
958
- await runBenchCheck({ dir, calibrate: { executor, inputMode: 'workspace', trials: 1,
959
- runsRoot, runGroup: 'workspace-calibration' }, log: () => { } });
960
- assert.equal(prompts.length, 2);
961
- assert.ok(prompts.every(p => !p.includes('Repository snapshot:')));
962
- const receipt = JSON.parse(readFileSync(join(runsRoot, 'workspace-calibration/easy-task/baseline/trial-1/_result.json'), 'utf8'));
963
- assert.equal(receipt.inputMode, 'workspace');
964
- });
965
- test('runBenchAdd --from-commit rejects test-only and test-less commits', async (t) => {
966
- const { repo, buggyCommit, testOnlyCommit, fixCommit } = gitRepoWithFixHistory(t);
967
- const benchDir = await freezeBench(t);
968
- const base = { benchDir, sourceDir: repo, yes: true, log: () => { } };
969
- await assert.rejects(() => runBenchAdd({ ...base, fromCommit: testOnlyCommit }), /only test files/);
970
- await assert.rejects(() => runBenchAdd({ ...base, fromCommit: buggyCommit }), /no test files/);
971
- await assert.rejects(() => runBenchAdd({ ...base, fromCommit: fixCommit, freeze: true, prompt: 'x', verifierCmd: 'y' }), /not both/);
972
- });
973
- test('runBenchAdd --from-commit mines a repository with non-ASCII paths', async (t) => {
974
- const repo = tmp(t, 'skillfit-mine-unicode-');
975
- mkdirSync(join(repo, 'src'), { recursive: true });
976
- writeFileSync(join(repo, 'src', 'add.js'), 'export function add(a, b) {\n return a - b;\n}\n');
977
- // git quotes and octal-escapes this in default ls-tree output, which used to reach `git show`
978
- // verbatim and fail: no repository containing an accented filename could be mined at all.
979
- writeFileSync(join(repo, 'src', 'café-notes.txt'), 'pricing edge cases\n');
980
- writeFileSync(join(repo, 'package.json'), '{ "type": "module" }\n');
981
- const git = (args) => execFileSync('git', args, { cwd: repo, encoding: 'utf8' }).trim();
982
- git(['init', '-q']);
983
- git(['config', 'user.email', 't@t']);
984
- git(['config', 'user.name', 't']);
985
- git(['add', '-A']);
986
- git(['commit', '-qm', 'initial: buggy add']);
987
- mkdirSync(join(repo, 'test'), { recursive: true });
988
- writeFileSync(join(repo, 'src', 'add.js'), 'export function add(a, b) {\n return a + b;\n}\n');
989
- writeFileSync(join(repo, 'test', 'add-fix.test.js'), `import { test } from 'node:test';\nimport assert from 'node:assert/strict';\nimport { add } from '../src/add.js';\ntest('add sums', () => { assert.equal(add(1, 2), 3); });\n`);
990
- git(['add', '-A']);
991
- git(['commit', '-qm', 'fix: add was subtracting']);
992
- const fixCommit = git(['rev-parse', 'HEAD']);
993
- const benchDir = await freezeBench(t);
994
- const result = await runBenchAdd({
995
- benchDir,
996
- fromCommit: fixCommit,
997
- sourceDir: repo,
998
- yes: true,
999
- log: () => { },
1000
- });
1001
- assert.ok(result);
1002
- const mined = join(benchDir, 'fixtures', result.taskId, 'src', 'café-notes.txt');
1003
- assert.ok(existsSync(mined), 'the accented file is part of the parent state and must be mined');
1004
- assert.equal(readFileSync(mined, 'utf8'), 'pricing edge cases\n');
1005
- });
1006
- test('runBenchAdd --from-commit refuses a parent state containing a submodule', async (t) => {
1007
- const repo = tmp(t, 'skillfit-mine-gitlink-');
1008
- mkdirSync(join(repo, 'src'), { recursive: true });
1009
- writeFileSync(join(repo, 'src', 'add.js'), 'export function add(a, b) {\n return a - b;\n}\n');
1010
- writeFileSync(join(repo, 'package.json'), '{ "type": "module" }\n');
1011
- const git = (args) => execFileSync('git', args, { cwd: repo, encoding: 'utf8' }).trim();
1012
- git(['init', '-q']);
1013
- git(['config', 'user.email', 't@t']);
1014
- git(['config', 'user.name', 't']);
1015
- git(['add', '-A']);
1016
- // A gitlink with no checkout behind it: ls-tree reports its size as `-`, which used to make the
1017
- // fixture total NaN and quietly disable the size guard.
1018
- git(['update-index', '--add', '--cacheinfo', '160000,0123456789abcdef0123456789abcdef01234567,vendor/lib']);
1019
- git(['commit', '-qm', 'initial: buggy add']);
1020
- mkdirSync(join(repo, 'test'), { recursive: true });
1021
- writeFileSync(join(repo, 'src', 'add.js'), 'export function add(a, b) {\n return a + b;\n}\n');
1022
- writeFileSync(join(repo, 'test', 'add-fix.test.js'), `import { test } from 'node:test';\nimport assert from 'node:assert/strict';\nimport { add } from '../src/add.js';\ntest('add sums', () => { assert.equal(add(1, 2), 3); });\n`);
1023
- git(['add', '-A']);
1024
- git(['commit', '-qm', 'fix: add was subtracting']);
1025
- const fixCommit = git(['rev-parse', 'HEAD']);
1026
- const benchDir = await freezeBench(t);
1027
- await assert.rejects(runBenchAdd({ benchDir, fromCommit: fixCommit, sourceDir: repo, yes: true, log: () => { } }), /gitlink \(submodule\) at "vendor\/lib"/);
1028
- });
1029
- test('runBenchAdd --from-commit honors --include and dry-run', async (t) => {
1030
- const { repo, fixCommit } = gitRepoWithFixHistory(t);
1031
- const benchDir = await freezeBench(t);
1032
- const { lines, log } = collector();
1033
- const dry = await runBenchAdd({
1034
- benchDir,
1035
- fromCommit: fixCommit,
1036
- sourceDir: repo,
1037
- include: ['src'],
1038
- dryRun: true,
1039
- log,
1040
- });
1041
- assert.equal(dry, null);
1042
- assert.ok(!existsSync(join(benchDir, 'fixtures', `fix-${fixCommit.slice(0, 7)}`)));
1043
- const result = await runBenchAdd({
1044
- benchDir,
1045
- fromCommit: fixCommit,
1046
- sourceDir: repo,
1047
- include: ['src'],
1048
- yes: true,
1049
- log: () => { },
1050
- });
1051
- assert.ok(result);
1052
- assert.ok(existsSync(join(benchDir, 'fixtures', result.taskId, 'src', 'add.js')));
1053
- assert.ok(!existsSync(join(benchDir, 'fixtures', result.taskId, 'package.json')), 'include filters the fixture');
1054
- });
1055
- function makeCalibBench(t) {
1056
- const dir = tmp(t, 'skillfit-calib-bench-');
1057
- mkdirSync(join(dir, 'prompts'), { recursive: true });
1058
- mkdirSync(join(dir, 'verifiers'), { recursive: true });
1059
- writeFileSync(join(dir, 'verifiers', 'ok.mjs'), `import fs from 'node:fs';\nconst out = fs.readFileSync(process.argv[2] + '/_output.md', 'utf8');\nprocess.exit(out.includes('ok') ? 0 : 1);\n`);
1060
- for (const id of ['easy-task', 'hard-task']) {
1061
- mkdirSync(join(dir, 'fixtures', id), { recursive: true });
1062
- writeFileSync(join(dir, 'fixtures', id, 'index.txt'), 'x\n');
1063
- writeFileSync(join(dir, 'prompts', `${id}.md`), `${id} prompt: reply.\n`);
1064
- }
1065
- writeFileSync(join(dir, 'bench.json'), JSON.stringify({
1066
- schemaVersion: 1,
1067
- name: 'calib',
1068
- tasks: [
1069
- { id: 'easy-task', fixture: 'fixtures/easy-task', prompt: 'prompts/easy-task.md', verifier: 'node verifiers/ok.mjs', shouldTrigger: true },
1070
- { id: 'hard-task', fixture: 'fixtures/hard-task', prompt: 'prompts/hard-task.md', verifier: 'node verifiers/ok.mjs', shouldTrigger: true },
1071
- ],
1072
- }));
1073
- return dir;
1074
- }
1075
- test('runBenchCheck --calibrate bands tasks by real baseline pass rate', async (t) => {
1076
- const dir = makeCalibBench(t);
1077
- const executor = {
1078
- describe: () => ({ kind: 'stub', model: 'stub' }),
1079
- run: (prompt) => Promise.resolve({ output: prompt.includes('easy') ? 'ok done' : 'nope' }),
1080
- };
1081
- const report = await runBenchCheck({
1082
- dir,
1083
- calibrate: {
1084
- executor,
1085
- trials: 2,
1086
- runsRoot: join(tmp(t, 'skillfit-calib-runs-'), 'runs'),
1087
- runGroup: 'calib-group',
1088
- },
1089
- log: () => { },
1090
- });
1091
- assert.equal(report.failures, 0);
1092
- assert.ok(report.checks.some((c) => c.message.includes('easy-task: baseline 2/2') && c.message.includes('too easy')));
1093
- assert.ok(report.checks.some((c) => c.message.includes('hard-task: baseline 0/2') && c.message.includes('too hard or broken')));
1094
- assert.ok(report.checks.some((c) => c.message.includes('0/2 task(s) in the discriminative band')));
1095
- });
1096
- test('runBenchCheck --calibrate requires an agent or executor', async (t) => {
1097
- const dir = makeCalibBench(t);
1098
- const report = await runBenchCheck({ dir, calibrate: {}, log: () => { } });
1099
- assert.ok(report.checks.some((c) => c.status === 'FAIL' && c.message.includes('needs --agent')));
1100
- });
1101
- // Same shape as makeCalibBench but with no shouldTrigger labels. Calibration used to route
1102
- // through trigger mode, whose label filter dropped every task here and then reported PASS 0/0.
1103
- function makeUnlabelledCalibBench(t) {
1104
- const dir = tmp(t, 'skillfit-calib-unlabelled-');
1105
- mkdirSync(join(dir, 'prompts'), { recursive: true });
1106
- mkdirSync(join(dir, 'verifiers'), { recursive: true });
1107
- writeFileSync(join(dir, 'verifiers', 'ok.mjs'), `import fs from 'node:fs';\nconst out = fs.readFileSync(process.argv[2] + '/_output.md', 'utf8');\nprocess.exit(out.includes('ok') ? 0 : 1);\n`);
1108
- for (const id of ['easy-task', 'hard-task']) {
1109
- mkdirSync(join(dir, 'fixtures', id), { recursive: true });
1110
- writeFileSync(join(dir, 'fixtures', id, 'index.txt'), 'x\n');
1111
- writeFileSync(join(dir, 'prompts', `${id}.md`), `${id} prompt: reply.\n`);
1112
- }
1113
- writeFileSync(join(dir, 'bench.json'), JSON.stringify({
1114
- schemaVersion: 1,
1115
- name: 'calib-unlabelled',
1116
- tasks: [
1117
- { id: 'easy-task', fixture: 'fixtures/easy-task', prompt: 'prompts/easy-task.md', verifier: 'node verifiers/ok.mjs' },
1118
- { id: 'hard-task', fixture: 'fixtures/hard-task', prompt: 'prompts/hard-task.md', verifier: 'node verifiers/ok.mjs' },
1119
- ],
1120
- }));
1121
- return dir;
1122
- }
1123
- test('runBenchCheck --calibrate measures a bench with no shouldTrigger labels', async (t) => {
1124
- const dir = makeUnlabelledCalibBench(t);
1125
- const executor = {
1126
- describe: () => ({ kind: 'stub', model: 'stub' }),
1127
- run: (prompt) => Promise.resolve({ output: prompt.includes('easy') ? 'ok done' : 'nope' }),
1128
- };
1129
- const report = await runBenchCheck({
1130
- dir,
1131
- calibrate: {
1132
- executor,
1133
- trials: 2,
1134
- runsRoot: join(tmp(t, 'skillfit-calib-runs-unlabelled-'), 'runs'),
1135
- runGroup: 'calib-unlabelled-group',
1136
- },
1137
- log: () => { },
1138
- });
1139
- assert.equal(report.failures, 0);
1140
- assert.ok(!report.checks.some((c) => c.message.includes('0/0 task(s) in the discriminative band')), 'calibration must never report a 0/0 band summary');
1141
- assert.ok(report.checks.some((c) => c.message.includes('easy-task: baseline 2/2') && c.message.includes('too easy')));
1142
- assert.ok(report.checks.some((c) => c.message.includes('hard-task: baseline 0/2') && c.message.includes('too hard or broken')));
1143
- assert.ok(report.checks.some((c) => c.message.includes('0/2 task(s) in the discriminative band')));
1144
- });
1145
- test('runBenchCheck --calibrate fails loudly when no task produced a completed run', async (t) => {
1146
- const dir = makeUnlabelledCalibBench(t);
1147
- const executor = {
1148
- describe: () => ({ kind: 'stub', model: 'stub' }),
1149
- run: () => Promise.reject(new Error('simulated executor failure')),
1150
- };
1151
- const report = await runBenchCheck({
1152
- dir,
1153
- calibrate: {
1154
- executor,
1155
- trials: 2,
1156
- runsRoot: join(tmp(t, 'skillfit-calib-runs-allerr-'), 'runs'),
1157
- runGroup: 'calib-allerr-group',
1158
- },
1159
- log: () => { },
1160
- });
1161
- // Errored runs are excluded from the rate, not counted as failures — and when that leaves
1162
- // nothing measured, the summary must fail rather than claim a band it never observed.
1163
- assert.ok(report.checks.some((c) => c.status === 'WARN' && c.message.includes('no completed runs') && c.message.includes('2 ungraded run(s)')));
1164
- assert.ok(report.checks.some((c) => c.status === 'FAIL' && c.message.includes('calibration ran 0 task(s)')));
1165
- assert.ok(!report.checks.some((c) => c.status === 'PASS' && c.message.includes('discriminative band')));
1166
- });