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
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { basename, dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { test } from 'node:test';
|
|
8
|
+
import { runBenchCheck, runBenchInit } from './bench.js';
|
|
9
|
+
import { runEval } from './eval.js';
|
|
10
|
+
import { readEvaluationReport } from './evaluation-report.js';
|
|
11
|
+
import { runEvalReport } from './eval-report.js';
|
|
12
|
+
import { exportEvaluation } from './eval-export.js';
|
|
13
|
+
import { ExperimentSession } from '../harness/experiment-session.js';
|
|
14
|
+
import { collectEvaluationTarget } from '../harness/target.js';
|
|
15
|
+
import { loadBench } from '../harness/bench.js';
|
|
16
|
+
import { ExecutorFailure } from '../harness/types.js';
|
|
17
|
+
const CLI = fileURLToPath(new URL('../cli.js', import.meta.url));
|
|
18
|
+
async function fixture(t, ids) {
|
|
19
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-report-modes-'));
|
|
20
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
21
|
+
const bench = join(root, 'bench'), skill = join(root, 'skill'), runsRoot = join(root, 'runs');
|
|
22
|
+
await runBenchInit({ dir: bench, yes: true, log: () => { } });
|
|
23
|
+
const path = join(bench, 'bench.json'), body = JSON.parse(readFileSync(path, 'utf8')), original = body.tasks[0];
|
|
24
|
+
body.tasks = ids.map(id => {
|
|
25
|
+
const prompt = `prompts/${id}.md`;
|
|
26
|
+
writeFileSync(join(bench, prompt), `CASE ${id}\nReply with skillfit-ok.\n`);
|
|
27
|
+
return { ...original, id, prompt, promptTrigger: prompt, shouldTrigger: !id.startsWith('neg'),
|
|
28
|
+
...(id === 'pos-fired' ? { triggerClass: 'explicit' } : id === 'pos-missed' ? { triggerClass: 'implicit' } : id === 'pos-unknown' ? { triggerClass: 'contextual' } : {}) };
|
|
29
|
+
});
|
|
30
|
+
writeFileSync(path, JSON.stringify(body));
|
|
31
|
+
mkdirSync(skill);
|
|
32
|
+
writeFileSync(join(skill, 'SKILL.md'), '# Synthetic mode-report test\n');
|
|
33
|
+
let calls = 0;
|
|
34
|
+
const perTask = new Map();
|
|
35
|
+
const executor = { describe: () => ({ kind: 'stub', model: 'offline-report-fixture' }), run: async (_prompt, workdir) => {
|
|
36
|
+
calls++;
|
|
37
|
+
const id = basename(dirname(dirname(workdir))), nth = (perTask.get(id) ?? 0) + 1;
|
|
38
|
+
perTask.set(id, nth);
|
|
39
|
+
if (id === 'neg-error')
|
|
40
|
+
throw new ExecutorFailure('synthetic executor error', { output: 'partial', tokens: { input: 4, output: 1 }, usageStatus: 'partial' });
|
|
41
|
+
return { output: id === 'hard' || (id === 'mixed' && nth === 2) ? 'wrong' : 'skillfit-ok',
|
|
42
|
+
tokens: { input: 10, cachedInput: 0, output: 1 },
|
|
43
|
+
...(id === 'pos-unknown' ? {} : { skillTriggered: id === 'pos-fired' || id === 'neg-fired' }) };
|
|
44
|
+
} };
|
|
45
|
+
const cli = (path, flags = []) => spawnSync(process.execPath, [CLI, 'report', 'eval', path, ...flags], { encoding: 'utf8', timeout: 30_000 });
|
|
46
|
+
return { root, bench, skill, runsRoot, executor, calls: () => calls, cli };
|
|
47
|
+
}
|
|
48
|
+
function observedFiles(run, final) {
|
|
49
|
+
return [final, '_plan.json', '_session.json', '_artifacts.json'].map(path => readFileSync(join(run, path), 'utf8'));
|
|
50
|
+
}
|
|
51
|
+
test('completed native calibration uses its own summary, state and difficulty metrics in both formats', async (t) => {
|
|
52
|
+
const f = await fixture(t, ['easy', 'hard', 'mixed']);
|
|
53
|
+
await runBenchCheck({ dir: f.bench, calibrate: { executor: f.executor, trials: 2, maxCalls: 6, runsRoot: f.runsRoot, runGroup: 'calibration' }, log: () => { } });
|
|
54
|
+
const run = join(f.runsRoot, 'calibration'), before = observedFiles(run, '_calibration.json');
|
|
55
|
+
const report = await readEvaluationReport(run);
|
|
56
|
+
assert.ok('evaluationType' in report && report.evaluationType === 'calibration');
|
|
57
|
+
assert.equal(report.status, 'completed');
|
|
58
|
+
assert.equal(report.kind, 'skillfit.calibration-report');
|
|
59
|
+
assert.deepEqual(report.summary?.tasks.map(t => t.difficulty), ['saturated', 'floor', 'discriminative']);
|
|
60
|
+
assert.deepEqual(report.summary?.metrics, { taskCount: 3, measuredTasks: 3, discriminativeTasks: 1, passes: 3, completed: 6, errors: 0, baselinePassRate: 0.5 });
|
|
61
|
+
assert.equal(report.usage?.metrics.input.knownTotal, 60);
|
|
62
|
+
assert.equal(report.usage?.metrics.cachedInput.knownTotal, 0);
|
|
63
|
+
assert.equal(report.usage?.metrics.cachedInput.coverage.final, 6);
|
|
64
|
+
assert.equal(report.acceptance.eligibleForUpgrade, false);
|
|
65
|
+
assert.equal(report.acceptance.automaticUpgrade, false);
|
|
66
|
+
assert.equal(report.evidence.verified, true);
|
|
67
|
+
assert.equal(report.evidence.scope, 'single-arm-native');
|
|
68
|
+
const human = f.cli(run), json = f.cli(run, ['--json']), file = f.cli(join(run, '_calibration.json'));
|
|
69
|
+
for (const output of [human, json, file])
|
|
70
|
+
assert.equal(output.status, 0, output.stderr);
|
|
71
|
+
assert.equal(JSON.parse(json.stdout).status, 'completed');
|
|
72
|
+
assert.equal(human.stdout, file.stdout);
|
|
73
|
+
assert.match(human.stdout, /Baseline pass rate: 3\/6 \(50.0%\)/);
|
|
74
|
+
assert.match(human.stdout, /discriminative tasks: 1\/3/);
|
|
75
|
+
assert.match(human.stdout, /saturated/);
|
|
76
|
+
assert.match(human.stdout, /floor/);
|
|
77
|
+
assert.doesNotMatch(human.stdout, /Overall verdict|State: stopped|McNemar/);
|
|
78
|
+
assert.equal((await exportEvaluation(run, join(f.root, 'export'), { log: () => { } })).status, 'planned');
|
|
79
|
+
assert.equal(existsSync(join(f.root, 'export')), false);
|
|
80
|
+
assert.deepEqual(observedFiles(run, '_calibration.json'), before);
|
|
81
|
+
assert.equal(f.calls(), 6);
|
|
82
|
+
rmSync(join(run, 'easy/baseline/trial-1/_result.json'));
|
|
83
|
+
const missing = await readEvaluationReport(run);
|
|
84
|
+
assert.ok('evaluationType' in missing);
|
|
85
|
+
assert.equal(missing.usage?.invocationsWithUnknownReceipts, 1);
|
|
86
|
+
assert.equal(missing.usage?.metrics.input.coverage.unknown, 1);
|
|
87
|
+
assert.equal(missing.acceptance.eligibleForUpgrade, false);
|
|
88
|
+
});
|
|
89
|
+
test('native trigger reports retain rates, Wilson intervals, classes, unknowns and errors without paired adoption', async (t) => {
|
|
90
|
+
const f = await fixture(t, ['pos-fired', 'pos-missed', 'pos-unknown', 'neg-fired', 'neg-quiet', 'neg-error']);
|
|
91
|
+
await runEval({ skillPath: f.skill, bench: f.bench, agent: 'codex', mode: 'trigger', executor: f.executor,
|
|
92
|
+
trials: 1, maxCalls: 6, runsRoot: f.runsRoot, runGroup: 'trigger', dryRun: false, yes: true, log: () => { } });
|
|
93
|
+
const run = join(f.runsRoot, 'trigger'), before = observedFiles(run, 'manifest.json');
|
|
94
|
+
const saved = JSON.parse(before[0]);
|
|
95
|
+
const report = await readEvaluationReport(run);
|
|
96
|
+
assert.ok('evaluationType' in report && report.evaluationType === 'trigger');
|
|
97
|
+
assert.equal(report.status, 'stopped');
|
|
98
|
+
assert.equal(report.kind, 'skillfit.trigger-report');
|
|
99
|
+
assert.deepEqual(report.summary?.metrics, saved.metrics);
|
|
100
|
+
assert.equal(report.summary?.metrics.recall, 0.5);
|
|
101
|
+
assert.equal(report.summary?.metrics.falseTriggerRate, 0.5);
|
|
102
|
+
assert.equal(report.summary?.metrics.precision, 0.5);
|
|
103
|
+
assert.equal(report.summary?.metrics.f1, 0.5);
|
|
104
|
+
assert.equal(report.summary?.tasks[2]?.unknown, 1);
|
|
105
|
+
assert.equal(report.summary?.tasks[5]?.errors, 1);
|
|
106
|
+
assert.equal(report.acceptance.eligibleForUpgrade, false);
|
|
107
|
+
assert.equal(report.acceptance.automaticUpgrade, false);
|
|
108
|
+
const human = f.cli(run), json = f.cli(join(run, 'manifest.json'), ['--json']);
|
|
109
|
+
assert.equal(human.status, 0, human.stderr);
|
|
110
|
+
assert.equal(json.status, 0, json.stderr);
|
|
111
|
+
assert.equal(JSON.parse(json.stdout).evaluationType, 'trigger');
|
|
112
|
+
assert.equal(JSON.parse(json.stdout).status, 'stopped');
|
|
113
|
+
for (const label of ['Recall: 50.0%', 'False-trigger rate: 50.0%', 'Precision: 50.0%', 'F1: 0.500', 'explicit recall:', 'implicit recall:', 'contextual recall: n/a', 'SKILL.md read', 'upper bound', 'Unknown | Errors'])
|
|
114
|
+
assert.ok(human.stdout.includes(label), label);
|
|
115
|
+
assert.doesNotMatch(human.stdout, /McNemar|Overall verdict|Installation decision/);
|
|
116
|
+
assert.deepEqual(observedFiles(run, 'manifest.json'), before);
|
|
117
|
+
assert.equal(f.calls(), 6);
|
|
118
|
+
});
|
|
119
|
+
test('completed trigger and standalone historical summaries preserve zero denominators and unknown provenance', async (t) => {
|
|
120
|
+
const f = await fixture(t, ['pos-missed', 'pos-unknown']);
|
|
121
|
+
await runEval({ skillPath: f.skill, bench: f.bench, mode: 'trigger', skillInstallDir: '.test-skills', executor: f.executor,
|
|
122
|
+
trials: 1, maxCalls: 2, runsRoot: f.runsRoot, runGroup: 'trigger', dryRun: false, yes: true, log: () => { } });
|
|
123
|
+
const run = join(f.runsRoot, 'trigger'), native = await readEvaluationReport(run);
|
|
124
|
+
assert.ok('evaluationType' in native && native.evaluationType === 'trigger');
|
|
125
|
+
assert.equal(native.status, 'completed');
|
|
126
|
+
assert.equal(native.summary?.metrics.recall, 0);
|
|
127
|
+
assert.equal(native.summary?.metrics.falseTriggerRate, null);
|
|
128
|
+
assert.equal(native.summary?.metrics.precision, null);
|
|
129
|
+
assert.equal(native.summary?.metrics.f1, null);
|
|
130
|
+
const value = JSON.parse(readFileSync(join(run, 'manifest.json'), 'utf8'));
|
|
131
|
+
delete value.experiment;
|
|
132
|
+
delete value.metrics.classRecall;
|
|
133
|
+
delete value.metrics.precisionCi95;
|
|
134
|
+
const standalone = join(f.root, 'historical.json');
|
|
135
|
+
writeFileSync(standalone, JSON.stringify(value));
|
|
136
|
+
const human = [];
|
|
137
|
+
await runEvalReport(standalone, line => human.push(line));
|
|
138
|
+
assert.match(human[0], /State: reported/);
|
|
139
|
+
assert.match(human[0], /False-trigger rate: n\/a/);
|
|
140
|
+
assert.match(human[0], /Precision: n\/a/);
|
|
141
|
+
assert.match(human[0], /F1: n\/a/);
|
|
142
|
+
assert.match(human[0], /Eligible for upgrade: no/);
|
|
143
|
+
assert.equal(f.calls(), 2);
|
|
144
|
+
});
|
|
145
|
+
test('standalone calibration excludes ungraded errors and leaves zero-completion difficulty unknown', async (t) => {
|
|
146
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-calibration-summary-'));
|
|
147
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
148
|
+
const path = join(root, 'renamed.json');
|
|
149
|
+
writeFileSync(path, JSON.stringify({ schemaVersion: 1, runGroup: 'historical', inputMode: 'snapshot', trials: 2,
|
|
150
|
+
tasks: [{ id: 'one', passes: 1, completed: 1, errors: 1 }, { id: 'none', passes: 0, completed: 0, errors: 2 }] }));
|
|
151
|
+
const report = await readEvaluationReport(path);
|
|
152
|
+
assert.ok('evaluationType' in report && report.evaluationType === 'calibration');
|
|
153
|
+
assert.equal(report.status, 'reported');
|
|
154
|
+
assert.equal(report.summary?.metrics.baselinePassRate, 1);
|
|
155
|
+
assert.equal(report.summary?.metrics.errors, 3);
|
|
156
|
+
assert.equal(report.summary?.tasks[1]?.passRate, null);
|
|
157
|
+
assert.equal(report.summary?.tasks[1]?.difficulty, 'unmeasured');
|
|
158
|
+
});
|
|
159
|
+
test('stopped and unfinished single-arm sessions never fabricate final metrics or completion', async (t) => {
|
|
160
|
+
for (const mode of ['calibration', 'trigger'])
|
|
161
|
+
await t.test(mode, async (t) => {
|
|
162
|
+
const f = await fixture(t, ['easy']);
|
|
163
|
+
const run = join(f.runsRoot, mode);
|
|
164
|
+
const session = new ExperimentSession({ bench: loadBench(f.bench), target: collectEvaluationTarget(f.skill), groupDir: run,
|
|
165
|
+
workspaces: [join(run, 'easy/baseline/trial-1')], plannedCalls: 1, maxCalls: 1, injected: true, details: { mode } });
|
|
166
|
+
session.finish(new Error('synthetic cancellation'));
|
|
167
|
+
const stopped = await readEvaluationReport(run);
|
|
168
|
+
assert.ok('evaluationType' in stopped);
|
|
169
|
+
assert.equal(stopped.status, 'stopped');
|
|
170
|
+
assert.equal(stopped.summary, null);
|
|
171
|
+
assert.equal(stopped.acceptance.eligibleForUpgrade, false);
|
|
172
|
+
const human = f.cli(run);
|
|
173
|
+
assert.equal(human.status, 0, human.stderr);
|
|
174
|
+
assert.match(human.stdout, /Metrics are unavailable/);
|
|
175
|
+
rmSync(join(run, '_session.json'));
|
|
176
|
+
const unfinished = await readEvaluationReport(run);
|
|
177
|
+
assert.equal(unfinished.status, 'incomplete');
|
|
178
|
+
assert.equal(f.calls(), 0);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
test('single-arm reports reject contradictory counts, metrics, schemas, session states and ignored options', async (t) => {
|
|
182
|
+
const f = await fixture(t, ['pos-fired', 'neg-quiet']);
|
|
183
|
+
await runEval({ skillPath: f.skill, bench: f.bench, mode: 'trigger', skillInstallDir: '.test-skills', executor: f.executor,
|
|
184
|
+
trials: 1, maxCalls: 2, runsRoot: f.runsRoot, runGroup: 'trigger', dryRun: false, yes: true, log: () => { } });
|
|
185
|
+
const run = join(f.runsRoot, 'trigger'), path = join(run, 'manifest.json'), original = readFileSync(path, 'utf8');
|
|
186
|
+
const scenarios = [
|
|
187
|
+
(v) => { v.tasks[0].fired = 2; },
|
|
188
|
+
(v) => { v.tasks[0].runs = -1; },
|
|
189
|
+
(v) => { v.tasks[0].unknown = 0.5; },
|
|
190
|
+
(v) => { v.tasks[1].id = v.tasks[0].id; },
|
|
191
|
+
(v) => { v.metrics.recall = 0; },
|
|
192
|
+
(v) => { v.metrics.recallCi95 = { lo: 0, hi: 0 }; },
|
|
193
|
+
(v) => { v.schemaVersion = 2; },
|
|
194
|
+
(v) => { v.experiment.status = 'incomplete'; },
|
|
195
|
+
];
|
|
196
|
+
for (const change of scenarios) {
|
|
197
|
+
const value = JSON.parse(original);
|
|
198
|
+
change(value);
|
|
199
|
+
writeFileSync(path, JSON.stringify(value));
|
|
200
|
+
await assert.rejects(() => readEvaluationReport(run));
|
|
201
|
+
}
|
|
202
|
+
writeFileSync(path, original);
|
|
203
|
+
for (const json of [false, true]) {
|
|
204
|
+
const replay = f.cli(run, ['--replay', ...(json ? ['--json'] : [])]);
|
|
205
|
+
assert.equal(replay.status, 0, replay.stderr);
|
|
206
|
+
if (json) {
|
|
207
|
+
const result = JSON.parse(replay.stdout);
|
|
208
|
+
assert.equal(result.evidence.verified, true);
|
|
209
|
+
assert.equal(result.evidence.replayedDeliveries, 2);
|
|
210
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (const flags of [['--policy', 'missing.json'], ['--records', run], ['--bench', f.bench]]) {
|
|
214
|
+
for (const json of [false, true]) {
|
|
215
|
+
const result = f.cli(run, [...flags, ...(json ? ['--json'] : [])]);
|
|
216
|
+
assert.equal(result.status, json ? 2 : 1);
|
|
217
|
+
if (json) {
|
|
218
|
+
const failure = JSON.parse(result.stdout);
|
|
219
|
+
assert.equal(failure.status, 'error');
|
|
220
|
+
assert.equal(failure.acceptance.eligibleForUpgrade, false);
|
|
221
|
+
}
|
|
222
|
+
else
|
|
223
|
+
assert.match(result.stderr, /do not support paired|only used with --replay/);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
copyFileSync(path, join(run, '_calibration.json'));
|
|
227
|
+
await assert.rejects(() => readEvaluationReport(run), /Ambiguous run/);
|
|
228
|
+
assert.equal(f.calls(), 2);
|
|
229
|
+
});
|
|
230
|
+
test('invalid calibration summaries fail rather than being mislabeled stopped or interpreted as trigger data', async (t) => {
|
|
231
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-invalid-calibration-'));
|
|
232
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
233
|
+
const path = join(root, '_calibration.json'), value = { schemaVersion: 1, runGroup: 'calibration', inputMode: 'workspace', trials: 2,
|
|
234
|
+
tasks: [{ id: 'one', completed: 1, errors: 1, passes: 1 }] };
|
|
235
|
+
for (const change of [(v) => { v.tasks[0].passes = 2; }, (v) => { v.tasks[0].errors = 2; },
|
|
236
|
+
(v) => { v.tasks[0].completed = null; }, (v) => { v.inputMode = 'unknown'; }, (v) => { v.tasks = []; }]) {
|
|
237
|
+
const changed = structuredClone(value);
|
|
238
|
+
change(changed);
|
|
239
|
+
writeFileSync(path, JSON.stringify(changed));
|
|
240
|
+
await assert.rejects(() => readEvaluationReport(path));
|
|
241
|
+
}
|
|
242
|
+
assert.ok(!existsSync(join(root, 'manifest.json')));
|
|
243
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
+
import { test } from 'node:test';
|
|
8
|
+
import { runBenchInit } from './bench.js';
|
|
9
|
+
import { runEval } from './eval.js';
|
|
10
|
+
import { killTree } from '../harness/kill-tree.js';
|
|
11
|
+
import { packageFiles } from '../harness/replay-package.js';
|
|
12
|
+
import { sha256File } from '../harness/hash.js';
|
|
13
|
+
const cli = fileURLToPath(new URL('../cli.js', import.meta.url));
|
|
14
|
+
const pause = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
15
|
+
const json = (path) => JSON.parse(readFileSync(path, 'utf8'));
|
|
16
|
+
function running(pid) {
|
|
17
|
+
try {
|
|
18
|
+
process.kill(pid, 0);
|
|
19
|
+
if (process.platform === 'linux' && readFileSync(`/proc/${pid}/stat`, 'utf8').split(')').at(-1).trim().startsWith('Z'))
|
|
20
|
+
return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function scenario(t, signal, repeat = false) {
|
|
28
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-replay-cancel-'));
|
|
29
|
+
const bench = join(root, 'bench'), skill = join(root, 'skill'), run = join(root, 'runs/saved');
|
|
30
|
+
const ready = join(root, 'ready.json'), heartbeat = join(root, 'heartbeat');
|
|
31
|
+
let child;
|
|
32
|
+
t.after(async () => {
|
|
33
|
+
if (child?.exitCode === null && child.signalCode === null)
|
|
34
|
+
killTree(child);
|
|
35
|
+
if (existsSync(ready))
|
|
36
|
+
for (const pid of json(ready).pids)
|
|
37
|
+
if (running(pid)) {
|
|
38
|
+
try {
|
|
39
|
+
process.kill(pid, 'SIGKILL');
|
|
40
|
+
}
|
|
41
|
+
catch { /* Already stopped. */ }
|
|
42
|
+
}
|
|
43
|
+
await pause(100);
|
|
44
|
+
rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
45
|
+
});
|
|
46
|
+
await runBenchInit({ dir: bench, yes: true, log: () => { } });
|
|
47
|
+
mkdirSync(skill);
|
|
48
|
+
writeFileSync(join(skill, 'SKILL.md'), '# Offline cancellation fixture\n');
|
|
49
|
+
const leaf = join(root, 'leaf.mjs');
|
|
50
|
+
writeFileSync(leaf, `import{appendFileSync}from'node:fs';process.on('SIGINT',()=>{});process.on('SIGTERM',()=>{});setInterval(()=>appendFileSync(${JSON.stringify(heartbeat)},'x'),30);setTimeout(()=>process.exit(),30000);`);
|
|
51
|
+
writeFileSync(join(bench, 'verifiers/example-task.mjs'), `import{spawn}from'node:child_process';import{existsSync,readFileSync,writeFileSync}from'node:fs';import{join}from'node:path';
|
|
52
|
+
if(process.env.SKILLFIT_OFFLINE_REPLAY_BLOCK==='yes'){
|
|
53
|
+
process.on('SIGINT',()=>{});process.on('SIGTERM',()=>{});
|
|
54
|
+
const leaf=spawn(process.execPath,[${JSON.stringify(leaf)}],{stdio:'ignore'});
|
|
55
|
+
const timer=setInterval(()=>{if(existsSync(${JSON.stringify(heartbeat)})){clearInterval(timer);writeFileSync(${JSON.stringify(ready)},JSON.stringify({pids:[process.pid,leaf.pid]}));}},20);
|
|
56
|
+
setTimeout(()=>process.exit(),30000);
|
|
57
|
+
}else{const out=join(process.argv[2],'_output.md');process.exit(existsSync(out)&&readFileSync(out,'utf8').trim()==='skillfit-ok'?0:1);}`);
|
|
58
|
+
let fakeCalls = 0;
|
|
59
|
+
await runEval({ skillPath: skill, bench, trials: 1, maxCalls: 2, runsRoot: join(root, 'runs'), runGroup: 'saved',
|
|
60
|
+
dryRun: false, yes: true, judgeExecutor: null, log: () => { }, executor: {
|
|
61
|
+
describe: () => ({ kind: 'stub', model: 'offline-only' }), run: async () => { fakeCalls++; return { output: 'skillfit-ok', tokens: { input: 10, cachedInput: 2, output: 3 } }; },
|
|
62
|
+
} });
|
|
63
|
+
assert.equal(fakeCalls, 2);
|
|
64
|
+
const evidence = packageFiles(run).map(path => [path, sha256File(join(run, path))]);
|
|
65
|
+
const harness = join(root, 'replay-harness.mjs');
|
|
66
|
+
writeFileSync(harness, `process.on('message',message=>{process.emit(message.signal);if(message.repeat){process.emit(message.signal);process.emit('SIGTERM');}});
|
|
67
|
+
process.argv=[process.execPath,${JSON.stringify(cli)},'report','eval',${JSON.stringify(run)},'--json','--replay'];
|
|
68
|
+
await import(${JSON.stringify(pathToFileURL(cli).href)});
|
|
69
|
+
const timer=setInterval(()=>{if(process.exitCode!==undefined&&process.listenerCount('SIGINT')===0){clearInterval(timer);process.disconnect();}},20);`);
|
|
70
|
+
child = spawn(process.execPath, [harness], { env: { ...process.env, SKILLFIT_OFFLINE_REPLAY_BLOCK: 'yes' }, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });
|
|
71
|
+
let stdout = '', stderr = '';
|
|
72
|
+
child.stdout.on('data', chunk => { stdout += chunk; });
|
|
73
|
+
child.stderr.on('data', chunk => { stderr += chunk; });
|
|
74
|
+
const closed = new Promise(resolve => child.once('close', (code, signal) => resolve({ code, signal })));
|
|
75
|
+
for (let i = 0; i < 200 && !existsSync(ready) && child.exitCode === null; i++)
|
|
76
|
+
await pause(50);
|
|
77
|
+
assert.ok(existsSync(ready), `Offline replay verifier did not start: ${stderr}`);
|
|
78
|
+
// Windows kill('SIGINT') terminates forcibly; IPC emits the same JS console event
|
|
79
|
+
// while taskkill /T remains the real process-tree cancellation implementation.
|
|
80
|
+
if (process.platform === 'win32' || repeat)
|
|
81
|
+
child.send({ signal, repeat });
|
|
82
|
+
else
|
|
83
|
+
child.kill(signal);
|
|
84
|
+
let timeout;
|
|
85
|
+
const exit = await Promise.race([closed, new Promise((_, reject) => { timeout = setTimeout(() => reject(new Error(`Replay did not stop: ${stderr}`)), 10_000); })]).finally(() => clearTimeout(timeout));
|
|
86
|
+
assert.deepEqual(exit, { code: signal === 'SIGINT' ? 130 : 143, signal: null }, stderr);
|
|
87
|
+
const result = JSON.parse(stdout);
|
|
88
|
+
assert.equal(result.kind, 'skillfit.eval-error');
|
|
89
|
+
assert.match(result.error.message, new RegExp(signal));
|
|
90
|
+
for (let i = 0; i < 100 && json(ready).pids.some(running); i++)
|
|
91
|
+
await pause(50);
|
|
92
|
+
assert.ok(json(ready).pids.every((pid) => !running(pid)), 'Replay verifier and its grandchild must stop.');
|
|
93
|
+
const finalHeartbeat = readFileSync(heartbeat, 'utf8');
|
|
94
|
+
await pause(100);
|
|
95
|
+
assert.equal(readFileSync(heartbeat, 'utf8'), finalHeartbeat);
|
|
96
|
+
assert.deepEqual(packageFiles(run).map(path => [path, sha256File(join(run, path))]), evidence, 'Read-only replay cancellation must leave native evidence unchanged.');
|
|
97
|
+
assert.equal(fakeCalls, 2, 'Replay adds no executor observations.');
|
|
98
|
+
}
|
|
99
|
+
for (const signal of ['SIGINT', 'SIGTERM'])
|
|
100
|
+
test(`${signal} cancels saved delivery replay, kills verifier descendants and emits one JSON document`, { timeout: 30_000 }, async (t) => {
|
|
101
|
+
await scenario(t, signal);
|
|
102
|
+
});
|
|
103
|
+
test('repeated replay interrupts preserve the first exit code and clean up without changing receipts', { timeout: 30_000 }, async (t) => {
|
|
104
|
+
await scenario(t, 'SIGINT', true);
|
|
105
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
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 { AgentPreflightFailed } from '../harness/agent-preflight.js';
|
|
9
|
+
import { runEval } from './eval.js';
|
|
10
|
+
import { runEvalCli } from './eval-cli.js';
|
|
11
|
+
const CLI = fileURLToPath(new URL('../cli.js', import.meta.url));
|
|
12
|
+
function fixture(t) {
|
|
13
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-workflow-'));
|
|
14
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
15
|
+
const bench = join(root, 'bench'), skill = join(root, 'skill'), home = join(root, 'home');
|
|
16
|
+
for (const dir of [join(bench, 'fixture'), join(skill, 'resources'), home])
|
|
17
|
+
mkdirSync(dir, { recursive: true });
|
|
18
|
+
writeFileSync(join(skill, 'SKILL.md'), '---\nname: workflow-skill\ndescription: Return the correct answer.\n---\nReturn OK.\n');
|
|
19
|
+
writeFileSync(join(skill, 'resources', 'image.bin'), Buffer.from([0, 1, 2, 3]));
|
|
20
|
+
writeFileSync(join(bench, 'fixture', 'input.txt'), 'input\n');
|
|
21
|
+
writeFileSync(join(bench, 'prompt.md'), 'Return OK.');
|
|
22
|
+
writeFileSync(join(bench, 'verify.mjs'), "import{readFileSync,existsSync}from'node:fs';import{join}from'node:path';const p=join(process.argv[2],'_output.md');const passed=existsSync(p)&&readFileSync(p,'utf8').trim()==='OK';console.log(JSON.stringify({passed,checks:[{name:'correct',pass:passed},{name:'complete',pass:passed}]}));process.exit(passed?0:1);");
|
|
23
|
+
writeFileSync(join(bench, 'oracle.mjs'), "import{writeFileSync}from'node:fs';import{join}from'node:path';writeFileSync(join(process.argv[2],'_output.md'),'OK');");
|
|
24
|
+
writeFileSync(join(bench, 'bench.json'), JSON.stringify({ schemaVersion: 1, name: 'workflow', tasks: [true, false].map((shouldTrigger, i) => ({
|
|
25
|
+
id: `task-${i + 1}`, fixture: 'fixture', prompt: 'prompt.md', verifier: 'node verify.mjs', oracle: 'node oracle.mjs', shouldTrigger,
|
|
26
|
+
})) }));
|
|
27
|
+
let calls = 0;
|
|
28
|
+
const base = { skillPath: skill, bench, mode: 'trigger', agent: 'codex', trials: 1, maxCalls: 2,
|
|
29
|
+
dryRun: false, yes: true, runsRoot: join(root, 'runs'), runGroup: 'trigger', log: () => { },
|
|
30
|
+
sessionOptions: { homeDir: home, env: { ...process.env, CODEX_HOME: join(home, 'profile') }, versionProbe: () => null },
|
|
31
|
+
executor: { describe: () => ({ kind: 'cli', model: 'offline-injected', sampling: null }), run: async () => {
|
|
32
|
+
calls++;
|
|
33
|
+
return { output: 'OK', skillTriggered: true, tokens: { input: 10, cachedInput: 4, output: 2 } };
|
|
34
|
+
} } };
|
|
35
|
+
const limits = { input: 10000, cachedInput: 10000, uncachedInput: 10000, output: 10000, durationSeconds: 10000 };
|
|
36
|
+
return { root, skill, bench, home, base, limits, calls: () => calls };
|
|
37
|
+
}
|
|
38
|
+
test('trigger shares reviewed JSON plans, configurable stop lines and sealed reports without paired adoption', async (t) => {
|
|
39
|
+
const f = fixture(t), base = { ...f.base, executorTimeoutSeconds: 19, spendingBudget: f.limits };
|
|
40
|
+
const preview = await runEvalCli({ ...base, dryRun: true });
|
|
41
|
+
assert.equal(preview.plan.evaluation.mode, 'trigger');
|
|
42
|
+
assert.equal(preview.plan.evaluation.plannedCalls, 2);
|
|
43
|
+
assert.equal(preview.plan.evaluation.executorTimeoutSeconds, 19);
|
|
44
|
+
assert.deepEqual(preview.plan.evaluation.spendingBudget, f.limits);
|
|
45
|
+
assert.equal(f.calls(), 0);
|
|
46
|
+
assert.equal(existsSync(base.runsRoot), false);
|
|
47
|
+
const result = await runEvalCli(base, preview.plan.sha256);
|
|
48
|
+
assert.ok('evaluationType' in result && result.evaluationType === 'trigger');
|
|
49
|
+
assert.equal(result.status, 'completed');
|
|
50
|
+
assert.equal(result.evidence.verified, true, result.evidence.reasons.join('; '));
|
|
51
|
+
assert.equal(result.usage?.runs, 2);
|
|
52
|
+
assert.equal(result.usage?.metrics.input.knownTotal, 20);
|
|
53
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
54
|
+
assert.equal(result.acceptance.automaticUpgrade, false);
|
|
55
|
+
const plan = JSON.parse(readFileSync(join(base.runsRoot, base.runGroup, '_plan.json'), 'utf8'));
|
|
56
|
+
assert.deepEqual(plan.details.reviewedPlan, preview.plan);
|
|
57
|
+
assert.equal(plan.details.executorTimeoutSeconds, 19);
|
|
58
|
+
assert.equal(f.calls(), 2);
|
|
59
|
+
});
|
|
60
|
+
test('trigger token stop lines retain the paid prefix and never dispatch the next task', async (t) => {
|
|
61
|
+
const f = fixture(t), base = { ...f.base, spendingBudget: { ...f.limits, input: 5 } };
|
|
62
|
+
const preview = await runEvalCli({ ...base, dryRun: true }), result = await runEvalCli(base, preview.plan.sha256);
|
|
63
|
+
assert.ok('evaluationType' in result && result.evaluationType === 'trigger');
|
|
64
|
+
assert.equal(result.status, 'stopped');
|
|
65
|
+
assert.equal(f.calls(), 1);
|
|
66
|
+
assert.equal(result.usage?.runs, 1);
|
|
67
|
+
assert.equal(result.usage?.metrics.input.knownTotal, 10);
|
|
68
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
69
|
+
assert.match(result.session?.stopReason ?? '', /SPENDING_BUDGET_REACHED/);
|
|
70
|
+
assert.equal(existsSync(join(base.runsRoot, base.runGroup, 'task-2', 'installed', 'trial-1')), false);
|
|
71
|
+
});
|
|
72
|
+
test('trigger missing final cache coverage stops rather than assuming a zero cache bill', async (t) => {
|
|
73
|
+
const f = fixture(t);
|
|
74
|
+
let calls = 0;
|
|
75
|
+
const base = { ...f.base, spendingBudget: f.limits, executor: { describe: () => ({ kind: 'cli', model: 'offline-missing-cache' }), run: async () => {
|
|
76
|
+
calls++;
|
|
77
|
+
return { output: 'OK', skillTriggered: true, tokens: { input: 10, output: 2 } };
|
|
78
|
+
} } };
|
|
79
|
+
const preview = await runEvalCli({ ...base, dryRun: true }), result = await runEvalCli(base, preview.plan.sha256);
|
|
80
|
+
assert.ok('evaluationType' in result);
|
|
81
|
+
assert.equal(result.status, 'stopped');
|
|
82
|
+
assert.equal(calls, 1);
|
|
83
|
+
assert.equal(result.usage?.metrics.cachedInput.coverage.unknown, 1);
|
|
84
|
+
assert.equal(result.usage?.metrics.input.knownTotal, 10);
|
|
85
|
+
assert.match(result.session?.stopReason ?? '', /FINAL_USAGE_MISSING/);
|
|
86
|
+
});
|
|
87
|
+
test('trigger plan confirmation pins binary Skill resources and spending settings before any dispatch', async (t) => {
|
|
88
|
+
const f = fixture(t), preview = await runEvalCli({ ...f.base, dryRun: true });
|
|
89
|
+
assert.ok(preview.plan.evaluation.installedFingerprint?.files.includes('resources/image.bin'));
|
|
90
|
+
writeFileSync(join(f.skill, 'resources', 'image.bin'), Buffer.from([8, 9]));
|
|
91
|
+
await assert.rejects(runEvalCli(f.base, preview.plan.sha256), /--plan-sha/);
|
|
92
|
+
assert.equal(f.calls(), 0);
|
|
93
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
94
|
+
const updated = await runEvalCli({ ...f.base, dryRun: true });
|
|
95
|
+
await assert.rejects(runEvalCli({ ...f.base, spendingBudget: f.limits }, updated.plan.sha256), /--plan-sha/);
|
|
96
|
+
assert.equal(f.calls(), 0);
|
|
97
|
+
});
|
|
98
|
+
test('public trigger JSON previews work without an installed agent and live missing-CLI failures remain structured', t => {
|
|
99
|
+
const f = fixture(t), env = { ...process.env, HOME: f.home, USERPROFILE: f.home, CODEX_HOME: join(f.home, 'profile'), SKILLFIT_JUDGE: '0' };
|
|
100
|
+
for (const key of Object.keys(env))
|
|
101
|
+
if (key.toLowerCase() === 'path')
|
|
102
|
+
delete env[key];
|
|
103
|
+
const isolated = { ...env, PATH: '' };
|
|
104
|
+
const args = ['eval', f.skill, '--bench', f.bench, '--mode', 'trigger', '--agent', 'codex', '--trials', '1', '--max-calls', '2', '--run-group', 'public-trigger', '--runs-root', join(f.root, 'runs'), '--json'];
|
|
105
|
+
const preview = spawnSync(process.execPath, [CLI, ...args, '--dry-run'], { encoding: 'utf8', env: isolated });
|
|
106
|
+
assert.equal(preview.status, 0, preview.stderr);
|
|
107
|
+
const planned = JSON.parse(preview.stdout);
|
|
108
|
+
assert.equal(planned.plan.evaluation.mode, 'trigger');
|
|
109
|
+
assert.equal(planned.plan.evaluation.agentPreflight.status, 'blocked');
|
|
110
|
+
const live = spawnSync(process.execPath, [CLI, ...args, '--plan-sha', planned.plan.sha256], { encoding: 'utf8', env: isolated });
|
|
111
|
+
assert.equal(live.status, 2, live.stderr);
|
|
112
|
+
const error = JSON.parse(live.stdout);
|
|
113
|
+
assert.equal(error.error.code, 'AGENT_PREFLIGHT_FAILED');
|
|
114
|
+
assert.equal(existsSync(join(f.root, 'runs')), false);
|
|
115
|
+
});
|
|
116
|
+
test('an explicitly enabled API judge without credentials blocks rather than silently running without judging', async (t) => {
|
|
117
|
+
const f = fixture(t), names = ['SKILLFIT_JUDGE', 'SKILLFIT_JUDGE_API_KEY', 'SKILLFIT_API_KEY', 'OPENAI_API_KEY'];
|
|
118
|
+
const previous = names.map(name => process.env[name]);
|
|
119
|
+
try {
|
|
120
|
+
for (const name of names)
|
|
121
|
+
delete process.env[name];
|
|
122
|
+
process.env['SKILLFIT_JUDGE'] = '1';
|
|
123
|
+
const base = { ...f.base, mode: 'inject', maxCalls: 4 };
|
|
124
|
+
const preview = await runEvalCli({ ...base, dryRun: true });
|
|
125
|
+
assert.equal(preview.plan.evaluation.agentPreflight.status, 'blocked');
|
|
126
|
+
assert.ok(preview.plan.evaluation.agentPreflight.checks.some(check => check.role === 'judge' && check.status === 'FAIL'));
|
|
127
|
+
await assert.rejects(runEval(base), AgentPreflightFailed);
|
|
128
|
+
assert.equal(f.calls(), 0);
|
|
129
|
+
assert.equal(existsSync(base.runsRoot), false);
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
names.forEach((name, i) => { if (previous[i] === undefined)
|
|
133
|
+
delete process.env[name];
|
|
134
|
+
else
|
|
135
|
+
process.env[name] = previous[i]; });
|
|
136
|
+
}
|
|
137
|
+
});
|