skillfit 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +68 -104
  2. package/README.zh-CN.md +68 -101
  3. package/benches/README.md +6 -2
  4. package/dist/cli.js +28 -16
  5. package/dist/commands/bench-calibration.js +5 -1
  6. package/dist/commands/bench-check-report.js +1 -34
  7. package/dist/commands/bench-draft.js +167 -0
  8. package/dist/commands/bench-draft.test.js +168 -0
  9. package/dist/commands/bench-manage.js +5 -4
  10. package/dist/commands/bench-source.js +101 -0
  11. package/dist/commands/bench-source.test.js +84 -0
  12. package/dist/commands/bench.js +157 -328
  13. package/dist/commands/eval-api-failure.test.js +46 -0
  14. package/dist/commands/eval-layout.test.js +126 -0
  15. package/dist/commands/eval-preflight-error.js +9 -0
  16. package/dist/commands/eval-preflight.js +4 -11
  17. package/dist/commands/eval-report.js +6 -459
  18. package/dist/commands/eval.js +7 -32
  19. package/dist/commands/install.js +14 -98
  20. package/dist/harness/agent-preflight.js +18 -2
  21. package/dist/harness/bench-check.js +277 -0
  22. package/dist/harness/bench-diagnostics.js +34 -0
  23. package/dist/harness/bench-location.js +29 -0
  24. package/dist/harness/bench-location.test.js +33 -0
  25. package/dist/harness/bench.js +8 -3
  26. package/dist/harness/eval-acceptance.js +1 -1
  27. package/dist/harness/eval-audit.js +2 -2
  28. package/dist/harness/eval-manifest.js +456 -0
  29. package/dist/harness/evaluation-layout.js +30 -0
  30. package/dist/harness/executors/api.js +20 -7
  31. package/dist/harness/executors/cli.js +15 -25
  32. package/dist/harness/experiment-session.js +5 -15
  33. package/dist/harness/hash.js +3 -1
  34. package/dist/harness/runner.js +5 -4
  35. package/dist/harness/single-arm-audit.js +1 -1
  36. package/dist/harness/trigger.js +1 -1
  37. package/dist/harness/verifier-timeout.js +8 -0
  38. package/dist/harness/verifier-timeout.test.js +76 -0
  39. package/dist/install/constants.js +1 -0
  40. package/dist/install/transaction.js +112 -0
  41. package/docs/README.md +65 -0
  42. package/docs/architecture.md +86 -0
  43. package/docs/archive-delivery.md +83 -0
  44. package/docs/archive-inventory.md +91 -0
  45. package/docs/bench-authoring.md +23 -3
  46. package/docs/bench-drafting.md +75 -0
  47. package/docs/case-management.md +12 -1
  48. package/docs/eval-agent-preflight.md +15 -2
  49. package/docs/eval-costs.md +28 -2
  50. package/docs/eval-planning.md +14 -0
  51. package/docs/evaluation-input-snapshots.md +20 -4
  52. package/docs/evaluation-reports.md +1 -1
  53. package/docs/first-real-eval.md +28 -3
  54. package/docs/growth-roadmap-2026-10.md +23 -18
  55. package/docs/package-contents.md +73 -0
  56. package/docs/plans/2026-10-17-workflow-foundations.md +37 -2
  57. package/docs/plans/2026-10-20-archive-replay-verification.json +125 -0
  58. package/docs/plans/2026-10-20-archive-source-verification.json +256 -0
  59. package/docs/plans/2026-10-20-delivery-verification.json +146 -0
  60. package/docs/plans/2026-10-20-docs-architecture-cleanup.md +233 -0
  61. package/docs/plans/2026-10-20-install-transactions-and-archive-delivery.md +233 -0
  62. package/docs/plans/2026-10-21-npm-0.13.0-release.md +41 -0
  63. package/docs/releases/0.11.0-ci-registry-install.json +130 -0
  64. package/docs/releases/0.11.0-feature-smoke.json +1576 -0
  65. package/docs/releases/0.11.0-local-attempt-1.json +24 -0
  66. package/docs/releases/0.11.0-local-attempt-1.log +19 -0
  67. package/docs/releases/0.11.0-local-registry-install.json +25 -0
  68. package/docs/releases/0.11.0-registry-metadata.json +33 -0
  69. package/docs/releases/0.11.0-signatures.txt +12 -0
  70. package/docs/releases/0.11.0-verification.json +95 -0
  71. package/docs/releases/0.11.0.md +54 -11
  72. package/docs/releases/0.12.0-attestation-check.json +22 -0
  73. package/docs/releases/0.12.0-attestations.json +155 -0
  74. package/docs/releases/0.12.0-ci-registry-install.json +90 -0
  75. package/docs/releases/0.12.0-feature-smoke.json +34 -0
  76. package/docs/releases/0.12.0-feature-smoke.mjs +73 -0
  77. package/docs/releases/0.12.0-foundations-smoke.json +1576 -0
  78. package/docs/releases/0.12.0-local-registry-install.json +75 -0
  79. package/docs/releases/0.12.0-preparation-attempt-1.json +22 -0
  80. package/docs/releases/0.12.0-registry-metadata.json +96 -0
  81. package/docs/releases/0.12.0-signatures.txt +6 -0
  82. package/docs/releases/0.12.0-verification.json +99 -0
  83. package/docs/releases/0.12.0.md +82 -0
  84. package/docs/releases/0.13.0-feature-smoke.mjs +114 -0
  85. package/docs/releases/0.13.0-preparation.json +102 -0
  86. package/docs/releases/0.13.0.md +61 -0
  87. package/docs/releases/archive-delivery-smoke.mjs +37 -0
  88. package/docs/reproducible-offline-example.md +1 -1
  89. package/docs/schemas/agent-preflight.schema.json +1 -1
  90. package/docs/verifier-contract.md +9 -0
  91. package/evidence/README.md +24 -1
  92. package/evidence/archive-catalog.v1.json +8044 -0
  93. package/evidence/fetch-archives.mjs +211 -0
  94. package/package.json +9 -2
  95. package/skills/skillfit/SKILL.md +25 -5
  96. package/dist/cli.test.js +0 -193
  97. package/dist/commands/bench-calibration.test.js +0 -237
  98. package/dist/commands/bench-check-json.test.js +0 -242
  99. package/dist/commands/bench-manage.test.js +0 -87
  100. package/dist/commands/bench.test.js +0 -1162
  101. package/dist/commands/bundle.test.js +0 -142
  102. package/dist/commands/calibration-cli.test.js +0 -145
  103. package/dist/commands/doctor.test.js +0 -280
  104. package/dist/commands/eval-agent-preflight.test.js +0 -245
  105. package/dist/commands/eval-export-modes.test.js +0 -350
  106. package/dist/commands/eval-export.test.js +0 -279
  107. package/dist/commands/eval-interruption.test.js +0 -238
  108. package/dist/commands/eval-preflight.test.js +0 -382
  109. package/dist/commands/eval-report.test.js +0 -367
  110. package/dist/commands/eval.test.js +0 -503
  111. package/dist/commands/evaluation-report.test.js +0 -243
  112. package/dist/commands/install.test.js +0 -555
  113. package/dist/commands/replay-cancellation.test.js +0 -105
  114. package/dist/commands/report.test.js +0 -110
  115. package/dist/commands/setup.test.js +0 -150
  116. package/dist/commands/upstream.test.js +0 -139
  117. package/dist/commands/workflow-entrypoints.test.js +0 -137
  118. package/dist/docs.test.js +0 -154
  119. package/dist/frontmatter.test.js +0 -49
  120. package/dist/harness/bench.test.js +0 -109
  121. package/dist/harness/bundle.test.js +0 -71
  122. package/dist/harness/codex-usage.test.js +0 -87
  123. package/dist/harness/costs.test.js +0 -92
  124. package/dist/harness/eval-budget.test.js +0 -237
  125. package/dist/harness/eval-component.test.js +0 -770
  126. package/dist/harness/eval-efficiency.test.js +0 -56
  127. package/dist/harness/execution-timing.test.js +0 -61
  128. package/dist/harness/executors/api.test.js +0 -136
  129. package/dist/harness/executors/cli.test.js +0 -510
  130. package/dist/harness/executors/mock.test.js +0 -43
  131. package/dist/harness/experiment-session.test.js +0 -317
  132. package/dist/harness/installed-skill.test.js +0 -162
  133. package/dist/harness/interruption.test.js +0 -31
  134. package/dist/harness/judge-accounting.test.js +0 -216
  135. package/dist/harness/judge.test.js +0 -181
  136. package/dist/harness/kimi-usage.test.js +0 -62
  137. package/dist/harness/native-diff.test.js +0 -53
  138. package/dist/harness/oss-lru-cache.test.js +0 -79
  139. package/dist/harness/oss-normalize-url.test.js +0 -64
  140. package/dist/harness/oss-regression-witness.test.js +0 -89
  141. package/dist/harness/oss-skill-followup.test.js +0 -59
  142. package/dist/harness/prompt.test.js +0 -48
  143. package/dist/harness/receipts.test.js +0 -148
  144. package/dist/harness/report.test.js +0 -297
  145. package/dist/harness/runner.test.js +0 -635
  146. package/dist/harness/skill-revision.test.js +0 -148
  147. package/dist/harness/stats.test.js +0 -124
  148. package/dist/harness/target.test.js +0 -60
  149. package/dist/harness/trigger.test.js +0 -261
  150. package/dist/harness/verifier-summary.test.js +0 -99
  151. package/dist/harness/verifier.test.js +0 -128
  152. package/dist/harness/waza-behavior.test.js +0 -139
  153. package/dist/mcp/probe.test.js +0 -139
  154. package/evidence/artifacts/2026-10-12-diagnosing-revision/calibration-records.tar.gz +0 -0
  155. package/evidence/artifacts/2026-10-12-diagnosing-revision/interrupted-records.tar.gz +0 -0
  156. package/evidence/artifacts/2026-10-12-diagnosing-revision/validation-records.tar.gz +0 -0
  157. package/evidence/artifacts/2026-10-12-diagnosing-v2/regression-records.tar.gz +0 -0
  158. package/evidence/artifacts/2026-10-12-diagnosing-v2/transfer-records.tar.gz +0 -0
  159. package/evidence/artifacts/2026-10-12-normalize-url-v2-available/readiness-records.tar.gz +0 -0
  160. package/evidence/artifacts/2026-10-12-normalize-url-v2-comparison/records.tar.gz +0 -0
  161. package/evidence/artifacts/2026-10-12-normalize-url-v2-recovery/records.tar.gz +0 -0
  162. package/evidence/artifacts/2026-10-12-normalize-url-v2-validated/records.tar.gz +0 -0
  163. package/evidence/artifacts/2026-10-13-debugging-completed-development/package.tar.gz +0 -0
  164. package/evidence/artifacts/2026-10-13-debugging-controls-and-sleep-stop/package.tar.gz +0 -0
  165. package/evidence/artifacts/2026-10-13-debugging-development-stops/package.tar.gz +0 -0
  166. package/evidence/artifacts/2026-10-14-debugging-followup-routing-stop/package.tar.gz +0 -0
  167. package/evidence/artifacts/2026-10-14-debugging-independent-validation/package.tar.gz +0 -0
  168. package/evidence/artifacts/2026-10-14-debugging-reading-pilot-and-cost-review/package.tar.gz +0 -0
  169. package/evidence/artifacts/2026-10-14-debugging-spending-stop/package.tar.gz +0 -0
  170. package/evidence/artifacts/2026-10-15-independent-comparison-regression-stop/package.tar.gz +0 -0
  171. package/evidence/artifacts/2026-10-15-native-diff-mechanism/package.tar.gz +0 -0
  172. package/evidence/artifacts/2026-10-15-receiver-mechanism-stop/package.tar.gz +0 -0
@@ -1,237 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { spawn } from 'node:child_process';
3
- import { existsSync, 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 { prepareBenchCalibration, runBenchCalibration, runBenchCheck, runBenchInit } from './bench.js';
9
- import { CasePreflightFailed } from './eval-preflight.js';
10
- import { AgentPreflightFailed } from '../harness/agent-preflight.js';
11
- import { killTree } from '../harness/kill-tree.js';
12
- import { evaluationSignal, withEvaluationInterrupts } from '../harness/interruption.js';
13
- import { sha256File } from '../harness/hash.js';
14
- import { readSingleArmReport } from './eval-single-arm-report.js';
15
- const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
16
- const json = (path) => JSON.parse(readFileSync(path, 'utf8'));
17
- const budget = { input: 1000, cachedInput: 1000, uncachedInput: 1000, output: 1000, durationSeconds: 1000 };
18
- const final = { output: 'skillfit-ok', tokens: { input: 10, cachedInput: 2, output: 3 } };
19
- async function fixture(t, kind = 'output') {
20
- const root = mkdtempSync(join(tmpdir(), 'skillfit-calibration-guard-')), dir = join(root, 'bench');
21
- t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
22
- await runBenchInit({ dir, kind, yes: true, log: () => { } });
23
- return { root, dir, runsRoot: join(root, 'runs'), runGroup: 'calibration' };
24
- }
25
- test('calibration refuses a solved fixture or broken oracle before any executor, version probe or native output', async (t) => {
26
- for (const gate of ['untouched', 'oracle'])
27
- await t.test(gate, async (t) => {
28
- const f = await fixture(t, 'command');
29
- if (gate === 'untouched')
30
- writeFileSync(join(f.dir, 'verifiers/example-task.mjs'), 'process.exit(0);');
31
- else
32
- writeFileSync(join(f.dir, 'ground-truth/oracle-example-task.mjs'), 'process.exit(4);');
33
- let calls = 0, versions = 0;
34
- const executor = { describe: () => ({ kind: 'cli', model: 'offline' }), run: async () => { calls++; return final; } };
35
- const report = await runBenchCheck({ dir: f.dir, calibrate: { executor, agent: 'codex', trials: 1,
36
- runsRoot: f.runsRoot, runGroup: f.runGroup, sessionOptions: { homeDir: join(f.root, 'home'),
37
- env: { CODEX_HOME: join(f.root, 'home/codex') }, versionProbe: () => { versions++; return 'offline'; } } }, log: () => { } });
38
- assert.ok(report.failures > 0);
39
- assert.ok(report.checks.some(check => check.code === 'CALIBRATION' && check.status === 'FAIL' && /preflight blocked/.test(check.message)));
40
- assert.equal(calls, 0);
41
- assert.equal(versions, 0);
42
- assert.ok(!existsSync(f.runsRoot));
43
- });
44
- });
45
- test('calibration preview fingerprints settings without executing verifier/oracle and rejects a stale plan', async (t) => {
46
- const f = await fixture(t), sentinel = join(f.root, 'probe');
47
- writeFileSync(join(f.dir, 'verifiers/example-task.mjs'), `import{writeFileSync}from'node:fs';writeFileSync(${JSON.stringify(sentinel)},'bad');process.exit(1);`);
48
- const options = { dir: f.dir, calibrate: { agent: 'codex', trials: 2, runsRoot: f.runsRoot, runGroup: f.runGroup,
49
- executorTimeoutSeconds: 17, spendingBudget: budget, sessionOptions: { homeDir: join(f.root, 'home'), env: { PATH: '' } } } };
50
- const plan = prepareBenchCalibration(options);
51
- assert.equal(plan.kind, 'skillfit.calibration-plan');
52
- assert.equal(plan.executorTimeoutSeconds, 17);
53
- assert.equal(plan.plannedCalls, 2);
54
- assert.equal(plan.maxCalls, 2);
55
- assert.equal(plan.agentPreflight.status, 'blocked');
56
- assert.ok(plan.agentPreflight.checks.some(check => check.code === 'AUTHENTICATION' && check.status === 'UNKNOWN'));
57
- assert.ok(!existsSync(sentinel));
58
- assert.ok(!existsSync(f.runsRoot));
59
- assert.deepEqual(prepareBenchCalibration(options), plan);
60
- await assert.rejects(runBenchCheck({ ...options, calibrate: { ...options.calibrate,
61
- executorTimeoutSeconds: 18, reviewedPlanSha256: plan.planSha256 }, log: () => { } }), /plan changed before execution/);
62
- assert.ok(!existsSync(sentinel));
63
- const lines = [];
64
- await runBenchCheck({ ...options, calibrate: { ...options.calibrate, dryRun: true }, log: line => lines.push(line) });
65
- assert.ok(!existsSync(sentinel));
66
- assert.match(lines.join('\n'), /no verifier, oracle or agent started/);
67
- });
68
- test('strict calibration exposes typed Agent and case preflight failures without changing legacy bench check', async (t) => {
69
- const f = await fixture(t, 'command');
70
- await assert.rejects(runBenchCalibration({ dir: f.dir, calibrate: { agent: 'codex', runsRoot: f.runsRoot, runGroup: f.runGroup,
71
- sessionOptions: { homeDir: join(f.root, 'home'), env: { PATH: '', CODEX_HOME: join(f.root, 'home/codex') } } }, log: () => { } }), (error) => error instanceof AgentPreflightFailed && error.agentPreflight.status === 'blocked');
72
- writeFileSync(join(f.dir, 'verifiers/example-task.mjs'), 'process.exit(0);');
73
- let calls = 0;
74
- const executor = { describe: () => ({ kind: 'cli', model: 'offline' }), run: async () => { calls++; return final; } };
75
- await assert.rejects(runBenchCalibration({ dir: f.dir, calibrate: { executor, runsRoot: f.runsRoot, runGroup: f.runGroup }, log: () => { } }), (error) => error instanceof CasePreflightFailed && error.preflight.checks.some(check => check.code === 'UNTOUCHED_FIXTURE' && check.status === 'FAIL'));
76
- assert.equal(calls, 0);
77
- assert.ok(!existsSync(f.runsRoot));
78
- });
79
- test('offline warnings and unknown winnability do not block calibration and are retained separately', async (t) => {
80
- const f = await fixture(t);
81
- const manifest = json(join(f.dir, 'bench.json'));
82
- delete manifest.tasks[0].oracle;
83
- writeFileSync(join(f.dir, 'bench.json'), JSON.stringify(manifest));
84
- writeFileSync(join(f.dir, 'fixtures/example-task/large.txt'), 'x'.repeat(66 * 1024));
85
- let calls = 0;
86
- const executor = { describe: () => ({ kind: 'cli', model: 'offline' }), run: async () => { calls++; return final; } };
87
- const options = { dir: f.dir, calibrate: { executor, trials: 1, runsRoot: f.runsRoot, runGroup: f.runGroup, spendingBudget: budget } };
88
- const preview = prepareBenchCalibration(options);
89
- const report = await runBenchCheck({ ...options, calibrate: { ...options.calibrate, reviewedPlanSha256: preview.planSha256 }, log: () => { } });
90
- assert.equal(report.failures, 0);
91
- assert.equal(calls, 1);
92
- const details = json(join(f.runsRoot, f.runGroup, '_plan.json')).details;
93
- assert.equal(details.reviewedPlan.planSha256, preview.planSha256);
94
- assert.equal(details.casePreflight.status, 'ready');
95
- assert.ok(details.casePreflight.checks.some((check) => check.code === 'ORACLE' && check.status === 'UNKNOWN'));
96
- assert.ok(details.casePreflight.checks.some((check) => check.code === 'FIXTURE_SIZE' && check.status === 'WARN'));
97
- assert.ok(details.agentPreflight.checks.some((check) => check.code === 'AUTHENTICATION' && check.status === 'UNKNOWN'));
98
- const result = json(join(f.runsRoot, f.runGroup, '_calibration.json'));
99
- assert.equal(result.experiment.status, 'completed');
100
- assert.equal(result.costs.attempts.baseline.metrics.input.knownTotal, 10);
101
- });
102
- test('calibration rechecks environment and bench changes introduced by offline probes before first dispatch', async (t) => {
103
- for (const change of ['environment', 'bench'])
104
- await t.test(change, async (t) => {
105
- const f = await fixture(t), home = join(f.root, 'home'), codex = join(home, 'codex');
106
- const path = join(f.dir, 'verifiers/example-task.mjs'), source = readFileSync(path, 'utf8');
107
- const mutation = change === 'environment'
108
- ? `mkdirSync(${JSON.stringify(join(codex, 'skills/calibration-none'))},{recursive:true});writeFileSync(${JSON.stringify(join(codex, 'skills/calibration-none/SKILL.md'))},'---\\nname: calibration-none\\n---\\nbody');`
109
- : `writeFileSync(${JSON.stringify(join(f.dir, 'prompts/example-task.md'))},'changed');`;
110
- writeFileSync(path, `import{mkdirSync,writeFileSync}from'node:fs';${mutation}\n${source}`);
111
- let calls = 0;
112
- const executor = { describe: () => ({ kind: 'cli', model: 'offline' }), run: async () => { calls++; return final; } };
113
- const options = { dir: f.dir, calibrate: { agent: 'codex', executor, trials: 1, runsRoot: f.runsRoot,
114
- runGroup: f.runGroup, sessionOptions: { homeDir: home, env: { CODEX_HOME: codex } } }, log: () => { } };
115
- if (change === 'environment')
116
- await assert.rejects(runBenchCheck(options), /Baseline contamination|environment preflight blocked/);
117
- else
118
- assert.ok((await runBenchCheck(options)).failures > 0);
119
- assert.equal(calls, 0);
120
- assert.ok(!existsSync(f.runsRoot));
121
- });
122
- });
123
- test('calibration budgets stop at the next boundary and retain stopped receipts without retries', async (t) => {
124
- for (const usage of ['reached', 'missing', 'error'])
125
- await t.test(usage, async (t) => {
126
- const f = await fixture(t);
127
- const manifest = json(join(f.dir, 'bench.json'));
128
- manifest.tasks.push({ ...manifest.tasks[0], id: 'later-task' });
129
- writeFileSync(join(f.dir, 'bench.json'), JSON.stringify(manifest));
130
- let calls = 0;
131
- const executor = { describe: () => ({ kind: 'cli', model: 'offline' }), run: async () => {
132
- calls++;
133
- if (usage === 'error')
134
- throw new Error('offline executor failure');
135
- return usage === 'missing' ? { output: final.output } : final;
136
- } };
137
- await assert.rejects(runBenchCheck({ dir: f.dir, calibrate: { executor, trials: 3,
138
- spendingBudget: { ...budget, input: usage === 'reached' ? 10 : 1000 }, runsRoot: f.runsRoot, runGroup: f.runGroup }, log: () => { } }), usage === 'reached' ? /SPENDING_BUDGET_REACHED/ : usage === 'missing' ? /FINAL_USAGE_MISSING/ : /EXECUTION_FAILED/);
139
- assert.equal(calls, 1);
140
- const group = join(f.runsRoot, f.runGroup), session = json(join(group, '_session.json'));
141
- assert.equal(session.status, 'stopped');
142
- assert.equal(session.callsStarted, 1);
143
- const result = json(join(group, '_calibration.json'));
144
- assert.equal(result.experiment.status, 'stopped');
145
- assert.deepEqual(result.tasks[1], { id: 'later-task', passes: 0, completed: 0, errors: 0 });
146
- const report = readSingleArmReport(group);
147
- assert.ok(report);
148
- assert.equal(report.status, 'stopped');
149
- const events = readFileSync(join(group, '_budget.jsonl'), 'utf8').trim().split('\n').map(line => JSON.parse(line));
150
- assert.equal(events.filter(event => event.phase === 'after-call').length, 1);
151
- assert.equal(events.at(-1).state.reason, usage === 'reached' ? 'SPENDING_BUDGET_REACHED' : usage === 'missing' ? 'FINAL_USAGE_MISSING' : 'EXECUTION_FAILED');
152
- const index = json(join(group, '_artifacts.json'));
153
- for (const [path, sha] of Object.entries(index.files))
154
- assert.equal(sha256File(join(group, path)), sha, path);
155
- });
156
- });
157
- test('standalone bench check reuses an enclosing evaluation cancellation context and removes only its own handlers', async (t) => {
158
- const f = await fixture(t);
159
- const counts = () => [process.listenerCount('SIGINT'), process.listenerCount('SIGTERM')], initial = counts();
160
- await withEvaluationInterrupts(async () => {
161
- const signal = evaluationSignal(), before = counts();
162
- const result = await runBenchCheck({ dir: f.dir, log: () => assert.equal(evaluationSignal(), signal) });
163
- assert.equal(result.failures, 0);
164
- assert.deepEqual(counts(), before);
165
- assert.equal(evaluationSignal(), signal);
166
- });
167
- assert.deepEqual(counts(), initial);
168
- assert.equal(evaluationSignal(), undefined);
169
- });
170
- function running(pid) {
171
- try {
172
- process.kill(pid, 0);
173
- if (process.platform === 'linux' && readFileSync(`/proc/${pid}/stat`, 'utf8').split(')').at(-1).trim().startsWith('Z'))
174
- return false;
175
- return true;
176
- }
177
- catch {
178
- return false;
179
- }
180
- }
181
- for (const signal of ['SIGINT', 'SIGTERM'])
182
- for (const stage of ['verifier', 'oracle']) {
183
- test(`${signal} cancels independent bench check ${stage} and its descendants and removes disposable probes`, { timeout: 30_000 }, async (t) => {
184
- const f = await fixture(t), ready = join(f.root, 'ready.json'), heartbeat = join(f.root, 'heartbeat'), leaf = join(f.root, 'leaf.mjs');
185
- let child;
186
- t.after(async () => {
187
- if (child?.exitCode === null && child.signalCode === null)
188
- killTree(child);
189
- if (existsSync(ready))
190
- for (const pid of json(ready).pids)
191
- if (running(pid))
192
- try {
193
- process.kill(pid, 'SIGKILL');
194
- }
195
- catch { /* already dead */ }
196
- await delay(100);
197
- });
198
- writeFileSync(leaf, `import{appendFileSync}from'node:fs';setInterval(()=>appendFileSync(${JSON.stringify(heartbeat)},'x'),30);setTimeout(()=>process.exit(),20000);`);
199
- const source = `import{spawn}from'node:child_process';import{existsSync,writeFileSync}from'node:fs';
200
- const leaf=spawn(process.execPath,[${JSON.stringify(leaf)}],{stdio:'ignore'});
201
- const timer=setInterval(()=>{if(existsSync(${JSON.stringify(heartbeat)})){clearInterval(timer);writeFileSync(${JSON.stringify(ready)},JSON.stringify({dir:process.argv[2],pids:[process.pid,leaf.pid]}));}},20);
202
- setTimeout(()=>process.exit(),20000);`;
203
- writeFileSync(join(f.dir, stage === 'oracle' ? 'ground-truth/oracle-example-task.mjs' : 'verifiers/example-task.mjs'), source);
204
- const module = pathToFileURL(fileURLToPath(new URL('./bench.js', import.meta.url))).href;
205
- const harness = join(f.root, 'harness.mjs');
206
- writeFileSync(harness, `import{writeFileSync}from'node:fs';import{runBenchCheck}from ${JSON.stringify(module)};
207
- const counts=()=>[process.listenerCount('SIGINT'),process.listenerCount('SIGTERM')],before=counts();
208
- process.on('message',message=>process.emit(message.signal));
209
- try{await runBenchCheck({dir:${JSON.stringify(f.dir)},log:()=>{}});}catch(error){writeFileSync(${JSON.stringify(join(f.root, 'error'))},error.message);}
210
- finally{writeFileSync(${JSON.stringify(join(f.root, 'done.json'))},JSON.stringify({before,after:counts()}));process.disconnect();}`);
211
- child = spawn(process.execPath, [harness], { stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });
212
- let stderr = '';
213
- child.stdout.resume();
214
- child.stderr.on('data', chunk => { stderr += chunk; });
215
- const exited = new Promise(resolve => child.on('exit', (code, signal) => resolve({ code, signal })));
216
- for (let index = 0; index < 200 && !existsSync(ready) && child.exitCode === null; index++)
217
- await delay(50);
218
- assert.ok(existsSync(ready), `Offline ${stage} did not start: ${stderr}`);
219
- if (process.platform === 'win32')
220
- child.send({ signal });
221
- else
222
- child.kill(signal);
223
- let timeout;
224
- const exit = await Promise.race([exited, new Promise((_, reject) => { timeout = setTimeout(() => reject(new Error(`bench check did not stop: ${stderr}`)), 8000); })]).finally(() => clearTimeout(timeout));
225
- assert.deepEqual(exit, { code: signal === 'SIGINT' ? 130 : 143, signal: null }, stderr);
226
- assert.deepEqual(json(join(f.root, 'done.json')).after, json(join(f.root, 'done.json')).before);
227
- assert.match(readFileSync(join(f.root, 'error'), 'utf8'), new RegExp(signal));
228
- assert.ok(!existsSync(json(ready).dir), 'the interrupted disposable fixture must be removed');
229
- for (let index = 0; index < 100 && json(ready).pids.some(running); index++)
230
- await delay(50);
231
- assert.ok(json(ready).pids.every((pid) => !running(pid)), 'both verifier/oracle and grandchild must stop');
232
- const before = readFileSync(heartbeat, 'utf8');
233
- await delay(100);
234
- assert.equal(readFileSync(heartbeat, 'utf8'), before);
235
- assert.ok(!existsSync(f.runsRoot), 'offline interruption must not create a calibration run');
236
- });
237
- }
@@ -1,242 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { spawnSync } from 'node:child_process';
3
- import { existsSync, 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 { runBenchCheck, runBenchInit } from './bench.js';
9
- import { benchCheckJson, benchDiagnostic } from './bench-check-report.js';
10
- import { MOCK_MARKER_FILE } from '../harness/constants.js';
11
- const ROOT = fileURLToPath(new URL('../..', import.meta.url));
12
- const CLI = join(ROOT, 'dist/cli.js');
13
- const SCHEMA = JSON.parse(readFileSync(join(ROOT, 'docs/schemas/bench-check.schema.json'), 'utf8'));
14
- async function scaffold(t, kind = 'command') {
15
- const cwd = mkdtempSync(join(tmpdir(), 'skillfit-check-json-'));
16
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
17
- const dir = join(cwd, 'my bench');
18
- await runBenchInit({ dir, kind, yes: true, log: () => { } });
19
- return { cwd, dir };
20
- }
21
- function cli(cwd, args, expectedExit, env = process.env) {
22
- const result = spawnSync(process.execPath, [CLI, ...args], { cwd, encoding: 'utf8', timeout: 30_000, env });
23
- assert.equal(result.status, expectedExit, result.stderr || result.stdout);
24
- assert.equal(result.stderr, '', 'JSON commands must not leak human logs to stderr');
25
- // Parsing the complete stdout also rejects prefixes, trailers, and multiple JSON documents.
26
- const data = JSON.parse(result.stdout);
27
- assert.deepEqual(Object.keys(data).sort(), [...SCHEMA.required].sort(), 'result keys follow the published schema');
28
- assert.equal(data.schemaVersion, 1);
29
- assert.equal(data.kind, 'skillfit.bench-check');
30
- assert.equal(data.scope, 'offline-integrity');
31
- if (data.summary) {
32
- for (const [field, status] of [['passed', 'PASS'], ['warnings', 'WARN'], ['failures', 'FAIL'], ['info', 'INFO']]) {
33
- assert.equal(data.summary[field], data.checks.filter((c) => c.status === status).length);
34
- }
35
- assert.equal(data.summary.total, data.checks.length);
36
- for (const check of data.checks) {
37
- const item = SCHEMA.properties.checks.items;
38
- assert.deepEqual(Object.keys(check).sort(), [...item.required].sort());
39
- assert.ok(item.properties.code.enum.includes(check.code), 'gate code is documented in the schema');
40
- assert.ok(item.properties.status.enum.includes(check.status));
41
- if (check.evidence) {
42
- assert.deepEqual(Object.keys(check.evidence).sort(), [...item.properties.evidence.required].sort());
43
- assert.ok(check.evidence.output.length <= item.properties.evidence.properties.output.maxLength);
44
- }
45
- assert.ok(check.code && check.message && check.location.path);
46
- if (check.status === 'WARN' || check.status === 'FAIL')
47
- assert.ok(check.remediation);
48
- else
49
- assert.equal(check.remediation, null);
50
- }
51
- }
52
- assert.ok(!existsSync(join(cwd, 'runs')), 'offline JSON checks must not create evaluation runs');
53
- return data;
54
- }
55
- test('bench check JSON preserves human gate outcomes, task identity and input fingerprints', async (t) => {
56
- const { cwd, dir } = await scaffold(t);
57
- const human = [];
58
- const report = await runBenchCheck({ dir, log: line => human.push(line) });
59
- const data = cli(cwd, ['bench', 'check', dir, '--json'], 0);
60
- assert.equal(data.status, 'passed');
61
- assert.equal(data.dir, dir);
62
- assert.equal(data.error, null);
63
- assert.equal(data.bench.taskCount, 1);
64
- assert.match(data.bench.sha256, /^[a-f0-9]{64}$/);
65
- assert.deepEqual(data.bench, report.bench);
66
- assert.deepEqual(data.checks.map((c) => [c.code, c.status, c.message]), report.checks.map(c => [c.code, c.status, c.message]));
67
- assert.equal(human.filter(line => line.startsWith('[')).length, data.summary.total);
68
- const nop = data.checks.find((c) => c.code === 'UNTOUCHED_FIXTURE');
69
- assert.equal(nop.taskId, 'example-task');
70
- assert.deepEqual(nop.location, { path: 'bench.json', field: 'tasks[].verifier' });
71
- assert.equal(nop.evidence.exitCode, 1, 'a failing untouched fixture is a passing integrity gate');
72
- assert.equal(nop.status, 'PASS');
73
- assert.equal(data.checks.find((c) => c.code === 'ORACLE').evidence.exitCode, 0);
74
- });
75
- test('warnings, output probes, mock arms and negative controls remain distinct in JSON', async (t) => {
76
- const { cwd, dir } = await scaffold(t, 'output');
77
- const path = join(dir, 'bench.json');
78
- const manifest = JSON.parse(readFileSync(path, 'utf8'));
79
- manifest.tasks[0].shouldTrigger = true;
80
- manifest.tasks.push({ ...manifest.tasks[0], id: 'negative-task', shouldTrigger: false });
81
- writeFileSync(path, JSON.stringify(manifest));
82
- const data = cli(cwd, ['--json', 'bench', 'check', dir], 0);
83
- assert.equal(data.status, 'passed');
84
- assert.ok(data.summary.warnings > 0, 'facet-count warnings must not disappear or become failures');
85
- for (const id of ['example-task', 'negative-task']) {
86
- for (const code of ['MISSING_OUTPUT', 'EMPTY_OUTPUT', 'FACET_COUNT', 'ORACLE', 'MOCK_BASELINE', 'MOCK_TREATMENT', 'FIXTURE_SIZE']) {
87
- assert.ok(data.checks.some((c) => c.code === code && c.taskId === id), `${id}: ${code}`);
88
- }
89
- }
90
- const negative = data.checks.find((c) => c.code === 'NEGATIVE_CONTROLS');
91
- assert.equal(negative.status, 'PASS');
92
- assert.equal(negative.taskId, null);
93
- });
94
- test('missing, malformed and missing-reference benches produce structured validation failures', async (t) => {
95
- const { cwd, dir } = await scaffold(t);
96
- for (const [name, contents] of [['missing', null], ['malformed', '{'], ['missing-reference', '{"schemaVersion":1,"tasks":[{"id":"bad","fixture":"absent","prompt":"p.md","verifier":"node v.mjs"}]}']]) {
97
- await t.test(name, () => {
98
- if (contents === null)
99
- rmSync(join(dir, 'bench.json'));
100
- else
101
- writeFileSync(join(dir, 'bench.json'), contents);
102
- const data = cli(cwd, ['bench', 'check', dir, '--json'], 1);
103
- assert.equal(data.status, 'failed');
104
- assert.equal(data.bench, null);
105
- assert.equal(data.summary.failures, 1);
106
- assert.equal(data.checks[0].code, 'BENCH_LOAD');
107
- assert.equal(data.checks[0].location.path, 'bench.json');
108
- assert.match(data.checks[0].message, /bench does not load/);
109
- });
110
- }
111
- });
112
- test('JSON warnings and marker failures identify the affected bench fields and fixture paths', async (t) => {
113
- const { cwd, dir } = await scaffold(t, 'output');
114
- const path = join(dir, 'bench.json');
115
- const manifest = JSON.parse(readFileSync(path, 'utf8'));
116
- delete manifest.tasks[0].oracle;
117
- manifest.tasks[0].shouldTrigger = true;
118
- writeFileSync(path, JSON.stringify(manifest));
119
- writeFileSync(join(dir, 'fixtures/example-task/large.txt'), 'x'.repeat(66 * 1024));
120
- const warnings = cli(cwd, ['bench', 'check', dir, '--json'], 0);
121
- const oracle = warnings.checks.find((c) => c.code === 'ORACLE');
122
- assert.equal(oracle.status, 'WARN');
123
- assert.equal(oracle.location.field, 'tasks[].oracle');
124
- assert.equal(oracle.evidence, null);
125
- const size = warnings.checks.find((c) => c.code === 'FIXTURE_SIZE');
126
- assert.equal(size.status, 'WARN');
127
- assert.equal(size.location.path, 'fixtures/example-task');
128
- assert.equal(warnings.checks.find((c) => c.code === 'NEGATIVE_CONTROLS').status, 'WARN');
129
- writeFileSync(join(dir, 'fixtures/example-task', MOCK_MARKER_FILE), '{');
130
- const failed = cli(cwd, ['bench', 'check', dir, '--json'], 1);
131
- const marker = failed.checks.find((c) => c.code === 'MOCK_MARKER');
132
- assert.equal(marker.status, 'FAIL');
133
- assert.equal(marker.taskId, 'example-task');
134
- assert.equal(marker.location.path, `fixtures/example-task/${MOCK_MARKER_FILE}`);
135
- });
136
- test('JSON identifies a failed oracle process and retains its real command, exit and stderr', async (t) => {
137
- const { cwd, dir } = await scaffold(t);
138
- writeFileSync(join(dir, 'ground-truth/oracle-example-task.mjs'), "console.error('reference unavailable'); process.exit(7);");
139
- const data = cli(cwd, ['bench', 'check', dir, '--json'], 1);
140
- const gate = data.checks.find((c) => c.code === 'ORACLE');
141
- assert.equal(gate.status, 'FAIL');
142
- assert.equal(gate.taskId, 'example-task');
143
- assert.equal(gate.evidence.command, 'node ground-truth/oracle-example-task.mjs');
144
- assert.equal(gate.evidence.exitCode, 7);
145
- assert.match(gate.evidence.output, /reference unavailable/);
146
- });
147
- test('JSON exposes the actual failing verifier facets after the reference repair', async (t) => {
148
- const { cwd, dir } = await scaffold(t);
149
- writeFileSync(join(dir, 'ground-truth/oracle-example-task.mjs'), "import {writeFileSync} from 'node:fs';import {join} from 'node:path';writeFileSync(join(process.argv[2],'index.js'),'export const add=(a,b)=>Math.abs(a+b);');");
150
- const data = cli(cwd, ['bench', 'check', dir, '--json'], 1);
151
- const gate = data.checks.find((c) => c.code === 'ORACLE');
152
- assert.equal(gate.status, 'FAIL');
153
- assert.equal(gate.evidence.command, 'node verifiers/example-task.mjs');
154
- assert.ok(gate.evidence.checks.some((c) => c.name === 'negative-numbers' && !c.pass));
155
- assert.ok(gate.evidence.checks.some((c) => c.name === 'positive-and-zero' && c.pass));
156
- const verifier = join(dir, 'verifiers/example-task.mjs');
157
- writeFileSync(verifier, readFileSync(verifier, 'utf8').replace('process.exit(passed ? 0 : 1)', 'process.exit(0)'));
158
- const inconsistent = cli(cwd, ['bench', 'check', dir, '--json'], 1);
159
- const lowScore = inconsistent.checks.find((c) => c.code === 'ORACLE');
160
- assert.equal(lowScore.status, 'FAIL', 'an oracle must pass every named check even when exit code is zero');
161
- assert.equal(lowScore.evidence.exitCode, 0);
162
- assert.match(lowScore.message, /checks are stricter/);
163
- });
164
- test('an unspawnable verifier is a JSON failure with an unknown exit, never a passing NOP gate', async (t) => {
165
- const { cwd, dir } = await scaffold(t);
166
- const path = join(dir, 'bench.json');
167
- const manifest = JSON.parse(readFileSync(path, 'utf8'));
168
- manifest.tasks[0].verifier = 'skillfit-no-such-verifier';
169
- writeFileSync(path, JSON.stringify(manifest));
170
- const data = cli(cwd, ['bench', 'check', dir, '--json'], 1);
171
- const gate = data.checks.find((c) => c.code === 'UNTOUCHED_FIXTURE');
172
- assert.equal(gate.status, 'FAIL');
173
- assert.equal(gate.evidence.exitCode, null);
174
- assert.ok(gate.evidence.error);
175
- assert.match(gate.message, /could not be started/);
176
- });
177
- test('noisy verifier output stays inside bounded JSON evidence while named facets are retained', async (t) => {
178
- const { cwd, dir } = await scaffold(t);
179
- const path = join(dir, 'verifiers/example-task.mjs');
180
- writeFileSync(path, "console.log('x'.repeat(10_000));console.error('verifier diagnostic');\n" + readFileSync(path, 'utf8'));
181
- const data = cli(cwd, ['bench', 'check', dir, '--json'], 0);
182
- const evidence = data.checks.find((c) => c.code === 'ORACLE').evidence;
183
- assert.equal(evidence.outputTruncated, true);
184
- assert.ok(evidence.output.length <= 8192);
185
- assert.equal(evidence.checks.length, 4);
186
- assert.ok(evidence.checks.every((c) => c.pass));
187
- });
188
- test('argument errors return offline bench JSON before any verifier or agent starts', async (t) => {
189
- const { cwd, dir } = await scaffold(t);
190
- const sentinel = join(cwd, 'verifier-started');
191
- writeFileSync(join(dir, 'verifiers/example-task.mjs'), `import {writeFileSync} from 'node:fs'; writeFileSync(${JSON.stringify(sentinel)},'unexpected'); process.exit(1);`);
192
- const cases = [
193
- ['--json', 'bench', 'check', dir, '--trials', 'nope'],
194
- ['bench', '--json', 'check', dir, '--unknown-option'],
195
- ['bench', 'check', dir, '--json', '--trials'],
196
- ['bench', 'check', dir, '--json=true'],
197
- ];
198
- for (const args of cases) {
199
- const data = cli(cwd, args, 2);
200
- assert.equal(data.status, 'error');
201
- assert.equal(data.summary, null);
202
- assert.equal(data.error.code, 'INVALID_OR_FAILED_CHECK');
203
- assert.ok(data.error.message);
204
- assert.deepEqual(data.checks, []);
205
- assert.ok(!existsSync(sentinel));
206
- }
207
- });
208
- test('JSON calibration has a distinct planned/error contract and never runs probes without confirmation', async (t) => {
209
- const { cwd, dir } = await scaffold(t);
210
- const sentinel = join(cwd, 'verifier-started');
211
- writeFileSync(join(dir, 'verifiers/example-task.mjs'), `import {writeFileSync} from 'node:fs';writeFileSync(${JSON.stringify(sentinel)},'unexpected');process.exit(1);`);
212
- const env = { ...Object.fromEntries(Object.entries(process.env).filter(([key]) => key.toUpperCase() !== 'PATH')),
213
- PATH: '', HOME: join(cwd, 'home'), USERPROFILE: join(cwd, 'home'), CODEX_HOME: join(cwd, 'home/codex') };
214
- for (const dryRun of [false, true]) {
215
- const result = spawnSync(process.execPath, [CLI, 'bench', 'check', dir, '--json', '--calibrate', '--agent', 'codex',
216
- ...(dryRun ? ['--dry-run'] : [])], { cwd, env, encoding: 'utf8', timeout: 30_000 });
217
- assert.equal(result.status, dryRun ? 0 : 2, result.stderr || result.stdout);
218
- assert.equal(result.stderr, '');
219
- const data = JSON.parse(result.stdout);
220
- assert.equal(data.kind, dryRun ? 'skillfit.calibration-result' : 'skillfit.eval-error');
221
- assert.equal(data.status, dryRun ? 'planned' : 'error');
222
- assert.equal(data.acceptance.eligibleForUpgrade, false);
223
- if (dryRun)
224
- assert.equal(data.plan.agentPreflight.status, 'blocked');
225
- else
226
- assert.match(data.error.message, /requires --plan-sha/);
227
- assert.ok(!existsSync(sentinel));
228
- assert.ok(!existsSync(join(cwd, 'runs')));
229
- }
230
- });
231
- test('unexpected local execution errors cannot be mistaken for a completed JSON validation', async (t) => {
232
- const { cwd, dir } = await scaffold(t);
233
- const absent = join(cwd, 'missing-temp-root');
234
- const data = cli(cwd, ['bench', 'check', dir, '--json'], 2, { ...process.env, TMPDIR: absent, TEMP: absent, TMP: absent });
235
- assert.equal(data.status, 'error');
236
- assert.equal(data.summary, null);
237
- assert.ok(data.error.message);
238
- });
239
- test('offline JSON formatter refuses calibration records', () => {
240
- assert.throws(() => benchCheckJson({ dir: '.', bench: null, failures: 0, warnings: 0,
241
- checks: [benchDiagnostic('CALIBRATION', 'INFO', 'calibration record')] }), /must be offline/);
242
- });
@@ -1,87 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { spawnSync } from 'node:child_process';
3
- import { existsSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { join } from 'node:path';
6
- import { fileURLToPath } from 'node:url';
7
- import { test } from 'node:test';
8
- import { inspectBench, manageBench } from './bench-manage.js';
9
- import { applyBenchWrites, runBenchInit } from './bench.js';
10
- import { loadBench } from '../harness/bench.js';
11
- const CLI = fileURLToPath(new URL('../cli.js', import.meta.url));
12
- async function setup(t) {
13
- const root = mkdtempSync(join(tmpdir(), 'skillfit-manage-'));
14
- t.after(() => rmSync(root, { recursive: true, force: true }));
15
- const dir = join(root, 'bench');
16
- await runBenchInit({ dir, kind: 'command', yes: true, log: () => { } });
17
- return { root, dir, path: join(dir, 'bench.json') };
18
- }
19
- test('case listing/showing and default edit plans are read-only', async (t) => {
20
- const { dir, path } = await setup(t), before = readFileSync(path, 'utf8');
21
- assert.equal(inspectBench(dir).tasks.length, 1);
22
- assert.equal(inspectBench(dir, 'example-task').tasks[0].verifierKind, 'command');
23
- assert.throws(() => inspectBench(dir, 'missing'), /Unknown task/);
24
- const result = manageBench({ dir, taskId: 'example-task', action: 'edit', set: ['shouldTrigger=false'], log: () => { } });
25
- assert.equal(result.status, 'planned');
26
- assert.equal(result.after.shouldTrigger, false);
27
- assert.equal(readFileSync(path, 'utf8'), before);
28
- assert.ok(!existsSync(path + '.skillfit-bak'));
29
- });
30
- test('case edits verify schema, preserve first backups and unregister without deleting shared files', async (t) => {
31
- const { dir, path } = await setup(t);
32
- const raw = JSON.parse(readFileSync(path, 'utf8'));
33
- raw.tasks.push({ ...raw.tasks[0], id: 'real-task', provenance: 'keep me' });
34
- writeFileSync(path, JSON.stringify(raw));
35
- const before = readFileSync(path, 'utf8');
36
- const base = { dir, taskId: 'real-task', yes: true, log: () => { } };
37
- assert.equal(manageBench({ ...base, action: 'edit', set: ['shouldTrigger=true'] }).status, 'applied');
38
- assert.equal(readFileSync(path + '.skillfit-bak', 'utf8'), before);
39
- assert.equal(JSON.parse(readFileSync(path, 'utf8')).tasks[1].provenance, 'keep me');
40
- manageBench({ ...base, action: 'edit', unset: ['shouldTrigger'] });
41
- assert.equal(readFileSync(path + '.skillfit-bak', 'utf8'), before);
42
- const result = manageBench({ ...base, taskId: 'example-task', action: 'remove' });
43
- assert.equal(result.status, 'applied');
44
- assert.deepEqual(loadBench(dir).tasks.map(task => task.id), ['real-task']);
45
- assert.ok(existsSync(join(dir, 'fixtures/example-task/index.js')));
46
- assert.ok(existsSync(join(dir, 'verifiers/example-task.mjs')));
47
- assert.throws(() => manageBench({ ...base, action: 'remove' }), /last task/);
48
- });
49
- test('invalid edits, repeated fields and rollback never replace a valid bench', async (t) => {
50
- const { dir, path } = await setup(t), before = readFileSync(path, 'utf8');
51
- for (const set of [['id=renamed'], ['fixture=../outside'], ['verifier='], ['shouldTrigger=maybe'], ['shouldTrigger=true', 'shouldTrigger=false']]) {
52
- assert.throws(() => manageBench({ dir, taskId: 'example-task', action: 'edit', set, yes: true, log: () => { } }));
53
- assert.equal(readFileSync(path, 'utf8'), before);
54
- }
55
- assert.throws(() => applyBenchWrites(dir, [{ target: path, content: '{' }]));
56
- assert.equal(readFileSync(path, 'utf8'), before);
57
- });
58
- test('a dangling backup symlink cannot write outside the case directory', async (t) => {
59
- const { root, dir, path } = await setup(t), outside = join(root, 'outside');
60
- try {
61
- symlinkSync(outside, path + '.skillfit-bak', 'file');
62
- }
63
- catch (error) {
64
- if (error.code === 'EPERM') {
65
- t.skip('File symlinks require platform privileges.');
66
- return;
67
- }
68
- throw error;
69
- }
70
- const before = readFileSync(path, 'utf8');
71
- assert.throws(() => manageBench({ dir, taskId: 'example-task', action: 'edit', set: ['shouldTrigger=true'], yes: true, log: () => { } }), /unsafe backup/);
72
- assert.equal(readFileSync(path, 'utf8'), before);
73
- assert.ok(!existsSync(outside));
74
- });
75
- test('case-management CLI returns JSON plans and structured errors without prompts', async (t) => {
76
- const { dir, path } = await setup(t), before = readFileSync(path, 'utf8');
77
- for (const args of [['list', dir], ['show', dir, 'example-task'], ['edit', dir, 'example-task', '--set', 'shouldTrigger=false']]) {
78
- const result = spawnSync(process.execPath, [CLI, 'bench', ...args, '--json'], { encoding: 'utf8', input: '', timeout: 30_000 });
79
- assert.equal(result.status, 0, result.stderr);
80
- assert.equal(result.stderr, '');
81
- assert.equal(JSON.parse(result.stdout).schemaVersion, 1);
82
- }
83
- assert.equal(readFileSync(path, 'utf8'), before);
84
- const bad = spawnSync(process.execPath, [CLI, 'bench', 'show', dir, 'missing', '--json'], { encoding: 'utf8' });
85
- assert.equal(bad.status, 2);
86
- assert.equal(JSON.parse(bad.stdout).kind, 'skillfit.bench-error');
87
- });