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
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
import { existsSync, statSync } from 'node:fs';
|
|
2
2
|
import { dirname, join, resolve } from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
3
|
import { assessEvaluation } from '../harness/eval-acceptance.js';
|
|
5
4
|
import { auditEvaluation, stoppedAccounting } from '../harness/eval-audit.js';
|
|
6
5
|
import { loadEvalRequest, parseAcceptancePolicy, policyHash, readComponentJson, record } from '../harness/eval-contract.js';
|
|
7
|
-
import { hashFileSet, listFilesRecursive, sha256Text } from '../harness/hash.js';
|
|
8
6
|
import { runEval } from './eval.js';
|
|
7
|
+
import { prepareEvalPlan, confirmEvalPlan, plannedEvalResult } from './eval-plan.js';
|
|
9
8
|
import { spendingBudgetReport } from '../harness/eval-budget.js';
|
|
10
9
|
import { verifyReplayPackage } from '../harness/replay-package.js';
|
|
11
10
|
import { CasePreflightFailed } from './eval-preflight.js';
|
|
11
|
+
import { AgentPreflightFailed } from '../harness/agent-preflight.js';
|
|
12
|
+
import { reportSingleArmEvaluation } from './eval-single-arm-replay.js';
|
|
13
|
+
import { historicalInvocationCosts, parseInvocationCosts } from '../harness/invocation-costs.js';
|
|
14
|
+
import { withEvaluationInterrupts } from '../harness/interruption.js';
|
|
12
15
|
export function componentError(error, code = 'INVALID_OR_FAILED_EVALUATION') {
|
|
13
16
|
return { schemaVersion: 1, kind: 'skillfit.eval-error', status: 'error',
|
|
14
|
-
error: { code: error instanceof CasePreflightFailed ? 'CASE_PREFLIGHT_FAILED' : code, message: error instanceof Error ? error.message : String(error) },
|
|
17
|
+
error: { code: error instanceof CasePreflightFailed ? 'CASE_PREFLIGHT_FAILED' : error instanceof AgentPreflightFailed ? 'AGENT_PREFLIGHT_FAILED' : code, message: error instanceof Error ? error.message : String(error) },
|
|
18
|
+
...(error instanceof AgentPreflightFailed ? { agentPreflight: error.agentPreflight } : {}),
|
|
15
19
|
...(error instanceof CasePreflightFailed ? { casePreflight: error.preflight } : {}),
|
|
16
20
|
acceptance: { decision: 'inconclusive', eligibleForUpgrade: false, automaticUpgrade: false } };
|
|
17
21
|
}
|
|
18
22
|
export async function reportEvalComponent(path, options = {}) {
|
|
23
|
+
return options.replay ? withEvaluationInterrupts(() => readSavedEvaluation(path, options)) : readSavedEvaluation(path, options);
|
|
24
|
+
}
|
|
25
|
+
async function readSavedEvaluation(path, options) {
|
|
19
26
|
if (statSync(resolve(path)).isDirectory() && existsSync(join(resolve(path), 'replay-package.json'))) {
|
|
20
27
|
if (options.recordsPath || options.benchDir)
|
|
21
28
|
throw new Error('Portable packages already pin their run and bench; external overrides are not allowed.');
|
|
22
29
|
const metadata = verifyReplayPackage(resolve(path));
|
|
23
|
-
return { ...await reportNativeEvaluation(join(resolve(path), 'run'), { ...options,
|
|
30
|
+
return { ...await reportNativeEvaluation(join(resolve(path), 'run'), { ...options,
|
|
31
|
+
...(options.replay ? { benchDir: join(resolve(path), 'inputs/bench') } : {}) }),
|
|
24
32
|
portablePackage: { integrityVerified: true, sourcePlanSha256: metadata.sourcePlanSha256, files: Object.keys(metadata.files).length } };
|
|
25
33
|
}
|
|
26
34
|
return reportNativeEvaluation(path, options);
|
|
27
35
|
}
|
|
28
36
|
async function reportNativeEvaluation(path, options) {
|
|
37
|
+
const single = await reportSingleArmEvaluation(path, options);
|
|
38
|
+
if (single) {
|
|
39
|
+
const spendingBudget = spendingBudgetReport(single.evidence.runDir);
|
|
40
|
+
return { ...single, ...(spendingBudget ? { spendingBudget } : {}) };
|
|
41
|
+
}
|
|
29
42
|
const input = resolve(path), directory = statSync(input).isDirectory();
|
|
30
43
|
const manifestPath = directory ? join(input, 'manifest.json') : input;
|
|
31
44
|
const runDir = resolve(options.recordsPath ?? (directory ? input : dirname(input)));
|
|
@@ -36,10 +49,13 @@ async function reportNativeEvaluation(path, options) {
|
|
|
36
49
|
const sessionPath = join(runDir, '_session.json');
|
|
37
50
|
const session = existsSync(sessionPath) ? record(readComponentJson(sessionPath).value, 'session') : null;
|
|
38
51
|
const nativePlan = record(readComponentJson(join(runDir, '_plan.json')).value, 'native plan');
|
|
52
|
+
const costs = stoppedAccounting(runDir);
|
|
39
53
|
return { schemaVersion: 1, kind: 'skillfit.eval-result', status: session ? 'stopped' : 'incomplete',
|
|
54
|
+
agentPreflight: nativePlan.details ? record(nativePlan.details, 'native plan details').agentPreflight ?? null : null,
|
|
40
55
|
casePreflight: nativePlan.details ? record(nativePlan.details, 'native plan details').casePreflight ?? null : null,
|
|
41
56
|
inputSnapshot: nativePlan.inputSnapshot ?? null,
|
|
42
|
-
manifest: null, session, costs
|
|
57
|
+
manifest: null, session, costs, invocationCosts: costs.invocationCosts,
|
|
58
|
+
evidence: { verified: false, runDir, reasons: ['No final evaluation manifest; retained spending only.'] },
|
|
43
59
|
...(spendingBudget ? { spendingBudget } : {}),
|
|
44
60
|
acceptance: { decision: 'inconclusive', eligibleForUpgrade: false, automaticUpgrade: false,
|
|
45
61
|
reasons: [{ code: 'EXPERIMENT_NOT_COMPLETED', message: 'No completed paired evaluation is available.' }] } };
|
|
@@ -48,8 +64,14 @@ async function reportNativeEvaluation(path, options) {
|
|
|
48
64
|
const audit = await auditEvaluation(data.value, runDir, options);
|
|
49
65
|
const policy = options.policyPath ? parseAcceptancePolicy(readComponentJson(resolve(options.policyPath)).value) : undefined;
|
|
50
66
|
const result = assessEvaluation(data.value, audit, policy);
|
|
67
|
+
const raw = record(data.value, 'manifest');
|
|
68
|
+
const populations = result.costs.populations?.attempts;
|
|
69
|
+
const invocationCosts = raw.invocationCosts === undefined
|
|
70
|
+
? populations ? historicalInvocationCosts(combinePopulations(populations.baseline, populations.treatment), raw.judge != null) : null
|
|
71
|
+
: parseInvocationCosts(raw.invocationCosts);
|
|
51
72
|
const nativePlan = audit.verified ? record(readComponentJson(join(runDir, '_plan.json')).value, 'native plan') : null;
|
|
52
|
-
return { ...result, manifest: { path: manifestPath, sha256: data.sha256, schemaVersion: 4 },
|
|
73
|
+
return { ...result, invocationCosts, manifest: { path: manifestPath, sha256: data.sha256, schemaVersion: 4 },
|
|
74
|
+
agentPreflight: nativePlan ? record(nativePlan.details, 'native plan details').agentPreflight ?? null : null,
|
|
53
75
|
casePreflight: nativePlan ? record(nativePlan.details, 'native plan details').casePreflight ?? null : null,
|
|
54
76
|
inputSnapshot: nativePlan?.inputSnapshot ?? null,
|
|
55
77
|
...(spendingBudget ? { spendingBudget } : {}),
|
|
@@ -62,16 +84,27 @@ async function reportNativeEvaluation(path, options) {
|
|
|
62
84
|
evidence: { ...result.evidence, runDir, planPath: join(runDir, '_plan.json'),
|
|
63
85
|
ledgerPath: join(runDir, '_calls.jsonl'), artifactsPath: join(runDir, '_artifacts.json') } };
|
|
64
86
|
}
|
|
87
|
+
function combinePopulations(a, b) {
|
|
88
|
+
const metrics = Object.fromEntries(Object.entries(a.metrics).map(([key, m]) => {
|
|
89
|
+
const other = b.metrics[key];
|
|
90
|
+
return [key, { knownTotal: m.knownTotal + other.knownTotal,
|
|
91
|
+
coverage: { final: m.coverage.final + other.coverage.final, partial: m.coverage.partial + other.coverage.partial, unknown: m.coverage.unknown + other.coverage.unknown } }];
|
|
92
|
+
}));
|
|
93
|
+
return { runs: a.runs + b.runs, passes: a.passes + b.passes, metrics };
|
|
94
|
+
}
|
|
95
|
+
async function pairedComponentReport(path) {
|
|
96
|
+
const result = await reportEvalComponent(path);
|
|
97
|
+
if ('evaluationType' in result)
|
|
98
|
+
throw new Error('A revision request must produce paired evaluation evidence.');
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
65
101
|
/** Machine interface to the existing installed A/B engine; never installs an accepted candidate. */
|
|
66
102
|
export async function runEvalComponent(requestPath, options) {
|
|
67
103
|
const path = resolve(requestPath), { request, sha256: requestSha256 } = loadEvalRequest(path);
|
|
68
104
|
const runDir = join(request.runsRoot, request.runGroup);
|
|
69
105
|
if (existsSync(runDir))
|
|
70
106
|
throw new Error('Run group already exists; declare a fresh group without overwriting evidence.');
|
|
71
|
-
const
|
|
72
|
-
const implementationFiles = listFilesRecursive(implementationDir);
|
|
73
|
-
const implementationSha256 = hashFileSet(implementationDir, implementationFiles);
|
|
74
|
-
const base = { skillPath: request.candidateSkill, baselineSkillPath: request.baselineSkill,
|
|
107
|
+
const base = { skillPath: request.candidateSkill, baselineSkillPath: request.baselineSkill ?? undefined,
|
|
75
108
|
bench: request.bench, agent: request.agent, mode: 'installed', inputMode: 'workspace', trials: request.trials,
|
|
76
109
|
maxCalls: request.maxCalls, pairOrder: request.pairOrder, runsRoot: request.runsRoot, runGroup: request.runGroup, yes: true, dryRun: true,
|
|
77
110
|
executorTimeoutSeconds: request.executorTimeoutSeconds,
|
|
@@ -79,35 +112,26 @@ export async function runEvalComponent(requestPath, options) {
|
|
|
79
112
|
...(request.spendingBudget ? { spendingBudget: request.spendingBudget } : {}),
|
|
80
113
|
judgeExecutor: null, executor: options.executor, sessionOptions: options.sessionOptions,
|
|
81
114
|
skillInstallDir: options.skillInstallDir, log: options.log ?? (() => { }) };
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
throw new Error('Component requires a paired installed Skill
|
|
86
|
-
const describe = (evaluation) => ({ schemaVersion: 1, kind: 'skillfit.eval-plan',
|
|
87
|
-
request, requestSha256, policySha256: policyHash(request.policy), implementationSha256, evaluation });
|
|
88
|
-
const planData = describe(prepared), previewSha256 = sha256Text(JSON.stringify(planData));
|
|
89
|
-
const plan = { ...planData, sha256: previewSha256 };
|
|
115
|
+
const prepared = await prepareEvalPlan(base, { request, requestSha256, policySha256: policyHash(request.policy) });
|
|
116
|
+
const { plan } = prepared, { sha256: previewSha256, implementationSha256 } = plan;
|
|
117
|
+
if (plan.evaluation.judge)
|
|
118
|
+
throw new Error('Component requires a paired installed Skill evaluation without a judge.');
|
|
90
119
|
if (options.dryRun)
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
reasons: [{ code: 'PLAN_ONLY', message: 'No agent call or outcome is available.' }] } };
|
|
94
|
-
if (!options.expectedPlanSha256 || !/^[0-9a-f]{64}$/i.test(options.expectedPlanSha256) || options.expectedPlanSha256.toLowerCase() !== previewSha256) {
|
|
95
|
-
throw new Error('Execution requires --plan-sha matching the current dry-run plan; inputs, policy, executor or implementation changed.');
|
|
96
|
-
}
|
|
120
|
+
return plannedEvalResult(plan);
|
|
121
|
+
confirmEvalPlan(options.expectedPlanSha256, previewSha256);
|
|
97
122
|
const component = { schemaVersion: 1, requestSha256, previewSha256, implementationSha256, policySha256: policyHash(request.policy),
|
|
98
123
|
purpose: request.purpose, policy: request.policy, synthetic: options.executor !== undefined };
|
|
99
124
|
try {
|
|
100
125
|
await runEval({ ...base, dryRun: false, component, guardFiles: [{ label: 'component request', path, sha256: requestSha256 }],
|
|
101
|
-
onPlan:
|
|
102
|
-
throw new Error('Plan changed before execution; no calls allowed.'); } });
|
|
126
|
+
onPlan: prepared.assertCurrent });
|
|
103
127
|
}
|
|
104
128
|
catch (error) {
|
|
105
129
|
if (!existsSync(join(runDir, '_plan.json')))
|
|
106
130
|
throw error;
|
|
107
|
-
const result = await
|
|
131
|
+
const result = await pairedComponentReport(runDir);
|
|
108
132
|
return { ...result, status: 'stopped', plan, executionError: error instanceof Error ? error.message : String(error),
|
|
109
133
|
acceptance: { ...result.acceptance, decision: result.acceptance.decision === 'reject' ? 'reject' : 'inconclusive', eligibleForUpgrade: false,
|
|
110
134
|
reasons: [...result.acceptance.reasons, { code: 'EXECUTION_STOPPED', message: 'Request execution failed; inspect retained receipts before a fresh declaration.' }] } };
|
|
111
135
|
}
|
|
112
|
-
return { ...await
|
|
136
|
+
return { ...await pairedComponentReport(runDir), plan };
|
|
113
137
|
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import { test } from 'node:test';
|
|
8
|
+
import { runBenchCheck, runBenchInit } from './bench.js';
|
|
9
|
+
import { runEval } from './eval.js';
|
|
10
|
+
import { exportEvaluation } from './eval-export.js';
|
|
11
|
+
import { readEvaluationReport } from './evaluation-report.js';
|
|
12
|
+
import { ExperimentSession } from '../harness/experiment-session.js';
|
|
13
|
+
import { loadBench } from '../harness/bench.js';
|
|
14
|
+
import { collectEvaluationTarget } from '../harness/target.js';
|
|
15
|
+
import { packageFiles, verifyReplayPackage } from '../harness/replay-package.js';
|
|
16
|
+
import { sha256File, sha256Text } from '../harness/hash.js';
|
|
17
|
+
import { createSpendingBudgetRecorder } from '../harness/eval-budget.js';
|
|
18
|
+
import { summarizeCosts } from '../harness/costs.js';
|
|
19
|
+
async function fixture(t, classified = true) {
|
|
20
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-export-modes-'));
|
|
21
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
22
|
+
const bench = join(root, 'bench'), skill = join(root, 'skill'), runsRoot = join(root, 'runs');
|
|
23
|
+
await runBenchInit({ dir: bench, yes: true, log: () => { } });
|
|
24
|
+
const file = join(bench, 'bench.json'), definition = JSON.parse(readFileSync(file, 'utf8'));
|
|
25
|
+
definition.tasks[0].shouldTrigger = true;
|
|
26
|
+
if (classified)
|
|
27
|
+
definition.tasks[0].triggerClass = 'explicit';
|
|
28
|
+
writeFileSync(file, JSON.stringify(definition));
|
|
29
|
+
mkdirSync(skill);
|
|
30
|
+
writeFileSync(join(skill, 'SKILL.md'), '# Offline export test\n');
|
|
31
|
+
let calls = 0;
|
|
32
|
+
const executor = { describe: () => ({ kind: 'stub', model: 'offline-only' }), run: async () => {
|
|
33
|
+
calls++;
|
|
34
|
+
return { output: 'skillfit-ok', skillTriggered: true, tokens: { input: 10, output: 3 }, usageStatus: 'partial' };
|
|
35
|
+
} };
|
|
36
|
+
return { root, bench, skill, runsRoot, executor, calls: () => calls };
|
|
37
|
+
}
|
|
38
|
+
function replay(root, verifyOnly = false) {
|
|
39
|
+
const result = spawnSync(process.execPath, [join(root, 'reproduce.mjs'), ...(verifyOnly ? ['--verify-only'] : [])], { encoding: 'utf8', timeout: 30_000, maxBuffer: 8 * 1024 * 1024 });
|
|
40
|
+
assert.equal(result.status, 0, result.stderr);
|
|
41
|
+
return JSON.parse(result.stdout);
|
|
42
|
+
}
|
|
43
|
+
function reseal(run) {
|
|
44
|
+
const index = JSON.parse(readFileSync(join(run, '_artifacts.json'), 'utf8'));
|
|
45
|
+
index.files = Object.fromEntries(packageFiles(run).filter(path => path !== '_artifacts.json').map(path => [path, sha256File(join(run, path))]));
|
|
46
|
+
writeFileSync(join(run, '_artifacts.json'), JSON.stringify(index));
|
|
47
|
+
}
|
|
48
|
+
function rewritePlan(run, change) {
|
|
49
|
+
const plan = JSON.parse(readFileSync(join(run, '_plan.json'), 'utf8'));
|
|
50
|
+
change(plan);
|
|
51
|
+
const bytes = JSON.stringify(plan, null, 2) + '\n', sha256 = sha256Text(bytes);
|
|
52
|
+
writeFileSync(join(run, '_plan.json'), bytes);
|
|
53
|
+
const session = JSON.parse(readFileSync(join(run, '_session.json'), 'utf8'));
|
|
54
|
+
session.planSha256 = sha256;
|
|
55
|
+
writeFileSync(join(run, '_session.json'), JSON.stringify(session));
|
|
56
|
+
const summaryName = plan.details.mode === 'calibration' ? '_calibration.json' : 'manifest.json';
|
|
57
|
+
const summary = JSON.parse(readFileSync(join(run, summaryName), 'utf8'));
|
|
58
|
+
summary.experiment = session;
|
|
59
|
+
writeFileSync(join(run, summaryName), JSON.stringify(summary));
|
|
60
|
+
const index = JSON.parse(readFileSync(join(run, '_artifacts.json'), 'utf8'));
|
|
61
|
+
index.planSha256 = sha256;
|
|
62
|
+
writeFileSync(join(run, '_artifacts.json'), JSON.stringify(index));
|
|
63
|
+
reseal(run);
|
|
64
|
+
}
|
|
65
|
+
test('calibration and trigger export/replay survive deleted inputs and retain single-arm observations, unknown cache and partial costs', async (t) => {
|
|
66
|
+
for (const variant of ['calibration', 'trigger', 'trigger-unclassified'])
|
|
67
|
+
await t.test(variant, async (t) => {
|
|
68
|
+
const mode = variant === 'calibration' ? 'calibration' : 'trigger';
|
|
69
|
+
const f = await fixture(t, variant !== 'trigger-unclassified'), run = join(f.runsRoot, mode), output = join(f.root, 'portable');
|
|
70
|
+
if (mode === 'calibration')
|
|
71
|
+
await runBenchCheck({ dir: f.bench, calibrate: { executor: f.executor, trials: 1, maxCalls: 1, runsRoot: f.runsRoot, runGroup: mode }, log: () => { } });
|
|
72
|
+
else
|
|
73
|
+
await runEval({ skillPath: f.skill, bench: f.bench, mode, skillInstallDir: '.test-skills', executor: f.executor, trials: 1, maxCalls: 1, runsRoot: f.runsRoot, runGroup: mode, dryRun: false, yes: true, log: () => { } });
|
|
74
|
+
const before = await readEvaluationReport(run);
|
|
75
|
+
assert.ok('evaluationType' in before && before.evaluationType === mode);
|
|
76
|
+
assert.equal(before.evidence.verified, true, JSON.stringify(before.evidence));
|
|
77
|
+
assert.equal(before.usage?.metrics.input.knownTotal, 10);
|
|
78
|
+
assert.equal(before.usage?.metrics.input.coverage.partial, 1);
|
|
79
|
+
assert.equal(before.usage?.metrics.cachedInput.coverage.unknown, 1);
|
|
80
|
+
const nativeFiles = packageFiles(run).map(file => [file, sha256File(join(run, file))]);
|
|
81
|
+
rmSync(f.bench, { recursive: true });
|
|
82
|
+
rmSync(f.skill, { recursive: true });
|
|
83
|
+
assert.equal((await exportEvaluation(run, output, { log: () => { } })).status, 'planned');
|
|
84
|
+
assert.equal(existsSync(output), false);
|
|
85
|
+
await exportEvaluation(run, output, { yes: true, log: () => { } });
|
|
86
|
+
assert.deepEqual(packageFiles(run).map(file => [file, sha256File(join(run, file))]), nativeFiles, 'Native receipts and ledgers remain untouched.');
|
|
87
|
+
const moved = join(f.root, 'received offline package');
|
|
88
|
+
renameSync(output, moved);
|
|
89
|
+
rmSync(run, { recursive: true });
|
|
90
|
+
assert.equal(verifyReplayPackage(moved).evaluationType, mode);
|
|
91
|
+
assert.equal(replay(moved, true).modelCalls, 0);
|
|
92
|
+
const result = replay(moved);
|
|
93
|
+
assert.equal(result.evaluationType, mode);
|
|
94
|
+
assert.equal(result.evidence.verified, true);
|
|
95
|
+
assert.equal(result.evidence.replayedDeliveries, 1);
|
|
96
|
+
assert.deepEqual(result.summary, JSON.parse(JSON.stringify(before.summary)));
|
|
97
|
+
assert.deepEqual(result.usage, before.usage);
|
|
98
|
+
assert.equal(result.acceptance.decision, 'inconclusive');
|
|
99
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
100
|
+
assert.equal(result.acceptance.automaticUpgrade, false);
|
|
101
|
+
assert.equal(result.portableReplay.modelCalls, 0);
|
|
102
|
+
assert.equal(f.calls(), 1);
|
|
103
|
+
const inspected = await readEvaluationReport(moved);
|
|
104
|
+
assert.ok('portablePackage' in inspected && inspected.portablePackage.integrityVerified);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
test('stopped single-arm exports preserve missing invocation receipt as unknown and never invent a summary', async (t) => {
|
|
108
|
+
for (const mode of ['calibration', 'trigger'])
|
|
109
|
+
await t.test(mode, async (t) => {
|
|
110
|
+
const f = await fixture(t), run = join(f.runsRoot, mode), arm = mode === 'calibration' ? 'baseline' : 'installed', workspace = join(run, 'example-task', arm, 'trial-1');
|
|
111
|
+
const session = new ExperimentSession({ bench: loadBench(f.bench), target: collectEvaluationTarget(f.skill), groupDir: run, workspaces: [workspace], plannedCalls: 1, maxCalls: 1, injected: true, details: { mode, trials: 1 } });
|
|
112
|
+
mkdirSync(workspace, { recursive: true });
|
|
113
|
+
const prompt = 'Saved invocation with a lost receipt';
|
|
114
|
+
writeFileSync(join(workspace, '_prompt.txt'), prompt);
|
|
115
|
+
await session.wrap(f.executor, 'agent').run(prompt, workspace);
|
|
116
|
+
session.finish(new Error('Synthetic interruption before receipt persistence'));
|
|
117
|
+
const before = await readEvaluationReport(run);
|
|
118
|
+
assert.ok('evaluationType' in before);
|
|
119
|
+
assert.equal(before.status, 'stopped');
|
|
120
|
+
assert.equal(before.summary, null);
|
|
121
|
+
assert.equal(before.evidence.verified, true, JSON.stringify(before.evidence));
|
|
122
|
+
assert.equal(before.usage?.invocationsWithUnknownReceipts, 1);
|
|
123
|
+
assert.equal(before.usage?.metrics.input.coverage.unknown, 1);
|
|
124
|
+
assert.equal(before.usage?.metrics.durationSeconds.coverage.unknown, 1);
|
|
125
|
+
const output = join(f.root, 'portable');
|
|
126
|
+
await exportEvaluation(run, output, { yes: true, log: () => { } });
|
|
127
|
+
rmSync(f.bench, { recursive: true });
|
|
128
|
+
rmSync(f.skill, { recursive: true });
|
|
129
|
+
rmSync(run, { recursive: true });
|
|
130
|
+
const result = replay(output);
|
|
131
|
+
assert.equal(result.status, 'stopped');
|
|
132
|
+
assert.equal(result.summary, null);
|
|
133
|
+
assert.deepEqual(result.usage, before.usage);
|
|
134
|
+
assert.equal(result.evidence.replayedDeliveries, 0);
|
|
135
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
136
|
+
assert.equal(f.calls(), 1);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
test('single-arm semantic audit rejects resealed wrong summary and changed local verdicts', async (t) => {
|
|
140
|
+
const f = await fixture(t), run = join(f.runsRoot, 'calibration');
|
|
141
|
+
await runBenchCheck({ dir: f.bench, calibrate: { executor: f.executor, trials: 1, runsRoot: f.runsRoot, runGroup: 'calibration' }, log: () => { } });
|
|
142
|
+
const file = join(run, '_calibration.json'), original = readFileSync(file, 'utf8'), summary = JSON.parse(original);
|
|
143
|
+
summary.tasks[0].passes = 0;
|
|
144
|
+
writeFileSync(file, JSON.stringify(summary));
|
|
145
|
+
reseal(run);
|
|
146
|
+
const bad = await readEvaluationReport(run);
|
|
147
|
+
assert.equal(bad.evidence.verified, false);
|
|
148
|
+
assert.match(JSON.stringify(bad.evidence), /summary differs from receipts/);
|
|
149
|
+
await assert.rejects(exportEvaluation(run, join(f.root, 'bad'), { yes: true, log: () => { } }), /audit failed/);
|
|
150
|
+
writeFileSync(file, original);
|
|
151
|
+
reseal(run);
|
|
152
|
+
const output = join(f.root, 'portable');
|
|
153
|
+
await exportEvaluation(run, output, { yes: true, log: () => { } });
|
|
154
|
+
const delivery = join(output, 'run/example-task/baseline/trial-1/_output.md');
|
|
155
|
+
writeFileSync(delivery, 'wrong delivery');
|
|
156
|
+
const index = JSON.parse(readFileSync(join(output, 'run/_artifacts.json'), 'utf8'));
|
|
157
|
+
index.files['example-task/baseline/trial-1/_output.md'] = sha256File(delivery);
|
|
158
|
+
writeFileSync(join(output, 'run/_artifacts.json'), JSON.stringify(index));
|
|
159
|
+
const metadata = JSON.parse(readFileSync(join(output, 'replay-package.json'), 'utf8'));
|
|
160
|
+
for (const file of Object.keys(metadata.files))
|
|
161
|
+
metadata.files[file] = sha256File(join(output, file));
|
|
162
|
+
writeFileSync(join(output, 'replay-package.json'), JSON.stringify(metadata));
|
|
163
|
+
const replayed = spawnSync(process.execPath, [join(output, 'reproduce.mjs')], { encoding: 'utf8', timeout: 30_000 });
|
|
164
|
+
assert.equal(replayed.status, 2);
|
|
165
|
+
assert.match(replayed.stderr, /verdict differs/);
|
|
166
|
+
assert.equal(f.calls(), 1);
|
|
167
|
+
});
|
|
168
|
+
test('paired judge portable replay retains both review calls and full costs without invoking judge again', async (t) => {
|
|
169
|
+
const f = await fixture(t);
|
|
170
|
+
let judgeCalls = 0;
|
|
171
|
+
const judge = { describe: () => ({ kind: 'stub', model: 'offline-judge' }), run: async () => {
|
|
172
|
+
judgeCalls++;
|
|
173
|
+
return { output: JSON.stringify({ A: { correct: true, complete: true, grounded: true }, B: { correct: true, complete: true, grounded: true } }), tokens: { input: 20, cachedInput: 4, output: 5 }, usageStatus: 'final' };
|
|
174
|
+
} };
|
|
175
|
+
const run = join(f.runsRoot, 'judge');
|
|
176
|
+
await runEval({ skillPath: f.skill, bench: f.bench, executor: f.executor, judgeExecutor: judge,
|
|
177
|
+
trials: 1, maxCalls: 4, runsRoot: f.runsRoot, runGroup: 'judge', dryRun: false, yes: true, log: () => { } });
|
|
178
|
+
const before = await readEvaluationReport(run);
|
|
179
|
+
assert.equal(before.evidence.verified, true, JSON.stringify(before.evidence));
|
|
180
|
+
const output = join(f.root, 'portable');
|
|
181
|
+
await exportEvaluation(run, output, { yes: true, log: () => { } });
|
|
182
|
+
rmSync(f.bench, { recursive: true });
|
|
183
|
+
rmSync(f.skill, { recursive: true });
|
|
184
|
+
rmSync(run, { recursive: true });
|
|
185
|
+
const result = replay(output);
|
|
186
|
+
assert.equal(result.evidence.verified, true);
|
|
187
|
+
assert.equal(result.evidence.replayedDeliveries, 2);
|
|
188
|
+
assert.deepEqual(result.invocationCosts, 'invocationCosts' in before ? before.invocationCosts : null);
|
|
189
|
+
assert.equal(result.invocationCosts.judge.runs, 2);
|
|
190
|
+
assert.equal(result.invocationCosts.judge.metrics.input.knownTotal, 40);
|
|
191
|
+
assert.equal(result.invocationCosts.agent.metrics.input.coverage.partial, 2);
|
|
192
|
+
assert.equal(result.invocationCosts.total.runs, 4);
|
|
193
|
+
assert.equal(result.acceptance.automaticUpgrade, false);
|
|
194
|
+
assert.equal(f.calls(), 2);
|
|
195
|
+
assert.equal(judgeCalls, 2);
|
|
196
|
+
});
|
|
197
|
+
test('resealing an outer inventory cannot hide missing plan inputs, a changed approval or a mismatched prompt', async (t) => {
|
|
198
|
+
for (const damage of ['inputs', 'approval', 'prompt', 'invoked'])
|
|
199
|
+
await t.test(damage, async (t) => {
|
|
200
|
+
const f = await fixture(t), run = join(f.runsRoot, 'calibration');
|
|
201
|
+
await runBenchCheck({ dir: f.bench, calibrate: { executor: f.executor, trials: 1, runsRoot: f.runsRoot, runGroup: 'calibration' }, log: () => { } });
|
|
202
|
+
if (damage === 'inputs')
|
|
203
|
+
rewritePlan(run, plan => { delete plan.inputs; });
|
|
204
|
+
if (damage === 'approval')
|
|
205
|
+
rewritePlan(run, plan => { plan.details.executorTimeoutSeconds += 1; });
|
|
206
|
+
if (damage === 'prompt') {
|
|
207
|
+
writeFileSync(join(run, 'example-task/baseline/trial-1/_prompt.txt'), 'different invocation');
|
|
208
|
+
reseal(run);
|
|
209
|
+
}
|
|
210
|
+
if (damage === 'invoked') {
|
|
211
|
+
const path = join(run, 'example-task/baseline/trial-1/_result.json'), receipt = JSON.parse(readFileSync(path, 'utf8'));
|
|
212
|
+
receipt.executorInvoked = false;
|
|
213
|
+
writeFileSync(path, JSON.stringify(receipt));
|
|
214
|
+
reseal(run);
|
|
215
|
+
}
|
|
216
|
+
const report = await readEvaluationReport(run);
|
|
217
|
+
assert.equal(report.evidence.verified, false, damage);
|
|
218
|
+
assert.ok(report.evidence.reasons.length);
|
|
219
|
+
await assert.rejects(exportEvaluation(run, join(f.root, 'refused'), { yes: true, log: () => { } }), /audit failed/);
|
|
220
|
+
assert.equal(existsSync(join(f.root, 'refused')), false);
|
|
221
|
+
assert.equal(f.calls(), 1);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
test('single-arm budget replay includes setup attempts that never invoked an Agent', async (t) => {
|
|
225
|
+
const f = await fixture(t), run = join(f.runsRoot, 'calibration'), workspace = join(run, 'example-task/baseline/trial-1');
|
|
226
|
+
const limits = { input: 100, cachedInput: 100, uncachedInput: 100, output: 100, durationSeconds: 100 };
|
|
227
|
+
const session = new ExperimentSession({ bench: loadBench(f.bench), target: collectEvaluationTarget(f.skill), groupDir: run,
|
|
228
|
+
workspaces: [workspace], plannedCalls: 1, maxCalls: 1, injected: true,
|
|
229
|
+
details: { mode: 'calibration', inputMode: 'snapshot', trials: 1, spendingBudget: limits } });
|
|
230
|
+
mkdirSync(workspace, { recursive: true });
|
|
231
|
+
const observation = { executorInvoked: false, passed: false, error: 'Synthetic Git setup refusal', durationSeconds: 0, tokens: null, usageStatus: 'unknown' };
|
|
232
|
+
writeFileSync(join(workspace, '_result.json'), JSON.stringify({ schemaVersion: 2, taskId: 'example-task', trial: 1, condition: 'baseline', ...observation }));
|
|
233
|
+
const budget = createSpendingBudgetRecorder({ budget: limits, groupDir: run }), identity = { taskId: 'example-task', condition: 'baseline', trial: 1 };
|
|
234
|
+
budget.before(identity);
|
|
235
|
+
let failure;
|
|
236
|
+
try {
|
|
237
|
+
budget.after(identity, observation);
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
failure = error;
|
|
241
|
+
}
|
|
242
|
+
assert.ok(failure);
|
|
243
|
+
const summary = { schemaVersion: 1, runGroup: 'calibration', inputMode: 'snapshot', trials: 1,
|
|
244
|
+
tasks: [{ id: 'example-task', passes: 0, completed: 0, errors: 1 }], costs: summarizeCosts({ baseline: [observation], treatment: [] }, { baseline: [], treatment: [] }), experiment: session.summary() };
|
|
245
|
+
writeFileSync(join(run, '_calibration.json'), JSON.stringify(summary));
|
|
246
|
+
session.finish(failure, summary, '_calibration.json');
|
|
247
|
+
const before = await readEvaluationReport(run);
|
|
248
|
+
assert.ok('evaluationType' in before);
|
|
249
|
+
assert.equal(before.evidence.verified, true, JSON.stringify(before.evidence));
|
|
250
|
+
assert.equal(before.usage?.runs, 0);
|
|
251
|
+
assert.equal(before.status, 'stopped');
|
|
252
|
+
const output = join(f.root, 'portable');
|
|
253
|
+
await exportEvaluation(run, output, { yes: true, log: () => { } });
|
|
254
|
+
const result = replay(output);
|
|
255
|
+
assert.equal(result.evidence.verified, true);
|
|
256
|
+
assert.equal(result.usage.runs, 0);
|
|
257
|
+
assert.equal(result.summary.metrics.errors, 1);
|
|
258
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
259
|
+
assert.equal(f.calls(), 0);
|
|
260
|
+
});
|
|
261
|
+
test('portable replay forwards interruption and waits for verifier cleanup before exiting', async (t) => {
|
|
262
|
+
for (const signal of ['SIGINT', 'SIGTERM'])
|
|
263
|
+
await t.test(signal, async (t) => {
|
|
264
|
+
const f = await fixture(t), enabled = join(f.root, 'enable-hanging-verifier'), pidFile = join(f.root, 'verifier.pid');
|
|
265
|
+
writeFileSync(join(f.bench, 'verifiers/example-task.mjs'), `import{existsSync,readFileSync,writeFileSync}from'node:fs';import{join}from'node:path';if(existsSync(${JSON.stringify(enabled)})){writeFileSync(${JSON.stringify(pidFile)},String(process.pid));setInterval(()=>{},1000);}else{const file=join(process.argv[2],'_output.md');const passed=existsSync(file)&&readFileSync(file,'utf8').includes('skillfit-ok');console.log(JSON.stringify({passed}));process.exit(passed?0:1);}`);
|
|
266
|
+
const run = join(f.runsRoot, 'cancel');
|
|
267
|
+
await runEval({ skillPath: f.skill, bench: f.bench, executor: f.executor, judgeExecutor: null,
|
|
268
|
+
trials: 1, runsRoot: f.runsRoot, runGroup: 'cancel', dryRun: false, yes: true, log: () => { } });
|
|
269
|
+
const output = join(f.root, 'portable');
|
|
270
|
+
await exportEvaluation(run, output, { yes: true, log: () => { } });
|
|
271
|
+
const before = packageFiles(output).map(path => [path, sha256File(join(output, path))]);
|
|
272
|
+
writeFileSync(enabled, 'hang only replay');
|
|
273
|
+
const entry = join(output, 'reproduce.mjs');
|
|
274
|
+
const argv = process.platform === 'win32' ? ['--input-type=module', '--eval', `process.on('message',message=>{if(message?.signal)process.emit(message.signal);});process.channel?.unref();await import(${JSON.stringify(pathToFileURL(entry).href)});`] : [entry];
|
|
275
|
+
const child = spawn(process.execPath, argv, { stdio: ['ignore', 'pipe', 'pipe', 'ipc'], windowsHide: true });
|
|
276
|
+
let stdout = '', stderr = '', verifierPid;
|
|
277
|
+
child.stdout.on('data', chunk => { stdout += String(chunk); });
|
|
278
|
+
child.stderr.on('data', chunk => { stderr += String(chunk); });
|
|
279
|
+
const closed = new Promise((resolve, reject) => { child.once('close', resolve); child.once('error', reject); });
|
|
280
|
+
t.after(() => { child.kill('SIGKILL'); if (verifierPid)
|
|
281
|
+
try {
|
|
282
|
+
process.kill(verifierPid, 'SIGKILL');
|
|
283
|
+
}
|
|
284
|
+
catch { /* Already cleaned. */ } });
|
|
285
|
+
const until = Date.now() + 15_000;
|
|
286
|
+
while (!existsSync(pidFile) && Date.now() < until)
|
|
287
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
288
|
+
assert.ok(existsSync(pidFile), `Pinned replay verifier did not start: ${stderr}`);
|
|
289
|
+
verifierPid = Number(readFileSync(pidFile, 'utf8'));
|
|
290
|
+
assert.doesNotThrow(() => process.kill(verifierPid, 0));
|
|
291
|
+
if (process.platform === 'win32')
|
|
292
|
+
child.send({ signal });
|
|
293
|
+
else
|
|
294
|
+
child.kill(signal);
|
|
295
|
+
let timer;
|
|
296
|
+
try {
|
|
297
|
+
const code = await Promise.race([closed, new Promise((_, reject) => { timer = setTimeout(() => reject(new Error('Portable replay did not finish verifier cleanup after interruption.')), 15_000); })]);
|
|
298
|
+
assert.equal(code, signal === 'SIGINT' ? 130 : 143, stderr);
|
|
299
|
+
}
|
|
300
|
+
finally {
|
|
301
|
+
if (timer)
|
|
302
|
+
clearTimeout(timer);
|
|
303
|
+
}
|
|
304
|
+
assert.equal(stdout, '', 'Interrupted replay must not emit a successful JSON assessment.');
|
|
305
|
+
assert.match(stderr, /waited for the pinned CLI/);
|
|
306
|
+
let alive = true;
|
|
307
|
+
try {
|
|
308
|
+
process.kill(verifierPid, 0);
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
alive = false;
|
|
312
|
+
}
|
|
313
|
+
assert.equal(alive, false, 'Local verifier must have exited before reproduce.mjs exits.');
|
|
314
|
+
verifierPid = undefined;
|
|
315
|
+
assert.deepEqual(packageFiles(output).map(path => [path, sha256File(join(output, path))]), before, 'Replay cancellation never alters sealed input evidence.');
|
|
316
|
+
assert.equal(f.calls(), 2);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
test('broken single-arm inventory preserves readable costs and counts lost or invalid receipts as unknown', async (t) => {
|
|
320
|
+
for (const mode of ['calibration', 'trigger'])
|
|
321
|
+
await t.test(mode, async (t) => {
|
|
322
|
+
const f = await fixture(t), run = join(f.runsRoot, mode), arm = mode === 'calibration' ? 'baseline' : 'installed';
|
|
323
|
+
if (mode === 'calibration')
|
|
324
|
+
await runBenchCheck({ dir: f.bench, calibrate: { executor: f.executor, trials: 2, runsRoot: f.runsRoot, runGroup: mode }, log: () => { } });
|
|
325
|
+
else
|
|
326
|
+
await runEval({ skillPath: f.skill, bench: f.bench, mode, skillInstallDir: '.test-skills', executor: f.executor,
|
|
327
|
+
trials: 2, runsRoot: f.runsRoot, runGroup: mode, dryRun: false, yes: true, log: () => { } });
|
|
328
|
+
const first = join(run, 'example-task', arm, 'trial-1/_result.json'), second = join(run, 'example-task', arm, 'trial-2/_result.json');
|
|
329
|
+
rmSync(first);
|
|
330
|
+
const missing = await readEvaluationReport(run);
|
|
331
|
+
assert.ok('evaluationType' in missing);
|
|
332
|
+
assert.equal(missing.evidence.verified, false);
|
|
333
|
+
assert.equal(missing.usage?.runs, 2);
|
|
334
|
+
assert.equal(missing.usage?.invocationsWithUnknownReceipts, 1);
|
|
335
|
+
assert.equal(missing.usage?.metrics.input.knownTotal, 10);
|
|
336
|
+
assert.equal(missing.usage?.metrics.input.coverage.partial, 1);
|
|
337
|
+
assert.equal(missing.usage?.metrics.input.coverage.unknown, 1);
|
|
338
|
+
writeFileSync(second, '{invalid raw receipt');
|
|
339
|
+
const invalid = await readEvaluationReport(run);
|
|
340
|
+
assert.ok('evaluationType' in invalid);
|
|
341
|
+
assert.equal(invalid.evidence.verified, false);
|
|
342
|
+
assert.equal(invalid.usage?.runs, 2);
|
|
343
|
+
assert.equal(invalid.usage?.invocationsWithUnknownReceipts, 2);
|
|
344
|
+
assert.equal(invalid.usage?.metrics.input.coverage.unknown, 2);
|
|
345
|
+
assert.match(invalid.usage?.scope ?? '', /Unaudited/);
|
|
346
|
+
assert.equal(invalid.acceptance.eligibleForUpgrade, false);
|
|
347
|
+
await assert.rejects(exportEvaluation(run, join(f.root, 'invalid'), { yes: true, log: () => { } }), /Native evidence inventory changed/);
|
|
348
|
+
assert.equal(f.calls(), 2);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
@@ -55,12 +55,20 @@ export async function exportEvaluation(input, output, options = {}) {
|
|
|
55
55
|
throw new Error(`Native evidence hash mismatch: ${path}`);
|
|
56
56
|
const report = await reportEvalComponent(run);
|
|
57
57
|
const hasManifest = existsSync(join(run, 'manifest.json'));
|
|
58
|
-
|
|
58
|
+
const singleArm = plan.details?.mode === 'calibration' || plan.details?.mode === 'trigger';
|
|
59
|
+
if ((hasManifest || singleArm) && (!('evidence' in report) || !report.evidence.verified))
|
|
59
60
|
throw new Error(`Native evidence audit failed; cannot export a complete replay package: ${'evidence' in report ? JSON.stringify(report.evidence) : 'missing audit'}`);
|
|
60
|
-
if (plan.details?.mode === 'trigger' || plan.details?.judge != null)
|
|
61
|
-
throw new Error('Portable replay currently requires paired native runs without a judge; separate judge spending is not fully recorded.');
|
|
62
61
|
if (!Array.isArray(plan.inputs) || typeof plan.packageVersion !== 'string')
|
|
63
62
|
throw new Error('Native input fingerprints or version are missing.');
|
|
63
|
+
const pinnedImplementation = plan.inputs.find((entry) => entry.label === 'implementation');
|
|
64
|
+
if (!pinnedImplementation?.files?.includes('harness/interruption.js'))
|
|
65
|
+
throw new Error('The original pinned runtime lacks replay cancellation support. Keep the native record; exporting must not silently replace its implementation.');
|
|
66
|
+
if (singleArm) {
|
|
67
|
+
for (const path of ['commands/eval-single-arm-replay.js', 'harness/single-arm-audit.js']) {
|
|
68
|
+
if (!pinnedImplementation?.files?.includes(path))
|
|
69
|
+
throw new Error('The original pinned runtime lacks single-arm replay support. Keep the native record; exporting must not silently replace its implementation.');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
64
72
|
const snapshot = verifyInputSnapshot(run, plan);
|
|
65
73
|
const copies = [];
|
|
66
74
|
const directories = new Set();
|
|
@@ -157,7 +165,7 @@ export async function exportEvaluation(input, output, options = {}) {
|
|
|
157
165
|
writeFileSync(join(stage, 'README.md'), '# Offline evaluation replay\n\nRun `node reproduce.mjs --verify-only` to check files, or `node reproduce.mjs` to regrade saved deliveries with the pinned implementation. No agent or model is started. Local verifiers are executable code; use trusted packages. Node.js 22+ and any external verifier toolchains are required.\n\nNative receipts are unchanged. Unknown/partial costs stay unknown/partial; a stopped run remains stopped. Checksums detect changes, not publisher identity. Review project data and paths before sharing. Runtime package metadata is reconstructed from the frozen native package version; compiled implementation bytes are copied unchanged.\n');
|
|
158
166
|
const payload = packageFiles(stage);
|
|
159
167
|
writeFileSync(join(stage, 'replay-package.json'), JSON.stringify({ schemaVersion: 1, kind: 'skillfit.replay-package',
|
|
160
|
-
sourcePlanSha256: planSha256, hasManifest, nativeStatus: session.status,
|
|
168
|
+
sourcePlanSha256: planSha256, hasManifest, nativeStatus: session.status, evaluationType: singleArm ? plan.details.mode : 'paired',
|
|
161
169
|
files: Object.fromEntries(payload.map(path => [path, sha256File(join(stage, path))])) }, null, 2) + '\n');
|
|
162
170
|
verifyReplayPackage(stage);
|
|
163
171
|
// Exclusive mkdir protects even empty directories and dangling symlinks that
|
|
@@ -44,6 +44,7 @@ async function scenario(t, mode, signal = 'SIGINT') {
|
|
|
44
44
|
rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
45
45
|
});
|
|
46
46
|
const bench = join(root, 'bench'), skill = join(root, 'skill'), old = join(root, 'old');
|
|
47
|
+
writeFileSync(join(root, 'draft-source.txt'), 'synthetic offline fixture');
|
|
47
48
|
await runBenchInit({ dir: bench, yes: true, log: () => { } });
|
|
48
49
|
for (const [dir, version] of [[skill, 'new'], [old, 'old']]) {
|
|
49
50
|
mkdirSync(dir);
|
|
@@ -79,7 +80,7 @@ setTimeout(()=>process.exit(),30000);`;
|
|
|
79
80
|
const harness = join(root, 'harness.mjs');
|
|
80
81
|
writeFileSync(harness, `import{writeFileSync}from'node:fs';
|
|
81
82
|
import{runEval}from ${moduleUrl('commands/eval.js')};
|
|
82
|
-
import{runBenchCheck}from ${moduleUrl('commands/bench.js')};
|
|
83
|
+
import{runBenchCheck,runBenchAdd}from ${moduleUrl('commands/bench.js')};
|
|
83
84
|
import{runEvalComponent}from ${moduleUrl('commands/eval-component.js')};
|
|
84
85
|
import{CliExecutor}from ${moduleUrl('harness/executors/cli.js')};
|
|
85
86
|
import{ApiExecutor}from ${moduleUrl('harness/executors/api.js')};
|
|
@@ -92,6 +93,7 @@ const api=new ApiExecutor({apiKey:'offline-only',fetchImpl:async(_url,options)=>
|
|
|
92
93
|
const base={skillPath:${JSON.stringify(skill)},bench:${JSON.stringify(bench)},trials:2,maxCalls:4,executor:mode==='verifier'||mode==='preflight'||mode==='judge'||mode==='between'?mock:mode==='api'?api:fake,judgeExecutor:mode==='judge'?fake:null,yes:true,dryRun:false,runsRoot:root+'/runs',runGroup:'saved',log:message=>{if(mode==='between'&&message.includes('/ treatment / trial 1'))process.emit('SIGINT');}};
|
|
93
94
|
try{
|
|
94
95
|
if(mode==='request'){const options={executor:fake,skillInstallDir:'skills',dryRun:true};const preview=await runEvalComponent(${JSON.stringify(request)},options);const result=await runEvalComponent(${JSON.stringify(request)},{...options,dryRun:false,expectedPlanSha256:preview.plan.sha256});writeFileSync(root+'/component.json',JSON.stringify(result));}
|
|
96
|
+
else if(mode==='draft')await runBenchAdd({benchDir:base.bench,sourceDir:root,include:['draft-source.txt'],task:'interrupted-draft',prompt:'Solve the task',freeze:true,decompose:true,executor:fake,yes:true,runsRoot:base.runsRoot,runGroup:base.runGroup,log:()=>{}});
|
|
95
97
|
else if(mode==='calibration')await runBenchCheck({dir:base.bench,log:()=>{},calibrate:{executor:fake,trials:2,maxCalls:2,runsRoot:base.runsRoot,runGroup:base.runGroup}});
|
|
96
98
|
else await runEval({...base,...(mode==='trigger'?{mode:'trigger',skillInstallDir:'skills'}:{}),...(mode==='judge'?{maxCalls:8}:{})});
|
|
97
99
|
}catch(error){writeFileSync(root+'/error.txt',error.message);}
|
|
@@ -128,6 +130,20 @@ finally{writeFileSync(root+'/done.json',JSON.stringify({before,after:counts(),ca
|
|
|
128
130
|
assert.ok(json(ready).pids.every((pid) => !running(pid)), 'preflight verifier and grandchild must stop');
|
|
129
131
|
return { root, run, done, session: null, events: [], stderr };
|
|
130
132
|
}
|
|
133
|
+
if (mode === 'draft') {
|
|
134
|
+
const session = json(join(run, '_summary.json'));
|
|
135
|
+
assert.equal(session.status, 'stopped');
|
|
136
|
+
assert.equal(session.callsStarted, 1);
|
|
137
|
+
assert.equal(session.callsFinished, 1);
|
|
138
|
+
assert.equal(session.automaticRetry, false);
|
|
139
|
+
for (let i = 0; i < 100 && json(ready).pids.some(running); i++)
|
|
140
|
+
await delay(50);
|
|
141
|
+
assert.ok(json(ready).pids.every((pid) => !running(pid)), 'drafting CLI and grandchild must stop');
|
|
142
|
+
const before = readFileSync(heartbeat, 'utf8');
|
|
143
|
+
await delay(100);
|
|
144
|
+
assert.equal(readFileSync(heartbeat, 'utf8'), before);
|
|
145
|
+
return { root, run, done, session, events: [], stderr };
|
|
146
|
+
}
|
|
131
147
|
const session = json(join(run, '_session.json'));
|
|
132
148
|
assert.equal(session.status, 'stopped');
|
|
133
149
|
assert.match(session.stopReason, new RegExp(signal));
|
|
@@ -179,6 +195,15 @@ for (const signal of ['SIGINT', 'SIGTERM'])
|
|
|
179
195
|
test(`${signal} cancels offline preflight without dispatch or a misleading completed run`, { timeout: 30_000 }, async (t) => {
|
|
180
196
|
await scenario(t, 'preflight', signal);
|
|
181
197
|
});
|
|
198
|
+
for (const signal of ['SIGINT', 'SIGTERM'])
|
|
199
|
+
test(`${signal} also stops a drafting process tree and retains its partial costs`, { timeout: 30_000 }, async (t) => {
|
|
200
|
+
const f = await scenario(t, 'draft', signal), receipt = json(join(f.run, '_result.json'));
|
|
201
|
+
assert.deepEqual(receipt.tokens, { input: 12, cachedInput: 7, output: 3 });
|
|
202
|
+
assert.equal(receipt.usageStatus, 'partial');
|
|
203
|
+
assert.equal(f.session.costs.metrics.input.knownTotal, 12);
|
|
204
|
+
assert.equal(f.session.costs.metrics.input.coverage.partial, 1);
|
|
205
|
+
assert.ok(!existsSync(join(f.root, 'bench/verifiers/interrupted-draft.mjs')));
|
|
206
|
+
});
|
|
182
207
|
test('interrupting a verifier kills its tree and preserves final agent usage', { timeout: 30_000 }, async (t) => {
|
|
183
208
|
const f = await scenario(t, 'verifier'), record = json(join(f.run, 'example-task/baseline/trial-1/_result.json'));
|
|
184
209
|
assert.deepEqual(record.tokens, { input: 20, cachedInput: 5, output: 4 });
|