skillfit 0.12.0 → 0.13.0

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 (127) 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/growth-roadmap-2026-10.md +14 -18
  22. package/docs/package-contents.md +73 -0
  23. package/docs/plans/2026-10-20-archive-replay-verification.json +125 -0
  24. package/docs/plans/2026-10-20-archive-source-verification.json +256 -0
  25. package/docs/plans/2026-10-20-delivery-verification.json +146 -0
  26. package/docs/plans/2026-10-20-docs-architecture-cleanup.md +233 -0
  27. package/docs/plans/2026-10-20-install-transactions-and-archive-delivery.md +233 -0
  28. package/docs/plans/2026-10-21-npm-0.13.0-release.md +41 -0
  29. package/docs/releases/0.12.0-attestation-check.json +22 -0
  30. package/docs/releases/0.12.0-attestations.json +155 -0
  31. package/docs/releases/0.12.0-ci-registry-install.json +90 -0
  32. package/docs/releases/0.12.0-feature-smoke.json +34 -0
  33. package/docs/releases/0.12.0-foundations-smoke.json +1576 -0
  34. package/docs/releases/0.12.0-local-registry-install.json +75 -0
  35. package/docs/releases/0.12.0-preparation-attempt-1.json +22 -0
  36. package/docs/releases/0.12.0-registry-metadata.json +96 -0
  37. package/docs/releases/0.12.0-signatures.txt +6 -0
  38. package/docs/releases/0.12.0-verification.json +99 -0
  39. package/docs/releases/0.12.0.md +14 -0
  40. package/docs/releases/0.13.0-feature-smoke.mjs +114 -0
  41. package/docs/releases/0.13.0-preparation.json +102 -0
  42. package/docs/releases/0.13.0.md +61 -0
  43. package/docs/releases/archive-delivery-smoke.mjs +37 -0
  44. package/docs/reproducible-offline-example.md +1 -1
  45. package/evidence/README.md +24 -1
  46. package/evidence/archive-catalog.v1.json +8044 -0
  47. package/evidence/fetch-archives.mjs +211 -0
  48. package/package.json +9 -2
  49. package/dist/cli.test.js +0 -193
  50. package/dist/commands/bench-calibration.test.js +0 -237
  51. package/dist/commands/bench-check-json.test.js +0 -242
  52. package/dist/commands/bench-manage.test.js +0 -87
  53. package/dist/commands/bench.test.js +0 -1166
  54. package/dist/commands/bundle.test.js +0 -142
  55. package/dist/commands/calibration-cli.test.js +0 -145
  56. package/dist/commands/doctor.test.js +0 -280
  57. package/dist/commands/eval-agent-preflight.test.js +0 -269
  58. package/dist/commands/eval-cli-usage.test.js +0 -75
  59. package/dist/commands/eval-export-modes.test.js +0 -350
  60. package/dist/commands/eval-export.test.js +0 -279
  61. package/dist/commands/eval-interruption.test.js +0 -263
  62. package/dist/commands/eval-preflight.test.js +0 -382
  63. package/dist/commands/eval-report.test.js +0 -367
  64. package/dist/commands/eval.test.js +0 -503
  65. package/dist/commands/evaluation-report.test.js +0 -243
  66. package/dist/commands/install.test.js +0 -555
  67. package/dist/commands/npm-first-run.test.js +0 -74
  68. package/dist/commands/replay-cancellation.test.js +0 -105
  69. package/dist/commands/report.test.js +0 -110
  70. package/dist/commands/setup.test.js +0 -150
  71. package/dist/commands/upstream.test.js +0 -139
  72. package/dist/commands/workflow-entrypoints.test.js +0 -137
  73. package/dist/docs.test.js +0 -154
  74. package/dist/frontmatter.test.js +0 -49
  75. package/dist/harness/bench.test.js +0 -109
  76. package/dist/harness/bundle.test.js +0 -71
  77. package/dist/harness/codex-usage.test.js +0 -87
  78. package/dist/harness/costs.test.js +0 -92
  79. package/dist/harness/eval-budget.test.js +0 -237
  80. package/dist/harness/eval-component.test.js +0 -770
  81. package/dist/harness/eval-efficiency.test.js +0 -56
  82. package/dist/harness/execution-timing.test.js +0 -61
  83. package/dist/harness/executors/api.test.js +0 -175
  84. package/dist/harness/executors/cli.test.js +0 -541
  85. package/dist/harness/executors/mock.test.js +0 -43
  86. package/dist/harness/experiment-session.test.js +0 -317
  87. package/dist/harness/installed-skill.test.js +0 -162
  88. package/dist/harness/interruption.test.js +0 -31
  89. package/dist/harness/judge-accounting.test.js +0 -216
  90. package/dist/harness/judge.test.js +0 -181
  91. package/dist/harness/kimi-usage.test.js +0 -62
  92. package/dist/harness/native-diff.test.js +0 -53
  93. package/dist/harness/oss-lru-cache.test.js +0 -79
  94. package/dist/harness/oss-normalize-url.test.js +0 -64
  95. package/dist/harness/oss-regression-witness.test.js +0 -89
  96. package/dist/harness/oss-skill-followup.test.js +0 -59
  97. package/dist/harness/prompt.test.js +0 -48
  98. package/dist/harness/receipts.test.js +0 -148
  99. package/dist/harness/report.test.js +0 -297
  100. package/dist/harness/runner.test.js +0 -635
  101. package/dist/harness/skill-revision.test.js +0 -148
  102. package/dist/harness/stats.test.js +0 -124
  103. package/dist/harness/target.test.js +0 -60
  104. package/dist/harness/trigger.test.js +0 -261
  105. package/dist/harness/verifier-summary.test.js +0 -99
  106. package/dist/harness/verifier.test.js +0 -128
  107. package/dist/harness/waza-behavior.test.js +0 -139
  108. package/dist/mcp/probe.test.js +0 -139
  109. package/evidence/artifacts/2026-10-12-diagnosing-revision/calibration-records.tar.gz +0 -0
  110. package/evidence/artifacts/2026-10-12-diagnosing-revision/interrupted-records.tar.gz +0 -0
  111. package/evidence/artifacts/2026-10-12-diagnosing-revision/validation-records.tar.gz +0 -0
  112. package/evidence/artifacts/2026-10-12-diagnosing-v2/regression-records.tar.gz +0 -0
  113. package/evidence/artifacts/2026-10-12-diagnosing-v2/transfer-records.tar.gz +0 -0
  114. package/evidence/artifacts/2026-10-12-normalize-url-v2-available/readiness-records.tar.gz +0 -0
  115. package/evidence/artifacts/2026-10-12-normalize-url-v2-comparison/records.tar.gz +0 -0
  116. package/evidence/artifacts/2026-10-12-normalize-url-v2-recovery/records.tar.gz +0 -0
  117. package/evidence/artifacts/2026-10-12-normalize-url-v2-validated/records.tar.gz +0 -0
  118. package/evidence/artifacts/2026-10-13-debugging-completed-development/package.tar.gz +0 -0
  119. package/evidence/artifacts/2026-10-13-debugging-controls-and-sleep-stop/package.tar.gz +0 -0
  120. package/evidence/artifacts/2026-10-13-debugging-development-stops/package.tar.gz +0 -0
  121. package/evidence/artifacts/2026-10-14-debugging-followup-routing-stop/package.tar.gz +0 -0
  122. package/evidence/artifacts/2026-10-14-debugging-independent-validation/package.tar.gz +0 -0
  123. package/evidence/artifacts/2026-10-14-debugging-reading-pilot-and-cost-review/package.tar.gz +0 -0
  124. package/evidence/artifacts/2026-10-14-debugging-spending-stop/package.tar.gz +0 -0
  125. package/evidence/artifacts/2026-10-15-independent-comparison-regression-stop/package.tar.gz +0 -0
  126. package/evidence/artifacts/2026-10-15-native-diff-mechanism/package.tar.gz +0 -0
  127. package/evidence/artifacts/2026-10-15-receiver-mechanism-stop/package.tar.gz +0 -0
@@ -1,263 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { spawn, spawnSync } from 'node:child_process';
3
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { join } from 'node:path';
6
- import { fileURLToPath, pathToFileURL } from 'node:url';
7
- import { test } from 'node:test';
8
- import { runBenchInit } from './bench.js';
9
- import { reportEvalComponent } from './eval-component.js';
10
- import { exportEvaluation } from './eval-export.js';
11
- import { sha256File } from '../harness/hash.js';
12
- import { killTree } from '../harness/kill-tree.js';
13
- const dist = fileURLToPath(new URL('..', import.meta.url));
14
- const moduleUrl = (path) => JSON.stringify(pathToFileURL(join(dist, path)).href);
15
- const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
16
- const json = (path) => JSON.parse(readFileSync(path, 'utf8'));
17
- function running(pid) {
18
- try {
19
- process.kill(pid, 0);
20
- // An orphan reaped late by a Linux container's init is dead, despite kill(pid, 0).
21
- if (process.platform === 'linux' && readFileSync(`/proc/${pid}/stat`, 'utf8').split(')').at(-1).trim().startsWith('Z'))
22
- return false;
23
- return true;
24
- }
25
- catch {
26
- return false;
27
- }
28
- }
29
- async function scenario(t, mode, signal = 'SIGINT') {
30
- const root = mkdtempSync(join(tmpdir(), 'skillfit-interrupt-'));
31
- let child;
32
- t.after(async () => {
33
- if (child?.exitCode === null && child.signalCode === null)
34
- killTree(child);
35
- if (existsSync(join(root, 'ready.json')))
36
- for (const pid of json(join(root, 'ready.json')).pids) {
37
- if (running(pid))
38
- try {
39
- process.kill(pid, 'SIGKILL');
40
- }
41
- catch { /* already gone */ }
42
- }
43
- await delay(100);
44
- rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
45
- });
46
- const bench = join(root, 'bench'), skill = join(root, 'skill'), old = join(root, 'old');
47
- writeFileSync(join(root, 'draft-source.txt'), 'synthetic offline fixture');
48
- await runBenchInit({ dir: bench, yes: true, log: () => { } });
49
- for (const [dir, version] of [[skill, 'new'], [old, 'old']]) {
50
- mkdirSync(dir);
51
- writeFileSync(join(dir, 'SKILL.md'), `---\nname: interrupt-skill\ndescription: Synthetic offline interruption test.\n---\n${version}\n`);
52
- }
53
- const raw = json(join(bench, 'bench.json'));
54
- raw.tasks[0].shouldTrigger = true;
55
- const leaf = join(root, 'leaf.mjs'), heartbeat = join(root, 'heartbeat'), ready = join(root, 'ready.json');
56
- writeFileSync(leaf, `import{appendFileSync}from'node:fs';process.on('SIGINT',()=>{});process.on('SIGTERM',()=>{});setInterval(()=>appendFileSync(${JSON.stringify(heartbeat)},'x'),30);setTimeout(()=>process.exit(),30000);`);
57
- const fakeSource = `import{spawn}from'node:child_process';import{existsSync,writeFileSync}from'node:fs';
58
- process.stdin.resume();process.on('SIGINT',()=>{});process.on('SIGTERM',()=>{});
59
- process.stdout.write(${JSON.stringify([
60
- JSON.stringify({ type: 'item.completed', item: { type: 'agent_message', text: 'retained partial output' } }),
61
- JSON.stringify({ type: 'turn.completed', usage: { input_tokens: 12, cached_input_tokens: 7, output_tokens: 3 } }),
62
- ].join('\n') + '\n')});
63
- const leaf=spawn(process.execPath,[${JSON.stringify(leaf)}],{stdio:'ignore'});
64
- const timer=setInterval(()=>{if(existsSync(${JSON.stringify(heartbeat)})){clearInterval(timer);writeFileSync(${JSON.stringify(ready)},JSON.stringify({pids:[process.pid,leaf.pid]}));}},20);
65
- setTimeout(()=>process.exit(),30000);`;
66
- const fake = join(root, 'fake.mjs');
67
- writeFileSync(fake, fakeSource);
68
- if (mode === 'verifier' || mode === 'preflight') {
69
- writeFileSync(join(bench, 'verifiers/live-block.mjs'), fakeSource);
70
- // Only the post-agent verifier blocks in the verifier scenario. Preflight
71
- // still exercises the real missing/empty/oracle gates of the starter.
72
- writeFileSync(join(bench, 'verifiers/block.mjs'), mode === 'preflight' ? fakeSource :
73
- "import{existsSync}from'node:fs';import{join}from'node:path';await import(existsSync(join(process.argv[2],'_prompt.txt'))?'./live-block.mjs':'./example-task.mjs');");
74
- raw.tasks[0].verifier = 'node verifiers/block.mjs';
75
- }
76
- writeFileSync(join(bench, 'bench.json'), JSON.stringify(raw));
77
- const request = join(root, 'request.json');
78
- writeFileSync(request, JSON.stringify({ schemaVersion: 1, baselineSkill: old, candidateSkill: skill,
79
- bench, agent: 'codex', purpose: 'development', trials: 2, maxCalls: 4, runsRoot: join(root, 'runs'), runGroup: 'saved' }));
80
- const harness = join(root, 'harness.mjs');
81
- writeFileSync(harness, `import{writeFileSync}from'node:fs';
82
- import{runEval}from ${moduleUrl('commands/eval.js')};
83
- import{runBenchCheck,runBenchAdd}from ${moduleUrl('commands/bench.js')};
84
- import{runEvalComponent}from ${moduleUrl('commands/eval-component.js')};
85
- import{CliExecutor}from ${moduleUrl('harness/executors/cli.js')};
86
- import{ApiExecutor}from ${moduleUrl('harness/executors/api.js')};
87
- const mode=${JSON.stringify(mode)}, root=${JSON.stringify(root)};
88
- const counts=()=>[process.listenerCount('SIGINT'),process.listenerCount('SIGTERM')],before=counts();
89
- process.on('message',message=>{process.emit(message.signal);if(message.repeat){process.emit(message.signal);process.emit('SIGTERM');}});
90
- const fake=new CliExecutor({argv:[process.execPath,${JSON.stringify(fake)}],shell:false,triggerSkillName:'interrupt-skill',timeoutMs:20000});
91
- let calls=0;const mock={describe:()=>({kind:'mock',model:'offline'}),run:async()=>{calls++;return{output:'offline answer',tokens:{input:20,cachedInput:5,output:4}}}};
92
- const api=new ApiExecutor({apiKey:'offline-only',fetchImpl:async(_url,options)=>{writeFileSync(${JSON.stringify(ready)},JSON.stringify({pids:[]}));return await new Promise((_,reject)=>options.signal.addEventListener('abort',()=>{writeFileSync(root+'/api-aborted','yes');reject(options.signal.reason);},{once:true}));}});
93
- const base={skillPath:${JSON.stringify(skill)},bench:${JSON.stringify(bench)},trials:2,maxCalls:4,executor:mode==='verifier'||mode==='preflight'||mode==='judge'||mode==='between'?mock:mode==='api'?api:fake,judgeExecutor:mode==='judge'?fake:null,yes:true,dryRun:false,runsRoot:root+'/runs',runGroup:'saved',log:message=>{if(mode==='between'&&message.includes('/ treatment / trial 1'))process.emit('SIGINT');}};
94
- try{
95
- if(mode==='request'){const options={executor:fake,skillInstallDir:'skills',dryRun:true};const preview=await runEvalComponent(${JSON.stringify(request)},options);const result=await runEvalComponent(${JSON.stringify(request)},{...options,dryRun:false,expectedPlanSha256:preview.plan.sha256});writeFileSync(root+'/component.json',JSON.stringify(result));}
96
- else if(mode==='draft')await runBenchAdd({benchDir:base.bench,sourceDir:root,include:['draft-source.txt'],task:'interrupted-draft',prompt:'Solve the task',freeze:true,decompose:true,executor:fake,yes:true,runsRoot:base.runsRoot,runGroup:base.runGroup,log:()=>{}});
97
- else if(mode==='calibration')await runBenchCheck({dir:base.bench,log:()=>{},calibrate:{executor:fake,trials:2,maxCalls:2,runsRoot:base.runsRoot,runGroup:base.runGroup}});
98
- else await runEval({...base,...(mode==='trigger'?{mode:'trigger',skillInstallDir:'skills'}:{}),...(mode==='judge'?{maxCalls:8}:{})});
99
- }catch(error){writeFileSync(root+'/error.txt',error.message);}
100
- finally{writeFileSync(root+'/done.json',JSON.stringify({before,after:counts(),calls,exitCode:process.exitCode}));process.disconnect();}
101
- `);
102
- child = spawn(process.execPath, [harness], { stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });
103
- let stderr = '';
104
- child.stdout.resume();
105
- child.stderr.on('data', chunk => { stderr += chunk; });
106
- const closed = new Promise(resolve => child.on('exit', (code, signal) => resolve({ code, signal })));
107
- if (mode !== 'between') {
108
- for (let i = 0; i < 300 && !existsSync(ready) && child.exitCode === null; i++)
109
- await delay(50);
110
- assert.ok(existsSync(ready), `Fake process did not start: ${stderr}`);
111
- await delay(100);
112
- // Windows kill('SIGINT') forcibly terminates rather than delivering a console
113
- // control event. Emit that event in the isolated harness; taskkill /T remains real.
114
- if (process.platform === 'win32' || mode === 'request')
115
- child.send({ signal, repeat: mode === 'request' });
116
- else
117
- child.kill(signal);
118
- }
119
- let timer;
120
- const exit = await Promise.race([closed, new Promise((_, reject) => { timer = setTimeout(() => reject(new Error(`Interrupted evaluation did not exit: ${stderr}`)), 10_000); })]).finally(() => clearTimeout(timer));
121
- assert.deepEqual(exit, { code: signal === 'SIGINT' ? 130 : 143, signal: null }, stderr);
122
- const run = join(root, 'runs/saved'), done = json(join(root, 'done.json'));
123
- assert.deepEqual(done.after, done.before, 'signal handlers must be removed after sealing');
124
- if (mode === 'preflight') {
125
- assert.equal(done.calls, 0);
126
- assert.ok(!existsSync(run));
127
- assert.match(readFileSync(join(root, 'error.txt'), 'utf8'), new RegExp(signal));
128
- for (let i = 0; i < 100 && json(ready).pids.some(running); i++)
129
- await delay(50);
130
- assert.ok(json(ready).pids.every((pid) => !running(pid)), 'preflight verifier and grandchild must stop');
131
- return { root, run, done, session: null, events: [], stderr };
132
- }
133
- if (mode === 'draft') {
134
- const session = json(join(run, '_summary.json'));
135
- assert.equal(session.status, 'stopped');
136
- assert.equal(session.callsStarted, 1);
137
- assert.equal(session.callsFinished, 1);
138
- assert.equal(session.automaticRetry, false);
139
- for (let i = 0; i < 100 && json(ready).pids.some(running); i++)
140
- await delay(50);
141
- assert.ok(json(ready).pids.every((pid) => !running(pid)), 'drafting CLI and grandchild must stop');
142
- const before = readFileSync(heartbeat, 'utf8');
143
- await delay(100);
144
- assert.equal(readFileSync(heartbeat, 'utf8'), before);
145
- return { root, run, done, session, events: [], stderr };
146
- }
147
- const session = json(join(run, '_session.json'));
148
- assert.equal(session.status, 'stopped');
149
- assert.match(session.stopReason, new RegExp(signal));
150
- const interruption = json(join(run, '_interruption.json'));
151
- assert.equal(interruption.signal, signal);
152
- assert.equal(interruption.automaticRetry, false);
153
- const index = json(join(run, '_artifacts.json'));
154
- for (const [path, sha] of Object.entries(index.files))
155
- assert.equal(sha256File(join(run, path)), sha, path);
156
- assert.ok(!existsSync(join(run, 'manifest.json')), 'an interrupted prefix must not publish a completed quality verdict');
157
- const events = readFileSync(join(run, '_calls.jsonl'), 'utf8').trim().split('\n').map(line => JSON.parse(line));
158
- assert.equal(events.filter(event => event.event === 'started').length, mode === 'judge' ? 5 : 1, 'no automatic retry, partner or extra trial');
159
- if (mode !== 'between') {
160
- for (let i = 0; i < 100 && json(ready).pids.some(running); i++)
161
- await delay(50);
162
- assert.ok(json(ready).pids.every((pid) => !running(pid)), 'fake CLI and grandchild must both stop');
163
- if (existsSync(heartbeat)) {
164
- const before = readFileSync(heartbeat, 'utf8');
165
- await delay(100);
166
- assert.equal(readFileSync(heartbeat, 'utf8'), before);
167
- }
168
- }
169
- return { root, run, done, session, events, stderr };
170
- }
171
- for (const signal of ['SIGINT', 'SIGTERM'])
172
- test(`${signal} stops the CLI process tree, retains partial usage and seals stopped records`, { timeout: 30_000 }, async (t) => {
173
- const f = await scenario(t, 'paired', signal), record = json(join(f.run, 'example-task/baseline/trial-1/_result.json'));
174
- assert.equal(record.executorInvoked, true);
175
- assert.equal(record.usageStatus, 'partial');
176
- assert.equal(record.verifierExitCode, null);
177
- assert.deepEqual(record.tokens, { input: 12, cachedInput: 7, output: 3 });
178
- assert.match(readFileSync(join(f.run, 'example-task/baseline/trial-1/_output.md'), 'utf8'), /retained partial output/);
179
- const report = await reportEvalComponent(f.run);
180
- assert.equal(report.status, 'stopped');
181
- assert.equal(report.acceptance.eligibleForUpgrade, false);
182
- assert.ok('costs' in report && 'startedAgentDispatches' in report.costs && report.costs.startedAgentDispatches === 1);
183
- if (signal === 'SIGINT') {
184
- const output = join(f.root, 'export');
185
- await exportEvaluation(f.run, output, { yes: true, log: () => { } });
186
- const replay = spawnSync(process.execPath, [join(output, 'reproduce.mjs')], { encoding: 'utf8', timeout: 20_000 });
187
- assert.equal(replay.status, 0, replay.stderr);
188
- const saved = JSON.parse(replay.stdout);
189
- assert.equal(saved.status, 'stopped');
190
- assert.equal(saved.acceptance.eligibleForUpgrade, false);
191
- assert.deepEqual(saved.costs, report.costs, 'sealed interruption costs must reproduce unchanged');
192
- }
193
- });
194
- for (const signal of ['SIGINT', 'SIGTERM'])
195
- test(`${signal} cancels offline preflight without dispatch or a misleading completed run`, { timeout: 30_000 }, async (t) => {
196
- await scenario(t, 'preflight', signal);
197
- });
198
- for (const signal of ['SIGINT', 'SIGTERM'])
199
- test(`${signal} also stops a drafting process tree and retains its partial costs`, { timeout: 30_000 }, async (t) => {
200
- const f = await scenario(t, 'draft', signal), receipt = json(join(f.run, '_result.json'));
201
- assert.deepEqual(receipt.tokens, { input: 12, cachedInput: 7, output: 3 });
202
- assert.equal(receipt.usageStatus, 'partial');
203
- assert.equal(f.session.costs.metrics.input.knownTotal, 12);
204
- assert.equal(f.session.costs.metrics.input.coverage.partial, 1);
205
- assert.ok(!existsSync(join(f.root, 'bench/verifiers/interrupted-draft.mjs')));
206
- });
207
- test('interrupting a verifier kills its tree and preserves final agent usage', { timeout: 30_000 }, async (t) => {
208
- const f = await scenario(t, 'verifier'), record = json(join(f.run, 'example-task/baseline/trial-1/_result.json'));
209
- assert.deepEqual(record.tokens, { input: 20, cachedInput: 5, output: 4 });
210
- assert.equal(record.usageStatus, 'final');
211
- assert.match(record.error, /SIGINT/);
212
- assert.equal(record.passed, false);
213
- });
214
- test('repeated interrupts keep a request stopped and never launch its partner', { timeout: 30_000 }, async (t) => {
215
- const f = await scenario(t, 'request'), result = json(join(f.root, 'component.json'));
216
- assert.equal(result.status, 'stopped');
217
- assert.equal(result.acceptance.eligibleForUpgrade, false);
218
- assert.equal(result.acceptance.automaticUpgrade, false);
219
- });
220
- test('trigger and calibration evaluations also seal an interrupted prefix', { timeout: 60_000 }, async (t) => {
221
- for (const mode of ['trigger', 'calibration']) {
222
- const f = await scenario(t, mode);
223
- const arm = mode === 'trigger' ? 'installed' : 'baseline';
224
- const record = json(join(f.run, `example-task/${arm}/trial-1/_result.json`));
225
- assert.deepEqual(record.tokens, { input: 12, cachedInput: 7, output: 3 });
226
- assert.equal(record.usageStatus, 'partial');
227
- assert.match(record.error, /SIGINT/);
228
- }
229
- });
230
- test('an interrupted judge keeps available output and does not run the reverse-order call', { timeout: 30_000 }, async (t) => {
231
- const f = await scenario(t, 'judge');
232
- const saved = json(join(f.run, '_interrupted-judge-5.json'));
233
- assert.match(saved.result.output, /retained partial output/);
234
- assert.equal(saved.result.usageStatus, 'partial');
235
- assert.deepEqual(saved.result.tokens, { input: 12, cachedInput: 7, output: 3 });
236
- });
237
- test('API interruption aborts the injected fetch and leaves unavailable usage unknown', { timeout: 30_000 }, async (t) => {
238
- const f = await scenario(t, 'api'), record = json(join(f.run, 'example-task/baseline/trial-1/_result.json'));
239
- assert.equal(readFileSync(join(f.root, 'api-aborted'), 'utf8'), 'yes');
240
- assert.equal(record.tokens, null);
241
- assert.equal(record.usageStatus, 'unknown');
242
- assert.match(record.error, /SIGINT/);
243
- });
244
- test('interrupting between calls preserves the settled receipt without dispatching another call', { timeout: 30_000 }, async (t) => {
245
- const f = await scenario(t, 'between');
246
- assert.equal(f.done.calls, 1);
247
- assert.ok(!existsSync(join(f.run, 'example-task/treatment/trial-1')));
248
- assert.deepEqual(json(join(f.run, 'example-task/baseline/trial-1/_result.json')).tokens, { input: 20, cachedInput: 5, output: 4 });
249
- });
250
- test('CLI plain and JSON errors preserve the interruption exit code instead of replacing it with 1 or 2', () => {
251
- for (const signal of ['SIGINT', 'SIGTERM'])
252
- for (const machine of [false, true]) {
253
- const args = machine ? ['eval', '--request', 'missing-offline-request.json', '--dry-run']
254
- : ['eval', 'missing-offline-skill', '--bench', 'missing-offline-bench', '--dry-run'];
255
- const script = `import{withEvaluationInterrupts}from ${moduleUrl('harness/interruption.js')};
256
- try{await withEvaluationInterrupts(async()=>{process.emit(${JSON.stringify(signal)});});}catch{}
257
- process.argv=[process.execPath,${JSON.stringify(join(dist, 'cli.js'))},...${JSON.stringify(args)}];await import(${moduleUrl('cli.js')});`;
258
- const result = spawnSync(process.execPath, ['--input-type=module', '-e', script], { encoding: 'utf8', timeout: 10_000 });
259
- assert.equal(result.status, signal === 'SIGINT' ? 130 : 143, result.stderr);
260
- if (machine)
261
- assert.equal(JSON.parse(result.stdout).kind, 'skillfit.eval-error');
262
- }
263
- });
@@ -1,382 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { spawnSync } from 'node:child_process';
3
- import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { delimiter, join } from 'node:path';
6
- import { fileURLToPath } from 'node:url';
7
- import { test } from 'node:test';
8
- import { runBenchInit } from './bench.js';
9
- import { componentError, reportEvalComponent } from './eval-component.js';
10
- import { runEval } from './eval.js';
11
- import { runEvalCli } from './eval-cli.js';
12
- import { exportEvaluation } from './eval-export.js';
13
- import { CasePreflightFailed } from './eval-preflight.js';
14
- import { MockExecutor } from '../harness/executors/mock.js';
15
- const read = (path) => JSON.parse(readFileSync(path, 'utf8'));
16
- async function setup(t, kind = 'command') {
17
- const root = mkdtempSync(join(tmpdir(), 'skillfit-preflight-'));
18
- t.after(() => rmSync(root, { recursive: true, force: true }));
19
- const bench = join(root, 'bench'), skill = join(root, 'new'), old = join(root, 'old');
20
- await runBenchInit({ dir: bench, kind, yes: true, log: () => { } });
21
- for (const [dir, version] of [[skill, 'new'], [old, 'old']]) {
22
- mkdirSync(dir);
23
- writeFileSync(join(dir, 'SKILL.md'), `---\nname: preflight-test\ndescription: Offline test.\n---\n${version}\n`);
24
- }
25
- let calls = 0, judges = 0;
26
- const mock = new MockExecutor();
27
- const executor = { describe: () => mock.describe(), run: async (...args) => { calls++; return mock.run(...args); } };
28
- const judge = { describe: () => mock.describe(), run: async () => { judges++; throw new Error('judge must not run'); } };
29
- const raw = read(join(bench, 'bench.json'));
30
- const save = () => writeFileSync(join(bench, 'bench.json'), JSON.stringify(raw));
31
- const base = { bench, skillPath: skill, trials: 1, maxCalls: 2, executor, judgeExecutor: null,
32
- runsRoot: join(root, 'runs'), runGroup: 'checked', yes: true, dryRun: false, log: () => { } };
33
- return { root, bench, skill, old, raw, save, base, judge, calls: () => calls, judges: () => judges,
34
- verifier: join(bench, 'verifiers/example-task.mjs'), oracle: join(bench, 'ground-truth/oracle-example-task.mjs') };
35
- }
36
- test('grader load/runtime/reported errors block output and command tasks without an oracle or any executor call', async (t) => {
37
- for (const kind of ['command', 'output'])
38
- for (const [name, source] of [
39
- ['syntax', 'const broken = ;'], ['runtime', 'missingGraderFunction();'],
40
- ['dependency', "import './absent-grader-dependency.mjs';"],
41
- ['reported-zero-exit', "console.log(JSON.stringify({schemaVersion:1,kind:'skillfit.verifier-error',message:'grader unavailable'}));"],
42
- ])
43
- await t.test(`${kind}: ${name}`, async (t) => {
44
- const f = await setup(t, kind);
45
- delete f.raw.tasks[0].oracle;
46
- writeFileSync(f.verifier, source);
47
- f.save();
48
- await assert.rejects(runEval(f.base), error => {
49
- assert.ok(error instanceof CasePreflightFailed);
50
- const gate = error.preflight.checks.find(c => c.code === (kind === 'command' ? 'UNTOUCHED_FIXTURE' : 'MISSING_OUTPUT'));
51
- assert.equal(gate?.status, 'FAIL');
52
- assert.match(gate.evidence.error, /VERIFIER_(RUNTIME|REPORTED)_ERROR/);
53
- assert.notEqual(gate.evidence.exitCode, null);
54
- return true;
55
- });
56
- assert.equal(f.calls(), 0);
57
- assert.equal(f.judges(), 0);
58
- assert.ok(!existsSync(f.base.runsRoot));
59
- });
60
- });
61
- test('an oracle explicitly reporting an infrastructure error cannot pass by exiting zero', async (t) => {
62
- const f = await setup(t);
63
- writeFileSync(f.oracle, "console.log(JSON.stringify({schemaVersion:1,kind:'skillfit.verifier-error',message:'reference environment unavailable'}));");
64
- await assert.rejects(runEval(f.base), error => {
65
- assert.ok(error instanceof CasePreflightFailed);
66
- const gate = error.preflight.checks.find(c => c.code === 'ORACLE');
67
- assert.equal(gate?.status, 'FAIL');
68
- assert.equal(gate.evidence.exitCode, 0);
69
- assert.match(gate.evidence.error, /VERIFIER_REPORTED_ERROR/);
70
- return true;
71
- });
72
- assert.equal(f.calls(), 0);
73
- assert.ok(!existsSync(f.base.runsRoot));
74
- });
75
- test('quoted verifier/oracle paths grade a real file repair, preserve failure/pass and replay without originals', async (t) => {
76
- const f = await setup(t);
77
- renameSync(f.verifier, join(f.bench, 'verifiers/check answer.mjs'));
78
- renameSync(f.oracle, join(f.bench, 'ground-truth/repair answer.mjs'));
79
- f.raw.tasks[0].verifier = 'node "verifiers/check answer.mjs"';
80
- f.raw.tasks[0].oracle = "node 'ground-truth/repair answer.mjs'";
81
- f.save();
82
- let calls = 0;
83
- const executor = { describe: () => ({ kind: 'mock', model: 'offline-quoted-repair' }), run: async (_p, dir) => {
84
- if (++calls === 2)
85
- writeFileSync(join(dir, 'index.js'), 'export const add = (a,b) => a+b;\n');
86
- return { output: 'done', tokens: { input: 10, cachedInput: 4, output: 2 } };
87
- } };
88
- const base = { ...f.base, executor }, preview = await runEvalCli({ ...base, dryRun: true });
89
- assert.ok('plan' in preview);
90
- const result = await runEvalCli(base, preview.plan.sha256);
91
- assert.equal(result.status, 'completed');
92
- assert.ok('quality' in result);
93
- assert.equal(result.evidence.verified, true);
94
- assert.equal(result.quality.improvedPairs, 1);
95
- assert.equal(result.quality.regressedPairs, 0);
96
- const run = join(base.runsRoot, base.runGroup);
97
- const before = read(join(run, 'example-task/baseline/trial-1/_result.json')), after = read(join(run, 'example-task/treatment/trial-1/_result.json'));
98
- assert.equal(before.error, null);
99
- assert.equal(before.passed, false);
100
- assert.equal(after.error, null);
101
- assert.equal(after.passed, true);
102
- for (const dir of [f.bench, f.skill, f.old])
103
- rmSync(dir, { recursive: true });
104
- const replay = await reportEvalComponent(run, { replay: true });
105
- assert.equal(replay.evidence.verified, true);
106
- assert.ok('costs' in replay);
107
- assert.deepEqual(replay.costs, result.costs);
108
- assert.ok('replayedDeliveries' in replay.evidence);
109
- assert.equal(replay.evidence.replayedDeliveries, 2);
110
- const output = join(f.root, 'portable');
111
- await exportEvaluation(run, output, { yes: true, log: () => { } });
112
- rmSync(run, { recursive: true });
113
- const child = spawnSync(process.execPath, [join(output, 'reproduce.mjs')], { encoding: 'utf8', timeout: 30_000 });
114
- assert.equal(child.status, 0, child.stderr);
115
- assert.equal(JSON.parse(child.stdout).evidence.verified, true);
116
- assert.deepEqual(JSON.parse(child.stdout).costs, result.costs);
117
- assert.equal(calls, 2);
118
- });
119
- test('a grader exception after an invoked repair stops a budgeted run and retains final invocation costs', async (t) => {
120
- const f = await setup(t);
121
- delete f.raw.tasks[0].oracle;
122
- f.save();
123
- writeFileSync(f.verifier, "import{readFileSync}from'node:fs';import{join}from'node:path';if(readFileSync(join(process.argv[2],'index.js'),'utf8').includes('a + b'))throw new TypeError('grader broke on repaired input');console.log(JSON.stringify({passed:false}));process.exit(1);");
124
- let calls = 0;
125
- const executor = { describe: () => ({ kind: 'mock', model: 'offline-grader-crash' }), run: async (_p, dir) => {
126
- calls++;
127
- writeFileSync(join(dir, 'index.js'), 'export const add = (a,b) => a + b;\n');
128
- return { output: 'fixed', tokens: { input: 10, cachedInput: 4, output: 2 } };
129
- } };
130
- const result = await runEvalCli({ ...f.base, executor, spendingBudget: { input: 100, cachedInput: 100, uncachedInput: 100, output: 100, durationSeconds: 100 } });
131
- assert.equal(result.status, 'stopped');
132
- assert.equal(calls, 1);
133
- assert.equal(result.acceptance.eligibleForUpgrade, false);
134
- const receipt = read(join(f.base.runsRoot, f.base.runGroup, 'example-task/baseline/trial-1/_result.json'));
135
- assert.match(receipt.error, /VERIFIER_RUNTIME_ERROR/);
136
- assert.equal(receipt.usageStatus, 'final');
137
- assert.deepEqual(receipt.tokens, { input: 10, cachedInput: 4, output: 2 });
138
- assert.ok('costs' in result);
139
- assert.equal(result.costs.populations.attempts.baseline.metrics.input.knownTotal, 10);
140
- assert.equal(result.costs.populations.attempts.baseline.metrics.input.coverage.final, 1);
141
- assert.ok(!existsSync(join(f.base.runsRoot, f.base.runGroup, 'example-task/treatment/trial-1')));
142
- });
143
- test('offline replay refuses a new verifier infrastructure error even when its nonzero exit matches the saved failure', async (t) => {
144
- const f = await setup(t), name = 'SKILLFIT_OFFLINE_VERIFIER_ERROR', previous = process.env[name];
145
- delete f.raw.tasks[0].oracle;
146
- f.save();
147
- writeFileSync(f.verifier, `if(process.env.${name})throw new Error('replay grader unavailable');console.log(JSON.stringify({passed:false}));process.exit(1);`);
148
- delete process.env[name];
149
- let calls = 0;
150
- const executor = { describe: () => ({ kind: 'mock', model: 'offline-replay-grader' }), run: async () => {
151
- calls++;
152
- return { output: 'done', tokens: { input: 10, cachedInput: 4, output: 2 } };
153
- } };
154
- try {
155
- await runEval({ ...f.base, executor });
156
- const run = join(f.base.runsRoot, f.base.runGroup), path = join(run, 'manifest.json'), original = readFileSync(path, 'utf8');
157
- const saved = await reportEvalComponent(run);
158
- assert.equal(saved.evidence.verified, true);
159
- assert.ok('costs' in saved);
160
- process.env[name] = '1';
161
- const replay = await reportEvalComponent(run, { replay: true });
162
- assert.equal(replay.evidence.verified, false);
163
- assert.ok('costs' in replay);
164
- assert.match(replay.evidence.reasons.join(' '), /Replay verifier failed: VERIFIER_RUNTIME_ERROR/);
165
- assert.equal(replay.acceptance.eligibleForUpgrade, false);
166
- assert.deepEqual(replay.costs, saved.costs);
167
- assert.equal(readFileSync(path, 'utf8'), original);
168
- assert.equal(calls, 2);
169
- }
170
- finally {
171
- if (previous === undefined)
172
- delete process.env[name];
173
- else
174
- process.env[name] = previous;
175
- }
176
- });
177
- for (const mode of ['inject', 'installed', 'trigger'])
178
- test(`${mode}: a broken NOP gate blocks all agent/judge calls before run creation`, async (t) => {
179
- const f = await setup(t);
180
- f.raw.tasks[0].shouldTrigger = true;
181
- f.save();
182
- writeFileSync(f.verifier, 'process.exit(0);');
183
- await assert.rejects(runEval({ ...f.base, mode, skillInstallDir: 'project-skills',
184
- ...(mode === 'installed' ? { baselineSkillPath: f.old } : {}),
185
- ...(mode !== 'trigger' ? { judgeExecutor: f.judge, maxCalls: 4 } : {}) }), error => {
186
- assert.ok(error instanceof CasePreflightFailed);
187
- assert.equal(error.preflight.status, 'blocked');
188
- assert.ok(error.preflight.checks.some(c => c.code === 'UNTOUCHED_FIXTURE' && c.status === 'FAIL' && c.evidence?.exitCode === 0));
189
- assert.match(error.message, /already passes/);
190
- assert.match(error.message, /Remedy:/);
191
- return true;
192
- });
193
- assert.equal(f.calls(), 0);
194
- assert.equal(f.judges(), 0);
195
- assert.ok(!existsSync(f.base.runsRoot));
196
- });
197
- test('missing/empty output, unspawnable verifiers and failed oracles are hard gates with process evidence', async (t) => {
198
- for (const issue of ['missing', 'empty', 'spawn', 'oracle-process', 'oracle-verifier'])
199
- await t.test(issue, async (t) => {
200
- const f = await setup(t, issue === 'missing' || issue === 'empty' ? 'output' : 'command');
201
- let code;
202
- if (issue === 'missing' || issue === 'empty') {
203
- delete f.raw.tasks[0].oracle;
204
- writeFileSync(f.verifier, issue === 'missing' ? 'process.exit(0);' :
205
- "import{existsSync}from'node:fs';import{join}from'node:path';process.exit(existsSync(join(process.argv[2],'_output.md'))?0:1);");
206
- code = issue === 'missing' ? 'MISSING_OUTPUT' : 'EMPTY_OUTPUT';
207
- }
208
- else if (issue === 'spawn') {
209
- f.raw.tasks[0].verifier = 'skillfit-no-such-verifier';
210
- code = 'UNTOUCHED_FIXTURE';
211
- }
212
- else {
213
- writeFileSync(f.oracle, issue === 'oracle-process' ? "console.error('reference failed');process.exit(7);" : 'process.exit(0);');
214
- code = 'ORACLE';
215
- }
216
- f.save();
217
- await assert.rejects(runEval(f.base), error => {
218
- assert.ok(error instanceof CasePreflightFailed);
219
- const check = error.preflight.checks.find(c => c.code === code && c.status === 'FAIL');
220
- assert.ok(check?.evidence);
221
- assert.ok(check.remediation);
222
- assert.equal(check.taskId, 'example-task');
223
- if (issue === 'spawn') {
224
- assert.equal(check.evidence.exitCode, null);
225
- assert.ok(check.evidence.error);
226
- }
227
- if (issue === 'oracle-process') {
228
- assert.equal(check.evidence.exitCode, 7);
229
- assert.match(check.evidence.output, /reference failed/);
230
- }
231
- assert.equal(componentError(error).error.code, 'CASE_PREFLIGHT_FAILED');
232
- return true;
233
- });
234
- assert.equal(f.calls(), 0);
235
- assert.ok(!existsSync(f.base.runsRoot));
236
- });
237
- });
238
- test('warnings and unknown coverage are distinct, nonblocking and frozen for offline reporting', async (t) => {
239
- const f = await setup(t);
240
- delete f.raw.tasks[0].oracle;
241
- f.raw.tasks[0].shouldTrigger = true;
242
- f.save();
243
- writeFileSync(join(f.bench, 'fixtures/example-task/large.txt'), 'x'.repeat(66 * 1024));
244
- const lines = [];
245
- await runEval({ ...f.base, log: line => lines.push(line) });
246
- assert.equal(f.calls(), 2);
247
- const run = join(f.base.runsRoot, f.base.runGroup), report = read(join(run, '_plan.json')).details.casePreflight;
248
- assert.equal(report.status, 'ready');
249
- assert.equal(report.summary.failures, 0);
250
- assert.ok(report.summary.warnings >= 2);
251
- assert.ok(report.summary.unknown >= 2);
252
- for (const [code, status] of [['ORACLE', 'UNKNOWN'], ['LIVE_DIFFICULTY', 'UNKNOWN'], ['FIXTURE_SIZE', 'WARN'], ['NEGATIVE_CONTROLS', 'WARN'], ['MOCK_COVERAGE', 'INFO']]) {
253
- assert.equal(report.checks.find((c) => c.code === code).status, status);
254
- }
255
- assert.equal(report.cost.modelCalls, 0);
256
- assert.ok(report.cost.durationMs >= 0);
257
- assert.match(lines.join('\n'), /\[UNKNOWN\] ORACLE/);
258
- assert.match(lines.join('\n'), /\[WARN\] FIXTURE_SIZE/);
259
- const saved = await reportEvalComponent(run, { replay: true });
260
- assert.ok('casePreflight' in saved);
261
- assert.deepEqual(saved.casePreflight, report);
262
- assert.equal(saved.acceptance.eligibleForUpgrade, false);
263
- assert.equal(f.calls(), 2);
264
- });
265
- test('only selected tasks are probed; trigger mode also skips unlabelled tasks', async (t) => {
266
- for (const trigger of [false, true])
267
- await t.test(String(trigger), async (t) => {
268
- const f = await setup(t);
269
- writeFileSync(join(f.bench, 'verifiers/unselected.mjs'), "console.log('must not be probed');process.exit(0);");
270
- f.raw.tasks.push({ ...f.raw.tasks[0], id: 'unselected', verifier: 'node verifiers/unselected.mjs' });
271
- if (trigger)
272
- f.raw.tasks[0].shouldTrigger = true;
273
- f.save();
274
- await runEval({ ...f.base, ...(trigger ? { mode: 'trigger', skillInstallDir: 'skills', maxCalls: 1,
275
- executor: { describe: () => ({ kind: 'cli', model: 'offline-trigger' }),
276
- run: async (...args) => ({ ...await f.base.executor.run(...args), skillTriggered: true }) } } : { taskIds: ['example-task'] }) });
277
- const report = read(join(f.base.runsRoot, f.base.runGroup, '_plan.json')).details.casePreflight;
278
- assert.deepEqual(report.bench.taskIds, ['example-task']);
279
- assert.ok(!report.checks.some((c) => c.taskId === 'unselected'));
280
- assert.equal(f.calls(), trigger ? 1 : 2);
281
- });
282
- });
283
- test('dry-run stays side-effect-free and declares pending preflight rather than claiming checks passed', async (t) => {
284
- const f = await setup(t), sentinel = join(f.root, 'probe-started');
285
- writeFileSync(f.verifier, `import{writeFileSync}from'node:fs';writeFileSync(${JSON.stringify(sentinel)},'unexpected');process.exit(0);`);
286
- await runEval({ ...f.base, dryRun: true, onPlan: plan => {
287
- assert.deepEqual(plan.casePreflight, { schemaVersion: 1, scope: 'offline-case-integrity', required: true, status: 'pending' });
288
- } });
289
- assert.equal(f.calls(), 0);
290
- assert.ok(!existsSync(sentinel));
291
- assert.ok(!existsSync(f.base.runsRoot));
292
- });
293
- test('missing mock coverage is unknown; malformed markers and overflowing mock probes block evaluation', async (t) => {
294
- for (const issue of ['absent', 'omitted-arm', 'malformed', 'overflow-probe'])
295
- await t.test(issue, async (t) => {
296
- const f = await setup(t, 'output'), marker = join(f.bench, 'fixtures/example-task/.skillfit-mock.json');
297
- if (issue === 'absent')
298
- rmSync(marker);
299
- else if (issue === 'omitted-arm')
300
- writeFileSync(marker, '{}');
301
- else if (issue === 'malformed')
302
- writeFileSync(marker, '{');
303
- else {
304
- const source = readFileSync(f.verifier, 'utf8');
305
- writeFileSync(f.verifier, "import{readFileSync as readProbe}from'node:fs';import{join as probePath}from'node:path';let overflow=false;try{overflow=readProbe(probePath(process.argv[2],'_output.md'),'utf8')==='overflow';}catch{}if(overflow){process.stdout.write('x'.repeat(9*1024*1024));setInterval(()=>{},1000);await new Promise(()=>{});}\n" + source);
306
- writeFileSync(marker, JSON.stringify({ baseline: { output: 'overflow' } }));
307
- }
308
- if (issue === 'malformed' || issue === 'overflow-probe') {
309
- await assert.rejects(runEval(f.base), error => {
310
- assert.ok(error instanceof CasePreflightFailed);
311
- assert.ok(error.preflight.checks.some(c => c.code === (issue === 'malformed' ? 'MOCK_MARKER' : 'MOCK_BASELINE') && c.status === 'FAIL'));
312
- return true;
313
- });
314
- assert.equal(f.calls(), 0);
315
- assert.ok(!existsSync(f.base.runsRoot));
316
- }
317
- else {
318
- await runEval(f.base);
319
- const report = read(join(f.base.runsRoot, f.base.runGroup, '_plan.json')).details.casePreflight;
320
- assert.equal(report.checks.find((c) => c.code === (issue === 'absent' ? 'MOCK_COVERAGE' : 'MOCK_BASELINE')).status, 'UNKNOWN');
321
- assert.equal(f.calls(), 2);
322
- }
323
- });
324
- });
325
- test('existing run groups are rejected before executing any offline probe or overwriting evidence', async (t) => {
326
- const f = await setup(t), run = join(f.base.runsRoot, f.base.runGroup), sentinel = join(f.root, 'probe-started');
327
- mkdirSync(run, { recursive: true });
328
- writeFileSync(join(run, 'kept'), 'original');
329
- writeFileSync(f.verifier, `import{writeFileSync}from'node:fs';writeFileSync(${JSON.stringify(sentinel)},'unexpected');process.exit(0);`);
330
- await assert.rejects(runEval(f.base), /already exists/);
331
- assert.equal(readFileSync(join(run, 'kept'), 'utf8'), 'original');
332
- assert.ok(!existsSync(sentinel));
333
- assert.equal(f.calls(), 0);
334
- });
335
- test('probe mutations of bench or either Skill cannot silently change the approved inputs', async (t) => {
336
- for (const which of ['bench', 'candidate', 'baseline'])
337
- await t.test(which, async (t) => {
338
- const f = await setup(t);
339
- const target = which === 'bench' ? join(f.bench, 'prompts/example-task.md') : join(which === 'candidate' ? f.skill : f.old, 'SKILL.md');
340
- writeFileSync(f.verifier, `import{appendFileSync}from'node:fs';appendFileSync(${JSON.stringify(target)},'changed');process.exit(1);`);
341
- delete f.raw.tasks[0].oracle;
342
- f.save();
343
- await assert.rejects(runEval({ ...f.base, mode: 'installed', baselineSkillPath: f.old, skillInstallDir: 'skills' }), error => {
344
- assert.ok(error instanceof CasePreflightFailed);
345
- assert.ok(error.preflight.checks.some(c => c.code === 'INPUT_CHANGED' && c.status === 'FAIL'));
346
- return true;
347
- });
348
- assert.equal(f.calls(), 0);
349
- assert.ok(!existsSync(f.base.runsRoot));
350
- });
351
- });
352
- test('request preflight failures produce JSON-only per-case diagnostics without starting an agent CLI', async (t) => {
353
- const f = await setup(t);
354
- writeFileSync(f.verifier, 'process.exit(0);');
355
- const cli = fileURLToPath(new URL('../cli.js', import.meta.url)), request = join(f.root, 'request.json');
356
- writeFileSync(request, JSON.stringify({ schemaVersion: 1, baselineSkill: f.old, candidateSkill: f.skill,
357
- bench: f.bench, agent: 'codex', purpose: 'development', trials: 1, maxCalls: 2, runsRoot: f.base.runsRoot, runGroup: f.base.runGroup }));
358
- // Shadow the real agent even if the gate regresses; this test cannot reach it.
359
- const bin = join(f.root, 'bin'), sentinel = join(f.root, 'fake-agent-started');
360
- mkdirSync(bin);
361
- const fake = join(bin, process.platform === 'win32' ? 'codex.cmd' : 'codex');
362
- writeFileSync(fake, process.platform === 'win32' ? `@echo offline>"${sentinel}"\r\n@exit /b 1\r\n` :
363
- `#!${process.execPath}\nimport{writeFileSync}from'node:fs';writeFileSync(${JSON.stringify(sentinel)},'unexpected');process.exit(1);\n`);
364
- chmodSync(fake, 0o755);
365
- const invoke = (args) => spawnSync(process.execPath, [cli, 'eval', '--request', request, ...args], {
366
- encoding: 'utf8', timeout: 20_000, env: { ...process.env, PATH: `${bin}${delimiter}${process.env.PATH ?? ''}` }
367
- });
368
- const preview = invoke(['--dry-run']);
369
- assert.equal(preview.status, 0, preview.stderr);
370
- const plan = JSON.parse(preview.stdout).plan;
371
- const executed = invoke(['--yes', '--plan-sha', plan.sha256]);
372
- assert.equal(executed.status, 2, executed.stderr);
373
- assert.match(executed.stderr, /Case preflight: blocked/);
374
- const result = JSON.parse(executed.stdout);
375
- assert.equal(result.error.code, 'CASE_PREFLIGHT_FAILED');
376
- assert.equal(result.casePreflight.status, 'blocked');
377
- assert.ok(result.casePreflight.checks.some((c) => c.code === 'UNTOUCHED_FIXTURE' && c.status === 'FAIL'));
378
- assert.equal(result.acceptance.eligibleForUpgrade, false);
379
- assert.equal(result.acceptance.automaticUpgrade, false);
380
- assert.ok(!existsSync(f.base.runsRoot));
381
- assert.ok(!existsSync(sentinel));
382
- });