skillfit 0.10.1 → 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 +43 -8
- package/README.zh-CN.md +43 -8
- package/benches/README.md +6 -2
- package/dist/cli.js +153 -37
- package/dist/cli.test.js +94 -0
- package/dist/commands/bench-calibration.js +201 -0
- package/dist/commands/bench-calibration.test.js +237 -0
- package/dist/commands/bench-check-json.test.js +24 -3
- 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 +227 -245
- package/dist/commands/bench.test.js +7 -3
- package/dist/commands/calibration-cli.test.js +145 -0
- package/dist/commands/eval-agent-preflight.test.js +269 -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-cli.js +31 -0
- package/dist/commands/eval-component.js +52 -28
- package/dist/commands/eval-export-modes.test.js +350 -0
- package/dist/commands/eval-export.js +12 -4
- package/dist/commands/eval-interruption.test.js +26 -1
- package/dist/commands/eval-layout.test.js +126 -0
- package/dist/commands/eval-plan.js +37 -0
- package/dist/commands/eval-preflight.test.js +144 -1
- package/dist/commands/eval-report.js +18 -3
- package/dist/commands/eval-single-arm-replay.js +21 -0
- package/dist/commands/eval-single-arm-report.js +223 -0
- package/dist/commands/eval.js +113 -88
- package/dist/commands/evaluation-report.js +5 -0
- package/dist/commands/evaluation-report.test.js +243 -0
- package/dist/commands/npm-first-run.test.js +74 -0
- package/dist/commands/replay-cancellation.test.js +105 -0
- package/dist/commands/workflow-entrypoints.test.js +137 -0
- package/dist/harness/agent-preflight.js +196 -0
- package/dist/harness/bench-location.js +29 -0
- package/dist/harness/bench-location.test.js +33 -0
- package/dist/harness/bench.js +10 -4
- package/dist/harness/command.js +49 -0
- package/dist/harness/eval-audit.js +162 -17
- package/dist/harness/eval-budget.js +46 -2
- package/dist/harness/eval-budget.test.js +26 -1
- package/dist/harness/eval-component.test.js +163 -0
- package/dist/harness/eval-contract.js +11 -5
- package/dist/harness/evaluation-layout.js +30 -0
- package/dist/harness/executors/api.js +24 -10
- package/dist/harness/executors/api.test.js +57 -0
- package/dist/harness/executors/cli.js +15 -25
- package/dist/harness/executors/cli.test.js +33 -2
- package/dist/harness/experiment-session.js +23 -25
- package/dist/harness/experiment-session.test.js +8 -0
- package/dist/harness/hash.js +3 -1
- package/dist/harness/invocation-costs.js +72 -0
- package/dist/harness/judge-accounting.test.js +216 -0
- package/dist/harness/judge-audit.js +56 -0
- package/dist/harness/judge.js +86 -21
- package/dist/harness/replay-package.js +71 -5
- package/dist/harness/runner.js +44 -33
- package/dist/harness/runner.test.js +23 -0
- package/dist/harness/single-arm-audit.js +436 -0
- package/dist/harness/trigger.js +22 -4
- package/dist/harness/trigger.test.js +12 -0
- package/dist/harness/verifier-error.js +65 -0
- package/dist/harness/verifier-timeout.js +8 -0
- package/dist/harness/verifier-timeout.test.js +76 -0
- package/dist/harness/verifier.test.js +128 -0
- package/docs/bench-authoring.md +57 -12
- package/docs/bench-check-json.md +28 -5
- package/docs/bench-drafting.md +75 -0
- package/docs/case-management.md +12 -1
- package/docs/eval-agent-preflight.md +114 -0
- package/docs/eval-case-preflight.md +5 -0
- package/docs/eval-component.md +38 -10
- package/docs/eval-costs.md +70 -0
- package/docs/eval-planning.md +167 -0
- package/docs/evaluation-input-snapshots.md +22 -5
- package/docs/evaluation-interruption.md +22 -10
- package/docs/evaluation-reports.md +97 -3
- package/docs/experiment-workflow.md +7 -0
- package/docs/first-real-eval.md +75 -3
- package/docs/growth-roadmap-2026-10.md +51 -10
- package/docs/metrics.md +40 -3
- package/docs/plans/2026-10-17-workflow-foundations.md +99 -0
- package/docs/releases/0.10.1-ci-registry-install.json +70 -0
- package/docs/releases/0.10.1-feature-smoke.json +28 -0
- package/docs/releases/0.10.1-local-registry-install.json +60 -0
- package/docs/releases/0.10.1-registry-metadata.json +33 -0
- package/docs/releases/0.10.1-signatures.txt +7 -0
- package/docs/releases/0.10.1-verification.json +90 -0
- package/docs/releases/0.10.1.md +37 -4
- 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-feature-smoke.mjs +224 -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 +90 -0
- package/docs/releases/0.12.0-feature-smoke.mjs +73 -0
- package/docs/releases/0.12.0.md +68 -0
- package/docs/replay-packages.md +38 -6
- package/docs/schemas/agent-preflight.schema.json +31 -0
- package/docs/schemas/calibration-plan.schema.json +22 -0
- package/docs/schemas/calibration-result.schema.json +17 -0
- package/docs/schemas/eval-request.schema.json +1 -1
- package/docs/schemas/eval-result.schema.json +3 -1
- package/docs/schemas/invocation-costs.schema.json +31 -0
- package/docs/schemas/judge-call.schema.json +22 -0
- package/docs/schemas/single-arm-report.schema.json +20 -0
- package/docs/schemas/verifier-error.schema.json +11 -0
- package/docs/sharing-results.md +3 -0
- package/docs/verifier-contract.md +108 -0
- package/package.json +1 -1
- package/skills/skillfit/SKILL.md +61 -8
|
@@ -664,6 +664,7 @@ test('runBenchAdd --freeze --decompose installs a gated draft with its oracle',
|
|
|
664
664
|
freeze: true,
|
|
665
665
|
sourceDir: source,
|
|
666
666
|
decompose: true,
|
|
667
|
+
runsRoot: tmp(t, 'skillfit-draft-records-'),
|
|
667
668
|
verifierKind: 'command',
|
|
668
669
|
executor: stubDrafter(DRAFTED_COMMAND_VERIFIER, DRAFTED_ORACLE),
|
|
669
670
|
yes: true,
|
|
@@ -689,6 +690,7 @@ test('runBenchAdd --decompose needs an agent or injected executor', async (t) =>
|
|
|
689
690
|
freeze: true,
|
|
690
691
|
sourceDir: source,
|
|
691
692
|
decompose: true,
|
|
693
|
+
runsRoot: tmp(t, 'skillfit-draft-records-'),
|
|
692
694
|
yes: true,
|
|
693
695
|
log: () => { },
|
|
694
696
|
}), /needs an agent/);
|
|
@@ -704,6 +706,7 @@ test('runBenchAdd --decompose rejects a draft that passes the untouched fixture'
|
|
|
704
706
|
freeze: true,
|
|
705
707
|
sourceDir: source,
|
|
706
708
|
decompose: true,
|
|
709
|
+
runsRoot: tmp(t, 'skillfit-draft-records-'),
|
|
707
710
|
executor: stubDrafter(laxVerifier, DRAFTED_ORACLE),
|
|
708
711
|
yes: true,
|
|
709
712
|
log: () => { },
|
|
@@ -722,6 +725,7 @@ test('runBenchAdd --decompose rejects a draft whose oracle does not solve the ta
|
|
|
722
725
|
freeze: true,
|
|
723
726
|
sourceDir: source,
|
|
724
727
|
decompose: true,
|
|
728
|
+
runsRoot: tmp(t, 'skillfit-draft-records-'),
|
|
725
729
|
verifierKind: 'command',
|
|
726
730
|
executor: stubDrafter(DRAFTED_COMMAND_VERIFIER, idleOracle),
|
|
727
731
|
yes: true,
|
|
@@ -762,6 +766,7 @@ test('runBenchAdd --decompose dry-run skips the agent and writes nothing', async
|
|
|
762
766
|
freeze: true,
|
|
763
767
|
sourceDir: source,
|
|
764
768
|
decompose: true,
|
|
769
|
+
runsRoot: tmp(t, 'skillfit-draft-records-'),
|
|
765
770
|
executor: spy,
|
|
766
771
|
dryRun: true,
|
|
767
772
|
log: () => { },
|
|
@@ -832,13 +837,11 @@ test('runBenchAdd backs up an existing file and rolls back a failed write', asyn
|
|
|
832
837
|
assert.equal(readFileSync(leftover + '.skillfit-bak', 'utf8'), 'original verifier\n');
|
|
833
838
|
assert.notEqual(readFileSync(leftover, 'utf8'), 'original verifier\n');
|
|
834
839
|
});
|
|
835
|
-
test('runBenchAdd works in a non-git source directory
|
|
840
|
+
test('runBenchAdd works in a non-git source directory with explicit file selection', async (t) => {
|
|
836
841
|
const source = tmp(t, 'skillfit-freeze-plain-');
|
|
837
842
|
writeFileSync(join(source, 'main.js'), 'console.log(1);\n');
|
|
838
843
|
mkdirSync(join(source, 'node_modules', 'junk'), { recursive: true });
|
|
839
844
|
writeFileSync(join(source, 'node_modules', 'junk', 'x.js'), 'x');
|
|
840
|
-
mkdirSync(join(source, '.git'));
|
|
841
|
-
writeFileSync(join(source, '.git', 'config'), 'x');
|
|
842
845
|
const benchDir = await freezeBench(t);
|
|
843
846
|
await runBenchAdd({
|
|
844
847
|
benchDir,
|
|
@@ -846,6 +849,7 @@ test('runBenchAdd works in a non-git source directory (filtered copy)', async (t
|
|
|
846
849
|
prompt: 'p',
|
|
847
850
|
freeze: true,
|
|
848
851
|
sourceDir: source,
|
|
852
|
+
include: ['main.js'],
|
|
849
853
|
verifierCmd: 'node main.js',
|
|
850
854
|
yes: true,
|
|
851
855
|
log: () => { },
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { 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 } from 'node:url';
|
|
7
|
+
import { test } from 'node:test';
|
|
8
|
+
import { runBenchInit } from './bench.js';
|
|
9
|
+
const CLI = fileURLToPath(new URL('../cli.js', import.meta.url));
|
|
10
|
+
const budget = { input: 100, cachedInput: 100, uncachedInput: 100, output: 100, durationSeconds: 60 };
|
|
11
|
+
async function fixture(t) {
|
|
12
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-calibration-cli-')), dir = join(root, 'bench with spaces');
|
|
13
|
+
t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
|
14
|
+
await runBenchInit({ dir, kind: 'command', yes: true, log: () => { } });
|
|
15
|
+
const home = join(root, 'home'), sentinel = join(root, 'unexpected-probe'), budgetPath = join(root, 'budget.json');
|
|
16
|
+
mkdirSync(home);
|
|
17
|
+
writeFileSync(budgetPath, JSON.stringify(budget));
|
|
18
|
+
const env = { ...Object.fromEntries(Object.entries(process.env).filter(([key]) => key.toUpperCase() !== 'PATH')),
|
|
19
|
+
PATH: '', HOME: home, USERPROFILE: home, CODEX_HOME: join(home, 'codex') };
|
|
20
|
+
const manifest = JSON.parse(readFileSync(join(dir, 'bench.json'), 'utf8'));
|
|
21
|
+
manifest.tasks.push({ ...manifest.tasks[0], id: 'second-task' });
|
|
22
|
+
writeFileSync(join(dir, 'bench.json'), JSON.stringify(manifest));
|
|
23
|
+
writeFileSync(join(dir, 'verifiers/example-task.mjs'), `import{writeFileSync}from'node:fs';writeFileSync(${JSON.stringify(sentinel)},'must never run');process.exit(1);`);
|
|
24
|
+
const args = ['bench', 'check', dir, '--calibrate', '--json', '--agent', 'codex', '--run-group', 'reviewed', '--runs-root', join(root, 'results')];
|
|
25
|
+
const cli = (extra, status, base = args) => {
|
|
26
|
+
const result = spawnSync(process.execPath, [CLI, ...base, ...extra], { cwd: root, env, encoding: 'utf8', timeout: 20_000 });
|
|
27
|
+
assert.equal(result.status, status, result.stderr || result.stdout);
|
|
28
|
+
const data = JSON.parse(result.stdout);
|
|
29
|
+
assert.equal(data.schemaVersion, 1);
|
|
30
|
+
assert.ok(!existsSync(sentinel), 'plans and rejected executions must not run even the verifier');
|
|
31
|
+
assert.ok(!existsSync(join(root, 'runs')));
|
|
32
|
+
assert.ok(!existsSync(join(root, 'results')));
|
|
33
|
+
return { data, stderr: result.stderr };
|
|
34
|
+
};
|
|
35
|
+
return { root, dir, sentinel, budgetPath, args, cli, env };
|
|
36
|
+
}
|
|
37
|
+
test('public calibration JSON preview is read-only and retains blocked CLI, capabilities, unknown login and effective settings', async (t) => {
|
|
38
|
+
const f = await fixture(t);
|
|
39
|
+
const settings = ['--dry-run', '--trials', '3', '--max-calls', '3', '--task', 'second-task', '--input', 'workspace',
|
|
40
|
+
'--executor-timeout-seconds', '13', '--spending-budget', f.budgetPath];
|
|
41
|
+
const first = f.cli(settings, 0), plan = first.data.plan;
|
|
42
|
+
assert.equal(first.stderr, '');
|
|
43
|
+
assert.equal(first.data.kind, 'skillfit.calibration-result');
|
|
44
|
+
assert.equal(first.data.status, 'planned');
|
|
45
|
+
assert.equal(plan.kind, 'skillfit.calibration-plan');
|
|
46
|
+
assert.match(plan.planSha256, /^[0-9a-f]{64}$/);
|
|
47
|
+
assert.match(plan.implementationSha256, /^[0-9a-f]{64}$/);
|
|
48
|
+
assert.match(plan.bench.sha256, /^[0-9a-f]{64}$/);
|
|
49
|
+
assert.deepEqual(plan.bench.taskIds, ['second-task']);
|
|
50
|
+
assert.equal(plan.trials, 3);
|
|
51
|
+
assert.equal(plan.plannedCalls, 3);
|
|
52
|
+
assert.equal(plan.maxCalls, 3);
|
|
53
|
+
assert.equal(plan.executorTimeoutSeconds, 13);
|
|
54
|
+
assert.equal(plan.inputMode, 'workspace');
|
|
55
|
+
assert.deepEqual(plan.spendingBudget, budget);
|
|
56
|
+
assert.equal(plan.outputDir, join(f.root, 'results/reviewed'));
|
|
57
|
+
assert.equal(plan.casePreflight.status, 'pending');
|
|
58
|
+
assert.equal(plan.agentPreflight.status, 'blocked');
|
|
59
|
+
assert.ok(plan.agentPreflight.checks.some((check) => check.code === 'CLI_AVAILABLE' && check.status === 'FAIL'));
|
|
60
|
+
assert.ok(plan.agentPreflight.checks.some((check) => check.code === 'MATRIX_CAPABILITY' && check.status === 'PASS'));
|
|
61
|
+
assert.ok(plan.agentPreflight.checks.some((check) => check.code === 'AUTHENTICATION' && check.status === 'UNKNOWN'));
|
|
62
|
+
assert.equal(plan.agentPreflight.cost.modelCalls, 0);
|
|
63
|
+
assert.equal(plan.agentPreflight.cost.cliInvocations, 0);
|
|
64
|
+
assert.equal(first.data.acceptance.automaticUpgrade, false);
|
|
65
|
+
assert.equal(first.data.acceptance.eligibleForUpgrade, false);
|
|
66
|
+
assert.deepEqual(f.cli(settings, 0).data, first.data, 'identical effective settings yield a reproducible plan');
|
|
67
|
+
});
|
|
68
|
+
test('JSON calibration execution requires a current plan and its explicit output group before any call', async (t) => {
|
|
69
|
+
const f = await fixture(t);
|
|
70
|
+
assert.match(f.cli([], 2).data.error.message, /requires --plan-sha/);
|
|
71
|
+
const withoutGroup = f.args.filter((_, index, values) => values[index - 1] !== '--run-group' && values[index] !== '--run-group');
|
|
72
|
+
assert.match(f.cli(['--plan-sha', '0'.repeat(64)], 2, withoutGroup).data.error.message, /requires --run-group/);
|
|
73
|
+
assert.match(f.cli(['--plan-sha', '0'.repeat(64)], 2).data.error.message, /plan changed/);
|
|
74
|
+
assert.match(f.cli(['--dry-run', '--plan-sha', '0'.repeat(64)], 2).data.error.message, /non-dry-run/);
|
|
75
|
+
const preview = f.cli(['--dry-run'], 0).data;
|
|
76
|
+
const live = f.cli(['--plan-sha', preview.plan.planSha256], 2);
|
|
77
|
+
assert.equal(live.data.kind, 'skillfit.eval-error');
|
|
78
|
+
assert.equal(live.data.error.code, 'AGENT_PREFLIGHT_FAILED');
|
|
79
|
+
assert.equal(live.data.agentPreflight.status, 'blocked');
|
|
80
|
+
assert.match(live.data.error.message, /CLI executable is missing/);
|
|
81
|
+
assert.doesNotMatch(live.data.error.message, /ENOENT|no such file or directory/i);
|
|
82
|
+
});
|
|
83
|
+
test('changing a calibration bench, spending lines, task set or executor deadline invalidates its reviewed plan', async (t) => {
|
|
84
|
+
for (const change of ['bench', 'budget', 'tasks', 'timeout'])
|
|
85
|
+
await t.test(change, async (t) => {
|
|
86
|
+
const f = await fixture(t), settings = ['--spending-budget', f.budgetPath];
|
|
87
|
+
const preview = f.cli(['--dry-run', ...settings], 0).data;
|
|
88
|
+
let altered = [];
|
|
89
|
+
if (change === 'bench')
|
|
90
|
+
writeFileSync(join(f.dir, 'prompts/example-task.md'), 'A new task.');
|
|
91
|
+
if (change === 'budget')
|
|
92
|
+
writeFileSync(f.budgetPath, JSON.stringify({ ...budget, input: 101 }));
|
|
93
|
+
if (change === 'tasks')
|
|
94
|
+
altered = ['--task', 'second-task'];
|
|
95
|
+
if (change === 'timeout')
|
|
96
|
+
altered = ['--executor-timeout-seconds', '12'];
|
|
97
|
+
const live = f.cli([...settings, ...altered, '--plan-sha', preview.plan.planSha256], 2).data;
|
|
98
|
+
assert.equal(live.kind, 'skillfit.eval-error');
|
|
99
|
+
assert.equal(live.status, 'error');
|
|
100
|
+
assert.equal(live.acceptance.eligibleForUpgrade, false);
|
|
101
|
+
assert.match(live.error.message, /plan changed/);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
test('invalid calibration task selection, budgets, timeout, output and paired-only settings fail before probes', async (t) => {
|
|
105
|
+
const f = await fixture(t), invalidBudget = join(f.root, 'bad-budget.json');
|
|
106
|
+
writeFileSync(invalidBudget, JSON.stringify({ ...budget, input: 0 }));
|
|
107
|
+
const malformedBudget = join(f.root, 'malformed-budget.json');
|
|
108
|
+
writeFileSync(malformedBudget, '{');
|
|
109
|
+
const cases = [
|
|
110
|
+
[['--task', 'missing'], /Unknown task/],
|
|
111
|
+
[['--task', 'second-task', '--task', 'second-task'], /Duplicate task/],
|
|
112
|
+
[['--max-calls', '1'], /exceeding --max-calls/],
|
|
113
|
+
[['--executor-timeout-seconds', '0'], /executorTimeoutSeconds/],
|
|
114
|
+
[['--executor-timeout-seconds', '3601'], /executorTimeoutSeconds/],
|
|
115
|
+
[['--executor-timeout-seconds', '1.5'], /executorTimeoutSeconds/],
|
|
116
|
+
[['--spending-budget', invalidBudget], /spendingBudget.input/],
|
|
117
|
+
[['--spending-budget', malformedBudget], /JSON/],
|
|
118
|
+
[['--pair-order', 'balanced'], /requires a paired eval/],
|
|
119
|
+
[['--run-group', '../outside'], /Invalid run group/],
|
|
120
|
+
];
|
|
121
|
+
for (const [extra, message] of cases) {
|
|
122
|
+
const data = f.cli(['--dry-run', ...extra], 2).data;
|
|
123
|
+
assert.equal(data.kind, 'skillfit.eval-error');
|
|
124
|
+
assert.match(data.error.message, message);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
test('ordinary offline bench JSON retains its own integrity contract while calibration JSON returns a plan', async (t) => {
|
|
128
|
+
const f = await fixture(t);
|
|
129
|
+
const ordinary = spawnSync(process.execPath, [CLI, 'bench', 'check', f.dir, '--json'], { cwd: f.root, env: f.env, encoding: 'utf8', timeout: 20_000 });
|
|
130
|
+
// PATH is deliberately empty, so Node verifier commands cannot start; that is an offline
|
|
131
|
+
// integrity failure, distinct from a paid calibration or a model outcome.
|
|
132
|
+
assert.equal(ordinary.status, 1, ordinary.stderr || ordinary.stdout);
|
|
133
|
+
assert.equal(ordinary.stderr, '');
|
|
134
|
+
const data = JSON.parse(ordinary.stdout);
|
|
135
|
+
assert.equal(data.kind, 'skillfit.bench-check');
|
|
136
|
+
assert.equal(data.scope, 'offline-integrity');
|
|
137
|
+
assert.equal(data.status, 'failed');
|
|
138
|
+
assert.ok(data.summary.failures > 0);
|
|
139
|
+
assert.equal(data.plan, undefined);
|
|
140
|
+
assert.ok(!existsSync(f.sentinel));
|
|
141
|
+
const preview = f.cli(['--dry-run'], 0).data;
|
|
142
|
+
assert.equal(preview.kind, 'skillfit.calibration-result');
|
|
143
|
+
assert.equal(preview.status, 'planned');
|
|
144
|
+
assert.ok(preview.plan);
|
|
145
|
+
});
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, 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 { getAgent } from '../agents.js';
|
|
9
|
+
import { findExecutable, globalSkillRoots, inspectAgentEnvironment, AgentPreflightFailed, assertRecordedAgentEnvironment } from '../harness/agent-preflight.js';
|
|
10
|
+
import { collectEvaluationTarget } from '../harness/target.js';
|
|
11
|
+
import { runEval } from './eval.js';
|
|
12
|
+
import { runEvalCli } from './eval-cli.js';
|
|
13
|
+
import { runEvalComponent, reportEvalComponent, componentError } from './eval-component.js';
|
|
14
|
+
import { exportEvaluation } from './eval-export.js';
|
|
15
|
+
import { runEvalReport } from './eval-report.js';
|
|
16
|
+
const CLI = fileURLToPath(new URL('../cli.js', import.meta.url));
|
|
17
|
+
function setup(t) {
|
|
18
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-agent-env-'));
|
|
19
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
20
|
+
const home = join(root, 'home'), profile = join(root, 'profile'), bin = join(root, 'bin'), skill = join(root, 'candidate'), bench = join(root, 'bench');
|
|
21
|
+
for (const dir of [home, profile, bin, skill, join(bench, 'fixture')])
|
|
22
|
+
mkdirSync(dir, { recursive: true });
|
|
23
|
+
writeFileSync(join(skill, 'SKILL.md'), '---\nname: actual-skill-name\ndescription: Test a local answer.\n---\nReturn OK.\n');
|
|
24
|
+
writeFileSync(join(bench, 'fixture/input.txt'), 'input');
|
|
25
|
+
writeFileSync(join(bench, 'prompt.md'), 'Return OK.');
|
|
26
|
+
const verifier = join(bench, 'verify.mjs');
|
|
27
|
+
writeFileSync(verifier, "import{existsSync,readFileSync}from'node:fs';import{join}from'node:path';const file=join(process.argv[2],'_output.md');const passed=existsSync(file)&&readFileSync(file,'utf8').trim()==='OK';console.log(JSON.stringify({passed}));process.exit(passed?0:1);");
|
|
28
|
+
writeFileSync(join(bench, 'bench.json'), JSON.stringify({ schemaVersion: 1, name: 'agent-preflight', tasks: [{ id: 't', fixture: 'fixture', prompt: 'prompt.md', verifier: 'node verify.mjs', shouldTrigger: true }] }));
|
|
29
|
+
const env = { ...process.env, HOME: home, USERPROFILE: home, CODEX_HOME: profile, PATH: bin, SKILLFIT_JUDGE: '0' };
|
|
30
|
+
// Native OS home resolution is not used by direct tests; child CLI tests use both home overrides.
|
|
31
|
+
const binary = join(bin, process.platform === 'win32' ? 'codex.CMD' : 'codex');
|
|
32
|
+
writeFileSync(binary, 'synthetic executable; must never be run');
|
|
33
|
+
chmodSync(binary, 0o755);
|
|
34
|
+
const target = collectEvaluationTarget(skill), definition = getAgent('codex');
|
|
35
|
+
const role = { role: 'agent', definition, executor: { kind: 'cli', model: 'cli-configured' }, injected: false };
|
|
36
|
+
const inspect = (roles = [role]) => inspectAgentEnvironment({ roles, target, mode: 'inject', homeDir: home, env });
|
|
37
|
+
const conflict = (folder = 'alias-folder', name = 'actual-skill-name') => {
|
|
38
|
+
const dir = join(globalSkillRoots(definition, home, env).at(-1), folder);
|
|
39
|
+
mkdirSync(dir, { recursive: true });
|
|
40
|
+
writeFileSync(join(dir, 'SKILL.md'), `---\nname: ${name}\ndescription: A synthetic global Skill.\n---\nPrivate body must not appear in the report.\n`);
|
|
41
|
+
return dir;
|
|
42
|
+
};
|
|
43
|
+
let calls = 0;
|
|
44
|
+
const base = { skillPath: skill, bench, agent: 'codex', trials: 1, maxCalls: 2, dryRun: false, yes: true,
|
|
45
|
+
runsRoot: join(root, 'runs'), runGroup: 'env', judgeExecutor: null, sessionOptions: { homeDir: home, env, versionProbe: () => null },
|
|
46
|
+
executor: { describe: () => ({ kind: 'mock', model: 'offline-agent-env' }), run: async () => {
|
|
47
|
+
calls++;
|
|
48
|
+
return { output: 'OK', tokens: { input: 10, cachedInput: 4, output: 2 } };
|
|
49
|
+
} }, log: () => { } };
|
|
50
|
+
return { root, home, profile, bin, binary, env, target, role, inspect, conflict, base, bench, skill, verifier, calls: () => calls };
|
|
51
|
+
}
|
|
52
|
+
test('PATH lookup inspects executable files without running a CLI or accepting config directories as installation', t => {
|
|
53
|
+
const f = setup(t);
|
|
54
|
+
assert.equal(findExecutable('codex', f.env), findExecutable(f.binary, f.env));
|
|
55
|
+
assert.equal(findExecutable('missing-agent', f.env), null);
|
|
56
|
+
assert.equal(findExecutable('codex', { ...f.env, PATH: '' }), null);
|
|
57
|
+
mkdirSync(join(f.bin, 'directory-agent'));
|
|
58
|
+
assert.equal(findExecutable('directory-agent', f.env), null);
|
|
59
|
+
if (process.platform !== 'win32') {
|
|
60
|
+
chmodSync(f.binary, 0o644);
|
|
61
|
+
assert.equal(findExecutable('codex', f.env), null);
|
|
62
|
+
}
|
|
63
|
+
const report = inspectAgentEnvironment({ roles: [f.role], target: f.target, mode: 'inject', homeDir: f.home, env: { ...f.env, PATH: '' } });
|
|
64
|
+
assert.equal(report.status, 'blocked');
|
|
65
|
+
assert.equal(report.checks.find(c => c.code === 'CLI_AVAILABLE').status, 'FAIL');
|
|
66
|
+
assert.deepEqual(report.cost, { modelCalls: 0, cliInvocations: 0 });
|
|
67
|
+
});
|
|
68
|
+
test('Windows PATH/PATHEXT lookup accepts command shims and case-insensitive environment keys', t => {
|
|
69
|
+
const f = setup(t), file = join(f.bin, 'offline.CMD');
|
|
70
|
+
writeFileSync(file, 'must never execute');
|
|
71
|
+
const path = findExecutable('offline', { Path: `"${f.bin}"`, PathExt: '.CMD;.EXE' }, 'win32');
|
|
72
|
+
assert.ok(path?.endsWith('offline.CMD'));
|
|
73
|
+
assert.equal(findExecutable('absent', { Path: f.bin, PATHEXT: '.CMD' }, 'win32'), null);
|
|
74
|
+
assert.equal(findExecutable('offline', { Path: 'missing', PATH: f.bin, PATHEXT: '.CMD' }, 'win32'), path);
|
|
75
|
+
});
|
|
76
|
+
test('local readiness never claims login even with credentials/config files present, and emits no secret values', t => {
|
|
77
|
+
const f = setup(t), secret = 'synthetic-secret-never-report';
|
|
78
|
+
writeFileSync(join(f.profile, 'auth.json'), JSON.stringify({ access_token: secret }));
|
|
79
|
+
const report = inspectAgentEnvironment({ roles: [f.role], target: f.target, mode: 'installed', homeDir: f.home,
|
|
80
|
+
env: { ...f.env, OPENAI_API_KEY: secret } });
|
|
81
|
+
assert.equal(report.status, 'ready');
|
|
82
|
+
assert.equal(report.checks.find(c => c.code === 'AUTHENTICATION').status, 'UNKNOWN');
|
|
83
|
+
assertRecordedAgentEnvironment(report);
|
|
84
|
+
assert.equal(JSON.stringify(report).includes(secret), false);
|
|
85
|
+
assert.deepEqual(f.inspect(), f.inspect());
|
|
86
|
+
assert.equal(f.calls(), 0);
|
|
87
|
+
});
|
|
88
|
+
test('capability checks use matrix declarations and cover trigger support, installation paths and the judge CLI', t => {
|
|
89
|
+
const f = setup(t), claude = getAgent('claude-code');
|
|
90
|
+
const trigger = inspectAgentEnvironment({ roles: [{ ...f.role, definition: claude }], target: f.target, mode: 'trigger', homeDir: f.home, env: f.env });
|
|
91
|
+
assert.equal(trigger.status, 'blocked');
|
|
92
|
+
assert.match(trigger.checks.find(c => c.code === 'MATRIX_CAPABILITY').message, /streamJson/);
|
|
93
|
+
const missingDirs = structuredClone(f.role.definition);
|
|
94
|
+
missingDirs.skills.projectDirs = [];
|
|
95
|
+
const installed = inspectAgentEnvironment({ roles: [{ ...f.role, definition: missingDirs }], target: f.target, mode: 'installed', homeDir: f.home, env: f.env });
|
|
96
|
+
assert.match(installed.checks.find(c => c.code === 'MATRIX_CAPABILITY').message, /project Skill directory/);
|
|
97
|
+
const judge = structuredClone(f.role.definition);
|
|
98
|
+
judge.headless.argv = ['missing-offline-judge'];
|
|
99
|
+
if (judge.headless.streamJson)
|
|
100
|
+
judge.headless.streamJson.argv = ['missing-offline-judge'];
|
|
101
|
+
const judged = f.inspect([f.role, { ...f.role, role: 'judge', definition: judge }]);
|
|
102
|
+
assert.equal(judged.status, 'blocked');
|
|
103
|
+
assert.equal(judged.checks.find(c => c.role === 'judge' && c.code === 'CLI_AVAILABLE').status, 'FAIL');
|
|
104
|
+
assert.equal(judged.checks.filter(c => c.code === 'AUTHENTICATION').length, 2);
|
|
105
|
+
});
|
|
106
|
+
test('budget preflight distinguishes supported, unavailable and unknown token counters for every role', t => {
|
|
107
|
+
const f = setup(t);
|
|
108
|
+
for (const [id, status] of [['codex', 'PASS'], ['kimi-code', 'FAIL'], ['claude-code', 'FAIL']]) {
|
|
109
|
+
const checked = inspectAgentEnvironment({ roles: [{ ...f.role, definition: getAgent(id) }], target: f.target,
|
|
110
|
+
mode: 'inject', spendingBudget: true, homeDir: f.home, env: f.env });
|
|
111
|
+
const check = checked.checks.find(c => c.code === 'USAGE_CAPABILITY');
|
|
112
|
+
assert.equal(check.status, status, id);
|
|
113
|
+
if (status === 'FAIL') {
|
|
114
|
+
assert.match(check.message, /unavailable counters/);
|
|
115
|
+
assert.ok(check.remediation);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const checked = inspectAgentEnvironment({ roles: [f.role, { ...f.role, role: 'judge', definition: getAgent('claude-code') }],
|
|
119
|
+
target: f.target, mode: 'inject', spendingBudget: true, homeDir: f.home, env: f.env });
|
|
120
|
+
assert.equal(checked.checks.find(c => c.code === 'USAGE_CAPABILITY' && c.role === 'judge').status, 'FAIL');
|
|
121
|
+
for (const role of [{ ...f.role, injected: true }, { role: 'agent', injected: false, executor: { kind: 'api', model: 'not-called' } }]) {
|
|
122
|
+
const unknown = inspectAgentEnvironment({ roles: [role], target: f.target, mode: 'inject', spendingBudget: true, homeDir: f.home, env: f.env });
|
|
123
|
+
assert.equal(unknown.checks.find(c => c.code === 'USAGE_CAPABILITY').status, 'UNKNOWN');
|
|
124
|
+
assert.equal(unknown.status, 'ready');
|
|
125
|
+
assert.deepEqual(unknown.cost, { modelCalls: 0, cliInvocations: 0 });
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
test('global conflicts include frontmatter aliases and configured home overrides without exposing Skill bodies', t => {
|
|
129
|
+
const f = setup(t), dir = f.conflict();
|
|
130
|
+
const report = f.inspect(), conflict = report.checks.find(c => c.code === 'GLOBAL_SKILL_CONFLICT');
|
|
131
|
+
assert.equal(report.status, 'blocked');
|
|
132
|
+
assert.equal(conflict.status, 'FAIL');
|
|
133
|
+
assert.deepEqual(conflict.paths, [dir]);
|
|
134
|
+
assert.match(conflict.message, /Baseline contamination risk/);
|
|
135
|
+
assert.equal(JSON.stringify(report).includes('Private body'), false);
|
|
136
|
+
rmSync(dir, { recursive: true });
|
|
137
|
+
f.conflict(f.target.name, 'different-frontmatter-name');
|
|
138
|
+
assert.equal(f.inspect().status, 'blocked', 'directory-name conflicts remain blocked too');
|
|
139
|
+
});
|
|
140
|
+
test('global alias directories are inspected, and unreadable roots remain explicitly unknown', t => {
|
|
141
|
+
const f = setup(t), real = join(f.root, 'external-skill');
|
|
142
|
+
mkdirSync(real);
|
|
143
|
+
writeFileSync(join(real, 'SKILL.md'), '---\nname: actual-skill-name\ndescription: Alias test.\n---\n');
|
|
144
|
+
const root = globalSkillRoots(f.role.definition, f.home, f.env)[0];
|
|
145
|
+
mkdirSync(root, { recursive: true });
|
|
146
|
+
symlinkSync(real, join(root, 'linked'), process.platform === 'win32' ? 'junction' : 'dir');
|
|
147
|
+
assert.equal(f.inspect().status, 'blocked');
|
|
148
|
+
rmSync(join(root, 'linked'));
|
|
149
|
+
rmSync(root, { recursive: true });
|
|
150
|
+
writeFileSync(root, 'not a directory');
|
|
151
|
+
const unknown = f.inspect().checks.find(c => c.code === 'GLOBAL_SKILL_SCAN');
|
|
152
|
+
assert.equal(unknown.status, 'UNKNOWN');
|
|
153
|
+
assert.ok(unknown.paths.includes(root));
|
|
154
|
+
});
|
|
155
|
+
test('injected executors cannot attest real CLI readiness and API execution does not require a CLI', t => {
|
|
156
|
+
const f = setup(t), injected = f.inspect([{ ...f.role, injected: true }]);
|
|
157
|
+
assert.equal(injected.checks.find(c => c.code === 'EXECUTOR_INJECTED').status, 'UNKNOWN');
|
|
158
|
+
const api = f.inspect([{ role: 'agent', injected: false, executor: { kind: 'api', model: 'offline-not-called' } }]);
|
|
159
|
+
assert.equal(api.status, 'ready');
|
|
160
|
+
assert.equal(api.checks.find(c => c.code === 'CLI_AVAILABLE').status, 'INFO');
|
|
161
|
+
const invalid = structuredClone(api);
|
|
162
|
+
invalid.checks.find(c => c.code === 'AUTHENTICATION').status = 'PASS';
|
|
163
|
+
assert.throws(() => assertRecordedAgentEnvironment(invalid), /environment check/);
|
|
164
|
+
});
|
|
165
|
+
test('capability mismatch is structured and blocks both preview and live execution without invoking API/agent', async (t) => {
|
|
166
|
+
const f = setup(t);
|
|
167
|
+
for (const dryRun of [true, false])
|
|
168
|
+
await assert.rejects(runEval({ ...f.base, dryRun, inputMode: 'workspace',
|
|
169
|
+
executor: { describe: () => ({ kind: 'api', model: 'offline-api' }), run: async () => { throw new Error('must never run'); } } }), error => {
|
|
170
|
+
assert.ok(error instanceof AgentPreflightFailed);
|
|
171
|
+
assert.equal(componentError(error).error.code, 'AGENT_PREFLIGHT_FAILED');
|
|
172
|
+
assert.equal(error.agentPreflight.checks.find(c => c.code === 'MATRIX_CAPABILITY').status, 'FAIL');
|
|
173
|
+
return true;
|
|
174
|
+
});
|
|
175
|
+
assert.equal(f.calls(), 0);
|
|
176
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
177
|
+
});
|
|
178
|
+
test('global conflict blocks before any case verifier, executor, version probe or native directory is created', async (t) => {
|
|
179
|
+
const f = setup(t), sentinel = join(f.root, 'verifier-started'), conflict = f.conflict();
|
|
180
|
+
writeFileSync(f.verifier, `import{writeFileSync}from'node:fs';writeFileSync(${JSON.stringify(sentinel)},'called');process.exit(1);`);
|
|
181
|
+
await assert.rejects(runEval({ ...f.base, sessionOptions: { ...f.base.sessionOptions,
|
|
182
|
+
versionProbe: () => { throw new Error('must not probe the CLI'); } } }), error => {
|
|
183
|
+
assert.ok(error instanceof AgentPreflightFailed);
|
|
184
|
+
assert.equal(error.agentPreflight.status, 'blocked');
|
|
185
|
+
assert.ok(error.message.includes(conflict));
|
|
186
|
+
return true;
|
|
187
|
+
});
|
|
188
|
+
assert.equal(existsSync(sentinel), false);
|
|
189
|
+
assert.equal(f.calls(), 0);
|
|
190
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
191
|
+
});
|
|
192
|
+
test('case probes cannot silently change Agent readiness before first dispatch', async (t) => {
|
|
193
|
+
const f = setup(t), globalDir = join(globalSkillRoots(f.role.definition, f.home, f.env)[0], 'new-global');
|
|
194
|
+
writeFileSync(f.verifier, `import{mkdirSync,writeFileSync}from'node:fs';import{join}from'node:path';mkdirSync(${JSON.stringify(globalDir)},{recursive:true});writeFileSync(join(${JSON.stringify(globalDir)},'SKILL.md'),${JSON.stringify('---\nname: actual-skill-name\ndescription: Changed during probe.\n---\n')});console.log(JSON.stringify({passed:false}));process.exit(1);`);
|
|
195
|
+
await assert.rejects(runEval(f.base), AgentPreflightFailed);
|
|
196
|
+
assert.equal(f.calls(), 0);
|
|
197
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
198
|
+
});
|
|
199
|
+
test('ordinary and request plans bind the same checks and stale global-readiness plans cannot execute', async (t) => {
|
|
200
|
+
const f = setup(t), request = join(f.root, 'request.json');
|
|
201
|
+
const body = { schemaVersion: 1, baselineSkill: null, candidateSkill: f.skill, bench: f.bench, agent: 'codex', purpose: 'development',
|
|
202
|
+
trials: 1, maxCalls: 2, runsRoot: f.base.runsRoot, runGroup: f.base.runGroup };
|
|
203
|
+
writeFileSync(request, JSON.stringify(body));
|
|
204
|
+
const ordinary = { ...f.base, mode: 'installed', inputMode: 'workspace', skillInstallDir: 'project-skills' };
|
|
205
|
+
const a = await runEvalCli({ ...ordinary, dryRun: true });
|
|
206
|
+
const b = await runEvalComponent(request, { ...f.base, dryRun: true, skillInstallDir: 'project-skills' });
|
|
207
|
+
assert.deepEqual(a.plan.evaluation.agentPreflight, b.plan.evaluation.agentPreflight);
|
|
208
|
+
f.conflict();
|
|
209
|
+
await assert.rejects(runEvalCli(ordinary, a.plan.sha256), /--plan-sha/);
|
|
210
|
+
assert.equal(f.calls(), 0);
|
|
211
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
212
|
+
});
|
|
213
|
+
test('public CLI previews expose blocked readiness and both human/confirmed JSON execution refuse a missing CLI', t => {
|
|
214
|
+
const f = setup(t), env = { ...f.env, PATH: '' }, args = ['eval', f.skill, '--bench', f.bench, '--agent', 'codex', '--trials', '1',
|
|
215
|
+
'--runs-root', f.base.runsRoot, '--run-group', f.base.runGroup, '--json'];
|
|
216
|
+
const preview = spawnSync(process.execPath, [CLI, ...args, '--dry-run'], { env, encoding: 'utf8', timeout: 30_000 });
|
|
217
|
+
assert.equal(preview.status, 0, preview.stderr);
|
|
218
|
+
const plan = JSON.parse(preview.stdout).plan;
|
|
219
|
+
assert.equal(plan.evaluation.agentPreflight.status, 'blocked');
|
|
220
|
+
const live = spawnSync(process.execPath, [CLI, ...args, '--plan-sha', plan.sha256], { env, encoding: 'utf8', timeout: 30_000 });
|
|
221
|
+
assert.equal(live.status, 2);
|
|
222
|
+
assert.equal(JSON.parse(live.stdout).error.code, 'AGENT_PREFLIGHT_FAILED');
|
|
223
|
+
const human = spawnSync(process.execPath, [CLI, ...args.slice(0, -1)], { env, encoding: 'utf8', timeout: 30_000 });
|
|
224
|
+
assert.equal(human.status, 1);
|
|
225
|
+
assert.match(human.stderr, /CLI executable is missing/);
|
|
226
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
227
|
+
const trigger = spawnSync(process.execPath, [CLI, ...args.slice(0, -1), '--mode', 'trigger'], { env, encoding: 'utf8', timeout: 30_000 });
|
|
228
|
+
assert.equal(trigger.status, 1);
|
|
229
|
+
assert.match(trigger.stderr, /CLI executable is missing/);
|
|
230
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
231
|
+
});
|
|
232
|
+
test('a missing judge CLI blocks before spending on the primary injected executor', async (t) => {
|
|
233
|
+
const f = setup(t);
|
|
234
|
+
await assert.rejects(runEval({ ...f.base, judgeExecutor: undefined, judgeAgent: 'claude-code', maxCalls: 4 }), error => {
|
|
235
|
+
assert.ok(error instanceof AgentPreflightFailed);
|
|
236
|
+
assert.equal(error.agentPreflight.checks.find(c => c.role === 'judge' && c.code === 'CLI_AVAILABLE').status, 'FAIL');
|
|
237
|
+
return true;
|
|
238
|
+
});
|
|
239
|
+
assert.equal(f.calls(), 0);
|
|
240
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
241
|
+
});
|
|
242
|
+
test('saved preflight survives changed machine inputs and portable replay without new readiness/auth probes', async (t) => {
|
|
243
|
+
const f = setup(t), preview = await runEvalCli({ ...f.base, dryRun: true });
|
|
244
|
+
const result = await runEvalCli(f.base, preview.plan.sha256);
|
|
245
|
+
assert.ok('agentPreflight' in result);
|
|
246
|
+
assert.ok('costs' in result);
|
|
247
|
+
assert.equal(result.status, 'completed');
|
|
248
|
+
assert.equal(result.evidence.verified, true);
|
|
249
|
+
assert.deepEqual(result.agentPreflight, preview.plan.evaluation.agentPreflight);
|
|
250
|
+
f.conflict();
|
|
251
|
+
rmSync(f.binary);
|
|
252
|
+
rmSync(f.skill, { recursive: true });
|
|
253
|
+
rmSync(f.bench, { recursive: true });
|
|
254
|
+
const run = join(f.base.runsRoot, f.base.runGroup), replay = await reportEvalComponent(run, { replay: true });
|
|
255
|
+
assert.equal(replay.evidence.verified, true);
|
|
256
|
+
assert.deepEqual(replay.agentPreflight, result.agentPreflight);
|
|
257
|
+
const lines = [];
|
|
258
|
+
await runEvalReport(run, line => lines.push(line));
|
|
259
|
+
assert.match(lines.join('\n'), /authentication remains unknown offline/);
|
|
260
|
+
assert.equal(lines.join('\n').includes(f.profile), false);
|
|
261
|
+
const output = join(f.root, 'portable');
|
|
262
|
+
await exportEvaluation(run, output, { yes: true, log: () => { } });
|
|
263
|
+
rmSync(run, { recursive: true });
|
|
264
|
+
const child = spawnSync(process.execPath, [join(output, 'reproduce.mjs')], { encoding: 'utf8', timeout: 30_000 });
|
|
265
|
+
assert.equal(child.status, 0, child.stderr);
|
|
266
|
+
assert.deepEqual(JSON.parse(child.stdout).agentPreflight, result.agentPreflight);
|
|
267
|
+
assert.deepEqual(JSON.parse(child.stdout).costs, result.costs);
|
|
268
|
+
assert.equal(f.calls(), 2);
|
|
269
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { 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 { ApiExecutor } from '../harness/executors/api.js';
|
|
7
|
+
import { runBenchInit } from './bench.js';
|
|
8
|
+
import { runEval } from './eval.js';
|
|
9
|
+
import { readEvaluationReport } from './evaluation-report.js';
|
|
10
|
+
for (const role of ['agent', 'judge'])
|
|
11
|
+
test(`failed ${role} API content retains known final costs in stopped reports`, async (t) => {
|
|
12
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-api-failure-'));
|
|
13
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
14
|
+
const skill = join(root, 'skill'), bench = join(root, 'bench'), run = join(root, 'runs', 'failed');
|
|
15
|
+
mkdirSync(skill);
|
|
16
|
+
writeFileSync(join(skill, 'SKILL.md'), '# Offline response failure regression\n');
|
|
17
|
+
await runBenchInit({ dir: bench, yes: true, log: () => { } });
|
|
18
|
+
let apiCalls = 0, primaryCalls = 0;
|
|
19
|
+
const payload = { choices: [{ message: { content: null, refusal: 'synthetic response' } }],
|
|
20
|
+
usage: { prompt_tokens: 123, completion_tokens: 17, prompt_tokens_details: { cached_tokens: 23 } } };
|
|
21
|
+
const api = new ApiExecutor({ apiKey: 'synthetic-api-key', fetchImpl: async () => { apiCalls++; return new Response(JSON.stringify(payload)); } });
|
|
22
|
+
const primary = { describe: () => ({ kind: 'mock', model: 'offline-primary' }), run: async () => {
|
|
23
|
+
primaryCalls++;
|
|
24
|
+
return { output: 'skillfit-ok', tokens: { input: 10, cachedInput: 4, output: 2 } };
|
|
25
|
+
} };
|
|
26
|
+
await assert.rejects(runEval({ skillPath: skill, bench, trials: 1, dryRun: false, yes: true, runsRoot: join(root, 'runs'), runGroup: 'failed',
|
|
27
|
+
executor: role === 'agent' ? api : primary, judgeExecutor: role === 'judge' ? api : null,
|
|
28
|
+
spendingBudget: { input: 1000, cachedInput: 1000, uncachedInput: 1000, output: 1000, durationSeconds: 1000 }, log: () => { } }), /EXECUTION_FAILED|choices\[0\]/);
|
|
29
|
+
assert.equal(apiCalls, 1);
|
|
30
|
+
assert.equal(primaryCalls, role === 'agent' ? 0 : 2);
|
|
31
|
+
const report = await readEvaluationReport(run);
|
|
32
|
+
assert.equal(report.status, 'stopped');
|
|
33
|
+
assert.ok('invocationCosts' in report);
|
|
34
|
+
const costs = report.invocationCosts?.total;
|
|
35
|
+
assert.ok(costs);
|
|
36
|
+
assert.equal(costs.metrics.input.knownTotal, role === 'agent' ? 123 : 143);
|
|
37
|
+
assert.equal(costs.metrics.cachedInput.knownTotal, role === 'agent' ? 23 : 31);
|
|
38
|
+
assert.equal(costs.metrics.output.knownTotal, role === 'agent' ? 17 : 21);
|
|
39
|
+
assert.equal(costs.metrics.input.coverage.final, role === 'agent' ? 1 : 3);
|
|
40
|
+
assert.equal(report.acceptance.eligibleForUpgrade, false);
|
|
41
|
+
assert.equal(report.acceptance.automaticUpgrade, false);
|
|
42
|
+
const evidence = role === 'agent' ? readFileSync(join(run, 'example-task/baseline/trial-1/_transcript.jsonl'), 'utf8')
|
|
43
|
+
: JSON.parse(readFileSync(join(run, 'example-task/judge-trial-1/call-1.json'), 'utf8')).rawOutput;
|
|
44
|
+
assert.deepEqual(JSON.parse(evidence), payload);
|
|
45
|
+
assert.equal(readFileSync(join(run, '_session.json'), 'utf8').includes('synthetic-api-key'), false);
|
|
46
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { prepareEvalPlan, confirmEvalPlan, plannedEvalResult } from './eval-plan.js';
|
|
4
|
+
import { reportEvalComponent } from './eval-component.js';
|
|
5
|
+
import { runEval } from './eval.js';
|
|
6
|
+
/** Preserve human CLI behavior while using the same reviewed plan as Agent requests. */
|
|
7
|
+
export async function runEvalCli(options, expectedPlanSha256) {
|
|
8
|
+
const prepared = await prepareEvalPlan(options, {}), { plan } = prepared;
|
|
9
|
+
if (options.dryRun) {
|
|
10
|
+
for (const line of prepared.lines)
|
|
11
|
+
options.log?.(line);
|
|
12
|
+
options.log?.(`Plan SHA : ${plan.sha256}`);
|
|
13
|
+
return plannedEvalResult(plan);
|
|
14
|
+
}
|
|
15
|
+
if (expectedPlanSha256 !== undefined)
|
|
16
|
+
confirmEvalPlan(expectedPlanSha256, plan.sha256);
|
|
17
|
+
const runDir = plan.evaluation.outputDir;
|
|
18
|
+
try {
|
|
19
|
+
await runEval({ ...prepared.options, dryRun: false, reviewedPlan: plan,
|
|
20
|
+
onPlan: preview => { prepared.assertCurrent(preview); options.onPlan?.(preview); } });
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (!existsSync(join(runDir, '_plan.json')))
|
|
24
|
+
throw error;
|
|
25
|
+
const result = await reportEvalComponent(runDir);
|
|
26
|
+
return { ...result, status: 'stopped', plan, executionError: error instanceof Error ? error.message : String(error),
|
|
27
|
+
acceptance: { ...result.acceptance, decision: result.acceptance.decision === 'reject' ? 'reject' : 'inconclusive', eligibleForUpgrade: false,
|
|
28
|
+
reasons: [...result.acceptance.reasons, { code: 'EXECUTION_STOPPED', message: 'Execution stopped; retained receipts do not authorize an upgrade.' }] } };
|
|
29
|
+
}
|
|
30
|
+
return { ...await reportEvalComponent(runDir), plan };
|
|
31
|
+
}
|