skillfit 0.12.0 → 0.13.1
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/first-real-eval.md +12 -10
- package/docs/growth-roadmap-2026-10.md +17 -18
- package/docs/package-contents.md +80 -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 +74 -0
- package/docs/plans/2026-10-21-npm-0.13.1-release.md +38 -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-archive-replays.json +266 -0
- package/docs/releases/0.13.0-archive-restoration.json +168 -0
- package/docs/releases/0.13.0-attestation-check.json +22 -0
- package/docs/releases/0.13.0-attestations.json +147 -0
- package/docs/releases/0.13.0-ci-registry-install.json +60 -0
- package/docs/releases/0.13.0-feature-smoke.json +41 -0
- package/docs/releases/0.13.0-feature-smoke.mjs +114 -0
- package/docs/releases/0.13.0-foundations-smoke.json +1576 -0
- package/docs/releases/0.13.0-local-registry-install.json +40 -0
- package/docs/releases/0.13.0-preparation.json +102 -0
- package/docs/releases/0.13.0-preview-review.json +16 -0
- package/docs/releases/0.13.0-registry-metadata.json +92 -0
- package/docs/releases/0.13.0-signatures.txt +12 -0
- package/docs/releases/0.13.0-verification.json +136 -0
- package/docs/releases/0.13.0.md +112 -0
- package/docs/releases/0.13.1-feature-smoke.mjs +116 -0
- package/docs/releases/0.13.1-preparation-failure-1.json +25 -0
- package/docs/releases/0.13.1-preparation.json +149 -0
- package/docs/releases/0.13.1.md +62 -0
- package/docs/releases/archive-delivery-smoke.mjs +37 -0
- package/docs/releases/release-docs-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/skills/skillfit/SKILL.md +20 -6
- 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
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { test } from 'node:test';
|
|
7
|
-
import { runEval } from '../commands/eval.js';
|
|
8
|
-
import { parseEvalReport, renderEvalMarkdown } from '../commands/eval-report.js';
|
|
9
|
-
import { loadBench } from './bench.js';
|
|
10
|
-
import { collectInstalledSkillTarget } from './installed-skill.js';
|
|
11
|
-
import { runExperiment } from './runner.js';
|
|
12
|
-
function setup(t) {
|
|
13
|
-
const root = mkdtempSync(join(tmpdir(), 'skillfit-revision-'));
|
|
14
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
15
|
-
const previous = join(root, 'old');
|
|
16
|
-
const current = join(root, 'new');
|
|
17
|
-
mkdirSync(join(previous, 'scripts'), { recursive: true });
|
|
18
|
-
writeFileSync(join(previous, 'SKILL.md'), '---\nname: revision-demo\ndescription: Write the local answer.\n---\nUse scripts/answer.cjs.\n');
|
|
19
|
-
writeFileSync(join(previous, '.value'), Buffer.from([1, 0, 255]));
|
|
20
|
-
writeFileSync(join(previous, 'scripts', 'answer.cjs'), "const fs=require('node:fs'),path=require('node:path');fs.writeFileSync('answer.txt',String(fs.readFileSync(path.join(__dirname,'../.value'))[0]));\n");
|
|
21
|
-
cpSync(previous, current, { recursive: true });
|
|
22
|
-
writeFileSync(join(current, '.value'), Buffer.from([2, 0, 255]));
|
|
23
|
-
const bench = join(root, 'bench');
|
|
24
|
-
mkdirSync(join(bench, 'fixture'), { recursive: true });
|
|
25
|
-
writeFileSync(join(bench, 'fixture', 'answer.txt'), 'pending');
|
|
26
|
-
writeFileSync(join(bench, 'prompt.md'), 'Write the answer to answer.txt.');
|
|
27
|
-
for (const [id, expected] of [['fix', '2'], ['regression', '1']]) {
|
|
28
|
-
writeFileSync(join(bench, `${id}.mjs`), `import {readFileSync} from 'node:fs';import {join} from 'node:path';const passed=readFileSync(join(process.argv[2],'answer.txt'),'utf8')===${JSON.stringify(expected)};console.log(JSON.stringify({passed,checks:[{name:'correct-answer',pass:passed}]}));process.exit(passed?0:1);\n`);
|
|
29
|
-
}
|
|
30
|
-
writeFileSync(join(bench, 'bench.json'), JSON.stringify({ schemaVersion: 1, name: 'independent-outcomes', tasks: ['fix', 'regression'].map(id => ({ id, fixture: 'fixture', prompt: 'prompt.md', verifier: `node ${id}.mjs`, verifierKind: 'command' })) }));
|
|
31
|
-
const runsRoot = join(root, 'runs');
|
|
32
|
-
const options = { skillPath: current, baselineSkillPath: previous, bench, mode: 'installed',
|
|
33
|
-
skillInstallDir: 'project-skills', dryRun: false, yes: true, trials: 1, runsRoot, runGroup: 'versions',
|
|
34
|
-
judgeExecutor: null, log: () => { } };
|
|
35
|
-
return { root, previous, current, bench, runsRoot, options };
|
|
36
|
-
}
|
|
37
|
-
function resourceExecutor(prompts = []) {
|
|
38
|
-
return { describe: () => ({ kind: 'mock', model: 'offline-revision-probe' }), run: async (prompt, workdir) => {
|
|
39
|
-
prompts.push(prompt);
|
|
40
|
-
const helper = join(workdir, 'project-skills', 'revision-demo', 'scripts', 'answer.cjs');
|
|
41
|
-
const result = spawnSync(process.execPath, [helper], { cwd: workdir, encoding: 'utf8' });
|
|
42
|
-
assert.equal(result.status, 0, result.stderr);
|
|
43
|
-
return { output: 'done', skillTriggered: true, tokens: { input: 10, output: 2 } };
|
|
44
|
-
} };
|
|
45
|
-
}
|
|
46
|
-
test('installed revision comparison runs both complete versions and exposes gains and regressions', async (t) => {
|
|
47
|
-
const { previous, current, runsRoot, options } = setup(t);
|
|
48
|
-
const oldTarget = collectInstalledSkillTarget(previous);
|
|
49
|
-
const newTarget = collectInstalledSkillTarget(current);
|
|
50
|
-
const prompts = [];
|
|
51
|
-
const manifest = await runEval({ ...options, executor: resourceExecutor(prompts) });
|
|
52
|
-
assert.equal(manifest.baselineTarget?.bundleSha256, oldTarget.sha256);
|
|
53
|
-
assert.equal(manifest.target.bundleSha256, newTarget.sha256);
|
|
54
|
-
assert.deepEqual(manifest.baselineTarget?.files, oldTarget.files);
|
|
55
|
-
assert.equal(manifest.tasks[0]?.deltaPassRate, 1);
|
|
56
|
-
assert.equal(manifest.tasks[1]?.deltaPassRate, -1);
|
|
57
|
-
assert.equal(manifest.tasks[0]?.facets[0]?.treatmentPassRate, 1);
|
|
58
|
-
assert.equal(manifest.tasks[1]?.facets[0]?.treatmentPassRate, 0);
|
|
59
|
-
assert.deepEqual(manifest.overall.stats.discordant, { improved: 1, regressed: 1 });
|
|
60
|
-
assert.equal(manifest.overall.verdict, 'inconclusive');
|
|
61
|
-
assert.equal(manifest.experiment?.callsFinished, 4);
|
|
62
|
-
assert.equal(manifest.experiment?.status, 'completed');
|
|
63
|
-
assert.equal(prompts.length, 4);
|
|
64
|
-
assert.equal(new Set(prompts).size, 1, 'natural prompts must be identical across versions');
|
|
65
|
-
assert.ok(!prompts[0]?.includes('Use scripts/answer.cjs'));
|
|
66
|
-
for (const [condition, target, value] of [['baseline', oldTarget, 1], ['treatment', newTarget, 2]]) {
|
|
67
|
-
const dir = join(runsRoot, options.runGroup, 'fix', condition, 'trial-1');
|
|
68
|
-
assert.deepEqual(readFileSync(join(dir, 'project-skills', 'revision-demo', '.value')), Buffer.from([value, 0, 255]));
|
|
69
|
-
const receipt = JSON.parse(readFileSync(join(dir, '_result.json'), 'utf8'));
|
|
70
|
-
assert.equal(receipt.target.bundleSha256, target.sha256);
|
|
71
|
-
assert.equal(receipt.target.applied, true);
|
|
72
|
-
assert.equal(receipt.skillTriggered, true);
|
|
73
|
-
}
|
|
74
|
-
const plan = JSON.parse(readFileSync(join(runsRoot, options.runGroup, '_plan.json'), 'utf8'));
|
|
75
|
-
assert.ok(plan.inputs.some((input) => input.label === 'baseline Skill' && input.root === oldTarget.sourceDir));
|
|
76
|
-
assert.equal(plan.details.baselineTarget.bundleSha256, oldTarget.sha256);
|
|
77
|
-
const report = renderEvalMarkdown(parseEvalReport(manifest));
|
|
78
|
-
assert.ok(report.includes(oldTarget.sha256) && report.includes(newTarget.sha256));
|
|
79
|
-
assert.match(report, /complete Skill installed in both conditions/);
|
|
80
|
-
assert.match(report, /not against no Skill/);
|
|
81
|
-
const cliReport = renderEvalMarkdown(parseEvalReport({ ...manifest, executor: { kind: 'cli', model: 'offline-report-fixture' } }));
|
|
82
|
-
assert.match(cliReport, /revision effects, not installation benefit/);
|
|
83
|
-
assert.match(cliReport, /Observed task regressions: regression/);
|
|
84
|
-
assert.ok(!report.includes('installed only in treatment'));
|
|
85
|
-
assert.match(report, /Synthetic harness run/);
|
|
86
|
-
assert.deepEqual(readFileSync(join(previous, '.value')), Buffer.from([1, 0, 255]));
|
|
87
|
-
assert.deepEqual(readFileSync(join(current, '.value')), Buffer.from([2, 0, 255]));
|
|
88
|
-
});
|
|
89
|
-
test('revision dry run prints both fingerprints and the unchanged paired budget without writes', async (t) => {
|
|
90
|
-
const { previous, current, runsRoot, options } = setup(t);
|
|
91
|
-
const lines = [];
|
|
92
|
-
const executor = { describe: () => ({ kind: 'mock', model: 'offline' }), run: async () => { throw new Error('must not run'); } };
|
|
93
|
-
const result = await runEval({ ...options, dryRun: true, executor, maxCalls: 4, log: line => lines.push(line) });
|
|
94
|
-
assert.equal(result, null);
|
|
95
|
-
const plan = lines.join('\n');
|
|
96
|
-
assert.ok(plan.includes(collectInstalledSkillTarget(previous).sha256.slice(0, 12)));
|
|
97
|
-
assert.ok(plan.includes(collectInstalledSkillTarget(current).sha256.slice(0, 12)));
|
|
98
|
-
assert.match(plan, /previous Skill in baseline vs target Skill in treatment/);
|
|
99
|
-
assert.match(plan, /installed in both conditions/);
|
|
100
|
-
assert.match(plan, /4 planned; ceiling 4/);
|
|
101
|
-
assert.equal(existsSync(runsRoot), false);
|
|
102
|
-
});
|
|
103
|
-
test('invalid revision modes, identities, inputs and budgets fail before calls or writes', async (t) => {
|
|
104
|
-
const { previous, current, runsRoot, options } = setup(t);
|
|
105
|
-
let calls = 0;
|
|
106
|
-
const executor = { describe: () => ({ kind: 'mock', model: 'offline' }), run: async () => { calls++; return { output: 'done' }; } };
|
|
107
|
-
for (const dryRun of [true, false]) {
|
|
108
|
-
for (const mode of ['inject', 'trigger']) {
|
|
109
|
-
await assert.rejects(runEval({ ...options, mode, dryRun, executor }), /requires --mode installed/);
|
|
110
|
-
}
|
|
111
|
-
await assert.rejects(runEval({ ...options, baselineSkillPath: current, dryRun, executor }), /identical complete-resource/);
|
|
112
|
-
await assert.rejects(runEval({ ...options, inputMode: 'snapshot', dryRun, executor }), /requires workspace/);
|
|
113
|
-
await assert.rejects(runEval({ ...options, maxCalls: 3, dryRun, executor }), /exceeding --max-calls/);
|
|
114
|
-
writeFileSync(join(previous, 'SKILL.md'), '---\nname: different-skill\ndescription: Different identity.\n---\n');
|
|
115
|
-
await assert.rejects(runEval({ ...options, dryRun, executor }), /same SKILL.md frontmatter name/);
|
|
116
|
-
cpSync(join(current, 'SKILL.md'), join(previous, 'SKILL.md'));
|
|
117
|
-
}
|
|
118
|
-
assert.equal(calls, 0);
|
|
119
|
-
assert.equal(existsSync(runsRoot), false);
|
|
120
|
-
});
|
|
121
|
-
test('baseline source drift after a call stops the session and keeps the receipt ungraded', async (t) => {
|
|
122
|
-
const { previous, runsRoot, options } = setup(t);
|
|
123
|
-
let calls = 0;
|
|
124
|
-
const executor = { describe: () => ({ kind: 'mock', model: 'offline' }), run: async () => {
|
|
125
|
-
calls++;
|
|
126
|
-
writeFileSync(join(previous, '.value'), Buffer.from([3]));
|
|
127
|
-
return { output: 'done' };
|
|
128
|
-
} };
|
|
129
|
-
await assert.rejects(runEval({ ...options, executor }), /changed after planning/);
|
|
130
|
-
assert.equal(calls, 1);
|
|
131
|
-
const group = join(runsRoot, options.runGroup);
|
|
132
|
-
const receipt = JSON.parse(readFileSync(join(group, 'fix', 'baseline', 'trial-1', '_result.json'), 'utf8'));
|
|
133
|
-
assert.match(receipt.error, /Frozen baseline Skill input changed/);
|
|
134
|
-
assert.equal(receipt.verifierExitCode, null);
|
|
135
|
-
const session = JSON.parse(readFileSync(join(group, '_session.json'), 'utf8'));
|
|
136
|
-
assert.equal(session.status, 'stopped');
|
|
137
|
-
assert.equal(existsSync(join(group, 'manifest.json')), false);
|
|
138
|
-
});
|
|
139
|
-
test('programmatic revision plans reject injection and mismatched names before workspace creation', async (t) => {
|
|
140
|
-
const { previous, current, bench, runsRoot } = setup(t);
|
|
141
|
-
const target = collectInstalledSkillTarget(current);
|
|
142
|
-
const baselineTarget = collectInstalledSkillTarget(previous);
|
|
143
|
-
const plan = { bench: loadBench(bench), target, baselineTarget, executor: resourceExecutor(), trials: 1, runsRoot, runGroup: 'blocked' };
|
|
144
|
-
await assert.rejects(runExperiment(plan), /requires installed delivery/);
|
|
145
|
-
await assert.rejects(runExperiment({ ...plan, inputMode: 'workspace', skillInstallDir: 'project-skills',
|
|
146
|
-
baselineTarget: { ...baselineTarget, name: 'different' } }), /same SKILL.md frontmatter name/);
|
|
147
|
-
assert.equal(existsSync(runsRoot), false);
|
|
148
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { test } from 'node:test';
|
|
3
|
-
import { MIN_DISCORDANT_FOR_SIGNIFICANCE, mcnemarExactP, pairedDeltaBootstrapCI, pairedScoreBootstrapCI, wilson95, } from './stats.js';
|
|
4
|
-
test('mcnemarExactP matches reference values', () => {
|
|
5
|
-
assert.equal(mcnemarExactP(6, 0), 0.03125);
|
|
6
|
-
assert.equal(mcnemarExactP(5, 0), 0.0625);
|
|
7
|
-
assert.equal(mcnemarExactP(9, 0), 0.00390625);
|
|
8
|
-
assert.equal(mcnemarExactP(3, 3), 1);
|
|
9
|
-
assert.equal(mcnemarExactP(0, 0), 1);
|
|
10
|
-
});
|
|
11
|
-
test('mcnemarExactP never increases as discordance grows more one-sided', () => {
|
|
12
|
-
let previous = 1;
|
|
13
|
-
for (let k = 1; k <= 15; k++) {
|
|
14
|
-
const p = mcnemarExactP(k, 0);
|
|
15
|
-
assert.ok(p <= previous, `p(${k},0)=${p} exceeds p(${k - 1},0)=${previous}`);
|
|
16
|
-
assert.equal(mcnemarExactP(0, k), p);
|
|
17
|
-
previous = p;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
test('MIN_DISCORDANT_FOR_SIGNIFICANCE is the first discordant count reaching p < 0.05', () => {
|
|
21
|
-
assert.equal(MIN_DISCORDANT_FOR_SIGNIFICANCE, 6);
|
|
22
|
-
assert.ok(mcnemarExactP(MIN_DISCORDANT_FOR_SIGNIFICANCE, 0) < 0.05);
|
|
23
|
-
assert.ok(mcnemarExactP(MIN_DISCORDANT_FOR_SIGNIFICANCE - 1, 0) >= 0.05);
|
|
24
|
-
});
|
|
25
|
-
function task(baseline, treatment) {
|
|
26
|
-
return { baseline, treatment };
|
|
27
|
-
}
|
|
28
|
-
function scoreTask(baseline, treatment) {
|
|
29
|
-
return { baseline, treatment };
|
|
30
|
-
}
|
|
31
|
-
const SAMPLE_TASKS = [
|
|
32
|
-
task([true, false, true, false, true], [true, true, true, false, true]),
|
|
33
|
-
task([false, false, true, false, false], [true, false, true, true, false]),
|
|
34
|
-
task([true, true, false, true, false], [true, true, true, true, true]),
|
|
35
|
-
task([false, true, false, false, true], [false, true, true, false, true]),
|
|
36
|
-
task([true, false, false, false, false], [true, false, true, false, true]),
|
|
37
|
-
task([false, false, false, true, false], [true, false, false, true, true]),
|
|
38
|
-
task([true, true, true, false, false], [true, true, false, true, true]),
|
|
39
|
-
task([false, false, false, false, false], [false, true, false, false, true]),
|
|
40
|
-
];
|
|
41
|
-
test('pairedDeltaBootstrapCI is deterministic for a fixed seed', () => {
|
|
42
|
-
const first = pairedDeltaBootstrapCI(SAMPLE_TASKS);
|
|
43
|
-
const second = pairedDeltaBootstrapCI(SAMPLE_TASKS);
|
|
44
|
-
assert.deepEqual(first, second);
|
|
45
|
-
});
|
|
46
|
-
test('pairedDeltaBootstrapCI brackets the pooled delta', () => {
|
|
47
|
-
const result = pairedDeltaBootstrapCI(SAMPLE_TASKS, { resamples: 500 });
|
|
48
|
-
assert.ok(result !== null);
|
|
49
|
-
assert.equal(result.resamples, 500);
|
|
50
|
-
assert.equal(result.point, 27 / 40 - 14 / 40);
|
|
51
|
-
assert.ok(result.lo <= result.point);
|
|
52
|
-
assert.ok(result.point <= result.hi);
|
|
53
|
-
});
|
|
54
|
-
test('pairedDeltaBootstrapCI returns a positive lower bound when treatment always wins', () => {
|
|
55
|
-
const tasks = Array.from({ length: 8 }, () => task([false, false, false], [true, true, true]));
|
|
56
|
-
const result = pairedDeltaBootstrapCI(tasks);
|
|
57
|
-
assert.ok(result !== null);
|
|
58
|
-
assert.equal(result.point, 1);
|
|
59
|
-
assert.ok(result.lo > 0);
|
|
60
|
-
});
|
|
61
|
-
test('pairedDeltaBootstrapCI returns null when there are no trials', () => {
|
|
62
|
-
assert.equal(pairedDeltaBootstrapCI([]), null);
|
|
63
|
-
assert.equal(pairedDeltaBootstrapCI([task([], [])]), null);
|
|
64
|
-
});
|
|
65
|
-
test('pairedDeltaBootstrapCI stays finite when some tasks have no graded survivors', () => {
|
|
66
|
-
const graded = task([false, true], [true, true]);
|
|
67
|
-
const empty = task([], []);
|
|
68
|
-
for (let seed = 1; seed <= 40; seed++) {
|
|
69
|
-
const mixed = pairedDeltaBootstrapCI([empty, graded], { seed, resamples: 300 });
|
|
70
|
-
const only = pairedDeltaBootstrapCI([graded], { seed, resamples: 300 });
|
|
71
|
-
assert.ok(mixed);
|
|
72
|
-
assert.ok(only);
|
|
73
|
-
assert.equal(Number.isFinite(mixed.lo) && Number.isFinite(mixed.hi), true);
|
|
74
|
-
assert.equal(mixed.point, only.point);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
test('wilson95 handles empty and saturated arms', () => {
|
|
78
|
-
assert.deepEqual(wilson95(0, 0), { lo: 0, hi: 1 });
|
|
79
|
-
const zero = wilson95(0, 3);
|
|
80
|
-
assert.equal(zero.lo, 0);
|
|
81
|
-
assert.ok(zero.hi > 0.4 && zero.hi < 0.7, `hi=${zero.hi}`);
|
|
82
|
-
const full = wilson95(3, 3);
|
|
83
|
-
assert.ok(full.lo > 0.3 && full.lo < 0.6, `lo=${full.lo}`);
|
|
84
|
-
assert.equal(full.hi, 1);
|
|
85
|
-
});
|
|
86
|
-
const SAMPLE_SCORE_TASKS = [
|
|
87
|
-
scoreTask([0.5, 0.75], [1, 1]),
|
|
88
|
-
scoreTask([0.25, 0.5], [0.75, 1]),
|
|
89
|
-
scoreTask([1, 0.5], [1, 1]),
|
|
90
|
-
scoreTask([0, 0.25], [0.5, 0.75]),
|
|
91
|
-
];
|
|
92
|
-
test('pairedScoreBootstrapCI is deterministic for a fixed seed', () => {
|
|
93
|
-
const first = pairedScoreBootstrapCI(SAMPLE_SCORE_TASKS);
|
|
94
|
-
const second = pairedScoreBootstrapCI(SAMPLE_SCORE_TASKS);
|
|
95
|
-
assert.deepEqual(first, second);
|
|
96
|
-
});
|
|
97
|
-
test('pairedScoreBootstrapCI brackets the pooled score delta', () => {
|
|
98
|
-
const result = pairedScoreBootstrapCI(SAMPLE_SCORE_TASKS, { resamples: 500 });
|
|
99
|
-
assert.ok(result !== null);
|
|
100
|
-
assert.equal(result.resamples, 500);
|
|
101
|
-
const baselineMean = (0.5 + 0.75 + 0.25 + 0.5 + 1 + 0.5 + 0 + 0.25) / 8;
|
|
102
|
-
const treatmentMean = (1 + 1 + 0.75 + 1 + 1 + 1 + 0.5 + 0.75) / 8;
|
|
103
|
-
assert.equal(result.point, treatmentMean - baselineMean);
|
|
104
|
-
assert.ok(result.lo <= result.point);
|
|
105
|
-
assert.ok(result.point <= result.hi);
|
|
106
|
-
});
|
|
107
|
-
test('pairedScoreBootstrapCI returns a positive lower bound when treatment always outscores', () => {
|
|
108
|
-
const tasks = Array.from({ length: 8 }, () => scoreTask([0.2, 0.4], [0.8, 1]));
|
|
109
|
-
const result = pairedScoreBootstrapCI(tasks);
|
|
110
|
-
assert.ok(result !== null);
|
|
111
|
-
assert.ok(result.point > 0);
|
|
112
|
-
assert.ok(result.lo > 0);
|
|
113
|
-
});
|
|
114
|
-
test('pairedScoreBootstrapCI matches pairedDeltaBootstrapCI on 0/1 inputs', () => {
|
|
115
|
-
const asScores = SAMPLE_TASKS.map((t) => ({
|
|
116
|
-
baseline: t.baseline.map((pass) => (pass ? 1 : 0)),
|
|
117
|
-
treatment: t.treatment.map((pass) => (pass ? 1 : 0)),
|
|
118
|
-
}));
|
|
119
|
-
assert.deepEqual(pairedScoreBootstrapCI(asScores), pairedDeltaBootstrapCI(SAMPLE_TASKS));
|
|
120
|
-
});
|
|
121
|
-
test('pairedScoreBootstrapCI returns null when there are no scored trials', () => {
|
|
122
|
-
assert.equal(pairedScoreBootstrapCI([]), null);
|
|
123
|
-
assert.equal(pairedScoreBootstrapCI([scoreTask([], [])]), null);
|
|
124
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { mkdtempSync, mkdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { test } from 'node:test';
|
|
6
|
-
import { collectEvaluationTarget, EXPERIMENT_FILE } from './target.js';
|
|
7
|
-
function tmp(t) {
|
|
8
|
-
const dir = mkdtempSync(join(tmpdir(), 'skillfit-target-'));
|
|
9
|
-
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
10
|
-
return dir;
|
|
11
|
-
}
|
|
12
|
-
test('collectEvaluationTarget keeps ordinary directories as skill targets', (t) => {
|
|
13
|
-
const dir = tmp(t);
|
|
14
|
-
writeFileSync(join(dir, 'SKILL.md'), '# demo\n');
|
|
15
|
-
const target = collectEvaluationTarget(dir);
|
|
16
|
-
assert.equal(target.kind, 'skill');
|
|
17
|
-
assert.match(target.payload ?? '', /<skill/);
|
|
18
|
-
assert.deepEqual(target.overlays, {});
|
|
19
|
-
});
|
|
20
|
-
test('collectEvaluationTarget loads a rules or MCP workspace experiment', (t) => {
|
|
21
|
-
const dir = tmp(t);
|
|
22
|
-
mkdirSync(join(dir, 'baseline', '.codex'), { recursive: true });
|
|
23
|
-
mkdirSync(join(dir, 'treatment', '.codex'), { recursive: true });
|
|
24
|
-
writeFileSync(join(dir, 'baseline', '.codex', 'config.toml'), '# no server\n');
|
|
25
|
-
writeFileSync(join(dir, 'treatment', '.codex', 'config.toml'), '[mcp_servers.context7]\n');
|
|
26
|
-
writeFileSync(join(dir, EXPERIMENT_FILE), JSON.stringify({ schemaVersion: 1, name: 'context7', kind: 'mcp', baseline: 'baseline', treatment: 'treatment' }));
|
|
27
|
-
const target = collectEvaluationTarget(dir);
|
|
28
|
-
assert.equal(target.kind, 'mcp');
|
|
29
|
-
assert.equal(target.name, 'context7');
|
|
30
|
-
assert.equal(target.payload, null);
|
|
31
|
-
assert.ok(target.overlays.baseline?.endsWith('baseline'));
|
|
32
|
-
assert.ok(target.overlays.treatment?.endsWith('treatment'));
|
|
33
|
-
assert.deepEqual(target.files, [
|
|
34
|
-
'baseline/.codex/config.toml',
|
|
35
|
-
'skillfit-experiment.json',
|
|
36
|
-
'treatment/.codex/config.toml',
|
|
37
|
-
]);
|
|
38
|
-
assert.equal(target.sha256.length, 64);
|
|
39
|
-
});
|
|
40
|
-
test('collectEvaluationTarget rejects traversal and empty treatment overlays', (t) => {
|
|
41
|
-
const dir = tmp(t);
|
|
42
|
-
writeFileSync(join(dir, EXPERIMENT_FILE), JSON.stringify({ schemaVersion: 1, kind: 'mcp', treatment: '..' }));
|
|
43
|
-
assert.throws(() => collectEvaluationTarget(dir), /escapes the experiment directory/);
|
|
44
|
-
mkdirSync(join(dir, 'empty'));
|
|
45
|
-
writeFileSync(join(dir, EXPERIMENT_FILE), JSON.stringify({ schemaVersion: 1, kind: 'rules', treatment: 'empty' }));
|
|
46
|
-
assert.throws(() => collectEvaluationTarget(dir), /must contain at least one file/);
|
|
47
|
-
});
|
|
48
|
-
test('collectEvaluationTarget rejects overlays that leave the experiment through a symlink', (t) => {
|
|
49
|
-
const dir = tmp(t);
|
|
50
|
-
const outside = tmp(t);
|
|
51
|
-
writeFileSync(join(outside, 'AGENTS.md'), '# outside\n');
|
|
52
|
-
symlinkSync(outside, join(dir, 'treatment'), 'junction');
|
|
53
|
-
writeFileSync(join(dir, EXPERIMENT_FILE), JSON.stringify({ schemaVersion: 1, kind: 'rules', treatment: 'treatment' }));
|
|
54
|
-
assert.throws(() => collectEvaluationTarget(dir), /escapes or aliases the experiment directory/);
|
|
55
|
-
});
|
|
56
|
-
test('collectEvaluationTarget rejects an overlay that aliases the experiment root', (t) => {
|
|
57
|
-
const dir = tmp(t);
|
|
58
|
-
writeFileSync(join(dir, EXPERIMENT_FILE), JSON.stringify({ schemaVersion: 1, kind: 'rules', treatment: '.' }));
|
|
59
|
-
assert.throws(() => collectEvaluationTarget(dir), /escapes or aliases the experiment directory/);
|
|
60
|
-
});
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { test } from 'node:test';
|
|
6
|
-
import { loadBench } from './bench.js';
|
|
7
|
-
import { collectInstalledSkillFingerprint, collectSkillBundle } from './bundle.js';
|
|
8
|
-
import { MockExecutor } from './executors/mock.js';
|
|
9
|
-
import { renderTriggerSummary, runTriggerExperiment, triggerMetrics } from './trigger.js';
|
|
10
|
-
function tmp(t, prefix) {
|
|
11
|
-
const dir = mkdtempSync(join(tmpdir(), prefix));
|
|
12
|
-
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
13
|
-
return dir;
|
|
14
|
-
}
|
|
15
|
-
const PASS_VERIFIER = `import fs from 'node:fs';
|
|
16
|
-
const out = fs.readFileSync(process.argv[2] + '/_output.md', 'utf8');
|
|
17
|
-
process.exit(out.includes('done') ? 0 : 1);
|
|
18
|
-
`;
|
|
19
|
-
function makeTriggerBench(t) {
|
|
20
|
-
const dir = tmp(t, 'skillfit-trigger-bench-');
|
|
21
|
-
for (const id of ['pos-task', 'neg-task']) {
|
|
22
|
-
mkdirSync(join(dir, 'fixtures', id), { recursive: true });
|
|
23
|
-
writeFileSync(join(dir, 'fixtures', id, 'index.txt'), 'x\n');
|
|
24
|
-
}
|
|
25
|
-
mkdirSync(join(dir, 'prompts'), { recursive: true });
|
|
26
|
-
writeFileSync(join(dir, 'prompts', 'pos.md'), 'Review this code and finish with done.\n');
|
|
27
|
-
writeFileSync(join(dir, 'prompts', 'pos.trigger.md'), 'TRIGGER variant: Review this code on disk and finish with done.\n');
|
|
28
|
-
writeFileSync(join(dir, 'prompts', 'neg.md'), 'Explain this library and finish with done.\n');
|
|
29
|
-
mkdirSync(join(dir, 'verifiers'), { recursive: true });
|
|
30
|
-
writeFileSync(join(dir, 'verifiers', 'pass.mjs'), PASS_VERIFIER);
|
|
31
|
-
writeFileSync(join(dir, 'bench.json'), JSON.stringify({
|
|
32
|
-
schemaVersion: 1,
|
|
33
|
-
name: 'trigger-bench',
|
|
34
|
-
tasks: [
|
|
35
|
-
{ id: 'pos-task', fixture: 'fixtures/pos-task', prompt: 'prompts/pos.md', promptTrigger: 'prompts/pos.trigger.md', verifier: 'node verifiers/pass.mjs', shouldTrigger: true },
|
|
36
|
-
{ id: 'neg-task', fixture: 'fixtures/neg-task', prompt: 'prompts/neg.md', verifier: 'node verifiers/pass.mjs', shouldTrigger: false },
|
|
37
|
-
],
|
|
38
|
-
}));
|
|
39
|
-
return dir;
|
|
40
|
-
}
|
|
41
|
-
function makeSkill(t) {
|
|
42
|
-
const dir = join(tmp(t, 'skillfit-trigger-skill-'), 'test-skill');
|
|
43
|
-
mkdirSync(dir, { recursive: true });
|
|
44
|
-
writeFileSync(join(dir, 'SKILL.md'), '# test skill\n');
|
|
45
|
-
return dir;
|
|
46
|
-
}
|
|
47
|
-
function stubExecutor(decide) {
|
|
48
|
-
return {
|
|
49
|
-
describe: () => ({ kind: 'stub', model: 'stub' }),
|
|
50
|
-
run: (prompt) => Promise.resolve({ tokens: { input: 10, output: 5 }, ...decide(prompt) }),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function makePlan(t, executor, overrides = {}) {
|
|
54
|
-
const runsRoot = join(tmp(t, 'skillfit-trigger-runs-'), 'runs');
|
|
55
|
-
return {
|
|
56
|
-
bench: loadBench(makeTriggerBench(t)),
|
|
57
|
-
skill: collectSkillBundle(makeSkill(t)),
|
|
58
|
-
executor,
|
|
59
|
-
trials: 3,
|
|
60
|
-
runsRoot,
|
|
61
|
-
runGroup: 'trigger-group',
|
|
62
|
-
skillInstallDir: '.test-skills',
|
|
63
|
-
log: () => { },
|
|
64
|
-
...overrides,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
test('trigger verifier exceptions are errors excluded from rates while their output and tokens stay in receipts', async (t) => {
|
|
68
|
-
const plan = makePlan(t, stubExecutor(() => ({ output: 'done', skillTriggered: true })), { trials: 1 });
|
|
69
|
-
writeFileSync(join(plan.bench.dir, 'verifiers/pass.mjs'), "throw new Error('trigger grader unavailable');");
|
|
70
|
-
plan.bench = loadBench(plan.bench.dir);
|
|
71
|
-
const result = await runTriggerExperiment(plan);
|
|
72
|
-
assert.equal(result.metrics.positives.runs, 0);
|
|
73
|
-
assert.equal(result.metrics.negatives.runs, 0);
|
|
74
|
-
assert.ok(result.tasks.every(task => task.errors === 1 && task.runs === 0));
|
|
75
|
-
const receipt = JSON.parse(readFileSync(join(plan.runsRoot, plan.runGroup, 'pos-task/installed/trial-1/_result.json'), 'utf8'));
|
|
76
|
-
assert.match(receipt.error, /VERIFIER_RUNTIME_ERROR/);
|
|
77
|
-
assert.deepEqual(receipt.tokens, { input: 10, output: 5 });
|
|
78
|
-
});
|
|
79
|
-
test('runTriggerExperiment measures recall and false-trigger rate', async (t) => {
|
|
80
|
-
const executor = stubExecutor((prompt) => ({
|
|
81
|
-
output: 'done',
|
|
82
|
-
skillTriggered: prompt.includes('Review this code'),
|
|
83
|
-
rawOutput: '{"role":"assistant"}\n',
|
|
84
|
-
}));
|
|
85
|
-
const plan = makePlan(t, executor);
|
|
86
|
-
const manifest = await runTriggerExperiment(plan);
|
|
87
|
-
assert.equal(manifest.mode, 'trigger');
|
|
88
|
-
assert.equal(manifest.tasks.length, 2);
|
|
89
|
-
const pos = manifest.tasks.find((task) => task.id === 'pos-task');
|
|
90
|
-
const neg = manifest.tasks.find((task) => task.id === 'neg-task');
|
|
91
|
-
assert.deepEqual({ fired: pos?.fired, runs: pos?.runs, passes: pos?.passes }, { fired: 3, runs: 3, passes: 3 });
|
|
92
|
-
assert.deepEqual({ fired: neg?.fired, runs: neg?.runs }, { fired: 0, runs: 3 });
|
|
93
|
-
assert.equal(manifest.metrics.recall, 1);
|
|
94
|
-
assert.equal(manifest.metrics.falseTriggerRate, 0);
|
|
95
|
-
assert.equal(manifest.metrics.precision, 1);
|
|
96
|
-
assert.equal(manifest.metrics.f1, 1);
|
|
97
|
-
assert.ok(manifest.metrics.recallCi95);
|
|
98
|
-
const trialDir = join(plan.runsRoot, 'trigger-group', 'pos-task', 'installed', 'trial-1');
|
|
99
|
-
assert.ok(existsSync(join(trialDir, '.test-skills', 'test-skill', 'SKILL.md')), 'skill installed');
|
|
100
|
-
assert.ok(existsSync(join(trialDir, '_transcript.jsonl')), 'raw transcript saved');
|
|
101
|
-
const prompt = readFileSync(join(trialDir, '_prompt.txt'), 'utf8');
|
|
102
|
-
assert.ok(!prompt.includes('<skill name='), 'skill is not injected into the prompt');
|
|
103
|
-
assert.ok(!prompt.includes('Experiment isolation rules'), 'no no-tools isolation block');
|
|
104
|
-
assert.ok(!prompt.includes('Repository snapshot'), 'trigger mode never inlines the repository snapshot');
|
|
105
|
-
assert.ok(prompt.includes('TRIGGER variant'), 'promptTrigger file is used when present');
|
|
106
|
-
assert.ok(existsSync(join(plan.runsRoot, 'trigger-group', 'manifest.json')));
|
|
107
|
-
});
|
|
108
|
-
test('trigger manifests and receipts identify all installed scripts and binary resources', async (t) => {
|
|
109
|
-
const skillDir = makeSkill(t);
|
|
110
|
-
mkdirSync(join(skillDir, 'scripts'));
|
|
111
|
-
writeFileSync(join(skillDir, 'scripts', 'helper.sh'), 'printf first\n');
|
|
112
|
-
writeFileSync(join(skillDir, 'asset.bin'), Buffer.from([0, 255]));
|
|
113
|
-
const executor = stubExecutor(() => ({ output: 'done', skillTriggered: true }));
|
|
114
|
-
const plan = makePlan(t, executor, { skill: collectSkillBundle(skillDir), trials: 1 });
|
|
115
|
-
const first = await runTriggerExperiment(plan);
|
|
116
|
-
assert.deepEqual(first.skill.installedFiles, ['SKILL.md', 'asset.bin', 'scripts/helper.sh']);
|
|
117
|
-
const installedDir = join(plan.runsRoot, plan.runGroup, 'pos-task', 'installed', 'trial-1', '.test-skills', 'test-skill');
|
|
118
|
-
assert.equal(first.skill.installedSha256, collectInstalledSkillFingerprint(installedDir).sha256);
|
|
119
|
-
const receipt = JSON.parse(readFileSync(join(installedDir, '..', '..', '_result.json'), 'utf8'));
|
|
120
|
-
assert.equal(receipt.skillInstalledSha256, first.skill.installedSha256);
|
|
121
|
-
assert.deepEqual(receipt.skillInstalledFiles, first.skill.installedFiles);
|
|
122
|
-
writeFileSync(join(skillDir, 'scripts', 'helper.sh'), 'printf second\n');
|
|
123
|
-
const second = await runTriggerExperiment({ ...plan, skill: collectSkillBundle(skillDir), runGroup: 'second' });
|
|
124
|
-
assert.equal(first.skill.bundleSha256, second.skill.bundleSha256);
|
|
125
|
-
assert.notEqual(first.skill.installedSha256, second.skill.installedSha256);
|
|
126
|
-
assert.match(renderTriggerSummary(second, 'manifest.json'), /Installed: sha256 .*3 files \(before execution\)/);
|
|
127
|
-
const legacy = { ...first, skill: { name: first.skill.name, sourceDir: first.skill.sourceDir, bundleSha256: first.skill.bundleSha256, files: first.skill.files } };
|
|
128
|
-
assert.match(renderTriggerSummary(legacy, 'manifest.json'), /Installed: not recorded \(legacy manifest/);
|
|
129
|
-
});
|
|
130
|
-
test('trigger rejects changed resources before running another trial under the same fingerprint', async (t) => {
|
|
131
|
-
const skillDir = makeSkill(t);
|
|
132
|
-
writeFileSync(join(skillDir, 'helper.sh'), 'first\n');
|
|
133
|
-
let calls = 0;
|
|
134
|
-
const executor = stubExecutor(() => {
|
|
135
|
-
calls++;
|
|
136
|
-
writeFileSync(join(skillDir, 'helper.sh'), 'changed\n');
|
|
137
|
-
return { output: 'done', skillTriggered: true };
|
|
138
|
-
});
|
|
139
|
-
const plan = makePlan(t, executor, { skill: collectSkillBundle(skillDir), trials: 2 });
|
|
140
|
-
await assert.rejects(runTriggerExperiment(plan), /Installed Skill content does not match the planned fingerprint/);
|
|
141
|
-
assert.equal(calls, 1);
|
|
142
|
-
});
|
|
143
|
-
test('trigger rejects nested symbolic links before creating a run or starting an executor', async (t) => {
|
|
144
|
-
const skillDir = makeSkill(t);
|
|
145
|
-
const outside = tmp(t, 'skillfit-trigger-link-target-');
|
|
146
|
-
writeFileSync(join(outside, 'helper.sh'), 'outside resource\n');
|
|
147
|
-
// Directory junctions require no symlink privilege on Windows CI.
|
|
148
|
-
symlinkSync(outside, join(skillDir, 'linked'), 'junction');
|
|
149
|
-
let calls = 0;
|
|
150
|
-
const executor = stubExecutor(() => { calls++; return { output: 'done' }; });
|
|
151
|
-
const plan = makePlan(t, executor, { skill: collectSkillBundle(skillDir), trials: 1 });
|
|
152
|
-
await assert.rejects(runTriggerExperiment(plan), /Symbolic links are not supported/);
|
|
153
|
-
assert.equal(calls, 0);
|
|
154
|
-
assert.ok(!existsSync(join(plan.runsRoot, plan.runGroup)));
|
|
155
|
-
});
|
|
156
|
-
test('runTriggerExperiment excludes undetectable transcripts from rates', async (t) => {
|
|
157
|
-
let calls = 0;
|
|
158
|
-
const executor = stubExecutor(() => {
|
|
159
|
-
calls++;
|
|
160
|
-
return calls <= 3
|
|
161
|
-
? { output: 'done', skillTriggered: true }
|
|
162
|
-
: { output: 'done' };
|
|
163
|
-
});
|
|
164
|
-
const manifest = await runTriggerExperiment(makePlan(t, executor));
|
|
165
|
-
const neg = manifest.tasks.find((task) => task.id === 'neg-task');
|
|
166
|
-
assert.deepEqual({ fired: neg?.fired, runs: neg?.runs, unknown: neg?.unknown }, { fired: 0, runs: 0, unknown: 3 });
|
|
167
|
-
assert.equal(manifest.metrics.falseTriggerRate, null);
|
|
168
|
-
assert.ok(manifest.warnings.some((w) => w.includes('detection was impossible')));
|
|
169
|
-
});
|
|
170
|
-
test('runTriggerExperiment records executor errors without crashing', async (t) => {
|
|
171
|
-
const executor = {
|
|
172
|
-
describe: () => ({ kind: 'stub', model: 'stub' }),
|
|
173
|
-
run: () => Promise.reject(new Error('agent exploded')),
|
|
174
|
-
};
|
|
175
|
-
const manifest = await runTriggerExperiment(makePlan(t, executor, { trials: 1 }));
|
|
176
|
-
assert.equal(manifest.tasks[0]?.errors, 1);
|
|
177
|
-
assert.equal(manifest.metrics.recall, null);
|
|
178
|
-
assert.ok(manifest.warnings.some((w) => w.includes('executor, verifier, or engagement error')));
|
|
179
|
-
});
|
|
180
|
-
test('runTriggerExperiment warns when the bench has no negative-control tasks', async (t) => {
|
|
181
|
-
const dir = makeTriggerBench(t);
|
|
182
|
-
const benchJson = JSON.parse(readFileSync(join(dir, 'bench.json'), 'utf8'));
|
|
183
|
-
benchJson.tasks = benchJson.tasks.filter((task) => task.id === 'pos-task');
|
|
184
|
-
writeFileSync(join(dir, 'bench.json'), JSON.stringify(benchJson));
|
|
185
|
-
const executor = stubExecutor(() => ({ output: 'done', skillTriggered: true }));
|
|
186
|
-
const plan = makePlan(t, executor);
|
|
187
|
-
const manifest = await runTriggerExperiment({ ...plan, bench: loadBench(dir) });
|
|
188
|
-
assert.ok(manifest.warnings.some((w) => w.includes('false-trigger rate is unmeasurable')));
|
|
189
|
-
});
|
|
190
|
-
test('runTriggerExperiment rejects the mock executor', async (t) => {
|
|
191
|
-
await assert.rejects(() => runTriggerExperiment(makePlan(t, new MockExecutor())), /requires a real CLI executor/);
|
|
192
|
-
});
|
|
193
|
-
test('runTriggerExperiment skips tasks without a shouldTrigger label', async (t) => {
|
|
194
|
-
const dir = makeTriggerBench(t);
|
|
195
|
-
const benchJson = JSON.parse(readFileSync(join(dir, 'bench.json'), 'utf8'));
|
|
196
|
-
benchJson.tasks.push({ id: 'unlabeled', fixture: 'fixtures/pos-task', prompt: 'prompts/pos.md', verifier: 'node verifiers/pass.mjs' });
|
|
197
|
-
writeFileSync(join(dir, 'bench.json'), JSON.stringify(benchJson));
|
|
198
|
-
const executor = stubExecutor(() => ({ output: 'done', skillTriggered: true }));
|
|
199
|
-
const plan = makePlan(t, executor, { trials: 1 });
|
|
200
|
-
const manifest = await runTriggerExperiment({ ...plan, bench: loadBench(dir) });
|
|
201
|
-
assert.equal(manifest.tasks.length, 2);
|
|
202
|
-
assert.ok(!existsSync(join(plan.runsRoot, 'trigger-group', 'unlabeled')));
|
|
203
|
-
});
|
|
204
|
-
test('triggerMetrics is null-safe at zero runs', () => {
|
|
205
|
-
const metrics = triggerMetrics([
|
|
206
|
-
{ id: 'a', shouldTrigger: true, runs: 0, fired: 0, unknown: 2, errors: 0, passes: 0, tokens: null },
|
|
207
|
-
]);
|
|
208
|
-
assert.equal(metrics.recall, null);
|
|
209
|
-
assert.equal(metrics.precision, null);
|
|
210
|
-
assert.equal(metrics.precisionCi95, null);
|
|
211
|
-
assert.equal(metrics.f1, null);
|
|
212
|
-
assert.equal(metrics.falseTriggerRate, null);
|
|
213
|
-
});
|
|
214
|
-
test('triggerMetrics carries a Wilson CI for precision and leaves F1 bare', () => {
|
|
215
|
-
const metrics = triggerMetrics([
|
|
216
|
-
{ id: 'pos', shouldTrigger: true, runs: 10, fired: 8, unknown: 0, errors: 0, passes: 8, tokens: null },
|
|
217
|
-
{ id: 'neg', shouldTrigger: false, runs: 10, fired: 2, unknown: 0, errors: 0, passes: 0, tokens: null },
|
|
218
|
-
]);
|
|
219
|
-
// precision = positives fired / all fired = 8 / (8 + 2)
|
|
220
|
-
assert.equal(metrics.precision, 0.8);
|
|
221
|
-
const ci = metrics.precisionCi95;
|
|
222
|
-
assert.ok(ci, 'precision is a proportion over the fired runs, so it gets an interval');
|
|
223
|
-
assert.ok(ci.lo >= 0 && ci.hi <= 1, `interval must stay in [0,1], got ${ci.lo}-${ci.hi}`);
|
|
224
|
-
assert.ok(ci.lo < 0.8 && 0.8 < ci.hi, `interval must bracket the point estimate, got ${ci.lo}-${ci.hi}`);
|
|
225
|
-
assert.ok(ci.lo > 0.4 && ci.hi < 1, 'a 10-run interval should be wide but not degenerate');
|
|
226
|
-
// F1 is a harmonic mean of two proportions: no closed-form binomial interval exists, so the
|
|
227
|
-
// metric stays bare rather than printing invented precision.
|
|
228
|
-
assert.equal(typeof metrics.f1, 'number');
|
|
229
|
-
assert.ok(!('f1Ci95' in metrics));
|
|
230
|
-
});
|
|
231
|
-
test('triggerClass is recorded only on positive tasks and splits recall', async (t) => {
|
|
232
|
-
const dir = makeTriggerBench(t);
|
|
233
|
-
const benchJson = JSON.parse(readFileSync(join(dir, 'bench.json'), 'utf8'));
|
|
234
|
-
benchJson.tasks[0]['triggerClass'] = 'explicit';
|
|
235
|
-
writeFileSync(join(dir, 'bench.json'), JSON.stringify(benchJson));
|
|
236
|
-
const executor = stubExecutor(() => ({ output: 'done', skillTriggered: true }));
|
|
237
|
-
const manifest = await runTriggerExperiment(makePlan(t, executor, { bench: loadBench(dir), trials: 1 }));
|
|
238
|
-
assert.equal(manifest.metrics.classRecall?.explicit?.fired, 1);
|
|
239
|
-
assert.equal(manifest.metrics.classRecall?.implicit, undefined);
|
|
240
|
-
benchJson.tasks[1]['triggerClass'] = 'explicit';
|
|
241
|
-
writeFileSync(join(dir, 'bench.json'), JSON.stringify(benchJson));
|
|
242
|
-
assert.throws(() => loadBench(dir), /shouldTrigger: true/);
|
|
243
|
-
});
|
|
244
|
-
test('a competing Skill is copied beside the Skill under test and recall is no longer described as alone', async (t) => {
|
|
245
|
-
const other = join(tmp(t, 'skillfit-other-skill-'), 'other-skill');
|
|
246
|
-
mkdirSync(other, { recursive: true });
|
|
247
|
-
writeFileSync(join(other, 'SKILL.md'), '# other\n');
|
|
248
|
-
const pin = collectInstalledSkillFingerprint(other);
|
|
249
|
-
const executor = stubExecutor(() => ({ output: 'done', skillTriggered: false }));
|
|
250
|
-
const plan = makePlan(t, executor, { trials: 1, detection: 'skill-read' });
|
|
251
|
-
const manifest = await runTriggerExperiment({
|
|
252
|
-
...plan,
|
|
253
|
-
competitors: [{ name: 'other-skill', sourceDir: other, sha256: pin.sha256 }],
|
|
254
|
-
});
|
|
255
|
-
assert.equal(manifest.competition?.mode, 'installed');
|
|
256
|
-
assert.equal(readFileSync(join(plan.runsRoot, plan.runGroup, 'pos-task', 'installed', 'trial-1', '.test-skills', 'other-skill', 'SKILL.md'), 'utf8'), '# other\n');
|
|
257
|
-
const summary = renderTriggerSummary(manifest, 'manifest.json');
|
|
258
|
-
assert.match(summary, /other-skill/);
|
|
259
|
-
assert.match(summary, /SKILL.md read, not a Skill-invocation event/);
|
|
260
|
-
assert.ok(!summary.includes('installed alone'));
|
|
261
|
-
});
|