skillfit 0.11.0 → 0.12.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.
- package/README.md +28 -5
- package/README.zh-CN.md +28 -5
- package/benches/README.md +6 -2
- package/dist/cli.js +28 -16
- package/dist/commands/bench-calibration.js +5 -1
- package/dist/commands/bench-draft.js +167 -0
- package/dist/commands/bench-draft.test.js +168 -0
- package/dist/commands/bench-manage.js +5 -4
- package/dist/commands/bench-source.js +101 -0
- package/dist/commands/bench-source.test.js +84 -0
- package/dist/commands/bench.js +165 -103
- package/dist/commands/bench.test.js +7 -3
- package/dist/commands/eval-agent-preflight.test.js +24 -0
- package/dist/commands/eval-api-failure.test.js +46 -0
- package/dist/commands/eval-cli-usage.test.js +75 -0
- package/dist/commands/eval-interruption.test.js +26 -1
- package/dist/commands/eval-layout.test.js +126 -0
- package/dist/commands/eval.js +7 -32
- package/dist/commands/npm-first-run.test.js +74 -0
- package/dist/harness/agent-preflight.js +18 -2
- package/dist/harness/bench-location.js +29 -0
- package/dist/harness/bench-location.test.js +33 -0
- package/dist/harness/bench.js +8 -3
- package/dist/harness/eval-audit.js +1 -1
- package/dist/harness/evaluation-layout.js +30 -0
- package/dist/harness/executors/api.js +20 -7
- package/dist/harness/executors/api.test.js +39 -0
- package/dist/harness/executors/cli.js +15 -25
- package/dist/harness/executors/cli.test.js +33 -2
- package/dist/harness/experiment-session.js +5 -15
- package/dist/harness/hash.js +3 -1
- package/dist/harness/runner.js +5 -4
- package/dist/harness/single-arm-audit.js +1 -1
- package/dist/harness/trigger.js +1 -1
- package/dist/harness/verifier-timeout.js +8 -0
- package/dist/harness/verifier-timeout.test.js +76 -0
- package/docs/bench-authoring.md +23 -3
- package/docs/bench-drafting.md +75 -0
- package/docs/case-management.md +12 -1
- package/docs/eval-agent-preflight.md +15 -2
- package/docs/eval-costs.md +28 -2
- package/docs/eval-planning.md +14 -0
- package/docs/evaluation-input-snapshots.md +20 -4
- package/docs/first-real-eval.md +28 -3
- package/docs/growth-roadmap-2026-10.md +23 -14
- package/docs/plans/2026-10-17-workflow-foundations.md +37 -2
- package/docs/releases/0.11.0-ci-registry-install.json +130 -0
- package/docs/releases/0.11.0-feature-smoke.json +1576 -0
- package/docs/releases/0.11.0-local-attempt-1.json +24 -0
- package/docs/releases/0.11.0-local-attempt-1.log +19 -0
- package/docs/releases/0.11.0-local-registry-install.json +25 -0
- package/docs/releases/0.11.0-registry-metadata.json +33 -0
- package/docs/releases/0.11.0-signatures.txt +12 -0
- package/docs/releases/0.11.0-verification.json +95 -0
- package/docs/releases/0.11.0.md +54 -11
- package/docs/releases/0.12.0-feature-smoke.mjs +73 -0
- package/docs/releases/0.12.0.md +68 -0
- package/docs/schemas/agent-preflight.schema.json +1 -1
- package/docs/verifier-contract.md +9 -0
- package/package.json +1 -1
- package/skills/skillfit/SKILL.md +25 -5
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
import { CliExecutor } from '../harness/executors/cli.js';
|
|
7
|
+
import { AgentPreflightFailed } from '../harness/agent-preflight.js';
|
|
8
|
+
import { runBenchInit, runBenchCalibration, prepareBenchCalibration } from './bench.js';
|
|
9
|
+
import { runEvalCli } from './eval-cli.js';
|
|
10
|
+
import { runEval } from './eval.js';
|
|
11
|
+
async function setup(t) {
|
|
12
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-cli-cost-'));
|
|
13
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
14
|
+
const skill = join(root, 'skill'), bench = join(root, 'bench'), home = join(root, 'home'), bin = join(root, 'bin');
|
|
15
|
+
for (const path of [skill, home, bin])
|
|
16
|
+
mkdirSync(path);
|
|
17
|
+
writeFileSync(join(skill, 'SKILL.md'), '---\nname: ordinary-cost\ndescription: Offline cost regression.\n---\nAnswer correctly.\n');
|
|
18
|
+
await runBenchInit({ dir: bench, yes: true, log: () => { } });
|
|
19
|
+
const limits = { input: 1000, cachedInput: 1000, uncachedInput: 1000, output: 1000, durationSeconds: 1000 };
|
|
20
|
+
const base = { skillPath: skill, bench, agent: 'codex', trials: 1, maxCalls: 4, dryRun: false, yes: true,
|
|
21
|
+
runsRoot: join(root, 'runs'), runGroup: 'ordinary', spendingBudget: limits, log: () => { },
|
|
22
|
+
sessionOptions: { homeDir: home, env: { PATH: bin }, versionProbe: () => { throw new Error('No real CLI probe allowed.'); } } };
|
|
23
|
+
return { root, skill, bench, home, bin, base, limits };
|
|
24
|
+
}
|
|
25
|
+
test('ordinary paired CLI and judge streams retain full costs and finish within a strict budget', async (t) => {
|
|
26
|
+
const f = await setup(t);
|
|
27
|
+
function executor(name, answer, input, cached, output) {
|
|
28
|
+
const script = join(f.root, name + '.cjs');
|
|
29
|
+
writeFileSync(script, `process.stdin.resume();process.stdin.on('end',()=>{console.log(JSON.stringify({type:'item.completed',item:{type:'agent_message',text:${JSON.stringify(answer)}}}));console.log(JSON.stringify({type:'turn.completed',usage:{input_tokens:${input},cached_input_tokens:${cached},output_tokens:${output}}}));});`);
|
|
30
|
+
return new CliExecutor({ argv: [process.execPath, script], shell: false, streamJson: true });
|
|
31
|
+
}
|
|
32
|
+
const primary = executor('primary', 'skillfit-ok', 10, 4, 2);
|
|
33
|
+
const judge = executor('judge', '{"A":{"correct":true,"complete":true,"grounded":true},"B":{"correct":true,"complete":true,"grounded":true}}', 5, 2, 1);
|
|
34
|
+
const base = { ...f.base, executor: primary, judgeExecutor: judge,
|
|
35
|
+
sessionOptions: { ...f.base.sessionOptions, versionProbe: () => 'synthetic offline CLI' } };
|
|
36
|
+
const preview = await runEvalCli({ ...base, dryRun: true });
|
|
37
|
+
const result = await runEvalCli(base, preview.plan.sha256);
|
|
38
|
+
assert.equal(result.status, 'completed', 'executionError' in result ? String(result.executionError) : '');
|
|
39
|
+
assert.ok('invocationCosts' in result);
|
|
40
|
+
assert.equal(result.evidence.verified, true);
|
|
41
|
+
assert.equal(result.invocationCosts?.agent?.runs, 2);
|
|
42
|
+
assert.equal(result.invocationCosts?.judge?.runs, 2);
|
|
43
|
+
assert.equal(result.invocationCosts?.total?.metrics.input.knownTotal, 30);
|
|
44
|
+
assert.equal(result.invocationCosts?.total?.metrics.cachedInput.knownTotal, 12);
|
|
45
|
+
assert.equal(result.invocationCosts?.total?.metrics.output.knownTotal, 6);
|
|
46
|
+
assert.equal(result.invocationCosts?.total?.metrics.input.coverage.final, 4);
|
|
47
|
+
const receipt = JSON.parse(readFileSync(join(f.base.runsRoot, 'ordinary/example-task/baseline/trial-1/_result.json'), 'utf8'));
|
|
48
|
+
assert.equal(readFileSync(join(f.base.runsRoot, 'ordinary/example-task/baseline/trial-1/_output.md'), 'utf8'), 'skillfit-ok');
|
|
49
|
+
assert.equal(receipt.skillTriggered, undefined);
|
|
50
|
+
assert.deepEqual(receipt.tokens, { input: 10, cachedInput: 4, output: 2 });
|
|
51
|
+
assert.match(readFileSync(join(f.base.runsRoot, 'ordinary/example-task/baseline/trial-1/_transcript.jsonl'), 'utf8'), /turn.completed/);
|
|
52
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
53
|
+
});
|
|
54
|
+
test('known missing CLI counters block primary, judge and calibration before probes or spending', async (t) => {
|
|
55
|
+
const f = await setup(t), sentinel = join(f.root, 'must-not-run');
|
|
56
|
+
writeFileSync(join(f.bench, 'verifiers/example-task.mjs'), `import{writeFileSync}from'node:fs';writeFileSync(${JSON.stringify(sentinel)},'called');process.exit(1);`);
|
|
57
|
+
for (const name of ['claude', 'codex']) {
|
|
58
|
+
const executable = join(f.bin, name + (process.platform === 'win32' ? '.CMD' : ''));
|
|
59
|
+
writeFileSync(executable, 'A synthetic availability marker, never executed.');
|
|
60
|
+
chmodSync(executable, 0o755);
|
|
61
|
+
}
|
|
62
|
+
const primary = { ...f.base, agent: 'claude-code', judgeExecutor: null };
|
|
63
|
+
const preview = await runEvalCli({ ...primary, dryRun: true });
|
|
64
|
+
assert.equal(preview.plan.evaluation.agentPreflight.status, 'blocked');
|
|
65
|
+
assert.equal(preview.plan.evaluation.agentPreflight.checks.find(c => c.code === 'CLI_AVAILABLE').status, 'PASS');
|
|
66
|
+
await assert.rejects(runEval(primary), AgentPreflightFailed);
|
|
67
|
+
await assert.rejects(runEval({ ...f.base, judgeAgent: 'claude-code' }), AgentPreflightFailed);
|
|
68
|
+
const calibrate = { agent: 'claude-code', trials: 1, spendingBudget: f.limits, runsRoot: f.base.runsRoot,
|
|
69
|
+
runGroup: 'calibration', sessionOptions: f.base.sessionOptions };
|
|
70
|
+
const calibration = prepareBenchCalibration({ dir: f.bench, calibrate });
|
|
71
|
+
assert.equal(calibration.agentPreflight.checks.find(c => c.code === 'USAGE_CAPABILITY').status, 'FAIL');
|
|
72
|
+
await assert.rejects(runBenchCalibration({ dir: f.bench, calibrate, log: () => { } }), AgentPreflightFailed);
|
|
73
|
+
assert.equal(existsSync(sentinel), false);
|
|
74
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
75
|
+
});
|
|
@@ -44,6 +44,7 @@ async function scenario(t, mode, signal = 'SIGINT') {
|
|
|
44
44
|
rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
45
45
|
});
|
|
46
46
|
const bench = join(root, 'bench'), skill = join(root, 'skill'), old = join(root, 'old');
|
|
47
|
+
writeFileSync(join(root, 'draft-source.txt'), 'synthetic offline fixture');
|
|
47
48
|
await runBenchInit({ dir: bench, yes: true, log: () => { } });
|
|
48
49
|
for (const [dir, version] of [[skill, 'new'], [old, 'old']]) {
|
|
49
50
|
mkdirSync(dir);
|
|
@@ -79,7 +80,7 @@ setTimeout(()=>process.exit(),30000);`;
|
|
|
79
80
|
const harness = join(root, 'harness.mjs');
|
|
80
81
|
writeFileSync(harness, `import{writeFileSync}from'node:fs';
|
|
81
82
|
import{runEval}from ${moduleUrl('commands/eval.js')};
|
|
82
|
-
import{runBenchCheck}from ${moduleUrl('commands/bench.js')};
|
|
83
|
+
import{runBenchCheck,runBenchAdd}from ${moduleUrl('commands/bench.js')};
|
|
83
84
|
import{runEvalComponent}from ${moduleUrl('commands/eval-component.js')};
|
|
84
85
|
import{CliExecutor}from ${moduleUrl('harness/executors/cli.js')};
|
|
85
86
|
import{ApiExecutor}from ${moduleUrl('harness/executors/api.js')};
|
|
@@ -92,6 +93,7 @@ const api=new ApiExecutor({apiKey:'offline-only',fetchImpl:async(_url,options)=>
|
|
|
92
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');}};
|
|
93
94
|
try{
|
|
94
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:()=>{}});
|
|
95
97
|
else if(mode==='calibration')await runBenchCheck({dir:base.bench,log:()=>{},calibrate:{executor:fake,trials:2,maxCalls:2,runsRoot:base.runsRoot,runGroup:base.runGroup}});
|
|
96
98
|
else await runEval({...base,...(mode==='trigger'?{mode:'trigger',skillInstallDir:'skills'}:{}),...(mode==='judge'?{maxCalls:8}:{})});
|
|
97
99
|
}catch(error){writeFileSync(root+'/error.txt',error.message);}
|
|
@@ -128,6 +130,20 @@ finally{writeFileSync(root+'/done.json',JSON.stringify({before,after:counts(),ca
|
|
|
128
130
|
assert.ok(json(ready).pids.every((pid) => !running(pid)), 'preflight verifier and grandchild must stop');
|
|
129
131
|
return { root, run, done, session: null, events: [], stderr };
|
|
130
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
|
+
}
|
|
131
147
|
const session = json(join(run, '_session.json'));
|
|
132
148
|
assert.equal(session.status, 'stopped');
|
|
133
149
|
assert.match(session.stopReason, new RegExp(signal));
|
|
@@ -179,6 +195,15 @@ for (const signal of ['SIGINT', 'SIGTERM'])
|
|
|
179
195
|
test(`${signal} cancels offline preflight without dispatch or a misleading completed run`, { timeout: 30_000 }, async (t) => {
|
|
180
196
|
await scenario(t, 'preflight', signal);
|
|
181
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
|
+
});
|
|
182
207
|
test('interrupting a verifier kills its tree and preserves final agent usage', { timeout: 30_000 }, async (t) => {
|
|
183
208
|
const f = await scenario(t, 'verifier'), record = json(join(f.run, 'example-task/baseline/trial-1/_result.json'));
|
|
184
209
|
assert.deepEqual(record.tokens, { input: 20, cachedInput: 5, output: 4 });
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, symlinkSync, 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 { runBenchInit, runBenchCalibration, prepareBenchCalibration } from './bench.js';
|
|
9
|
+
import { runEval } from './eval.js';
|
|
10
|
+
import { runEvalCli } from './eval-cli.js';
|
|
11
|
+
import { readEvaluationReport } from './evaluation-report.js';
|
|
12
|
+
import { exportEvaluation } from './eval-export.js';
|
|
13
|
+
import { loadBench } from '../harness/bench.js';
|
|
14
|
+
import { hashFileSet, listFilesRecursive } from '../harness/hash.js';
|
|
15
|
+
import { assertEvaluationOutputLayout } from '../harness/evaluation-layout.js';
|
|
16
|
+
async function fixture(t) {
|
|
17
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-layout-'));
|
|
18
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
19
|
+
const bench = join(root, 'bench'), skill = join(root, 'skill'), old = join(root, 'old'), home = join(root, 'home');
|
|
20
|
+
await runBenchInit({ dir: bench, yes: true, log: () => { } });
|
|
21
|
+
for (const [dir, body] of [[skill, 'new'], [old, 'old']]) {
|
|
22
|
+
mkdirSync(dir);
|
|
23
|
+
writeFileSync(join(dir, 'SKILL.md'), `---\nname: layout-skill\ndescription: Offline layout regression.\n---\n${body}\n`);
|
|
24
|
+
}
|
|
25
|
+
mkdirSync(home);
|
|
26
|
+
const definition = JSON.parse(readFileSync(join(bench, 'bench.json'), 'utf8'));
|
|
27
|
+
definition.tasks[0].shouldTrigger = true;
|
|
28
|
+
writeFileSync(join(bench, 'bench.json'), JSON.stringify(definition));
|
|
29
|
+
let calls = 0;
|
|
30
|
+
const base = { skillPath: skill, bench, agent: 'codex', trials: 1, maxCalls: 2, dryRun: false, yes: true,
|
|
31
|
+
runsRoot: join(root, 'runs'), runGroup: 'study', judgeExecutor: null, log: () => { },
|
|
32
|
+
sessionOptions: { homeDir: home, env: {}, versionProbe: () => null },
|
|
33
|
+
executor: { describe: () => ({ kind: 'cli', model: 'offline-layout', detail: 'Injected offline test executor.' }), run: async () => {
|
|
34
|
+
calls++;
|
|
35
|
+
return { output: 'skillfit-ok', skillTriggered: true, tokens: { input: 10, cachedInput: 2, output: 3 } };
|
|
36
|
+
} } };
|
|
37
|
+
return { root, bench, skill, old, base, calls: () => calls };
|
|
38
|
+
}
|
|
39
|
+
test('bench Git directories/worktree files do not change input hashes; real task bytes still do', async (t) => {
|
|
40
|
+
const f = await fixture(t), original = loadBench(f.bench).contentSha256;
|
|
41
|
+
assert.equal(original, hashFileSet(f.bench, listFilesRecursive(f.bench)), 'Git-free fingerprints keep their previous meaning.');
|
|
42
|
+
mkdirSync(join(f.bench, '.git'));
|
|
43
|
+
writeFileSync(join(f.bench, '.git', 'HEAD'), 'ref: refs/heads/main\n');
|
|
44
|
+
const nested = join(f.bench, 'fixtures', 'example-task', '.git');
|
|
45
|
+
writeFileSync(nested, 'gitdir: /unread-worktree-metadata\n');
|
|
46
|
+
assert.equal(loadBench(f.bench).contentSha256, original);
|
|
47
|
+
writeFileSync(join(f.bench, '.git', 'HEAD'), 'ref: refs/heads/other\n');
|
|
48
|
+
assert.equal(loadBench(f.bench).contentSha256, original);
|
|
49
|
+
rmSync(join(f.bench, '.git'), { recursive: true });
|
|
50
|
+
writeFileSync(join(f.bench, '.git'), 'gitdir: /unread-worktree-metadata\n');
|
|
51
|
+
assert.equal(loadBench(f.bench).contentSha256, original);
|
|
52
|
+
writeFileSync(join(f.bench, 'prompts', 'example-task.md'), 'Changed actual task.');
|
|
53
|
+
assert.notEqual(loadBench(f.bench).contentSha256, original);
|
|
54
|
+
const definition = JSON.parse(readFileSync(join(f.bench, 'bench.json'), 'utf8'));
|
|
55
|
+
definition.tasks[0].prompt = '.git';
|
|
56
|
+
writeFileSync(join(f.bench, 'bench.json'), JSON.stringify(definition));
|
|
57
|
+
assert.throws(() => loadBench(f.bench), /cannot reference Git metadata/);
|
|
58
|
+
});
|
|
59
|
+
for (const mode of ['inject', 'installed', 'trigger', 'calibration'])
|
|
60
|
+
test(`${mode}: Git-root benches seal and audit without Git data`, async (t) => {
|
|
61
|
+
const f = await fixture(t);
|
|
62
|
+
mkdirSync(join(f.bench, '.git'));
|
|
63
|
+
writeFileSync(join(f.bench, '.git', 'HEAD'), 'metadata before preview');
|
|
64
|
+
const group = join(f.base.runsRoot, f.base.runGroup);
|
|
65
|
+
if (mode === 'calibration') {
|
|
66
|
+
const calibrate = { executor: f.base.executor, trials: 1, maxCalls: 1, runsRoot: f.base.runsRoot, runGroup: f.base.runGroup };
|
|
67
|
+
const preview = prepareBenchCalibration({ dir: f.bench, calibrate });
|
|
68
|
+
writeFileSync(join(f.bench, '.git', 'HEAD'), 'metadata after preview');
|
|
69
|
+
assert.equal(prepareBenchCalibration({ dir: f.bench, calibrate }).planSha256, preview.planSha256);
|
|
70
|
+
await runBenchCalibration({ dir: f.bench, calibrate: { ...calibrate, reviewedPlanSha256: preview.planSha256 }, log: () => { } });
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const base = { ...f.base, mode, ...(mode === 'installed' ? { baselineSkillPath: f.old } : {}) };
|
|
74
|
+
const preview = await runEvalCli({ ...base, dryRun: true });
|
|
75
|
+
writeFileSync(join(f.bench, '.git', 'HEAD'), 'metadata after preview');
|
|
76
|
+
assert.equal((await runEvalCli({ ...base, dryRun: true })).plan.sha256, preview.plan.sha256);
|
|
77
|
+
const executed = await runEvalCli(base, preview.plan.sha256);
|
|
78
|
+
assert.equal(executed.status, 'completed', 'executionError' in executed ? String(executed.executionError) : 'Expected a completed offline run.');
|
|
79
|
+
}
|
|
80
|
+
assert.equal(existsSync(join(group, '_inputs', 'bench', '.git')), false);
|
|
81
|
+
const report = await readEvaluationReport(group, { replay: true });
|
|
82
|
+
assert.equal(report.status, 'completed', readFileSync(join(group, '_session.json'), 'utf8'));
|
|
83
|
+
assert.equal(report.evidence.verified, true, report.evidence.reasons.join('; '));
|
|
84
|
+
const calls = f.calls();
|
|
85
|
+
assert.equal(calls, mode === 'calibration' || mode === 'trigger' ? 1 : 2);
|
|
86
|
+
if (mode === 'inject') {
|
|
87
|
+
const portable = join(f.root, 'portable');
|
|
88
|
+
await exportEvaluation(group, portable, { yes: true, log: () => { } });
|
|
89
|
+
const moved = join(f.root, 'moved');
|
|
90
|
+
renameSync(portable, moved);
|
|
91
|
+
rmSync(f.bench, { recursive: true });
|
|
92
|
+
rmSync(f.skill, { recursive: true });
|
|
93
|
+
rmSync(group, { recursive: true });
|
|
94
|
+
const replay = spawnSync(process.execPath, [join(moved, 'reproduce.mjs')], { encoding: 'utf8', timeout: 30_000, maxBuffer: 8 * 1024 * 1024 });
|
|
95
|
+
assert.equal(replay.status, 0, replay.stderr);
|
|
96
|
+
assert.equal(JSON.parse(replay.stdout).evidence.verified, true);
|
|
97
|
+
assert.equal(f.calls(), calls);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
test('every preview rejects output inside inputs before probes, calls or directories, including aliases', async (t) => {
|
|
101
|
+
const f = await fixture(t), marker = join(f.root, 'verifier-ran');
|
|
102
|
+
writeFileSync(join(f.bench, 'verifiers', 'example-task.mjs'), `import{writeFileSync}from'node:fs';writeFileSync(${JSON.stringify(marker)},'probed');process.exit(1);`);
|
|
103
|
+
const alias = join(f.root, 'bench-alias');
|
|
104
|
+
symlinkSync(f.bench, alias, process.platform === 'win32' ? 'junction' : 'dir');
|
|
105
|
+
const roots = [join(f.bench, 'runs'), join(f.bench, 'fixtures', 'example-task', 'runs'), join(f.skill, 'runs'), join(alias, 'new', 'runs'), join(f.root, '.git', 'runs')];
|
|
106
|
+
for (const mode of ['inject', 'installed', 'trigger']) {
|
|
107
|
+
for (const runsRoot of [...roots, ...(mode === 'installed' ? [join(f.old, 'runs')] : [])]) {
|
|
108
|
+
await assert.rejects(runEvalCli({ ...f.base, mode, runsRoot, dryRun: true,
|
|
109
|
+
...(mode === 'installed' ? { baselineSkillPath: f.old } : {}) }), /output must be outside/);
|
|
110
|
+
assert.equal(existsSync(join(runsRoot, 'study')), false);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const runsRoot of [roots[0], roots[3], roots[4]])
|
|
114
|
+
assert.throws(() => prepareBenchCalibration({ dir: f.bench,
|
|
115
|
+
calibrate: { executor: f.base.executor, trials: 1, runsRoot, runGroup: 'study' } }), /output must be outside/);
|
|
116
|
+
await assert.rejects(runEval({ ...f.base, runsRoot: roots[0] }), /output must be outside/);
|
|
117
|
+
assert.equal(existsSync(marker), false);
|
|
118
|
+
assert.equal(f.calls(), 0);
|
|
119
|
+
assert.throws(() => assertEvaluationOutputLayout(fileURLToPath(new URL('../not-created', import.meta.url)), { benchDir: f.bench }), /output must be outside/);
|
|
120
|
+
const cli = spawnSync(process.execPath, [fileURLToPath(new URL('../cli.js', import.meta.url)), 'eval', f.skill,
|
|
121
|
+
'--bench', f.bench, '--agent', 'codex', '--runs-root', roots[0], '--run-group', 'study', '--dry-run', '--json'], { encoding: 'utf8', env: { PATH: '' } });
|
|
122
|
+
assert.equal(cli.status, 2);
|
|
123
|
+
assert.equal(JSON.parse(cli.stdout).kind, 'skillfit.eval-error');
|
|
124
|
+
assert.equal(existsSync(marker), false);
|
|
125
|
+
assert.equal(f.calls(), 0);
|
|
126
|
+
});
|
package/dist/commands/eval.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { existsSync,
|
|
1
|
+
import { existsSync, statSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
4
|
import { getAgent } from '../agents.js';
|
|
6
5
|
import { loadBench, selectBenchTasks } from '../harness/bench.js';
|
|
6
|
+
import { resolveBenchDir } from '../harness/bench-location.js';
|
|
7
7
|
import { RUN_GROUP_PATTERN } from '../harness/constants.js';
|
|
8
8
|
import { ExperimentSession, validateCallBudget } from '../harness/experiment-session.js';
|
|
9
9
|
import { ApiExecutor, DEFAULT_API_TIMEOUT_MS } from '../harness/executors/api.js';
|
|
@@ -23,38 +23,9 @@ import { parseSpendingBudget } from '../harness/eval-budget.js';
|
|
|
23
23
|
import { withEvaluationInterrupts, throwIfEvaluationInterrupted } from '../harness/interruption.js';
|
|
24
24
|
import { CASE_PREFLIGHT_POLICY, checkEvalCases } from './eval-preflight.js';
|
|
25
25
|
import { INPUT_SNAPSHOT_POLICY } from '../harness/input-snapshot.js';
|
|
26
|
+
import { assertEvaluationOutputLayout } from '../harness/evaluation-layout.js';
|
|
26
27
|
import { inspectAgentEnvironment, assertAgentEnvironment, assertAgentEnvironmentUnchanged, renderAgentEnvironment } from '../harness/agent-preflight.js';
|
|
27
28
|
export const DEFAULT_EVAL_TRIALS = 5;
|
|
28
|
-
function bundledBenchesRoot() {
|
|
29
|
-
return fileURLToPath(new URL('../../benches', import.meta.url));
|
|
30
|
-
}
|
|
31
|
-
function resolveBenchDir(bench) {
|
|
32
|
-
const root = bundledBenchesRoot();
|
|
33
|
-
const candidates = existsSync(root)
|
|
34
|
-
? readdirSync(root)
|
|
35
|
-
.map((entry) => join(root, entry))
|
|
36
|
-
.filter((dir) => statSync(dir).isDirectory() && existsSync(join(dir, 'bench.json')))
|
|
37
|
-
: [];
|
|
38
|
-
if (bench) {
|
|
39
|
-
const dir = resolve(bench);
|
|
40
|
-
if (existsSync(join(dir, 'bench.json'))) {
|
|
41
|
-
return dir;
|
|
42
|
-
}
|
|
43
|
-
const byName = candidates.find((candidate) => candidate.split(/[\\/]/).pop() === bench);
|
|
44
|
-
if (byName) {
|
|
45
|
-
return byName;
|
|
46
|
-
}
|
|
47
|
-
throw new Error(`Not a bench directory (missing bench.json): ${dir}`);
|
|
48
|
-
}
|
|
49
|
-
if (candidates.length === 1 && candidates[0]) {
|
|
50
|
-
return candidates[0];
|
|
51
|
-
}
|
|
52
|
-
if (candidates.length === 0) {
|
|
53
|
-
throw new Error(`No bundled benches found under ${root}; pass --bench <path>`);
|
|
54
|
-
}
|
|
55
|
-
const names = candidates.map((dir) => ` --bench ${dir.split(/[\\/]/).pop() ?? dir}`).join('\n');
|
|
56
|
-
throw new Error(`More than one bundled bench is available; pick one explicitly:\n${names}`);
|
|
57
|
-
}
|
|
58
29
|
function resolveExecutor(agent, target, installed = false, executorTimeoutSeconds) {
|
|
59
30
|
if (agent) {
|
|
60
31
|
const definition = getAgent(agent);
|
|
@@ -113,6 +84,7 @@ function inspectEvalAgent(options, target, executor, judge, capabilityError, res
|
|
|
113
84
|
roles.push({ role: 'judge', definition: options.judgeAgent ? getAgent(options.judgeAgent) : undefined,
|
|
114
85
|
executor: judge?.describe() ?? null, injected: options.judgeExecutor != null, resolutionError: judgeError });
|
|
115
86
|
return inspectAgentEnvironment({ roles, mode: options.mode ?? 'inject', target, capabilityError,
|
|
87
|
+
spendingBudget: options.spendingBudget !== undefined,
|
|
116
88
|
homeDir: options.sessionOptions?.homeDir, env: options.sessionOptions?.env });
|
|
117
89
|
}
|
|
118
90
|
function sessionFor(options, bench, target, trials, runsRoot, runGroup, armNames, plannedCalls, details, baselineTarget) {
|
|
@@ -242,6 +214,7 @@ async function runEvalTrigger(options, bench, skill, trials, log) {
|
|
|
242
214
|
const agentPreflight = inspect();
|
|
243
215
|
if (!RUN_GROUP_PATTERN.test(runGroup))
|
|
244
216
|
throw new Error(`Invalid run group: ${runGroup}`);
|
|
217
|
+
assertEvaluationOutputLayout(join(runsRoot, runGroup), { benchDir: bench.dir, targetDirs: [skill.sourceDir] });
|
|
245
218
|
const competitors = options.competeInstalled && options.agent
|
|
246
219
|
? installedUserSkills(getAgent(options.agent), options.sessionOptions?.homeDir ?? homedir(), options.sessionOptions?.env ?? process.env)
|
|
247
220
|
.filter((entry) => entry.name !== skill.name)
|
|
@@ -445,6 +418,8 @@ export async function runEval(options) {
|
|
|
445
418
|
const pairOrder = parsePairOrder(options.pairOrder);
|
|
446
419
|
if (!RUN_GROUP_PATTERN.test(runGroup))
|
|
447
420
|
throw new Error(`Invalid run group: ${runGroup}`);
|
|
421
|
+
assertEvaluationOutputLayout(join(runsRoot, runGroup), { benchDir: bench.dir,
|
|
422
|
+
targetDirs: [target.sourceDir, ...(baselineTarget ? [baselineTarget.sourceDir] : [])] });
|
|
448
423
|
options.onPlan?.({
|
|
449
424
|
mode: installed ? 'installed' : 'inject',
|
|
450
425
|
agentPreflight,
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, 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
|
+
const pkg = fileURLToPath(new URL('../..', import.meta.url)), cli = join(pkg, 'dist/cli.js');
|
|
9
|
+
function setup(t) {
|
|
10
|
+
const cwd = realpathSync(mkdtempSync(join(tmpdir(), 'skillfit-first-run-')));
|
|
11
|
+
t.after(() => rmSync(cwd, { recursive: true, force: true }));
|
|
12
|
+
const skill = join(cwd, 'my-skill');
|
|
13
|
+
mkdirSync(skill);
|
|
14
|
+
writeFileSync(join(skill, 'SKILL.md'), '---\nname: npm-first-run-offline\ndescription: Offline first-run regression.\n---\nInspect files.\n');
|
|
15
|
+
const invoke = (args, expected = 0, pure = false) => {
|
|
16
|
+
const result = spawnSync(process.execPath, [cli, ...args], { cwd, encoding: 'utf8', timeout: 30_000,
|
|
17
|
+
env: pure ? { PATH: '' } : { ...process.env, SKILLFIT_JUDGE: '0' } });
|
|
18
|
+
assert.equal(result.status, expected, result.stderr || result.stdout);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
return { cwd, skill, invoke };
|
|
22
|
+
}
|
|
23
|
+
test('installed-CLI onboarding works from an empty project without a source checkout or agent', t => {
|
|
24
|
+
const f = setup(t);
|
|
25
|
+
f.invoke(['bench', 'init', 'my-bench', '--kind', 'command', '--dry-run']);
|
|
26
|
+
assert.equal(existsSync(join(f.cwd, 'my-bench')), false);
|
|
27
|
+
f.invoke(['bench', 'init', 'my-bench', '--kind', 'command', '--yes']);
|
|
28
|
+
const checked = JSON.parse(f.invoke(['bench', 'check', './my-bench', '--json']).stdout);
|
|
29
|
+
assert.equal(checked.status, 'passed');
|
|
30
|
+
assert.equal(checked.summary.failures, 0);
|
|
31
|
+
const result = JSON.parse(f.invoke(['eval', f.skill, '--bench', './my-bench', '--mode', 'installed', '--agent', 'codex',
|
|
32
|
+
'--trials', '1', '--max-calls', '2', '--runs-root', './runs', '--run-group', 'first-eval', '--json', '--dry-run'], 0, true).stdout);
|
|
33
|
+
assert.equal(result.status, 'planned');
|
|
34
|
+
assert.equal(result.plan.evaluation.plannedCalls, 2);
|
|
35
|
+
assert.equal(result.plan.evaluation.agentPreflight.status, 'blocked');
|
|
36
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
37
|
+
assert.equal(existsSync(join(f.cwd, 'runs')), false);
|
|
38
|
+
});
|
|
39
|
+
test('bundled names work in read-only commands and calibration preview without mutating the package', t => {
|
|
40
|
+
const f = setup(t), manifest = join(pkg, 'benches/code-review/bench.json'), original = readFileSync(manifest, 'utf8');
|
|
41
|
+
const checked = JSON.parse(f.invoke(['bench', 'check', 'code-review', '--json']).stdout);
|
|
42
|
+
assert.equal(checked.status, 'passed');
|
|
43
|
+
assert.equal(checked.bench.taskCount, 5);
|
|
44
|
+
const listed = JSON.parse(f.invoke(['bench', 'list', 'code-review', '--json'], 0, true).stdout);
|
|
45
|
+
const shown = JSON.parse(f.invoke(['bench', 'show', 'code-review', 'review-r1', '--json'], 0, true).stdout);
|
|
46
|
+
assert.equal(listed.tasks.length, 5);
|
|
47
|
+
assert.equal(shown.tasks[0].id, 'review-r1');
|
|
48
|
+
const preview = JSON.parse(f.invoke(['eval', f.skill, '--bench', 'code-review', '--agent', 'codex', '--trials', '1', '--json', '--dry-run'], 0, true).stdout);
|
|
49
|
+
assert.equal(preview.plan.evaluation.bench.sha256, checked.bench.sha256);
|
|
50
|
+
const calibration = JSON.parse(f.invoke(['bench', 'check', 'code-review', '--calibrate', '--agent', 'codex', '--trials', '1',
|
|
51
|
+
'--runs-root', './runs', '--run-group', 'calibration', '--json', '--dry-run'], 0, true).stdout);
|
|
52
|
+
assert.equal(calibration.plan.bench.sha256, checked.bench.sha256);
|
|
53
|
+
assert.equal(calibration.plan.plannedCalls, 5);
|
|
54
|
+
const edit = f.invoke(['bench', 'edit', 'code-review', 'review-r1', '--set', 'shouldTrigger=false', '--yes', '--json'], 2, true);
|
|
55
|
+
assert.equal(JSON.parse(edit.stdout).kind, 'skillfit.bench-error');
|
|
56
|
+
assert.equal(readFileSync(manifest, 'utf8'), original);
|
|
57
|
+
assert.equal(existsSync(join(f.cwd, 'runs')), false);
|
|
58
|
+
});
|
|
59
|
+
test('local names take precedence and broken local inputs cannot fall back to bundled cases', t => {
|
|
60
|
+
const f = setup(t);
|
|
61
|
+
f.invoke(['bench', 'init', 'code-review', '--kind', 'command', '--yes']);
|
|
62
|
+
const local = JSON.parse(f.invoke(['bench', 'check', 'code-review', '--json']).stdout);
|
|
63
|
+
assert.equal(local.status, 'passed');
|
|
64
|
+
assert.equal(local.bench.taskCount, 1);
|
|
65
|
+
assert.equal(local.dir, join(f.cwd, 'code-review'));
|
|
66
|
+
writeFileSync(join(f.cwd, 'code-review/bench.json'), '{invalid local data');
|
|
67
|
+
const failed = JSON.parse(f.invoke(['bench', 'check', 'code-review', '--json'], 1).stdout);
|
|
68
|
+
assert.equal(failed.status, 'failed');
|
|
69
|
+
assert.equal(failed.dir, join(f.cwd, 'code-review'));
|
|
70
|
+
assert.match(failed.checks[0].message, /Invalid bench.json/);
|
|
71
|
+
mkdirSync(join(f.cwd, 'debugging'));
|
|
72
|
+
const missing = JSON.parse(f.invoke(['bench', 'check', 'debugging', '--json'], 1).stdout);
|
|
73
|
+
assert.match(missing.checks[0].message, /missing bench.json/);
|
|
74
|
+
});
|
|
@@ -40,6 +40,10 @@ function report(checks) {
|
|
|
40
40
|
summary: { failures: count('FAIL'), passed: count('PASS'), unknown: count('UNKNOWN'), info: count('INFO') },
|
|
41
41
|
cost: { modelCalls: 0, cliInvocations: 0 } };
|
|
42
42
|
}
|
|
43
|
+
export function agentTokenCounters(agent) {
|
|
44
|
+
return agent.headless.streamJson?.wireShape === 'codex-items'
|
|
45
|
+
? ['input', 'cachedInput', 'output'] : agent.headless.usageFromSessionLog ? ['input', 'output'] : [];
|
|
46
|
+
}
|
|
43
47
|
export function inspectAgentEnvironment(options) {
|
|
44
48
|
const checks = [], env = options.env ?? process.env;
|
|
45
49
|
const home = options.homeDir ?? homedir();
|
|
@@ -55,8 +59,8 @@ export function inspectAgentEnvironment(options) {
|
|
|
55
59
|
for (const role of options.roles) {
|
|
56
60
|
const agent = role.definition;
|
|
57
61
|
const add = (code, status, message, remediation = null, paths = []) => checks.push({ code, status, message, remediation, paths, role: role.role, agent: agent?.id ?? null });
|
|
58
|
-
const
|
|
59
|
-
const argv =
|
|
62
|
+
const trigger = role.role === 'agent' && options.mode === 'trigger';
|
|
63
|
+
const argv = trigger ? agent?.headless.streamJson?.argv : agent?.headless.streamJson?.argv ?? agent?.headless.argv;
|
|
60
64
|
const binary = argv?.[0] ?? agent?.headless.argv[0] ?? agent?.detect.binaries[0];
|
|
61
65
|
if (role.injected)
|
|
62
66
|
add('EXECUTOR_INJECTED', 'UNKNOWN', 'Injected executor: installed CLI availability and runtime capabilities are not attested.');
|
|
@@ -78,6 +82,18 @@ export function inspectAgentEnvironment(options) {
|
|
|
78
82
|
error = 'No executor available; pass --agent or set SKILLFIT_API_KEY.';
|
|
79
83
|
add('MATRIX_CAPABILITY', error ? 'FAIL' : role.injected && !agent ? 'UNKNOWN' : 'PASS', error ??
|
|
80
84
|
(agent ? 'Declared matrix capabilities match this evaluation; installed CLI flag compatibility was not probed.' : 'Executor supports the declared evaluation surface.'), error ? 'Select a compatible agent/input/mode or correct its configuration, then create a fresh preview.' : null);
|
|
85
|
+
if (agent && !role.injected) {
|
|
86
|
+
// These are adapter capabilities declared by matrix wire shape, not a probe
|
|
87
|
+
// or a guarantee that this installed CLI/provider will return final counters.
|
|
88
|
+
const metrics = agentTokenCounters(agent);
|
|
89
|
+
const missing = ['input', 'cachedInput', 'output'].filter(metric => !metrics.includes(metric));
|
|
90
|
+
const blocked = options.spendingBudget && missing.length > 0;
|
|
91
|
+
add('USAGE_CAPABILITY', blocked ? 'FAIL' : options.spendingBudget ? 'PASS' : 'INFO', `CLI adapter token counters: ${metrics.join(', ') || 'none'}. ${blocked
|
|
92
|
+
? `Whole-batch spending limits require unavailable counters: ${missing.join(', ')}; no calls may start.`
|
|
93
|
+
: 'Actual missing/partial final counters remain unknown and stop a budgeted batch.'}`, blocked ? 'Choose an adapter/provider with all required counters or explicitly review a new plan without token spending limits; unknown usage cannot be treated as zero.' : null);
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
add('USAGE_CAPABILITY', 'UNKNOWN', 'Final token/cache coverage cannot be confirmed offline for this API or injected executor; runtime spending guards still require complete final counters.');
|
|
81
97
|
add('AUTHENTICATION', 'UNKNOWN', 'Login and credential validity cannot be confirmed offline; no authentication command, credential file or network probe was used.', 'Confirm authentication separately before authorizing a live run.');
|
|
82
98
|
if (role.role !== 'agent' || options.target.kind !== 'skill')
|
|
83
99
|
continue;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
/** Paths win over bundled names. Explicit/existing local paths never fall back. */
|
|
5
|
+
export function resolveBenchDir(bench, options = {}) {
|
|
6
|
+
const root = options.bundledRoot ?? fileURLToPath(new URL('../../benches', import.meta.url));
|
|
7
|
+
const cwd = options.cwd ?? process.cwd();
|
|
8
|
+
if (bench !== undefined) {
|
|
9
|
+
const dir = resolve(cwd, bench);
|
|
10
|
+
if (existsSync(join(dir, 'bench.json')))
|
|
11
|
+
return dir;
|
|
12
|
+
if (existsSync(dir) || isAbsolute(bench) || /[\\/]/.test(bench) || bench === '.' || bench === '..') {
|
|
13
|
+
throw new Error(`Not a bench directory (missing bench.json): ${dir}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const candidates = existsSync(root) ? readdirSync(root).sort().map(name => ({ name, dir: join(root, name) }))
|
|
17
|
+
.filter(entry => statSync(entry.dir).isDirectory() && existsSync(join(entry.dir, 'bench.json'))) : [];
|
|
18
|
+
if (bench !== undefined) {
|
|
19
|
+
const match = candidates.find(entry => entry.name === bench);
|
|
20
|
+
if (match)
|
|
21
|
+
return match.dir;
|
|
22
|
+
throw new Error(`Not a bench directory (missing bench.json): ${resolve(cwd, bench)}`);
|
|
23
|
+
}
|
|
24
|
+
if (candidates.length === 1)
|
|
25
|
+
return candidates[0].dir;
|
|
26
|
+
if (!candidates.length)
|
|
27
|
+
throw new Error(`No bundled benches found under ${root}; pass --bench <path>`);
|
|
28
|
+
throw new Error(`More than one bundled bench is available; pick one explicitly:\n${candidates.map(entry => ` --bench ${entry.name}`).join('\n')}`);
|
|
29
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
import { resolveBenchDir } from './bench-location.js';
|
|
7
|
+
test('bench references prefer local inputs, preserve explicit-path errors and choose bundled names consistently', t => {
|
|
8
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-bench-reference-'));
|
|
9
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
10
|
+
const cwd = join(root, 'user'), bundledRoot = join(root, 'package', 'benches');
|
|
11
|
+
mkdirSync(cwd);
|
|
12
|
+
mkdirSync(bundledRoot, { recursive: true });
|
|
13
|
+
const options = { cwd, bundledRoot };
|
|
14
|
+
assert.throws(() => resolveBenchDir(undefined, options), /No bundled benches/);
|
|
15
|
+
const bundled = join(bundledRoot, 'example');
|
|
16
|
+
mkdirSync(bundled);
|
|
17
|
+
writeFileSync(join(bundled, 'bench.json'), '{}');
|
|
18
|
+
assert.equal(resolveBenchDir('example', options), bundled);
|
|
19
|
+
assert.equal(resolveBenchDir(undefined, options), bundled);
|
|
20
|
+
assert.throws(() => resolveBenchDir('./example', options), /Not a bench directory/);
|
|
21
|
+
assert.throws(() => resolveBenchDir('absent', options), /missing bench.json/);
|
|
22
|
+
const local = join(cwd, 'example');
|
|
23
|
+
mkdirSync(local);
|
|
24
|
+
assert.throws(() => resolveBenchDir('example', options), /Not a bench directory/, 'An existing local directory must not silently use a bundled case.');
|
|
25
|
+
writeFileSync(join(local, 'bench.json'), '{malformed-but-local');
|
|
26
|
+
assert.equal(resolveBenchDir('example', options), local);
|
|
27
|
+
assert.equal(resolveBenchDir('./example', options), local);
|
|
28
|
+
assert.equal(resolveBenchDir('.', { ...options, cwd: local }), local);
|
|
29
|
+
const other = join(bundledRoot, 'other');
|
|
30
|
+
mkdirSync(other);
|
|
31
|
+
writeFileSync(join(other, 'bench.json'), '{}');
|
|
32
|
+
assert.throws(() => resolveBenchDir(undefined, options), /pick one explicitly/);
|
|
33
|
+
});
|
package/dist/harness/bench.js
CHANGED
|
@@ -2,9 +2,12 @@ import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
|
2
2
|
import { basename, isAbsolute, join, resolve, sep } from 'node:path';
|
|
3
3
|
import { hashFileSet, listFilesRecursive } from './hash.js';
|
|
4
4
|
import { parseCommand } from './command.js';
|
|
5
|
+
import { parseVerifierTimeoutSeconds } from './verifier-timeout.js';
|
|
5
6
|
export const BENCH_SCHEMA_VERSION = 1;
|
|
6
7
|
const TASK_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
7
8
|
function assertRelativeInside(benchDir, rel, label) {
|
|
9
|
+
if (rel.split(/[\\/]/).includes('.git'))
|
|
10
|
+
throw new Error(`${label} cannot reference Git metadata: ${rel}`);
|
|
8
11
|
if (isAbsolute(rel) || rel.split(/[\\/]/).includes('..')) {
|
|
9
12
|
throw new Error(`${label} must be a relative path inside the bench directory: ${rel}`);
|
|
10
13
|
}
|
|
@@ -49,6 +52,8 @@ export function validateBenchTask(benchDir, raw, index) {
|
|
|
49
52
|
throw new Error(`bench.json task "${id}" has an invalid "verifierKind" field (expected "output" or "command")`);
|
|
50
53
|
}
|
|
51
54
|
const verifierKindField = verifierKind === undefined ? {} : { verifierKind: verifierKind };
|
|
55
|
+
const timeoutField = task['verifierTimeoutSeconds'] === undefined ? {} :
|
|
56
|
+
{ verifierTimeoutSeconds: parseVerifierTimeoutSeconds(task['verifierTimeoutSeconds']) };
|
|
52
57
|
if (shouldTrigger !== undefined && typeof shouldTrigger !== 'boolean') {
|
|
53
58
|
throw new Error(`bench.json task "${id}" has an invalid "shouldTrigger" field`);
|
|
54
59
|
}
|
|
@@ -98,9 +103,9 @@ export function validateBenchTask(benchDir, raw, index) {
|
|
|
98
103
|
if (!existsSync(rubricAbs) || !statSync(rubricAbs).isFile()) {
|
|
99
104
|
throw new Error(`task "${id}" rubric file not found: ${rubric}`);
|
|
100
105
|
}
|
|
101
|
-
return { id, fixture, prompt, verifier, rubric, ...triggerField, ...promptTriggerField, ...verifierKindField, ...oracleField };
|
|
106
|
+
return { id, fixture, prompt, verifier, rubric, ...triggerField, ...promptTriggerField, ...verifierKindField, ...timeoutField, ...oracleField };
|
|
102
107
|
}
|
|
103
|
-
return { id, fixture, prompt, verifier, ...triggerField, ...promptTriggerField, ...verifierKindField, ...oracleField };
|
|
108
|
+
return { id, fixture, prompt, verifier, ...triggerField, ...promptTriggerField, ...verifierKindField, ...timeoutField, ...oracleField };
|
|
104
109
|
}
|
|
105
110
|
export function loadBench(benchDir) {
|
|
106
111
|
const dir = resolve(benchDir);
|
|
@@ -130,7 +135,7 @@ export function loadBench(benchDir) {
|
|
|
130
135
|
seen.add(task.id);
|
|
131
136
|
}
|
|
132
137
|
const name = typeof raw.name === 'string' && raw.name.trim() !== '' ? raw.name : basename(dir);
|
|
133
|
-
const contentSha256 = hashFileSet(dir, listFilesRecursive(dir));
|
|
138
|
+
const contentSha256 = hashFileSet(dir, listFilesRecursive(dir, { excludeGitMetadata: true }));
|
|
134
139
|
return { dir, name, schemaVersion: BENCH_SCHEMA_VERSION, tasks, contentSha256 };
|
|
135
140
|
}
|
|
136
141
|
/** Keep manifest order so selecting IDs cannot silently change balanced pair order. */
|
|
@@ -228,7 +228,7 @@ export async function auditEvaluation(value, runDir, options = {}) {
|
|
|
228
228
|
const scratch = mkdtempSync(join(tmpdir(), 'skillfit-eval-replay-'));
|
|
229
229
|
try {
|
|
230
230
|
cpSync(join(root, task.id, arm, `trial-${trial}`), scratch, { recursive: true, filter: path => basename(path) !== '.git' });
|
|
231
|
-
const grade = await runVerifier(bench.dir, definition.verifier, scratch), summary = verdictFromOutput(grade.output);
|
|
231
|
+
const grade = await runVerifier(bench.dir, definition.verifier, scratch, definition.verifierTimeoutSeconds), summary = verdictFromOutput(grade.output);
|
|
232
232
|
assert.equal(grade.error, null, `Replay verifier failed: ${grade.error}`);
|
|
233
233
|
assert.notEqual(grade.exitCode, null);
|
|
234
234
|
assert.equal(grade.exitCode, r.verifierExitCode);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
/** Resolve existing ancestors so an uncreated output cannot hide behind an alias. */
|
|
5
|
+
export function physicalPath(path) {
|
|
6
|
+
let parent = resolve(path);
|
|
7
|
+
const parts = [];
|
|
8
|
+
while (!existsSync(parent)) {
|
|
9
|
+
parts.unshift(basename(parent));
|
|
10
|
+
parent = dirname(parent);
|
|
11
|
+
}
|
|
12
|
+
return join(realpathSync(parent), ...parts);
|
|
13
|
+
}
|
|
14
|
+
function contains(root, path) {
|
|
15
|
+
const rel = relative(root, path);
|
|
16
|
+
return !isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`);
|
|
17
|
+
}
|
|
18
|
+
/** Preview and session setup share this read-only rule. */
|
|
19
|
+
export function assertEvaluationOutputLayout(output, inputs) {
|
|
20
|
+
const actual = physicalPath(output);
|
|
21
|
+
if ([resolve(output), actual].some(path => path.split(/[\\/]/).includes('.git'))) {
|
|
22
|
+
throw new Error('Experiment output must be outside Git metadata; choose a separate --runs-root.');
|
|
23
|
+
}
|
|
24
|
+
const implementation = fileURLToPath(new URL('../', import.meta.url));
|
|
25
|
+
for (const input of [inputs.benchDir, ...(inputs.targetDirs ?? []), implementation]) {
|
|
26
|
+
if (contains(physicalPath(input), actual)) {
|
|
27
|
+
throw new Error('Experiment output must be outside the bench, Skill/overlay and compiled runtime inputs; choose a sibling --runs-root before previewing or running.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|