skillfit 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +28 -5
  2. package/README.zh-CN.md +28 -5
  3. package/benches/README.md +6 -2
  4. package/dist/cli.js +28 -16
  5. package/dist/commands/bench-calibration.js +5 -1
  6. package/dist/commands/bench-draft.js +167 -0
  7. package/dist/commands/bench-draft.test.js +168 -0
  8. package/dist/commands/bench-manage.js +5 -4
  9. package/dist/commands/bench-source.js +101 -0
  10. package/dist/commands/bench-source.test.js +84 -0
  11. package/dist/commands/bench.js +165 -103
  12. package/dist/commands/bench.test.js +7 -3
  13. package/dist/commands/eval-agent-preflight.test.js +24 -0
  14. package/dist/commands/eval-api-failure.test.js +46 -0
  15. package/dist/commands/eval-cli-usage.test.js +75 -0
  16. package/dist/commands/eval-interruption.test.js +26 -1
  17. package/dist/commands/eval-layout.test.js +126 -0
  18. package/dist/commands/eval.js +7 -32
  19. package/dist/commands/npm-first-run.test.js +74 -0
  20. package/dist/harness/agent-preflight.js +18 -2
  21. package/dist/harness/bench-location.js +29 -0
  22. package/dist/harness/bench-location.test.js +33 -0
  23. package/dist/harness/bench.js +8 -3
  24. package/dist/harness/eval-audit.js +1 -1
  25. package/dist/harness/evaluation-layout.js +30 -0
  26. package/dist/harness/executors/api.js +20 -7
  27. package/dist/harness/executors/api.test.js +39 -0
  28. package/dist/harness/executors/cli.js +15 -25
  29. package/dist/harness/executors/cli.test.js +33 -2
  30. package/dist/harness/experiment-session.js +5 -15
  31. package/dist/harness/hash.js +3 -1
  32. package/dist/harness/runner.js +5 -4
  33. package/dist/harness/single-arm-audit.js +1 -1
  34. package/dist/harness/trigger.js +1 -1
  35. package/dist/harness/verifier-timeout.js +8 -0
  36. package/dist/harness/verifier-timeout.test.js +76 -0
  37. package/docs/bench-authoring.md +23 -3
  38. package/docs/bench-drafting.md +75 -0
  39. package/docs/case-management.md +12 -1
  40. package/docs/eval-agent-preflight.md +15 -2
  41. package/docs/eval-costs.md +28 -2
  42. package/docs/eval-planning.md +14 -0
  43. package/docs/evaluation-input-snapshots.md +20 -4
  44. package/docs/first-real-eval.md +28 -3
  45. package/docs/growth-roadmap-2026-10.md +23 -14
  46. package/docs/plans/2026-10-17-workflow-foundations.md +37 -2
  47. package/docs/releases/0.11.0-ci-registry-install.json +130 -0
  48. package/docs/releases/0.11.0-feature-smoke.json +1576 -0
  49. package/docs/releases/0.11.0-local-attempt-1.json +24 -0
  50. package/docs/releases/0.11.0-local-attempt-1.log +19 -0
  51. package/docs/releases/0.11.0-local-registry-install.json +25 -0
  52. package/docs/releases/0.11.0-registry-metadata.json +33 -0
  53. package/docs/releases/0.11.0-signatures.txt +12 -0
  54. package/docs/releases/0.11.0-verification.json +95 -0
  55. package/docs/releases/0.11.0.md +54 -11
  56. package/docs/releases/0.12.0-feature-smoke.mjs +73 -0
  57. package/docs/releases/0.12.0.md +68 -0
  58. package/docs/schemas/agent-preflight.schema.json +1 -1
  59. package/docs/verifier-contract.md +9 -0
  60. package/package.json +1 -1
  61. package/skills/skillfit/SKILL.md +25 -5
@@ -0,0 +1,168 @@
1
+ import assert from 'node:assert/strict';
2
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
3
+ import { spawnSync } from 'node:child_process';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { test } from 'node:test';
8
+ import { runBenchAdd, runBenchInit } from './bench.js';
9
+ import { ExecutorFailure } from '../harness/types.js';
10
+ import { loadBench } from '../harness/bench.js';
11
+ const json = (path) => JSON.parse(readFileSync(path, 'utf8'));
12
+ const verifier = `import fs from 'node:fs';import path from 'node:path';const p=path.join(process.argv[2],'_output.md');const passed=fs.existsSync(p)&&fs.readFileSync(p,'utf8')==='done';console.log(JSON.stringify({passed,checks:[{name:'answer',pass:passed},{name:'exact',pass:passed}]}));process.exit(passed?0:1);`;
13
+ const oracle = `import fs from 'node:fs';import path from 'node:path';fs.writeFileSync(path.join(process.argv[2],'_output.md'),'done');`;
14
+ const budget = { input: 1000, cachedInput: 1000, uncachedInput: 1000, output: 1000, durationSeconds: 60 };
15
+ async function fixture(t) {
16
+ const root = mkdtempSync(join(tmpdir(), 'skillfit-draft-regression-'));
17
+ t.after(() => rmSync(root, { recursive: true, force: true }));
18
+ const source = join(root, 'source'), bench = join(root, 'bench');
19
+ mkdirSync(source);
20
+ writeFileSync(join(source, 'input.txt'), 'unsolved');
21
+ await runBenchInit({ dir: bench, yes: true, log: () => { } });
22
+ let calls = 0;
23
+ const executor = (after, response) => ({
24
+ describe: () => ({ kind: 'mock', model: 'offline-drafter' }),
25
+ run: async (_prompt, cwd) => {
26
+ calls++;
27
+ writeFileSync(join(cwd, 'verifier.mjs'), verifier);
28
+ writeFileSync(join(cwd, 'oracle.mjs'), oracle);
29
+ after?.(cwd);
30
+ return response ?? { output: 'drafted', tokens: { input: 123, cachedInput: 30, output: 10 }, rawOutput: 'public response only', usageStatus: 'final' };
31
+ },
32
+ });
33
+ const options = { cwd: root, benchDir: bench, sourceDir: source, include: ['input.txt'], task: 'drafted', prompt: 'Answer done',
34
+ freeze: true, decompose: true, runsRoot: join(root, 'runs'), runGroup: 'saved', log: () => { } };
35
+ return { root, source, bench, options, executor, calls: () => calls, records: join(root, 'runs/saved') };
36
+ }
37
+ test('drafting confirmation and predictable write failures precede every model call', async (t) => {
38
+ const f = await fixture(t), original = readFileSync(join(f.bench, 'bench.json'), 'utf8');
39
+ assert.equal(await runBenchAdd({ ...f.options, executor: f.executor(), confirm: async () => false }), null);
40
+ assert.equal(f.calls(), 0);
41
+ assert.equal(existsSync(f.records), false);
42
+ mkdirSync(join(f.bench, 'prompts/drafted.md'));
43
+ await assert.rejects(runBenchAdd({ ...f.options, executor: f.executor(), yes: true }), /non-file/);
44
+ assert.equal(f.calls(), 0);
45
+ assert.equal(existsSync(f.records), false);
46
+ assert.equal(readFileSync(join(f.bench, 'bench.json'), 'utf8'), original);
47
+ });
48
+ test('symlinked output parents cannot write outside the bench or start a draft', async (t) => {
49
+ const f = await fixture(t), outside = join(f.root, 'outside');
50
+ mkdirSync(outside);
51
+ symlinkSync(outside, join(f.bench, 'fixtures/drafted'), process.platform === 'win32' ? 'junction' : 'dir');
52
+ await assert.rejects(runBenchAdd({ ...f.options, executor: f.executor(), yes: true }), /symlink/);
53
+ assert.equal(f.calls(), 0);
54
+ assert.equal(existsSync(join(outside, 'drafted')), false);
55
+ });
56
+ test('draft dry-run exposes one-call budget and deadlines while creating no records', async (t) => {
57
+ const f = await fixture(t), lines = [];
58
+ await runBenchAdd({ ...f.options, executor: f.executor(), dryRun: true, executorTimeoutSeconds: 13,
59
+ maxCalls: 1, spendingBudget: budget, log: line => lines.push(line) });
60
+ assert.equal(f.calls(), 0);
61
+ assert.equal(existsSync(f.records), false);
62
+ assert.match(lines.join('\n'), /1 call; ceiling 1; executor deadline 13s/);
63
+ assert.match(lines.join('\n'), /"cachedInput":1000/);
64
+ });
65
+ test('a successful draft retains original inputs, reported usage, gate evidence and the one-call ledger', async (t) => {
66
+ const f = await fixture(t);
67
+ await runBenchAdd({ ...f.options, executor: f.executor(), yes: true, spendingBudget: budget, verifierTimeoutSeconds: 7 });
68
+ assert.equal(f.calls(), 1);
69
+ const summary = json(join(f.records, '_summary.json')), plan = json(join(f.records, '_plan.json'));
70
+ assert.equal(summary.status, 'completed');
71
+ assert.equal(summary.callsStarted, 1);
72
+ assert.equal(summary.callsFinished, 1);
73
+ assert.equal(summary.costs.metrics.input.knownTotal, 123);
74
+ assert.equal(summary.costs.metrics.uncachedInput.knownTotal, 93);
75
+ assert.equal(summary.costs.metrics.output.knownTotal, 10);
76
+ assert.equal(summary.costs.metrics.cachedInput.coverage.final, 1);
77
+ assert.equal(plan.verifierTimeoutSeconds, 7);
78
+ assert.equal(plan.automaticRetry, false);
79
+ assert.equal(readFileSync(join(f.records, '_inputs/fixture/input.txt'), 'utf8'), 'unsolved');
80
+ assert.equal(readFileSync(join(f.records, '_transcript.jsonl'), 'utf8'), 'public response only');
81
+ assert.equal(readFileSync(join(f.records, '_gates.jsonl'), 'utf8').trim().split('\n').length, 3);
82
+ assert.equal(readFileSync(join(f.records, '_calls.jsonl'), 'utf8').trim().split('\n').length, 2);
83
+ assert.equal(loadBench(f.bench).tasks.find(task => task.id === 'drafted').verifierTimeoutSeconds, 7);
84
+ const before = readFileSync(join(f.records, '_summary.json'), 'utf8');
85
+ await assert.rejects(runBenchAdd({ ...f.options, task: 'other', executor: f.executor(), yes: true }), /already exists/);
86
+ assert.equal(f.calls(), 1);
87
+ assert.equal(readFileSync(join(f.records, '_summary.json'), 'utf8'), before);
88
+ });
89
+ for (const [name, response, expected] of [
90
+ ['missing counters', { output: 'drafted' }, /FINAL_USAGE_MISSING/],
91
+ ['failed executor', null, /Draft executor failed/],
92
+ ])
93
+ test(`a draft with ${name} stops once and preserves available costs`, async (t) => {
94
+ const f = await fixture(t);
95
+ const executor = response ? f.executor(undefined, response) : f.executor(() => {
96
+ throw new ExecutorFailure('offline failure', { output: 'partial', tokens: { input: 99, output: 5 }, usageStatus: 'partial' });
97
+ });
98
+ await assert.rejects(runBenchAdd({ ...f.options, executor, yes: true, ...(response ? { spendingBudget: budget } : {}) }), expected);
99
+ assert.equal(f.calls(), 1);
100
+ assert.equal(loadBench(f.bench).tasks.length, 1);
101
+ const summary = json(join(f.records, '_summary.json'));
102
+ assert.equal(summary.status, 'stopped');
103
+ assert.equal(summary.callsFinished, 1);
104
+ if (response)
105
+ assert.equal(summary.costs.metrics.input.coverage.unknown, 1);
106
+ else {
107
+ assert.equal(summary.costs.metrics.input.knownTotal, 99);
108
+ assert.equal(summary.costs.metrics.input.coverage.partial, 1);
109
+ }
110
+ });
111
+ test('a rejected draft retains its cost and gate failure rather than deleting the attempt', async (t) => {
112
+ const f = await fixture(t);
113
+ await assert.rejects(runBenchAdd({ ...f.options, executor: f.executor(cwd => writeFileSync(join(cwd, 'verifier.mjs'), 'process.exit(0);')), yes: true }), /NOP gate/);
114
+ const summary = json(join(f.records, '_summary.json'));
115
+ assert.equal(summary.status, 'stopped');
116
+ assert.equal(summary.costs.metrics.input.knownTotal, 123);
117
+ assert.equal(f.calls(), 1);
118
+ assert.equal(loadBench(f.bench).tasks.length, 1);
119
+ assert.equal(json(join(f.records, '_result.json')).tokens.cachedInput, 30);
120
+ });
121
+ test('a drafter cannot silently replace the pristine fixture', async (t) => {
122
+ const f = await fixture(t);
123
+ await assert.rejects(runBenchAdd({ ...f.options, executor: f.executor(cwd => writeFileSync(join(cwd, 'fixture/input.txt'), 'solved')), yes: true }), /modified the pristine fixture/);
124
+ assert.equal(f.calls(), 1);
125
+ assert.equal(json(join(f.records, '_summary.json')).status, 'stopped');
126
+ assert.equal(readFileSync(join(f.records, '_inputs/fixture/input.txt'), 'utf8'), 'unsolved');
127
+ });
128
+ test('a draft cannot overwrite concurrent bench edits and still retains its paid attempt', async (t) => {
129
+ const f = await fixture(t), manifest = join(f.bench, 'bench.json');
130
+ await assert.rejects(runBenchAdd({ ...f.options, executor: f.executor(() => {
131
+ const edited = json(manifest);
132
+ edited.description = 'new user work';
133
+ writeFileSync(manifest, JSON.stringify(edited));
134
+ }), yes: true }), /Bench outputs changed/);
135
+ assert.equal(f.calls(), 1);
136
+ assert.equal(json(manifest).description, 'new user work');
137
+ assert.equal(loadBench(f.bench).tasks.length, 1);
138
+ assert.equal(json(join(f.records, '_summary.json')).status, 'stopped');
139
+ assert.equal(json(join(f.records, '_result.json')).tokens.input, 123);
140
+ });
141
+ test('invalid draft budgets and deadlines are rejected offline before records or calls', async (t) => {
142
+ const f = await fixture(t);
143
+ for (const change of [{ maxCalls: 0 }, { executorTimeoutSeconds: 0 }, { verifierTimeoutSeconds: 0 },
144
+ { spendingBudget: { ...budget, input: 0 } }, { runGroup: '../bad' }]) {
145
+ await assert.rejects(runBenchAdd({ ...f.options, ...change, executor: f.executor(), yes: true }));
146
+ }
147
+ assert.equal(f.calls(), 0);
148
+ assert.equal(existsSync(f.records), false);
149
+ });
150
+ test('CLI drafting previews accept budget/output controls without executing the selected CLI', async (t) => {
151
+ const f = await fixture(t), bin = join(f.root, 'bin');
152
+ mkdirSync(bin);
153
+ const marker = join(f.root, 'must-not-execute');
154
+ const binary = join(bin, process.platform === 'win32' ? 'codex.cmd' : 'codex');
155
+ writeFileSync(binary, process.platform === 'win32' ? `@echo executed>"${marker}"\r\n` : `#!/bin/sh\nprintf executed > '${marker}'\n`);
156
+ chmodSync(binary, 0o755);
157
+ const budgetPath = join(f.root, 'budget.json');
158
+ writeFileSync(budgetPath, JSON.stringify(budget));
159
+ const cli = fileURLToPath(new URL('../cli.js', import.meta.url));
160
+ const result = spawnSync(process.execPath, [cli, 'bench', 'add', f.bench, '--freeze', '--source-dir', f.source,
161
+ '--include', 'input.txt', '--task', 'cli-draft', '--prompt', 'Answer done', '--decompose', '--agent', 'codex',
162
+ '--max-calls', '1', '--executor-timeout-seconds', '13', '--verifier-timeout-seconds', '7', '--spending-budget', budgetPath,
163
+ '--runs-root', f.options.runsRoot, '--run-group', 'cli-preview', '--dry-run'], { cwd: f.root, env: { ...process.env, PATH: bin + (process.platform === 'win32' ? ';' : ':') + process.env.PATH }, encoding: 'utf8' });
164
+ assert.equal(result.status, 0, result.stderr);
165
+ assert.match(result.stdout, /1 call; ceiling 1; executor deadline 13s/);
166
+ assert.equal(existsSync(marker), false);
167
+ assert.equal(existsSync(join(f.options.runsRoot, 'cli-preview')), false);
168
+ });
@@ -1,12 +1,13 @@
1
1
  import { lstatSync, readFileSync } from 'node:fs';
2
2
  import { join, resolve } from 'node:path';
3
3
  import { loadBench, validateBenchTask } from '../harness/bench.js';
4
+ import { resolveBenchDir } from '../harness/bench-location.js';
4
5
  import { applyBenchWrites } from './bench.js';
5
6
  import { BACKUP_SUFFIX } from './install.js';
6
- const EDITABLE = ['fixture', 'prompt', 'promptTrigger', 'verifier', 'verifierKind', 'oracle', 'rubric', 'shouldTrigger'];
7
- const OPTIONAL = ['promptTrigger', 'oracle', 'rubric', 'shouldTrigger'];
7
+ const EDITABLE = ['fixture', 'prompt', 'promptTrigger', 'verifier', 'verifierKind', 'verifierTimeoutSeconds', 'oracle', 'rubric', 'shouldTrigger'];
8
+ const OPTIONAL = ['promptTrigger', 'verifierTimeoutSeconds', 'oracle', 'rubric', 'shouldTrigger'];
8
9
  export function inspectBench(dir, taskId) {
9
- const bench = loadBench(dir);
10
+ const bench = loadBench(resolveBenchDir(dir));
10
11
  const tasks = taskId === undefined ? bench.tasks : bench.tasks.filter(task => task.id === taskId);
11
12
  if (!tasks.length)
12
13
  throw new Error(`Unknown task: ${taskId}`);
@@ -53,7 +54,7 @@ export function manageBench(options) {
53
54
  next[field] = value === 'true';
54
55
  }
55
56
  else
56
- next[field] = value;
57
+ next[field] = field === 'verifierTimeoutSeconds' ? Number(value) : value;
57
58
  }
58
59
  for (const field of options.unset ?? []) {
59
60
  if (!OPTIONAL.includes(field))
@@ -0,0 +1,101 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, lstatSync, readdirSync, readFileSync } from 'node:fs';
3
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
4
+ import { physicalPath } from '../harness/evaluation-layout.js';
5
+ const MAX_FILES = 200;
6
+ const MAX_BYTES = 1024 * 1024;
7
+ const excluded = (rel) => rel.split(/[\\/]/).some(part => part === '.git' || part === 'node_modules');
8
+ const inside = (root, path) => {
9
+ const rel = relative(root, path);
10
+ return rel === '' || (!isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`));
11
+ };
12
+ /** Never dereference a selected link, including links in a path's parent directories. */
13
+ function ordinaryPath(root, rel) {
14
+ let current = root;
15
+ for (const part of rel.split(/[\\/]/)) {
16
+ current = join(current, part);
17
+ const stat = lstatSync(current);
18
+ if (stat.isSymbolicLink())
19
+ throw new Error(`Refusing a symbolic link in frozen source: ${current}. Select ordinary files with --include.`);
20
+ if (!stat.isFile() && !stat.isDirectory())
21
+ throw new Error(`Unsupported frozen source entry: ${current}`);
22
+ }
23
+ }
24
+ export function captureSourceFiles(sourceDir, include) {
25
+ const root = resolve(sourceDir);
26
+ if (!lstatSync(root).isDirectory())
27
+ throw new Error(`--source-dir must be an ordinary directory: ${root}`);
28
+ const selected = include?.map(value => {
29
+ const rel = value.replace(/\\/g, '/').replace(/\/$/, '');
30
+ if (!rel || rel === '.' || isAbsolute(rel) || /^[A-Za-z]:/.test(rel) || rel.split('/').some(part => part === '..' || part === '.' || part === '')) {
31
+ throw new Error(`--include must name a file or subdirectory inside --source-dir: ${value}`);
32
+ }
33
+ if (excluded(rel))
34
+ throw new Error(`--include cannot select Git metadata or node_modules: ${value}`);
35
+ return rel;
36
+ });
37
+ const git = spawnSync('git', ['ls-files', '-z'], { cwd: root, encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 });
38
+ let files;
39
+ if (git.status === 0) {
40
+ files = git.stdout.split('\0').filter(Boolean);
41
+ if (!files.length)
42
+ throw new Error('No git-tracked files in --source-dir. Stage the intended fixture files first; ignored/untracked files are never a fallback.');
43
+ }
44
+ else {
45
+ // A broken repository or failed Git executable must not silently widen capture.
46
+ let parent = root;
47
+ while (true) {
48
+ if (existsSync(join(parent, '.git')))
49
+ throw new Error('Cannot read the Git index for --source-dir; fix Git before freezing files.');
50
+ if (dirname(parent) === parent)
51
+ break;
52
+ parent = dirname(parent);
53
+ }
54
+ if (git.error || git.status !== 128)
55
+ throw new Error('Cannot determine Git tracking for --source-dir; fix Git before freezing files.');
56
+ if (!selected?.length)
57
+ throw new Error('Non-Git --source-dir requires --include <file-or-dir> (repeatable); select the fixture explicitly.');
58
+ files = [];
59
+ const walk = (rel) => {
60
+ if (excluded(rel))
61
+ return;
62
+ ordinaryPath(root, rel);
63
+ const stat = lstatSync(join(root, rel));
64
+ if (stat.isFile())
65
+ files.push(rel);
66
+ else
67
+ for (const name of readdirSync(join(root, rel)))
68
+ walk(`${rel}/${name}`);
69
+ };
70
+ for (const rel of selected)
71
+ walk(rel);
72
+ }
73
+ files = [...new Set(files)].filter(rel => !excluded(rel) && (!selected?.length || selected.some(prefix => rel === prefix || rel.startsWith(`${prefix}/`)))).sort();
74
+ for (const prefix of selected ?? [])
75
+ if (!files.some(rel => rel === prefix || rel.startsWith(`${prefix}/`))) {
76
+ throw new Error(`--include matches no capturable files: ${prefix}`);
77
+ }
78
+ for (const rel of files) {
79
+ if (isAbsolute(rel) || rel.split(/[\\/]/).includes('..'))
80
+ throw new Error(`Frozen source path escapes --source-dir: ${rel}`);
81
+ ordinaryPath(root, rel);
82
+ if (!lstatSync(join(root, rel)).isFile())
83
+ throw new Error(`Frozen source is not an ordinary file (submodules are unsupported): ${rel}`);
84
+ }
85
+ return files;
86
+ }
87
+ export function freezeSourceFiles(sourceDir, benchDir, include) {
88
+ const root = resolve(sourceDir), bench = physicalPath(benchDir);
89
+ const files = captureSourceFiles(root, include);
90
+ if (files.length > MAX_FILES)
91
+ throw new Error(`Frozen source has ${files.length} files; limit is ${MAX_FILES}. Narrow it with --include.`);
92
+ let bytes = 0;
93
+ return files.map(rel => {
94
+ if (inside(bench, physicalPath(join(root, rel))))
95
+ throw new Error(`Frozen source includes the destination bench: ${rel}. Narrow it with --include.`);
96
+ bytes += lstatSync(join(root, rel)).size;
97
+ if (bytes > MAX_BYTES)
98
+ throw new Error(`Frozen source exceeds ${MAX_BYTES} bytes. Narrow it with --include.`);
99
+ return { rel, content: readFileSync(join(root, rel)) };
100
+ });
101
+ }
@@ -0,0 +1,84 @@
1
+ import assert from 'node:assert/strict';
2
+ import { execFileSync } from 'node:child_process';
3
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ import { test } from 'node:test';
7
+ import { captureSourceFiles, freezeSourceFiles } from './bench-source.js';
8
+ import { runBenchAdd, runBenchInit } from './bench.js';
9
+ function fixture(t) {
10
+ const root = mkdtempSync(join(tmpdir(), 'skillfit-freeze-boundary-'));
11
+ t.after(() => rmSync(root, { recursive: true, force: true }));
12
+ const source = join(root, 'source'), bench = join(root, 'bench');
13
+ mkdirSync(source);
14
+ return { root, source, bench };
15
+ }
16
+ const git = (cwd, ...args) => execFileSync('git', args, { cwd, stdio: 'pipe' });
17
+ test('empty Git index never falls back to ignored or untracked files, including dry runs', async (t) => {
18
+ const f = fixture(t);
19
+ git(f.source, 'init', '-q');
20
+ writeFileSync(join(f.source, '.gitignore'), '.env\nbuild/\n');
21
+ writeFileSync(join(f.source, '.env'), 'SYNTHETIC_ONLY=not-a-secret');
22
+ mkdirSync(join(f.source, 'build'));
23
+ writeFileSync(join(f.source, 'build', 'out'), 'artifact');
24
+ await runBenchInit({ dir: f.bench, yes: true, log: () => { } });
25
+ for (const dryRun of [true, false])
26
+ await assert.rejects(runBenchAdd({ benchDir: f.bench, sourceDir: f.source,
27
+ task: 'freeze', freeze: true, prompt: 'Solve', expect: 'done', dryRun, yes: true, log: () => { } }), /No git-tracked files/);
28
+ assert.equal(existsSync(join(f.bench, 'fixtures', 'freeze')), false);
29
+ });
30
+ test('non-Git sources require explicit includes; Git sources support the same narrowing', t => {
31
+ const f = fixture(t);
32
+ mkdirSync(join(f.source, 'src'));
33
+ writeFileSync(join(f.source, 'src', 'app.js'), 'app');
34
+ writeFileSync(join(f.source, '.env'), 'synthetic');
35
+ assert.throws(() => captureSourceFiles(f.source), /requires --include/);
36
+ assert.deepEqual(captureSourceFiles(f.source, ['src']), ['src/app.js']);
37
+ git(f.source, 'init', '-q');
38
+ git(f.source, 'add', '.');
39
+ assert.deepEqual(captureSourceFiles(f.source, ['src/app.js']), ['src/app.js']);
40
+ for (const rel of ['../outside', '/absolute', '.', '.git', 'node_modules', 'src/../.env', 'missing']) {
41
+ assert.throws(() => captureSourceFiles(f.source, [rel]), /--include/);
42
+ }
43
+ });
44
+ test('tracked file and directory links cannot be dereferenced into frozen inputs', t => {
45
+ const f = fixture(t);
46
+ git(f.source, 'init', '-q');
47
+ writeFileSync(join(f.root, 'outside.txt'), 'SYNTHETIC_OUTSIDE');
48
+ // Git does not support tracked symlinks on every Windows checkout; the ordinary
49
+ // directory-junction check below still covers Windows parent traversal.
50
+ if (process.platform !== 'win32') {
51
+ symlinkSync('../outside.txt', join(f.source, 'link.txt'));
52
+ git(f.source, 'add', 'link.txt');
53
+ assert.throws(() => freezeSourceFiles(f.source, f.bench), /symbolic link/);
54
+ }
55
+ const target = join(f.root, 'directory');
56
+ mkdirSync(target);
57
+ writeFileSync(join(target, 'outside.txt'), 'synthetic');
58
+ symlinkSync(target, join(f.source, 'linked-dir'), process.platform === 'win32' ? 'junction' : 'dir');
59
+ // Explicit non-Git capture must also reject a linked parent, before reading it.
60
+ const plain = join(f.root, 'plain');
61
+ mkdirSync(plain);
62
+ symlinkSync(target, join(plain, 'linked-dir'), process.platform === 'win32' ? 'junction' : 'dir');
63
+ assert.throws(() => captureSourceFiles(plain, ['linked-dir/outside.txt']), /symbolic link/);
64
+ });
65
+ test('broken Git metadata never widens selection to the working directory', t => {
66
+ const f = fixture(t);
67
+ mkdirSync(join(f.source, '.git'));
68
+ writeFileSync(join(f.source, 'safe.txt'), 'fixture');
69
+ assert.throws(() => captureSourceFiles(f.source, ['safe.txt']), /Cannot read the Git index/);
70
+ });
71
+ test('destination bench and oversized inputs are rejected before copying, with explicit narrowing available', async (t) => {
72
+ const f = fixture(t);
73
+ const bench = join(f.source, 'my-bench');
74
+ await runBenchInit({ dir: bench, yes: true, log: () => { } });
75
+ writeFileSync(join(f.source, 'app.js'), 'app');
76
+ git(f.source, 'init', '-q');
77
+ git(f.source, 'add', '.');
78
+ assert.throws(() => freezeSourceFiles(f.source, bench), /destination bench/);
79
+ assert.equal(freezeSourceFiles(f.source, bench, ['app.js'])[0].content.toString(), 'app');
80
+ writeFileSync(join(f.source, 'large.bin'), Buffer.alloc(1024 * 1024 + 1));
81
+ git(f.source, 'add', 'large.bin');
82
+ assert.throws(() => freezeSourceFiles(f.source, f.bench, ['large.bin']), /exceeds/);
83
+ assert.equal(readFileSync(join(bench, 'bench.json'), 'utf8').includes('example-task'), true);
84
+ });