skillfit 0.12.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.
- package/README.md +60 -119
- package/README.zh-CN.md +60 -116
- package/dist/commands/bench-check-report.js +1 -34
- package/dist/commands/bench.js +6 -239
- package/dist/commands/eval-preflight-error.js +9 -0
- package/dist/commands/eval-preflight.js +4 -11
- package/dist/commands/eval-report.js +6 -459
- package/dist/commands/install.js +14 -98
- package/dist/harness/bench-check.js +277 -0
- package/dist/harness/bench-diagnostics.js +34 -0
- package/dist/harness/eval-acceptance.js +1 -1
- package/dist/harness/eval-audit.js +1 -1
- package/dist/harness/eval-manifest.js +456 -0
- package/dist/install/constants.js +1 -0
- package/dist/install/transaction.js +112 -0
- package/docs/README.md +65 -0
- package/docs/architecture.md +86 -0
- package/docs/archive-delivery.md +83 -0
- package/docs/archive-inventory.md +91 -0
- package/docs/evaluation-reports.md +1 -1
- package/docs/growth-roadmap-2026-10.md +14 -18
- package/docs/package-contents.md +73 -0
- package/docs/plans/2026-10-20-archive-replay-verification.json +125 -0
- package/docs/plans/2026-10-20-archive-source-verification.json +256 -0
- package/docs/plans/2026-10-20-delivery-verification.json +146 -0
- package/docs/plans/2026-10-20-docs-architecture-cleanup.md +233 -0
- package/docs/plans/2026-10-20-install-transactions-and-archive-delivery.md +233 -0
- package/docs/plans/2026-10-21-npm-0.13.0-release.md +41 -0
- package/docs/releases/0.12.0-attestation-check.json +22 -0
- package/docs/releases/0.12.0-attestations.json +155 -0
- package/docs/releases/0.12.0-ci-registry-install.json +90 -0
- package/docs/releases/0.12.0-feature-smoke.json +34 -0
- package/docs/releases/0.12.0-foundations-smoke.json +1576 -0
- package/docs/releases/0.12.0-local-registry-install.json +75 -0
- package/docs/releases/0.12.0-preparation-attempt-1.json +22 -0
- package/docs/releases/0.12.0-registry-metadata.json +96 -0
- package/docs/releases/0.12.0-signatures.txt +6 -0
- package/docs/releases/0.12.0-verification.json +99 -0
- package/docs/releases/0.12.0.md +14 -0
- package/docs/releases/0.13.0-feature-smoke.mjs +114 -0
- package/docs/releases/0.13.0-preparation.json +102 -0
- package/docs/releases/0.13.0.md +61 -0
- package/docs/releases/archive-delivery-smoke.mjs +37 -0
- package/docs/reproducible-offline-example.md +1 -1
- package/evidence/README.md +24 -1
- package/evidence/archive-catalog.v1.json +8044 -0
- package/evidence/fetch-archives.mjs +211 -0
- package/package.json +9 -2
- package/dist/cli.test.js +0 -193
- package/dist/commands/bench-calibration.test.js +0 -237
- package/dist/commands/bench-check-json.test.js +0 -242
- package/dist/commands/bench-manage.test.js +0 -87
- package/dist/commands/bench.test.js +0 -1166
- package/dist/commands/bundle.test.js +0 -142
- package/dist/commands/calibration-cli.test.js +0 -145
- package/dist/commands/doctor.test.js +0 -280
- package/dist/commands/eval-agent-preflight.test.js +0 -269
- package/dist/commands/eval-cli-usage.test.js +0 -75
- package/dist/commands/eval-export-modes.test.js +0 -350
- package/dist/commands/eval-export.test.js +0 -279
- package/dist/commands/eval-interruption.test.js +0 -263
- package/dist/commands/eval-preflight.test.js +0 -382
- package/dist/commands/eval-report.test.js +0 -367
- package/dist/commands/eval.test.js +0 -503
- package/dist/commands/evaluation-report.test.js +0 -243
- package/dist/commands/install.test.js +0 -555
- package/dist/commands/npm-first-run.test.js +0 -74
- package/dist/commands/replay-cancellation.test.js +0 -105
- package/dist/commands/report.test.js +0 -110
- package/dist/commands/setup.test.js +0 -150
- package/dist/commands/upstream.test.js +0 -139
- package/dist/commands/workflow-entrypoints.test.js +0 -137
- package/dist/docs.test.js +0 -154
- package/dist/frontmatter.test.js +0 -49
- package/dist/harness/bench.test.js +0 -109
- package/dist/harness/bundle.test.js +0 -71
- package/dist/harness/codex-usage.test.js +0 -87
- package/dist/harness/costs.test.js +0 -92
- package/dist/harness/eval-budget.test.js +0 -237
- package/dist/harness/eval-component.test.js +0 -770
- package/dist/harness/eval-efficiency.test.js +0 -56
- package/dist/harness/execution-timing.test.js +0 -61
- package/dist/harness/executors/api.test.js +0 -175
- package/dist/harness/executors/cli.test.js +0 -541
- package/dist/harness/executors/mock.test.js +0 -43
- package/dist/harness/experiment-session.test.js +0 -317
- package/dist/harness/installed-skill.test.js +0 -162
- package/dist/harness/interruption.test.js +0 -31
- package/dist/harness/judge-accounting.test.js +0 -216
- package/dist/harness/judge.test.js +0 -181
- package/dist/harness/kimi-usage.test.js +0 -62
- package/dist/harness/native-diff.test.js +0 -53
- package/dist/harness/oss-lru-cache.test.js +0 -79
- package/dist/harness/oss-normalize-url.test.js +0 -64
- package/dist/harness/oss-regression-witness.test.js +0 -89
- package/dist/harness/oss-skill-followup.test.js +0 -59
- package/dist/harness/prompt.test.js +0 -48
- package/dist/harness/receipts.test.js +0 -148
- package/dist/harness/report.test.js +0 -297
- package/dist/harness/runner.test.js +0 -635
- package/dist/harness/skill-revision.test.js +0 -148
- package/dist/harness/stats.test.js +0 -124
- package/dist/harness/target.test.js +0 -60
- package/dist/harness/trigger.test.js +0 -261
- package/dist/harness/verifier-summary.test.js +0 -99
- package/dist/harness/verifier.test.js +0 -128
- package/dist/harness/waza-behavior.test.js +0 -139
- package/dist/mcp/probe.test.js +0 -139
- package/evidence/artifacts/2026-10-12-diagnosing-revision/calibration-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-diagnosing-revision/interrupted-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-diagnosing-revision/validation-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-diagnosing-v2/regression-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-diagnosing-v2/transfer-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-normalize-url-v2-available/readiness-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-normalize-url-v2-comparison/records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-normalize-url-v2-recovery/records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-normalize-url-v2-validated/records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-13-debugging-completed-development/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-13-debugging-controls-and-sleep-stop/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-13-debugging-development-stops/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-14-debugging-followup-routing-stop/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-14-debugging-independent-validation/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-14-debugging-reading-pilot-and-cost-review/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-14-debugging-spending-stop/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-15-independent-comparison-regression-stop/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-15-native-diff-mechanism/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-15-receiver-mechanism-stop/package.tar.gz +0 -0
package/dist/docs.test.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { dirname, resolve } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { test } from 'node:test';
|
|
6
|
-
const PACKAGE_ROOT = fileURLToPath(new URL('..', import.meta.url));
|
|
7
|
-
const GUIDE = 'docs/bench-authoring.md';
|
|
8
|
-
const READMES = ['README.md', 'README.zh-CN.md'];
|
|
9
|
-
function read(rel) {
|
|
10
|
-
return readFileSync(resolve(PACKAGE_ROOT, rel), 'utf8');
|
|
11
|
-
}
|
|
12
|
-
// AGENTS.md requires the English and Simplified Chinese READMEs to mirror each other section by
|
|
13
|
-
// section. A link added to one and forgotten in the other is the drift these checks prevent.
|
|
14
|
-
test('the bench authoring guide is linked from every README and every entry point', () => {
|
|
15
|
-
for (const readme of READMES) {
|
|
16
|
-
assert.match(read(readme), /\(docs\/bench-authoring\.md\)/, `${readme} must link the guide`);
|
|
17
|
-
}
|
|
18
|
-
for (const doc of ['benches/README.md', 'benches/contrib/README.md', 'docs/metrics.md', 'CONTRIBUTING.md']) {
|
|
19
|
-
assert.match(read(doc), /bench-authoring\.md\)/, `${doc} must link the guide`);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
test('portable Codex setup is linked and its command block matches across README languages', () => {
|
|
23
|
-
const normalized = (file) => read(file).replace(/\r\n/g, '\n');
|
|
24
|
-
const english = normalized('README.md');
|
|
25
|
-
const commandBlock = /```bash\nnode dist\/cli\.js bundle export \.\/personal-codex --dry-run[\s\S]*?node \.\/personal-codex\/setup\.mjs --yes\n```/.exec(english)?.[0];
|
|
26
|
-
assert.ok(commandBlock);
|
|
27
|
-
for (const readme of READMES) {
|
|
28
|
-
const content = normalized(readme);
|
|
29
|
-
assert.match(content, /\(docs\/portable-codex\.md\)/, `${readme} must link the portable setup guide`);
|
|
30
|
-
assert.ok(content.includes(commandBlock), `${readme} must use the same setup commands`);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
test('selectable Codex setup commands match across README languages', () => {
|
|
34
|
-
const normalized = (file) => read(file).replace(/\r\n/g, '\n');
|
|
35
|
-
const english = normalized('README.md');
|
|
36
|
-
const commandBlock = /```bash\nnode dist\/cli\.js setup codex --list[\s\S]*?node dist\/cli\.js setup codex --skill vibe-coding --skill diagnosing-bugs --yes\n```/.exec(english)?.[0];
|
|
37
|
-
assert.ok(commandBlock);
|
|
38
|
-
for (const readme of READMES) {
|
|
39
|
-
const content = normalized(readme);
|
|
40
|
-
assert.match(content, /\(docs\/selectable-codex\.md\)/, `${readme} must link the selectable setup guide`);
|
|
41
|
-
assert.ok(content.includes(commandBlock), `${readme} must use the same selectable setup commands`);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
test('the first-run commands work in Bash and PowerShell and match across README languages', () => {
|
|
45
|
-
const normalized = (file) => read(file).replace(/\r\n/g, '\n');
|
|
46
|
-
const english = normalized('README.md');
|
|
47
|
-
const commandBlock = /```bash\ngit clone https:\/\/github\.com\/remote-controlled-man\/skillfit\.git\ncd skillfit[\s\S]*?node dist\/cli\.js install --agent codex --dry-run\n```/.exec(english)?.[0];
|
|
48
|
-
assert.ok(commandBlock);
|
|
49
|
-
const commands = commandBlock.split('\n').slice(1, -1).join('\n');
|
|
50
|
-
assert.doesNotMatch(commands, /\b(?:bash|cp)\s|~\/|some-skill|my-server\.probe\.json/);
|
|
51
|
-
for (const readme of READMES) {
|
|
52
|
-
const content = normalized(readme);
|
|
53
|
-
assert.ok(content.includes(commandBlock), `${readme} must use the same first-run commands`);
|
|
54
|
-
assert.match(content, /\(docs\/growth-roadmap-2026-10\.md\)/, `${readme} must link the delivery plan`);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
test('a read-only synthetic report is discoverable in every README language', () => {
|
|
58
|
-
const normalized = (file) => read(file).replace(/\r\n/g, '\n');
|
|
59
|
-
const commandBlock = '```bash\nnode dist/cli.js report eval docs/examples/eval-manifest.synthetic.json\n```';
|
|
60
|
-
for (const readme of READMES) {
|
|
61
|
-
const content = normalized(readme);
|
|
62
|
-
assert.ok(content.includes(commandBlock), `${readme} must show the same runnable report example`);
|
|
63
|
-
assert.match(content, /\(docs\/sharing-results\.md\)/, `${readme} must link the sharing guide`);
|
|
64
|
-
}
|
|
65
|
-
assert.ok(existsSync(resolve(PACKAGE_ROOT, 'docs/examples/eval-manifest.synthetic.json')));
|
|
66
|
-
assert.ok(existsSync(resolve(PACKAGE_ROOT, 'docs/examples/bench-check.yml')));
|
|
67
|
-
});
|
|
68
|
-
test('the first real evaluation guide and its five-trial default are visible in every README language', () => {
|
|
69
|
-
for (const readme of READMES) {
|
|
70
|
-
const content = read(readme);
|
|
71
|
-
assert.match(content, /\(docs\/first-real-eval\.md\)/, `${readme} must link the guide`);
|
|
72
|
-
assert.match(content, /\*\*5\s*(?:trials|次|回|회|intentos)/, `${readme} must explain the default`);
|
|
73
|
-
}
|
|
74
|
-
const guide = read('docs/first-real-eval.md');
|
|
75
|
-
assert.match(guide, /8 distinct tasks × 5 trials per condition/);
|
|
76
|
-
assert.match(guide, /80 agent executions/);
|
|
77
|
-
assert.match(guide, /already available globally/);
|
|
78
|
-
});
|
|
79
|
-
test('the evidence index links only to files present in a clean checkout', () => {
|
|
80
|
-
const base = resolve(PACKAGE_ROOT, 'evidence');
|
|
81
|
-
for (const [, target] of read('evidence/README.md').matchAll(/\]\(([^)#]+?)(?:#[^)]*)?\)/g)) {
|
|
82
|
-
if (!target || /^https?:/.test(target))
|
|
83
|
-
continue;
|
|
84
|
-
assert.ok(existsSync(resolve(base, target)), `broken evidence index link: ${target}`);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
test('rules and MCP evaluation tour stays present across README languages', () => {
|
|
88
|
-
for (const [readme, figure, language, label] of [
|
|
89
|
-
['README.md', 'docs/assets/skillfit-flow.en.svg', 'en', 'Baseline'],
|
|
90
|
-
['README.zh-CN.md', 'docs/assets/skillfit-flow.zh-CN.svg', 'zh-CN', '基线组'],
|
|
91
|
-
]) {
|
|
92
|
-
const content = read(readme).replace(/\r\n/g, '\n');
|
|
93
|
-
assert.ok(content.includes('docs/assets/skillfit-mark.svg'), `${readme} must show the logo`);
|
|
94
|
-
assert.ok(content.includes(figure), `${readme} must show its localized evidence loop`);
|
|
95
|
-
const svg = read(figure);
|
|
96
|
-
assert.ok(svg.includes(`lang="${language}"`), `${figure} must declare its language`);
|
|
97
|
-
assert.ok(svg.includes(label), `${figure} must contain localized copy`);
|
|
98
|
-
assert.ok(!/9\/20|16\/20/.test(svg), `${figure} must not imply unpublished evaluation results`);
|
|
99
|
-
assert.match(content, /skillfit mcp check/, `${readme} must mention MCP preflight`);
|
|
100
|
-
assert.match(content, /node dist\/cli\.js eval \.\/context7-experiment --bench \.\/my-context7-bench --agent codex --trials 5/, `${readme} must show config A\/B`);
|
|
101
|
-
assert.match(content, /\(docs\/config-experiments\.md\)/, `${readme} must link the config experiment guide`);
|
|
102
|
-
assert.match(content, /\| `mcp check <spec>` \|/, `${readme} must list the MCP command`);
|
|
103
|
-
assert.match(content, /npm ci\nnpm run build\nnode dist\/cli\.js --help\nnode dist\/cli\.js bench check benches\/code-review/, `${readme} must provide an offline first run`);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
test('bench-authoring.md carries all seven steps and both gates', () => {
|
|
107
|
-
const guide = read(GUIDE);
|
|
108
|
-
for (const step of [
|
|
109
|
-
'### 1. Start from a real failure',
|
|
110
|
-
'### 2. Freeze the scene, then shrink it',
|
|
111
|
-
'### 3. Write the grader',
|
|
112
|
-
'### 4. Or mine it from git history',
|
|
113
|
-
'### 5. Write the trigger variant',
|
|
114
|
-
'### 6. Label it, load it, and plant decoys',
|
|
115
|
-
'### 7. Rehearse before you pay',
|
|
116
|
-
]) {
|
|
117
|
-
assert.ok(guide.includes(step), `missing step heading: ${step}`);
|
|
118
|
-
}
|
|
119
|
-
assert.match(guide, /\*\*NOP\*\*/, 'the NOP gate must be named');
|
|
120
|
-
assert.match(guide, /\*\*Oracle\*\*/, 'the oracle gate must be named');
|
|
121
|
-
});
|
|
122
|
-
// The guide describes gates that must actually exist, so each threshold it quotes is read back out of
|
|
123
|
-
// the source: changing a constant now breaks the doc's test instead of silently making the doc wrong.
|
|
124
|
-
test('bench-authoring.md quotes the thresholds the code enforces', () => {
|
|
125
|
-
const guide = read(GUIDE);
|
|
126
|
-
const benchSrc = read('src/commands/bench.ts');
|
|
127
|
-
const reportSrc = read('src/harness/report.ts');
|
|
128
|
-
const statsSrc = read('src/harness/stats.ts');
|
|
129
|
-
const minFacets = /MIN_FACET_CHECKS = (\d+)/.exec(benchSrc)?.[1];
|
|
130
|
-
const maxFacets = /MAX_FACET_CHECKS = (\d+)/.exec(benchSrc)?.[1];
|
|
131
|
-
const controlTarget = /NEGATIVE_CONTROL_TARGET = ([\d.]+)/.exec(benchSrc)?.[1];
|
|
132
|
-
const conclusiveTasks = /CONCLUSIVE_TASKS = (\d+)/.exec(reportSrc)?.[1];
|
|
133
|
-
const conclusiveTrials = /CONCLUSIVE_TRIALS = (\d+)/.exec(reportSrc)?.[1];
|
|
134
|
-
const minDiscordant = /MIN_DISCORDANT_FOR_SIGNIFICANCE = (\d+)/.exec(statsSrc)?.[1];
|
|
135
|
-
const thresholds = { minFacets, maxFacets, controlTarget, conclusiveTasks, conclusiveTrials, minDiscordant };
|
|
136
|
-
for (const [name, value] of Object.entries(thresholds)) {
|
|
137
|
-
assert.ok(value !== undefined, `could not read ${name} out of the source`);
|
|
138
|
-
}
|
|
139
|
-
assert.ok(guide.includes(`${minFacets}–${maxFacets} checks`), 'facet-check range');
|
|
140
|
-
assert.ok(guide.includes(`${Math.round(Number(controlTarget) * 100)}%`), 'negative-control target');
|
|
141
|
-
assert.ok(guide.includes(`${conclusiveTasks} tasks × ${conclusiveTrials} trials`), 'conclusive bar');
|
|
142
|
-
assert.ok(guide.includes(`${minDiscordant} discordant pairs`), 'significance floor');
|
|
143
|
-
});
|
|
144
|
-
test('every relative link in the guide resolves', () => {
|
|
145
|
-
const guide = read(GUIDE);
|
|
146
|
-
const base = dirname(resolve(PACKAGE_ROOT, GUIDE));
|
|
147
|
-
const targets = [...guide.matchAll(/\]\(([^)#]+?)(?:#[^)]*)?\)/g)].map((match) => match[1]);
|
|
148
|
-
assert.ok(targets.length >= 4, 'expected the guide to link the rest of the doc set');
|
|
149
|
-
for (const target of targets) {
|
|
150
|
-
if (/^https?:/.test(target))
|
|
151
|
-
continue;
|
|
152
|
-
assert.ok(existsSync(resolve(base, target)), `broken link in ${GUIDE}: ${target}`);
|
|
153
|
-
}
|
|
154
|
-
});
|
package/dist/frontmatter.test.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { test } from 'node:test';
|
|
3
|
-
import { parseFrontmatter } from './frontmatter.js';
|
|
4
|
-
test('parses name and description', () => {
|
|
5
|
-
const fields = parseFrontmatter('---\nname: demo\ndescription: does things\n---\nbody');
|
|
6
|
-
assert.deepEqual(fields, { name: 'demo', description: 'does things' });
|
|
7
|
-
});
|
|
8
|
-
test('returns null without a closing fence or any frontmatter', () => {
|
|
9
|
-
assert.equal(parseFrontmatter('---\nname: demo\n'), null);
|
|
10
|
-
assert.equal(parseFrontmatter('no frontmatter here'), null);
|
|
11
|
-
});
|
|
12
|
-
test('handles CRLF line endings', () => {
|
|
13
|
-
assert.equal(parseFrontmatter('---\r\nname: x\r\n---\r\n')?.name, 'x');
|
|
14
|
-
});
|
|
15
|
-
// The four cases below are the reason this module exists. doctor and install each had their own
|
|
16
|
-
// parser and disagreed on all four, so the same SKILL.md could pass `doctor` and be rejected by
|
|
17
|
-
// `install` — or validate with the two characters ">-" as its description.
|
|
18
|
-
test('tolerates a byte-order mark', () => {
|
|
19
|
-
const fields = parseFrontmatter('\uFEFF---\nname: demo\ndescription: does things\n---\n');
|
|
20
|
-
assert.deepEqual(fields, { name: 'demo', description: 'does things' });
|
|
21
|
-
});
|
|
22
|
-
test('tolerates trailing spaces after the opening fence', () => {
|
|
23
|
-
const fields = parseFrontmatter('--- \nname: demo\ndescription: does things\n---\n');
|
|
24
|
-
assert.deepEqual(fields, { name: 'demo', description: 'does things' });
|
|
25
|
-
});
|
|
26
|
-
test('unquotes single- and double-quoted scalars', () => {
|
|
27
|
-
const fields = parseFrontmatter('---\nname: "demo skill"\ndescription: \'does things\'\n---\n');
|
|
28
|
-
assert.equal(fields?.name, 'demo skill');
|
|
29
|
-
assert.equal(fields?.description, 'does things');
|
|
30
|
-
});
|
|
31
|
-
test('joins a folded block scalar with spaces', () => {
|
|
32
|
-
const fields = parseFrontmatter('---\nname: demo\ndescription: >\n first line\n second line\n---\n');
|
|
33
|
-
assert.equal(fields?.description, 'first line second line');
|
|
34
|
-
});
|
|
35
|
-
test('keeps line breaks in a literal block scalar', () => {
|
|
36
|
-
const fields = parseFrontmatter('---\nname: demo\ndescription: |\n first line\n second line\n---\n');
|
|
37
|
-
assert.equal(fields?.description, 'first line\nsecond line');
|
|
38
|
-
});
|
|
39
|
-
test('handles chomping indicators, which both old parsers stored literally', () => {
|
|
40
|
-
for (const indicator of ['>-', '|-', '>+', '|+']) {
|
|
41
|
-
const fields = parseFrontmatter(`---\nname: demo\ndescription: ${indicator}\n does things\n across lines\n---\n`);
|
|
42
|
-
assert.ok(fields?.description?.includes('does things'), `description: ${indicator} should be read as a block scalar, got ${JSON.stringify(fields?.description)}`);
|
|
43
|
-
assert.ok(!fields?.description?.includes(indicator), `the indicator itself must not end up in the value, got ${JSON.stringify(fields?.description)}`);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
test('a key with no value is empty rather than absent', () => {
|
|
47
|
-
const fields = parseFrontmatter('---\nname: demo\ndescription:\n---\n');
|
|
48
|
-
assert.deepEqual(fields, { name: 'demo', description: '' });
|
|
49
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { test } from 'node:test';
|
|
7
|
-
import { loadBench } from './bench.js';
|
|
8
|
-
const PACKAGE_ROOT = fileURLToPath(new URL('../..', import.meta.url));
|
|
9
|
-
const BUNDLED_CODE_REVIEW = join(PACKAGE_ROOT, 'benches', 'code-review');
|
|
10
|
-
function makeBench(t, benchJson) {
|
|
11
|
-
const dir = mkdtempSync(join(tmpdir(), 'skillfit-bench-'));
|
|
12
|
-
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
13
|
-
mkdirSync(join(dir, 'fixtures', 't1'), { recursive: true });
|
|
14
|
-
mkdirSync(join(dir, 'prompts'), { recursive: true });
|
|
15
|
-
mkdirSync(join(dir, 'verifiers'), { recursive: true });
|
|
16
|
-
writeFileSync(join(dir, 'fixtures', 't1', 'index.txt'), 'fixture\n');
|
|
17
|
-
writeFileSync(join(dir, 'prompts', 't1.md'), 'do it\n');
|
|
18
|
-
writeFileSync(join(dir, 'verifiers', 't1.mjs'), 'process.exit(0);\n');
|
|
19
|
-
writeFileSync(join(dir, 'bench.json'), JSON.stringify(benchJson));
|
|
20
|
-
return dir;
|
|
21
|
-
}
|
|
22
|
-
const validTask = {
|
|
23
|
-
id: 't1',
|
|
24
|
-
fixture: 'fixtures/t1',
|
|
25
|
-
prompt: 'prompts/t1.md',
|
|
26
|
-
verifier: 'node verifiers/t1.mjs',
|
|
27
|
-
};
|
|
28
|
-
test('loadBench loads the bundled code-review bench', () => {
|
|
29
|
-
const bench = loadBench(BUNDLED_CODE_REVIEW);
|
|
30
|
-
assert.equal(bench.name, 'code-review');
|
|
31
|
-
assert.equal(bench.schemaVersion, 1);
|
|
32
|
-
assert.equal(bench.tasks.length, 5);
|
|
33
|
-
assert.equal(bench.tasks[0]?.id, 'review-r1');
|
|
34
|
-
assert.equal(bench.tasks[0]?.rubric, 'ground-truth/r1.md');
|
|
35
|
-
assert.equal(bench.tasks[0]?.oracle, 'node ground-truth/oracle-r1.mjs');
|
|
36
|
-
assert.equal(bench.tasks[0]?.shouldTrigger, true);
|
|
37
|
-
assert.equal(bench.tasks[0]?.promptTrigger, 'prompts/review-r1.trigger.md');
|
|
38
|
-
assert.equal(bench.tasks[1]?.id, 'review-r2');
|
|
39
|
-
assert.equal(bench.tasks[1]?.verifier, 'node verifiers/review-r2.mjs');
|
|
40
|
-
assert.equal(bench.tasks[2]?.id, 'review-r3');
|
|
41
|
-
assert.equal(bench.tasks[2]?.rubric, 'ground-truth/r3.md');
|
|
42
|
-
assert.equal(bench.tasks[3]?.id, 'explain-x1');
|
|
43
|
-
assert.equal(bench.tasks[3]?.shouldTrigger, false);
|
|
44
|
-
assert.equal(bench.tasks[4]?.id, 'summarize-s1');
|
|
45
|
-
assert.equal(bench.tasks[4]?.shouldTrigger, false);
|
|
46
|
-
assert.equal(bench.tasks[4]?.oracle, 'node ground-truth/oracle-summarize-s1.mjs');
|
|
47
|
-
assert.match(bench.contentSha256, /^[0-9a-f]{64}$/);
|
|
48
|
-
});
|
|
49
|
-
test('loadBench accepts a valid synthetic bench', (t) => {
|
|
50
|
-
const dir = makeBench(t, { schemaVersion: 1, tasks: [validTask] });
|
|
51
|
-
const bench = loadBench(dir);
|
|
52
|
-
assert.equal(bench.tasks.length, 1);
|
|
53
|
-
assert.equal(bench.tasks[0]?.verifier, 'node verifiers/t1.mjs');
|
|
54
|
-
});
|
|
55
|
-
test('loadBench rejects unsupported schemaVersion', (t) => {
|
|
56
|
-
const dir = makeBench(t, { schemaVersion: 2, tasks: [validTask] });
|
|
57
|
-
assert.throws(() => loadBench(dir), /Unsupported bench schemaVersion 2/);
|
|
58
|
-
});
|
|
59
|
-
test('loadBench rejects a missing bench.json', () => {
|
|
60
|
-
assert.throws(() => loadBench(join(tmpdir(), 'skillfit-no-such-bench')), /missing bench\.json/);
|
|
61
|
-
});
|
|
62
|
-
test('loadBench rejects an empty task list', (t) => {
|
|
63
|
-
const dir = makeBench(t, { schemaVersion: 1, tasks: [] });
|
|
64
|
-
assert.throws(() => loadBench(dir), /at least one task/);
|
|
65
|
-
});
|
|
66
|
-
test('loadBench rejects a missing fixture directory', (t) => {
|
|
67
|
-
const dir = makeBench(t, { schemaVersion: 1, tasks: [{ ...validTask, fixture: 'fixtures/nope' }] });
|
|
68
|
-
assert.throws(() => loadBench(dir), /fixture directory not found/);
|
|
69
|
-
});
|
|
70
|
-
test('loadBench rejects a missing verifier script', (t) => {
|
|
71
|
-
const dir = makeBench(t, { schemaVersion: 1, tasks: [{ ...validTask, verifier: 'node verifiers/nope.mjs' }] });
|
|
72
|
-
assert.throws(() => loadBench(dir), /missing file: verifiers\/nope\.mjs/);
|
|
73
|
-
});
|
|
74
|
-
test('loadBench rejects duplicate task ids', (t) => {
|
|
75
|
-
const dir = makeBench(t, { schemaVersion: 1, tasks: [validTask, validTask] });
|
|
76
|
-
assert.throws(() => loadBench(dir), /Duplicate task id/);
|
|
77
|
-
});
|
|
78
|
-
test('loadBench rejects paths escaping the bench directory', (t) => {
|
|
79
|
-
const dir = makeBench(t, { schemaVersion: 1, tasks: [{ ...validTask, fixture: '../elsewhere' }] });
|
|
80
|
-
assert.throws(() => loadBench(dir), /relative path inside the bench directory/);
|
|
81
|
-
});
|
|
82
|
-
test('loadBench accepts a task with a valid oracle command', (t) => {
|
|
83
|
-
const dir = makeBench(t, {
|
|
84
|
-
schemaVersion: 1,
|
|
85
|
-
tasks: [{ ...validTask, oracle: 'node ground-truth/o1.mjs' }],
|
|
86
|
-
});
|
|
87
|
-
mkdirSync(join(dir, 'ground-truth'), { recursive: true });
|
|
88
|
-
writeFileSync(join(dir, 'ground-truth', 'o1.mjs'), 'process.exit(0);\n');
|
|
89
|
-
const bench = loadBench(dir);
|
|
90
|
-
assert.equal(bench.tasks[0]?.oracle, 'node ground-truth/o1.mjs');
|
|
91
|
-
});
|
|
92
|
-
test('loadBench rejects an oracle referencing a missing file', (t) => {
|
|
93
|
-
const dir = makeBench(t, {
|
|
94
|
-
schemaVersion: 1,
|
|
95
|
-
tasks: [{ ...validTask, oracle: 'node ground-truth/nope.mjs' }],
|
|
96
|
-
});
|
|
97
|
-
assert.throws(() => loadBench(dir), /oracle references a missing file: ground-truth\/nope\.mjs/);
|
|
98
|
-
});
|
|
99
|
-
test('loadBench rejects an oracle escaping the bench directory', (t) => {
|
|
100
|
-
const dir = makeBench(t, {
|
|
101
|
-
schemaVersion: 1,
|
|
102
|
-
tasks: [{ ...validTask, oracle: 'node ../elsewhere/o1.mjs' }],
|
|
103
|
-
});
|
|
104
|
-
assert.throws(() => loadBench(dir), /relative path inside the bench directory/);
|
|
105
|
-
});
|
|
106
|
-
test('loadBench rejects a non-string oracle field', (t) => {
|
|
107
|
-
const dir = makeBench(t, { schemaVersion: 1, tasks: [{ ...validTask, oracle: 42 }] });
|
|
108
|
-
assert.throws(() => loadBench(dir), /invalid "oracle" field/);
|
|
109
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { test } from 'node:test';
|
|
6
|
-
import { collectInstalledSkillFingerprint, collectSkillBundle } from './bundle.js';
|
|
7
|
-
function makeSkillDir(t) {
|
|
8
|
-
const dir = mkdtempSync(join(tmpdir(), 'skillfit-bundle-'));
|
|
9
|
-
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
10
|
-
mkdirSync(join(dir, 'refs'), { recursive: true });
|
|
11
|
-
writeFileSync(join(dir, 'SKILL.md'), '# My Skill\nDo the thing.\n');
|
|
12
|
-
writeFileSync(join(dir, 'refs', 'rules.yaml'), 'rule: one\n');
|
|
13
|
-
writeFileSync(join(dir, 'data.json'), '{"a":1}\n');
|
|
14
|
-
writeFileSync(join(dir, 'ignore.txt'), 'not injectable\n');
|
|
15
|
-
writeFileSync(join(dir, 'run.js'), 'console.log(1)\n');
|
|
16
|
-
return dir;
|
|
17
|
-
}
|
|
18
|
-
test('collectSkillBundle collects only md/yaml/json files, sorted', (t) => {
|
|
19
|
-
const dir = makeSkillDir(t);
|
|
20
|
-
const bundle = collectSkillBundle(dir, 'my-skill');
|
|
21
|
-
assert.deepEqual(bundle.files, ['SKILL.md', 'data.json', 'refs/rules.yaml']);
|
|
22
|
-
assert.equal(bundle.name, 'my-skill');
|
|
23
|
-
});
|
|
24
|
-
test('collectSkillBundle hash is deterministic and content-sensitive', (t) => {
|
|
25
|
-
const dir = makeSkillDir(t);
|
|
26
|
-
const first = collectSkillBundle(dir, 'my-skill');
|
|
27
|
-
const second = collectSkillBundle(dir, 'my-skill');
|
|
28
|
-
assert.equal(first.sha256, second.sha256);
|
|
29
|
-
assert.match(first.sha256, /^[0-9a-f]{64}$/);
|
|
30
|
-
writeFileSync(join(dir, 'SKILL.md'), '# Changed\n');
|
|
31
|
-
const third = collectSkillBundle(dir, 'my-skill');
|
|
32
|
-
assert.notEqual(first.sha256, third.sha256);
|
|
33
|
-
});
|
|
34
|
-
test('installed fingerprints cover scripts and binary assets while injectable identity stays stable', (t) => {
|
|
35
|
-
const dir = makeSkillDir(t);
|
|
36
|
-
mkdirSync(join(dir, 'scripts'));
|
|
37
|
-
writeFileSync(join(dir, 'scripts', 'helper.sh'), 'printf first\n');
|
|
38
|
-
writeFileSync(join(dir, 'asset.bin'), Buffer.from([0, 255, 128]));
|
|
39
|
-
const bundle = collectSkillBundle(dir);
|
|
40
|
-
const first = collectInstalledSkillFingerprint(dir);
|
|
41
|
-
assert.deepEqual(first.files, ['SKILL.md', 'asset.bin', 'data.json', 'ignore.txt', 'refs/rules.yaml', 'run.js', 'scripts/helper.sh']);
|
|
42
|
-
assert.equal(first.sha256, collectInstalledSkillFingerprint(dir).sha256);
|
|
43
|
-
writeFileSync(join(dir, 'scripts', 'helper.sh'), 'printf second\n');
|
|
44
|
-
const second = collectInstalledSkillFingerprint(dir);
|
|
45
|
-
assert.notEqual(first.sha256, second.sha256);
|
|
46
|
-
writeFileSync(join(dir, 'asset.bin'), Buffer.from([0, 255, 129]));
|
|
47
|
-
assert.notEqual(second.sha256, collectInstalledSkillFingerprint(dir).sha256);
|
|
48
|
-
assert.equal(bundle.sha256, collectSkillBundle(dir).sha256);
|
|
49
|
-
assert.equal(bundle.payload, collectSkillBundle(dir).payload);
|
|
50
|
-
});
|
|
51
|
-
test('collectSkillBundle payload wraps files in a <skill> block', (t) => {
|
|
52
|
-
const dir = makeSkillDir(t);
|
|
53
|
-
const bundle = collectSkillBundle(dir, 'my-skill');
|
|
54
|
-
assert.match(bundle.payload, /<skill name="my-skill">/);
|
|
55
|
-
assert.match(bundle.payload, /--- skill file: SKILL\.md ---/);
|
|
56
|
-
assert.match(bundle.payload, /# My Skill/);
|
|
57
|
-
assert.match(bundle.payload, /<\/skill>/);
|
|
58
|
-
assert.ok(!bundle.payload.includes('not injectable'));
|
|
59
|
-
});
|
|
60
|
-
test('collectSkillBundle defaults the name to the directory basename', (t) => {
|
|
61
|
-
const dir = makeSkillDir(t);
|
|
62
|
-
const bundle = collectSkillBundle(dir);
|
|
63
|
-
assert.equal(bundle.name, dir.split(/[\\/]/).pop());
|
|
64
|
-
});
|
|
65
|
-
test('collectSkillBundle rejects missing dirs and empty skills', (t) => {
|
|
66
|
-
assert.throws(() => collectSkillBundle(join(tmpdir(), 'skillfit-does-not-exist')), /not a directory/);
|
|
67
|
-
const dir = mkdtempSync(join(tmpdir(), 'skillfit-bundle-empty-'));
|
|
68
|
-
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
69
|
-
writeFileSync(join(dir, 'only.txt'), 'x\n');
|
|
70
|
-
assert.throws(() => collectSkillBundle(dir), /No injectable skill files/);
|
|
71
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { test } from 'node:test';
|
|
6
|
-
import { probeCodexPartialUsage } from './codex-usage.js';
|
|
7
|
-
import { CliExecutor } from './executors/cli.js';
|
|
8
|
-
import { ExecutorFailure } from './types.js';
|
|
9
|
-
const ID = '11111111-1111-4111-8111-111111111111';
|
|
10
|
-
const sessions = { dir: '~/sessions', homeOverride: { env: 'TEST_SESSION_HOME', relativePath: 'sessions' },
|
|
11
|
-
transcriptGlob: '**/rollout-*.jsonl', wireShape: 'codex-rollout', docs: null };
|
|
12
|
-
function setup(t) {
|
|
13
|
-
const root = mkdtempSync(join(tmpdir(), 'skillfit-partial-usage-'));
|
|
14
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
15
|
-
const workdir = join(root, 'workspace');
|
|
16
|
-
mkdirSync(workdir);
|
|
17
|
-
const folder = join(root, 'sessions');
|
|
18
|
-
mkdirSync(folder);
|
|
19
|
-
const file = join(folder, 'rollout-fixture-' + ID + '.jsonl'), now = Date.now();
|
|
20
|
-
const meta = { timestamp: new Date(now).toISOString(), type: 'session_meta', payload: { id: ID, cwd: workdir } };
|
|
21
|
-
const usage = (input = 100, cached = 60, output = 20, at = now + 10) => ({ timestamp: new Date(at).toISOString(),
|
|
22
|
-
type: 'event_msg', payload: { type: 'token_count', info: { total_token_usage: { input_tokens: input, cached_input_tokens: cached, output_tokens: output } } } });
|
|
23
|
-
const save = (events) => writeFileSync(file, events.map(e => JSON.stringify(e)).join('\n') + '\n');
|
|
24
|
-
const options = { sessions, stdout: JSON.stringify({ type: 'thread.started', thread_id: ID }), workdir,
|
|
25
|
-
startedAtMs: now, finishedAtMs: now + 1000, homeDir: root, env: { TEST_SESSION_HOME: '/must-not-read' } };
|
|
26
|
-
return { root, file, folder, now, meta, usage, save, options };
|
|
27
|
-
}
|
|
28
|
-
test('partial counters bind identity, canonical workspace and time; cumulative snapshots are not summed', t => {
|
|
29
|
-
const f = setup(t);
|
|
30
|
-
f.save([f.meta, f.usage(100, 60, 20), { type: 'response_item', payload: { text: 'PRIVATE_BODY_DO_NOT_EXPORT' } }, f.usage(150, 90, 30)]);
|
|
31
|
-
const result = probeCodexPartialUsage({ ...f.options, workdir: join(f.options.workdir, '.') });
|
|
32
|
-
assert.deepEqual(result?.tokens, { input: 150, cachedInput: 90, output: 30 });
|
|
33
|
-
assert.equal(result?.evidence.threadId, ID);
|
|
34
|
-
assert.match(result.evidence.recordSha256, /^[0-9a-f]{64}$/);
|
|
35
|
-
assert.ok(!JSON.stringify(result).includes('PRIVATE_BODY'));
|
|
36
|
-
assert.ok(!JSON.stringify(result).includes(f.root));
|
|
37
|
-
assert.match(result.evidence.scope, /Partial/);
|
|
38
|
-
});
|
|
39
|
-
test('wrong or stale identity, future counters and ambiguous files never borrow another session usage', t => {
|
|
40
|
-
const f = setup(t);
|
|
41
|
-
f.save([{ ...f.meta, payload: { id: ID, cwd: '/another-workspace' } }, f.usage()]);
|
|
42
|
-
assert.equal(probeCodexPartialUsage(f.options), undefined);
|
|
43
|
-
f.save([{ ...f.meta, timestamp: new Date(f.now - 6000).toISOString() }, f.usage()]);
|
|
44
|
-
assert.equal(probeCodexPartialUsage(f.options), undefined);
|
|
45
|
-
f.save([f.meta, f.usage(100, 60, 20, f.now + 1001)]);
|
|
46
|
-
assert.equal(probeCodexPartialUsage(f.options), undefined);
|
|
47
|
-
f.save([f.meta, f.usage()]);
|
|
48
|
-
writeFileSync(join(f.folder, 'rollout-second-' + ID + '.jsonl'), readFileSync(f.file));
|
|
49
|
-
assert.equal(probeCodexPartialUsage(f.options), undefined);
|
|
50
|
-
});
|
|
51
|
-
test('malformed partitions, decreasing counters and missing public thread identity remain unknown', t => {
|
|
52
|
-
const f = setup(t);
|
|
53
|
-
for (const events of [[f.meta, f.usage(100, 101)], [f.meta, f.usage(1.5)], [f.meta, f.usage(100), f.usage(99)], [f.usage(), f.meta]]) {
|
|
54
|
-
f.save(events);
|
|
55
|
-
assert.equal(probeCodexPartialUsage(f.options), undefined);
|
|
56
|
-
}
|
|
57
|
-
f.save([f.meta, f.usage()]);
|
|
58
|
-
assert.equal(probeCodexPartialUsage({ ...f.options, stdout: 'not a public JSON thread' }), undefined);
|
|
59
|
-
assert.equal(probeCodexPartialUsage({ ...f.options, stdout: f.options.stdout + '\n' + JSON.stringify({ type: 'thread.started', thread_id: '22222222-2222-4222-8222-222222222222' }) }), undefined);
|
|
60
|
-
assert.equal(probeCodexPartialUsage({ ...f.options, sessions: { ...sessions, wireShape: 'content-blocks' } }), undefined);
|
|
61
|
-
});
|
|
62
|
-
test('a failed fake CLI keeps partial local usage and numeric provenance without invoking a model', async (t) => {
|
|
63
|
-
const f = setup(t);
|
|
64
|
-
f.save([f.meta, f.usage(100, 60, 20, f.now)]);
|
|
65
|
-
const child = `console.log(JSON.stringify({type:'thread.started',thread_id:${JSON.stringify(ID)}}));process.exitCode=1;`;
|
|
66
|
-
const executor = new CliExecutor({ argv: [process.execPath, '-e', child], shell: false, triggerSkillName: 'offline-fixture',
|
|
67
|
-
partialUsageFromSessionLog: true, sessions, homeDir: f.root });
|
|
68
|
-
await assert.rejects(executor.run('offline', f.options.workdir), error => {
|
|
69
|
-
assert.ok(error instanceof ExecutorFailure);
|
|
70
|
-
assert.equal(error.result.usageStatus, 'partial');
|
|
71
|
-
assert.deepEqual(error.result.tokens, { input: 100, cachedInput: 60, output: 20 });
|
|
72
|
-
assert.equal(error.result.usageEvidence?.source, 'local-session-token-count');
|
|
73
|
-
return true;
|
|
74
|
-
});
|
|
75
|
-
const disabled = new CliExecutor({ argv: [process.execPath, '-e', child], shell: false, triggerSkillName: 'offline-fixture', sessions, homeDir: f.root });
|
|
76
|
-
await assert.rejects(disabled.run('offline', f.options.workdir), error => { assert.ok(error instanceof ExecutorFailure); assert.equal(error.result.tokens, undefined); return true; });
|
|
77
|
-
});
|
|
78
|
-
test('a healthy fake CLI uses public final counters without replacing them with a local snapshot', async (t) => {
|
|
79
|
-
const f = setup(t);
|
|
80
|
-
f.save([f.meta, f.usage(100, 60, 20, f.now)]);
|
|
81
|
-
const child = `console.log(JSON.stringify({type:'thread.started',thread_id:${JSON.stringify(ID)}}));console.log(JSON.stringify({type:'turn.completed',usage:{input_tokens:50,cached_input_tokens:10,output_tokens:5}}));`;
|
|
82
|
-
const executor = new CliExecutor({ argv: [process.execPath, '-e', child], shell: false, triggerSkillName: 'offline-fixture',
|
|
83
|
-
partialUsageFromSessionLog: true, sessions, homeDir: f.root });
|
|
84
|
-
const result = await executor.run('offline', f.options.workdir);
|
|
85
|
-
assert.deepEqual(result.tokens, { input: 50, cachedInput: 10, output: 5 });
|
|
86
|
-
assert.equal(result.usageEvidence, undefined);
|
|
87
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { test } from 'node:test';
|
|
3
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { renderCostLines, summarizeCosts } from './costs.js';
|
|
7
|
-
import { parseEvalReport, renderEvalMarkdown } from '../commands/eval-report.js';
|
|
8
|
-
function run(input, passed = true, extra = {}) {
|
|
9
|
-
return { executorInvoked: true, passed, error: null, durationSeconds: 5,
|
|
10
|
-
tokens: { input, cachedInput: input / 2, output: 2 }, usageStatus: 'final', ...extra };
|
|
11
|
-
}
|
|
12
|
-
test('lower total tokens can cost more per success because graded failures consume usage', () => {
|
|
13
|
-
const rows = { baseline: [run(10), run(10)], treatment: [run(8), run(8, false)] };
|
|
14
|
-
const costs = summarizeCosts(rows, rows);
|
|
15
|
-
const output = renderCostLines(costs).join('\n');
|
|
16
|
-
assert.match(output, /Input tokens \| 20 \| 16 \| -20.0% \| 10.000 \/ 16.000 \| \+60.0%/);
|
|
17
|
-
assert.equal(costs.attempts.treatment.passes, 1);
|
|
18
|
-
});
|
|
19
|
-
test('attempts retain timeout spending and the excluded successful partner; quality remains paired', () => {
|
|
20
|
-
const b1 = run(10), t1 = run(8);
|
|
21
|
-
const timeout = run(3, false, { error: 'timeout', durationSeconds: 600, usageStatus: 'partial' });
|
|
22
|
-
const refused = run(0, false, { executorInvoked: false, error: 'guard refusal', tokens: null, usageStatus: 'unknown' });
|
|
23
|
-
const costs = summarizeCosts({ baseline: [b1, run(10), refused], treatment: [t1, timeout, refused] }, { baseline: [b1], treatment: [t1] });
|
|
24
|
-
assert.equal(costs.paired.baseline.runs, 1);
|
|
25
|
-
assert.equal(costs.attempts.baseline.passes, 2);
|
|
26
|
-
assert.equal(costs.attempts.treatment.metrics.input.knownTotal, 11);
|
|
27
|
-
assert.deepEqual(costs.attempts.treatment.metrics.input.coverage, { final: 1, partial: 1, unknown: 0 });
|
|
28
|
-
assert.equal(costs.attempts.treatment.metrics.durationSeconds.knownTotal, 605);
|
|
29
|
-
assert.equal(costs.notInvoked.treatment, 1);
|
|
30
|
-
const output = renderCostLines(costs).join('\n');
|
|
31
|
-
assert.match(output, /Input tokens \| 20 \| >= 11 \| n\/a \| 10.000 \/ >= 11.000 \| n\/a/);
|
|
32
|
-
assert.match(output, /Elapsed seconds \| 10.000 \| 605.000 \| \+5950.0%/);
|
|
33
|
-
});
|
|
34
|
-
test('zero cache counts are known, missing or invalid partitions remain unknown', () => {
|
|
35
|
-
const rows = { baseline: [run(10, true, { tokens: { input: 10, cachedInput: 0 } })],
|
|
36
|
-
treatment: [run(10, true, { tokens: { input: 10, cachedInput: 11 } })] };
|
|
37
|
-
const costs = summarizeCosts(rows, rows);
|
|
38
|
-
assert.equal(costs.paired.baseline.metrics.uncachedInput.knownTotal, 10);
|
|
39
|
-
assert.equal(costs.paired.baseline.metrics.cachedInput.coverage.final, 1);
|
|
40
|
-
assert.equal(costs.paired.treatment.metrics.cachedInput.coverage.unknown, 1);
|
|
41
|
-
assert.equal(costs.paired.treatment.metrics.uncachedInput.coverage.unknown, 1);
|
|
42
|
-
assert.match(renderCostLines(costs).join('\n'), /Cached input tokens \| 0 \| unrecorded \| n\/a/);
|
|
43
|
-
});
|
|
44
|
-
test('missing timeout usage and no successes suppress cost ratios without inventing zero cost', () => {
|
|
45
|
-
const timeout = run(0, false, { error: 'timeout', tokens: null, usageStatus: 'unknown', durationSeconds: 600 });
|
|
46
|
-
const costs = summarizeCosts({ baseline: [run(0)], treatment: [timeout] }, { baseline: [], treatment: [] });
|
|
47
|
-
const output = renderCostLines(costs).join('\n');
|
|
48
|
-
assert.match(output, /Input tokens \| 0 \| unrecorded \| n\/a \| 0.000 \/ n\/a \(no successes\)/);
|
|
49
|
-
assert.equal(costs.attempts.treatment.metrics.input.coverage.unknown, 1);
|
|
50
|
-
assert.equal(costs.attempts.treatment.metrics.durationSeconds.coverage.final, 1);
|
|
51
|
-
});
|
|
52
|
-
test('published real Skill revision receipts reproduce cost regressions and unknown timeout usage offline', () => {
|
|
53
|
-
const root = join(fileURLToPath(new URL('../..', import.meta.url)), 'evidence/artifacts/2026-10-12-diagnosing-revision');
|
|
54
|
-
const analysis = JSON.parse(readFileSync(join(root, 'cost-analysis.json'), 'utf8'));
|
|
55
|
-
const manifest = JSON.parse(readFileSync(join(root, 'manifest.json'), 'utf8'));
|
|
56
|
-
assert.equal(manifest.experiment.callsStarted, 30);
|
|
57
|
-
const originalQuality = JSON.stringify(manifest.overall);
|
|
58
|
-
const observation = (row) => ({
|
|
59
|
-
executorInvoked: true, passed: row['passed'], error: row['error'], durationSeconds: row['seconds'],
|
|
60
|
-
usageStatus: row['input'] === null && row['output'] === null ? 'unknown' : 'final',
|
|
61
|
-
tokens: {
|
|
62
|
-
...(row['input'] === null ? {} : { input: row['input'] }),
|
|
63
|
-
...(row['output'] === null ? {} : { output: row['output'] }),
|
|
64
|
-
...(row['cachedInput'] === null ? {} : { cachedInput: row['cachedInput'] }),
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
const summarize = (pairs) => {
|
|
68
|
-
const arms = (rows) => ({ baseline: rows.map(r => observation(r.baseline)), treatment: rows.map(r => observation(r.treatment)) });
|
|
69
|
-
return summarizeCosts(arms(pairs), arms(pairs.filter(r => r.graded)));
|
|
70
|
-
};
|
|
71
|
-
const costs = summarize(analysis.observations);
|
|
72
|
-
for (const metric of ['input', 'cachedInput', 'uncachedInput', 'output']) {
|
|
73
|
-
for (const arm of ['baseline', 'treatment'])
|
|
74
|
-
assert.equal(costs.paired[arm].metrics[metric].knownTotal, analysis.metrics[metric].totals[arm]);
|
|
75
|
-
}
|
|
76
|
-
assert.equal(costs.attempts.baseline.passes, 15);
|
|
77
|
-
assert.equal(costs.attempts.treatment.passes, 12);
|
|
78
|
-
assert.equal(costs.attempts.treatment.metrics.input.coverage.unknown, 1);
|
|
79
|
-
assert.equal(costs.attempts.treatment.metrics.durationSeconds.coverage.final, 15);
|
|
80
|
-
for (const task of manifest.tasks)
|
|
81
|
-
task.costs = summarize(analysis.observations.filter((row) => row.task === task.id));
|
|
82
|
-
manifest.overall.costs = costs;
|
|
83
|
-
const output = renderEvalMarkdown(parseEvalReport(manifest));
|
|
84
|
-
assert.match(output, /Input tokens \| 5257320 \| 3890644 \| -26.0%/);
|
|
85
|
-
assert.match(output, /Uncached input tokens.*\+6.5%/);
|
|
86
|
-
assert.match(output, /Output tokens.*\+5.4%/);
|
|
87
|
-
assert.match(output, /Elapsed seconds.*\+4.5%/);
|
|
88
|
-
assert.match(output, /Elapsed seconds.*\+17.5%/);
|
|
89
|
-
assert.match(output, /15\/0\/0 \/ 14\/0\/1/);
|
|
90
|
-
delete manifest.overall.costs;
|
|
91
|
-
assert.equal(JSON.stringify(manifest.overall), originalQuality, 'descriptive accounting leaves quality untouched');
|
|
92
|
-
});
|