harness-everything 1.2.2 → 1.3.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +23 -0
- package/ci/fixtures/468-dispatch/agy-quota-PROVENANCE.md +19 -0
- package/ci/fixtures/468-dispatch/agy-quota-direct-individual.stderr +2 -0
- package/ci/fixtures/468-dispatch/agy-quota-direct-third-party.stderr +2 -0
- package/ci/fixtures/468-dispatch/agy-quota-exec-individual.log +3 -0
- package/ci/mechanism-468-dispatch-cli.test.js +1496 -4
- package/ci/mechanism-548-bigint-identity.test.js +531 -0
- package/ci/mechanism-error-ledger-oracle.test.js +786 -3
- package/ci/mechanism-error-ledger-scan.test.js +981 -0
- package/ci/mechanism-report-writer.test.js +45 -0
- package/docs/error-handling/details/c8-dispatch-cli.md +109 -13
- package/error-ledger-bootstrap/SKILL.md +1 -1
- package/error-ledger-bootstrap/references/workflow.md +42 -7
- package/error-ledger-bootstrap/scripts/promote.js +8 -6
- package/error-ledger-bootstrap/scripts/scan.js +525 -12
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +1 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +42 -7
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +8 -6
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +525 -12
- package/sbom.cdx.json +7 -7
- package/scripts/dispatch.js +499 -87
- package/scripts/error-ledger-oracle.js +521 -27
- package/scripts/errors-sync.js +4 -3
- package/scripts/report-writer.js +4 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const assert = require('node:assert/strict');
|
|
4
|
-
const { spawnSync } = require('node:child_process');
|
|
4
|
+
const { spawn, spawnSync } = require('node:child_process');
|
|
5
5
|
const fs = require('node:fs');
|
|
6
6
|
const os = require('node:os');
|
|
7
7
|
const path = require('node:path');
|
|
@@ -9,6 +9,17 @@ const path = require('node:path');
|
|
|
9
9
|
const root = path.resolve(__dirname, '..');
|
|
10
10
|
const entry = path.join(root, 'scripts', 'dispatch.js');
|
|
11
11
|
const fixtureRunner = path.join(__dirname, 'fixtures', '468-dispatch', 'runner.js');
|
|
12
|
+
const quotaFixtureDir = path.join(__dirname, 'fixtures', '468-dispatch');
|
|
13
|
+
const thirdPartyPair = fs.readFileSync(path.join(quotaFixtureDir, 'agy-quota-direct-third-party.stderr'), 'utf8');
|
|
14
|
+
const individualPair = fs.readFileSync(path.join(quotaFixtureDir, 'agy-quota-direct-individual.stderr'), 'utf8');
|
|
15
|
+
const execIndividualLog = fs.readFileSync(path.join(quotaFixtureDir, 'agy-quota-exec-individual.log'), 'utf8');
|
|
16
|
+
const execIndividualPair = execIndividualLog.replace(/^\[stderr\]\r?\n/, '');
|
|
17
|
+
assert.ok(thirdPartyPair.startsWith('error: Third-party quota reached.') && thirdPartyPair.includes('AGY_ERROR: '));
|
|
18
|
+
assert.ok(individualPair.startsWith('error: Individual quota reached.') && individualPair.includes('AGY_ERROR: '));
|
|
19
|
+
assert.ok(execIndividualPair.startsWith('error: Individual quota reached.') && execIndividualPair.includes('AGY_ERROR: '),
|
|
20
|
+
'the managed execution fixture must retain the live Individual stderr shape');
|
|
21
|
+
const [individualErrorLine, individualJsonLine] = individualPair.trimEnd().split(/\r?\n/);
|
|
22
|
+
const retiredAgyQuotaLine = '429 RESOURCE_EXHAUSTED: Quota exceeded for model claude-sonnet-5-5-medium. Resets in 2h 15m.\n';
|
|
12
23
|
const tempParent = process.env.TMPDIR || os.tmpdir();
|
|
13
24
|
const rootReal = fs.realpathSync.native(root);
|
|
14
25
|
const tempRelative = path.relative(rootReal, fs.realpathSync.native(path.resolve(tempParent)));
|
|
@@ -31,6 +42,10 @@ const symlinkedParent = path.join(fixtureRoot, 'symlinked parent');
|
|
|
31
42
|
const reports = path.join(fixtureRoot, 'reports with spaces');
|
|
32
43
|
const runnerBin = path.join(fixtureRoot, 'runner bin');
|
|
33
44
|
const openCodeOnlyBin = path.join(fixtureRoot, 'opencode only bin');
|
|
45
|
+
const rawOverridePreload = path.join(fixtureRoot, 'raw-override.cjs');
|
|
46
|
+
const admissionPreload = path.join(fixtureRoot, 'admission-preload.cjs');
|
|
47
|
+
const agyStubScript = path.join(fixtureRoot, 'agy-stub.cjs');
|
|
48
|
+
const agyWinPreload = path.join(fixtureRoot, 'agy-win-preload.cjs');
|
|
34
49
|
const packet = path.join(worktree, 'packet with spaces.md');
|
|
35
50
|
const failures = [];
|
|
36
51
|
const passed = [];
|
|
@@ -69,6 +84,138 @@ function makeRunnerPath() {
|
|
|
69
84
|
linkNodeExecutable(openCodeOnlyBin, 'opencode');
|
|
70
85
|
fs.copyFileSync(fixtureRunner, path.join(worktree, 'exec'));
|
|
71
86
|
fs.copyFileSync(fixtureRunner, path.join(worktree, 'run'));
|
|
87
|
+
fs.writeFileSync(agyStubScript, `'use strict';
|
|
88
|
+
const fs = require('node:fs');
|
|
89
|
+
const args = process.argv.slice(2);
|
|
90
|
+
const pIndex = args.indexOf('-p');
|
|
91
|
+
const prompt = pIndex >= 0 ? (args[pIndex + 1] || '') : '';
|
|
92
|
+
const phase = prompt === 'Reply with the single word READY' ? 'readiness' : 'execution';
|
|
93
|
+
const scenario = process.env['DISPATCH_FIXTURE_' + phase.toUpperCase()] || (phase === 'readiness' ? 'ready' : 'done');
|
|
94
|
+
const input = fs.readFileSync(0, 'utf8');
|
|
95
|
+
fs.appendFileSync(process.env.DISPATCH_FIXTURE_LOG, JSON.stringify({
|
|
96
|
+
runner: 'agy',
|
|
97
|
+
phase,
|
|
98
|
+
scenario,
|
|
99
|
+
args,
|
|
100
|
+
cwd: process.cwd(),
|
|
101
|
+
tmpdir: process.env.TMPDIR,
|
|
102
|
+
stdin: input,
|
|
103
|
+
stdinIsCharacterDevice: fs.fstatSync(0).isCharacterDevice(),
|
|
104
|
+
pid: process.pid,
|
|
105
|
+
}) + '\\n');
|
|
106
|
+
const quotaLine = '429 RESOURCE_EXHAUSTED: Quota exceeded for model claude-sonnet-5-5-medium. Resets in 2h 15m.\\n';
|
|
107
|
+
const pairStderr = process.env.DISPATCH_FIXTURE_STDERR || '';
|
|
108
|
+
const pairStdout = process.env.DISPATCH_FIXTURE_STDOUT || '';
|
|
109
|
+
function hang() { setInterval(() => {}, 1000); }
|
|
110
|
+
if (scenario === 'agy-quota-pair') {
|
|
111
|
+
if (pairStdout) process.stdout.write(pairStdout);
|
|
112
|
+
process.stderr.write(pairStderr);
|
|
113
|
+
process.exitCode = 3;
|
|
114
|
+
} else if (scenario === 'agy-quota-pair-exit1') {
|
|
115
|
+
process.stderr.write(pairStderr);
|
|
116
|
+
process.exitCode = 1;
|
|
117
|
+
} else if (scenario === 'agy-quota-pair-signal') {
|
|
118
|
+
process.stderr.write(pairStderr);
|
|
119
|
+
process.kill(process.pid, 'SIGTERM');
|
|
120
|
+
} else if (phase === 'readiness') {
|
|
121
|
+
if (scenario === 'timeout') hang();
|
|
122
|
+
else if (scenario === 'ready') process.stdout.write('READY\\n');
|
|
123
|
+
else if (scenario === 'ready-period') process.stdout.write('READY.\\n');
|
|
124
|
+
else if (scenario === 'ready-host-label') process.stdout.write('READY\\n<!-- harness-label {"v":1,"validity":"actionable","tier":"tier1","intents":[],"workflow":null,"skills":[]} -->\\n');
|
|
125
|
+
else if (scenario === 'create-stale-report') {
|
|
126
|
+
fs.writeFileSync(process.env.DISPATCH_FIXTURE_REPORT_PATH, 'Stale report.\\nSTATUS: DONE\\n');
|
|
127
|
+
process.stdout.write('READY\\n');
|
|
128
|
+
} else if (scenario === 'ready-failed') {
|
|
129
|
+
process.stdout.write('READY\\n');
|
|
130
|
+
process.exitCode = 1;
|
|
131
|
+
} else if (scenario === 'agy-quota') {
|
|
132
|
+
process.stderr.write('\\u001b[91m' + quotaLine + '\\u001b[0m');
|
|
133
|
+
process.exitCode = 3;
|
|
134
|
+
} else if (scenario === 'agy-exit3-generic') {
|
|
135
|
+
process.stderr.write('Error: generic exit 3 failure\\n');
|
|
136
|
+
process.exitCode = 3;
|
|
137
|
+
} else if (scenario === 'agy-exit3-bare-429') {
|
|
138
|
+
process.stderr.write('429 Too Many Requests\\n');
|
|
139
|
+
process.exitCode = 3;
|
|
140
|
+
} else if (scenario === 'agy-exit3-no-reset') {
|
|
141
|
+
process.stderr.write('429 RESOURCE_EXHAUSTED: Quota exceeded.\\n');
|
|
142
|
+
process.exitCode = 3;
|
|
143
|
+
} else if (scenario === 'agy-exit3-quoted') {
|
|
144
|
+
process.stderr.write('Quoted text: ' + quotaLine);
|
|
145
|
+
process.exitCode = 3;
|
|
146
|
+
} else if (scenario === 'agy-exit3-stdout') {
|
|
147
|
+
process.stdout.write(quotaLine);
|
|
148
|
+
process.exitCode = 3;
|
|
149
|
+
} else if (scenario === 'agy-exit1-quota') {
|
|
150
|
+
process.stderr.write(quotaLine);
|
|
151
|
+
process.exitCode = 1;
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
if (scenario === 'timeout') {
|
|
155
|
+
process.stdout.write('agy partial output before timeout\\n');
|
|
156
|
+
hang();
|
|
157
|
+
} else if (scenario === 'done') {
|
|
158
|
+
fs.writeFileSync(process.env.DISPATCH_FIXTURE_REPORT_PATH, 'Fixture completed the packet.\\nSTATUS: DONE\\n');
|
|
159
|
+
process.stdout.write('agy fixture child output\\n');
|
|
160
|
+
} else if (scenario === 'blocked') {
|
|
161
|
+
fs.writeFileSync(process.env.DISPATCH_FIXTURE_REPORT_PATH, 'Fixture could not verify the packet.\\nSTATUS: BLOCKED: missing evidence\\n');
|
|
162
|
+
process.stdout.write('agy fixture child output\\n');
|
|
163
|
+
} else if (scenario === 'permission-denied') {
|
|
164
|
+
process.stderr.write('jetski: no output produced — a tool required the "read_file" permission that headless mode cannot prompt for, so it was auto-denied.\\n');
|
|
165
|
+
} else if (scenario === 'agy-quota') {
|
|
166
|
+
process.stderr.write(quotaLine);
|
|
167
|
+
process.exitCode = 3;
|
|
168
|
+
} else if (scenario === 'agy-exit3-generic') {
|
|
169
|
+
process.stderr.write('Error: generic exit 3 failure\\n');
|
|
170
|
+
process.exitCode = 3;
|
|
171
|
+
} else if (scenario === 'agy-exit3-no-reset') {
|
|
172
|
+
process.stderr.write('429 RESOURCE_EXHAUSTED: Quota exceeded.\\n');
|
|
173
|
+
process.exitCode = 3;
|
|
174
|
+
} else if (scenario === 'agy-exit3-with-report') {
|
|
175
|
+
fs.writeFileSync(process.env.DISPATCH_FIXTURE_REPORT_PATH, 'Fixture completed the packet.\\nSTATUS: DONE\\n');
|
|
176
|
+
process.stderr.write(quotaLine);
|
|
177
|
+
process.exitCode = 3;
|
|
178
|
+
} else if (scenario === 'agy-exit1-quota') {
|
|
179
|
+
process.stderr.write(quotaLine);
|
|
180
|
+
process.exitCode = 1;
|
|
181
|
+
} else if (scenario === 'exit-failure') {
|
|
182
|
+
process.stderr.write('agy execution error\\n');
|
|
183
|
+
process.exitCode = 7;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
`);
|
|
187
|
+
if (process.platform === 'win32') {
|
|
188
|
+
fs.writeFileSync(path.join(runnerBin, 'agy.cmd'), '@echo off\r\n');
|
|
189
|
+
fs.writeFileSync(agyWinPreload, `'use strict';
|
|
190
|
+
const cp = require('node:child_process');
|
|
191
|
+
const fs = require('node:fs');
|
|
192
|
+
const path = require('node:path');
|
|
193
|
+
const origSpawnSync = cp.spawnSync;
|
|
194
|
+
const origSpawn = cp.spawn;
|
|
195
|
+
function isAgyFixture(command, options) {
|
|
196
|
+
if (command !== 'agy') return false;
|
|
197
|
+
const pathEnv = (options && options.env && (options.env.PATH || options.env.Path)) || '';
|
|
198
|
+
const dirs = pathEnv.split(path.delimiter).filter(Boolean);
|
|
199
|
+
return dirs.some(dir => fs.existsSync(path.join(dir, 'agy.cmd')));
|
|
200
|
+
}
|
|
201
|
+
cp.spawnSync = function (command, args, options) {
|
|
202
|
+
if (isAgyFixture(command, options)) {
|
|
203
|
+
return origSpawnSync.call(this, process.execPath, [${JSON.stringify(agyStubScript)}, ...(args || [])], options);
|
|
204
|
+
}
|
|
205
|
+
return origSpawnSync.call(this, command, args, options);
|
|
206
|
+
};
|
|
207
|
+
cp.spawn = function (command, args, options) {
|
|
208
|
+
if (isAgyFixture(command, options)) {
|
|
209
|
+
return origSpawn.call(this, process.execPath, [${JSON.stringify(agyStubScript)}, ...(args || [])], options);
|
|
210
|
+
}
|
|
211
|
+
return origSpawn.call(this, command, args, options);
|
|
212
|
+
};
|
|
213
|
+
`);
|
|
214
|
+
} else {
|
|
215
|
+
const agyBin = path.join(runnerBin, 'agy');
|
|
216
|
+
fs.writeFileSync(agyBin, `#!/bin/sh\nexec ${JSON.stringify(process.execPath)} ${JSON.stringify(agyStubScript)} "$@"\n`);
|
|
217
|
+
fs.chmodSync(agyBin, 0o755);
|
|
218
|
+
}
|
|
72
219
|
}
|
|
73
220
|
|
|
74
221
|
function makeCase(label) {
|
|
@@ -91,7 +238,7 @@ function argsFor(testCase, runner = 'codex', model = runner === 'codex' ? 'fixtu
|
|
|
91
238
|
];
|
|
92
239
|
}
|
|
93
240
|
|
|
94
|
-
function
|
|
241
|
+
function cliEnv(testCase, config = {}) {
|
|
95
242
|
const env = {
|
|
96
243
|
...process.env,
|
|
97
244
|
PATH: config.path || runnerBin,
|
|
@@ -103,7 +250,28 @@ function cli(args, testCase, config = {}) {
|
|
|
103
250
|
DISPATCH_FIXTURE_READINESS: config.readiness || 'ready',
|
|
104
251
|
DISPATCH_FIXTURE_EXECUTION: config.execution || 'done',
|
|
105
252
|
};
|
|
253
|
+
const preloads = [];
|
|
254
|
+
if (process.platform === 'win32') preloads.push(`--require "${agyWinPreload.replace(/\\/g, '/')}"`);
|
|
255
|
+
if (config.rawOverride !== undefined) {
|
|
256
|
+
env.DISPATCH_FIXTURE_RAW_OVERRIDE = config.rawOverride;
|
|
257
|
+
preloads.push(`--require "${rawOverridePreload.replace(/\\/g, '/')}"`);
|
|
258
|
+
}
|
|
259
|
+
if (config.admissionHook) {
|
|
260
|
+
if (config.admissionHook.snapshotFile) env.DISPATCH_FIXTURE_SNAPSHOT_FILE = config.admissionHook.snapshotFile;
|
|
261
|
+
if (config.admissionHook.snapshotDir) env.DISPATCH_FIXTURE_SNAPSHOT_DIR = config.admissionHook.snapshotDir;
|
|
262
|
+
if (config.admissionHook.enteredFile) env.DISPATCH_FIXTURE_ENTERED_FILE = config.admissionHook.enteredFile;
|
|
263
|
+
if (config.admissionHook.gateFile) env.DISPATCH_FIXTURE_GATE_FILE = config.admissionHook.gateFile;
|
|
264
|
+
if (config.admissionHook.epermPid !== undefined) env.DISPATCH_FIXTURE_EPERM_PID = String(config.admissionHook.epermPid);
|
|
265
|
+
preloads.push(`--require "${admissionPreload.replace(/\\/g, '/')}"`);
|
|
266
|
+
}
|
|
267
|
+
if (config.extraEnv) Object.assign(env, config.extraEnv);
|
|
268
|
+
if (preloads.length) env.NODE_OPTIONS = `${process.env.NODE_OPTIONS || ''} ${preloads.join(' ')}`.trim();
|
|
106
269
|
delete env.HARNESS_SYSTEM_ONE_MODE;
|
|
270
|
+
return env;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function cli(args, testCase, config = {}) {
|
|
274
|
+
const env = cliEnv(testCase, config);
|
|
107
275
|
const result = spawnSync(process.execPath, [entry, ...args], {
|
|
108
276
|
cwd: root,
|
|
109
277
|
env,
|
|
@@ -271,6 +439,64 @@ function runReportInvalidCase(runner, scenario) {
|
|
|
271
439
|
|
|
272
440
|
makeRepository();
|
|
273
441
|
makeRunnerPath();
|
|
442
|
+
fs.writeFileSync(rawOverridePreload, `'use strict';
|
|
443
|
+
const fs = require('node:fs');
|
|
444
|
+
const path = require('node:path');
|
|
445
|
+
if (
|
|
446
|
+
path.basename(process.argv[1] || '') === 'exec' &&
|
|
447
|
+
process.env.DISPATCH_FIXTURE_RAW_OVERRIDE !== undefined &&
|
|
448
|
+
process.argv.at(-1) !== 'Reply with the single word READY'
|
|
449
|
+
) {
|
|
450
|
+
const oIndex = process.argv.indexOf('-o');
|
|
451
|
+
const outputPath = oIndex >= 0 ? process.argv[oIndex + 1] : null;
|
|
452
|
+
const writeFileSync = fs.writeFileSync;
|
|
453
|
+
fs.writeFileSync = function (file, data, ...rest) {
|
|
454
|
+
if (outputPath && file === outputPath) {
|
|
455
|
+
return writeFileSync.call(this, file, process.env.DISPATCH_FIXTURE_RAW_OVERRIDE, ...rest);
|
|
456
|
+
}
|
|
457
|
+
return writeFileSync.call(this, file, data, ...rest);
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
`);
|
|
461
|
+
fs.writeFileSync(admissionPreload, `'use strict';
|
|
462
|
+
const fs = require('node:fs');
|
|
463
|
+
const path = require('node:path');
|
|
464
|
+
const epermPid = process.env.DISPATCH_FIXTURE_EPERM_PID ? Number(process.env.DISPATCH_FIXTURE_EPERM_PID) : null;
|
|
465
|
+
if (Number.isSafeInteger(epermPid)) {
|
|
466
|
+
const origKill = process.kill;
|
|
467
|
+
process.kill = function (pid, signal) {
|
|
468
|
+
if (Number(pid) === epermPid && (signal === 0 || signal === undefined)) {
|
|
469
|
+
const err = new Error('operation not permitted');
|
|
470
|
+
err.code = 'EPERM';
|
|
471
|
+
throw err;
|
|
472
|
+
}
|
|
473
|
+
return origKill.call(this, pid, signal);
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
const scriptBase = path.basename(process.argv[1] || '');
|
|
477
|
+
const isRunnerChild = scriptBase === 'exec' || scriptBase === 'run' || scriptBase === 'agy-stub.cjs';
|
|
478
|
+
const isReadiness = process.argv.at(-1) === 'Reply with the single word READY' || process.argv.includes('Reply with the single word READY');
|
|
479
|
+
if (isRunnerChild && isReadiness) {
|
|
480
|
+
const snapDir = process.env.DISPATCH_FIXTURE_SNAPSHOT_DIR;
|
|
481
|
+
const snapFile = process.env.DISPATCH_FIXTURE_SNAPSHOT_FILE;
|
|
482
|
+
if (snapDir && snapFile && fs.existsSync(snapDir)) {
|
|
483
|
+
const slots = fs.readdirSync(snapDir).sort().map(name => ({
|
|
484
|
+
name,
|
|
485
|
+
content: fs.readFileSync(path.join(snapDir, name), 'utf8'),
|
|
486
|
+
}));
|
|
487
|
+
fs.writeFileSync(snapFile, JSON.stringify({ childPid: process.pid, slots }));
|
|
488
|
+
}
|
|
489
|
+
if (process.env.DISPATCH_FIXTURE_ENTERED_FILE) {
|
|
490
|
+
fs.writeFileSync(process.env.DISPATCH_FIXTURE_ENTERED_FILE, String(process.pid));
|
|
491
|
+
}
|
|
492
|
+
const gateFile = process.env.DISPATCH_FIXTURE_GATE_FILE;
|
|
493
|
+
if (gateFile) {
|
|
494
|
+
const wait = new Int32Array(new SharedArrayBuffer(4));
|
|
495
|
+
const deadline = Date.now() + 10000;
|
|
496
|
+
while (!fs.existsSync(gateFile) && Date.now() < deadline) Atomics.wait(wait, 0, 0, 20);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
`);
|
|
274
500
|
fs.mkdirSync(reports);
|
|
275
501
|
fs.mkdirSync(path.join(fixtureRoot, `${path.basename(worktree)}-sibling`));
|
|
276
502
|
fs.symlinkSync(repositoryParent, symlinkedParent, process.platform === 'win32' ? 'junction' : 'dir');
|
|
@@ -283,7 +509,7 @@ try {
|
|
|
283
509
|
assert.match(human.stdout, /Usage:.*dispatch/);
|
|
284
510
|
assert.equal(human.stderr, '');
|
|
285
511
|
const json = jsonResponse(cli(['--json', '--help'], testCase), 0, 'HELP');
|
|
286
|
-
assert.match(json.message, /--runner <codex\|opencode>/);
|
|
512
|
+
assert.match(json.message, /--runner <codex\|opencode\|agy>/);
|
|
287
513
|
assertNoRunner(testCase);
|
|
288
514
|
assertNoScratchOrReport(testCase);
|
|
289
515
|
});
|
|
@@ -648,6 +874,66 @@ try {
|
|
|
648
874
|
assert.equal(fs.readFileSync(testCase.report, 'utf8'), 'Fixture completed the packet.\nSTATUS: DONE\n');
|
|
649
875
|
});
|
|
650
876
|
|
|
877
|
+
for (const { label, raw, expectedReport } of [
|
|
878
|
+
{
|
|
879
|
+
label: 'padded DONE spaces',
|
|
880
|
+
raw: 'Fixture completed the packet.\nSTATUS: DONE \n',
|
|
881
|
+
expectedReport: 'Fixture completed the packet.\nSTATUS: DONE\n',
|
|
882
|
+
},
|
|
883
|
+
{
|
|
884
|
+
label: 'padded DONE tab with blank line and host label',
|
|
885
|
+
raw: 'Fixture completed the packet.\nSTATUS: DONE\t\n\n<!-- harness-label {"v":1,"validity":"actionable","tier":"tier2","intents":["fix"],"workflow":"iterative-single","skills":[]} -->\n',
|
|
886
|
+
expectedReport: 'Fixture completed the packet.\nSTATUS: DONE\n',
|
|
887
|
+
},
|
|
888
|
+
]) {
|
|
889
|
+
check(`441-A Codex ${label} -> DONE with preserved raw bytes and canonical report`, () => {
|
|
890
|
+
const testCase = makeCase(`Codex ${label}`);
|
|
891
|
+
const response = jsonResponse(cli([...argsFor(testCase), '--json'], testCase, { rawOverride: raw }), 0, 'DONE');
|
|
892
|
+
assert.equal(fs.readFileSync(response.evidence.rawOutput, 'utf8'), raw);
|
|
893
|
+
assert.equal(fs.readFileSync(testCase.report, 'utf8'), expectedReport);
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
for (const { label, raw, expectedReport } of [
|
|
898
|
+
{
|
|
899
|
+
label: 'padded BLOCKED spaces',
|
|
900
|
+
raw: 'Fixture could not verify the packet.\nSTATUS: BLOCKED: missing evidence \n',
|
|
901
|
+
expectedReport: 'Fixture could not verify the packet.\nSTATUS: BLOCKED: missing evidence\n',
|
|
902
|
+
},
|
|
903
|
+
{
|
|
904
|
+
label: 'padded BLOCKED tab with host label',
|
|
905
|
+
raw: 'Fixture could not verify the packet.\nSTATUS: BLOCKED: missing evidence\t \n<!-- harness-label {"v":1,"validity":"actionable","tier":"tier2","intents":["fix"],"workflow":"iterative-single","skills":[]} -->\n',
|
|
906
|
+
expectedReport: 'Fixture could not verify the packet.\nSTATUS: BLOCKED: missing evidence\n',
|
|
907
|
+
},
|
|
908
|
+
]) {
|
|
909
|
+
check(`441-A Codex ${label} -> WORKER_BLOCKED with preserved raw bytes and canonical report`, () => {
|
|
910
|
+
const testCase = makeCase(`Codex ${label}`);
|
|
911
|
+
const response = jsonResponse(cli([...argsFor(testCase), '--json'], testCase, { rawOverride: raw }), 17, 'WORKER_BLOCKED');
|
|
912
|
+
assert.equal(response.message, 'worker delivered a valid BLOCKED report: missing evidence');
|
|
913
|
+
assert.equal(fs.readFileSync(response.evidence.rawOutput, 'utf8'), raw);
|
|
914
|
+
assert.equal(fs.readFileSync(testCase.report, 'utf8'), expectedReport);
|
|
915
|
+
assert.match(fs.readFileSync(response.evidence.reportWriterLog, 'utf8'), /valid \(STATUS: BLOCKED: missing evidence\)/);
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
for (const { label, raw } of [
|
|
920
|
+
{ label: 'leading space DONE', raw: 'Fixture completed the packet.\n STATUS: DONE\n' },
|
|
921
|
+
{ label: 'leading space BLOCKED', raw: 'Fixture could not verify the packet.\n STATUS: BLOCKED: missing evidence\n' },
|
|
922
|
+
{ label: 'leading space BLOCKED reason', raw: 'Fixture could not verify the packet.\nSTATUS: BLOCKED: missing evidence\n' },
|
|
923
|
+
{ label: 'non-ASCII trailing space DONE', raw: 'Fixture completed the packet.\nSTATUS: DONE\u00a0\n' },
|
|
924
|
+
{ label: 'non-ASCII trailing space BLOCKED', raw: 'Fixture could not verify the packet.\nSTATUS: BLOCKED: missing evidence\u00a0\n' },
|
|
925
|
+
{ label: 'nonterminal padded DONE', raw: 'Fixture completed the packet.\nSTATUS: DONE \nextra line\n' },
|
|
926
|
+
{ label: 'duplicate padded DONE', raw: 'Fixture completed the packet.\nSTATUS: DONE \nSTATUS: DONE\n' },
|
|
927
|
+
{ label: 'label without newline after padded STATUS', raw: 'Fixture completed the packet.\nSTATUS: DONE <!-- harness-label {"v":1,"validity":"actionable","tier":"tier2","intents":["fix"],"workflow":"iterative-single","skills":[]} -->\n' },
|
|
928
|
+
]) {
|
|
929
|
+
check(`441-A Codex refusal control (${label}) -> REPORT_INVALID`, () => {
|
|
930
|
+
const testCase = makeCase(`Codex refusal ${label}`);
|
|
931
|
+
const response = jsonResponse(cli([...argsFor(testCase), '--json'], testCase, { rawOverride: raw }), 16, 'REPORT_INVALID');
|
|
932
|
+
assert.equal(fs.readFileSync(response.evidence.rawOutput, 'utf8'), raw);
|
|
933
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
|
|
651
937
|
for (const scenario of ['missing-raw', 'no-status', 'multiple-status', 'bad-label']) {
|
|
652
938
|
check(`Codex ${scenario} -> REPORT_INVALID`, () => runReportInvalidCase('codex', scenario));
|
|
653
939
|
}
|
|
@@ -666,10 +952,1216 @@ try {
|
|
|
666
952
|
check('entry usage mentions every option used by the CLI contract', () => {
|
|
667
953
|
const testCase = makeCase('usage options');
|
|
668
954
|
const response = jsonResponse(cli(['--help', '--json'], testCase), 0, 'HELP');
|
|
669
|
-
for (const option of ['--runner', '--model', '--packet', '--worktree', '--scratch', '--report', '--effort', '--dry-run', '--json', '--help']) {
|
|
955
|
+
for (const option of ['--runner', '--model', '--packet', '--worktree', '--scratch', '--report', '--effort', '--assignment', '--admission-policy', '--dry-run', '--json', '--help']) {
|
|
670
956
|
assert.ok(response.message.includes(option), `usage is missing ${option}`);
|
|
671
957
|
}
|
|
672
958
|
});
|
|
959
|
+
|
|
960
|
+
// #466 D-gate: managed C8 structured gate assignment (rows G1-G7).
|
|
961
|
+
const defaultAdmissionDir = path.join(fixtureRoot, 'shared-admission-default');
|
|
962
|
+
const defaultAdmissionPolicy = path.join(fixtureRoot, 'default-admission-policy.json');
|
|
963
|
+
fs.writeFileSync(defaultAdmissionPolicy, JSON.stringify({
|
|
964
|
+
schemaVersion: 1,
|
|
965
|
+
dir: defaultAdmissionDir,
|
|
966
|
+
pools: {
|
|
967
|
+
'codex-pilot': { cap: 2 },
|
|
968
|
+
'opencode-pilot': { cap: 2 },
|
|
969
|
+
'agy-shared': { cap: 2 },
|
|
970
|
+
},
|
|
971
|
+
routes: [
|
|
972
|
+
{ runner: 'codex', model: 'fixture/codex-model', pool: 'codex-pilot' },
|
|
973
|
+
{ runner: 'opencode', model: 'fixture/opencode-model', pool: 'opencode-pilot' },
|
|
974
|
+
{ runner: 'agy', model: 'gemini-4-neon-medium', pool: 'agy-shared' },
|
|
975
|
+
],
|
|
976
|
+
}));
|
|
977
|
+
function writeAssignment(testCase, value, raw) {
|
|
978
|
+
const file = path.join(fixtureRoot, `assignment ${caseNumber}.json`);
|
|
979
|
+
fs.writeFileSync(file, raw !== undefined ? raw : JSON.stringify(value));
|
|
980
|
+
return file;
|
|
981
|
+
}
|
|
982
|
+
function managedArgs(testCase, assignment, runner = 'codex', admissionPolicy = defaultAdmissionPolicy) {
|
|
983
|
+
return [...argsFor(testCase, runner), '--assignment', assignment, ...(admissionPolicy === null ? [] : ['--admission-policy', admissionPolicy])];
|
|
984
|
+
}
|
|
985
|
+
function assertRefusedBeforeSpawn(testCase) {
|
|
986
|
+
assertNoRunner(testCase);
|
|
987
|
+
assertNoScratchOrReport(testCase);
|
|
988
|
+
}
|
|
989
|
+
const focused = [
|
|
990
|
+
{ id: 'node --test ci/mechanism-468-dispatch-cli.test.js', actor: 'worker' },
|
|
991
|
+
{ id: 'npm run test:consistency', actor: 'worker' },
|
|
992
|
+
];
|
|
993
|
+
|
|
994
|
+
for (const gate of ['verify:all', 'verify:all --fast']) {
|
|
995
|
+
check(`G1/G2 sandboxed codex worker gate "${gate}" -> GATE_REFUSED before probe/spawn`, () => {
|
|
996
|
+
const testCase = makeCase('gate sandboxed refusal');
|
|
997
|
+
const assignment = writeAssignment(testCase, { schemaVersion: 1, gates: [...focused, { id: gate, actor: 'worker' }] });
|
|
998
|
+
const response = jsonResponse(cli([...managedArgs(testCase, assignment), '--json'], testCase), 18, 'GATE_REFUSED');
|
|
999
|
+
assert.equal(response.phase, 'gate');
|
|
1000
|
+
assert.equal(response.evidence, undefined);
|
|
1001
|
+
assert.ok(response.message.includes(gate));
|
|
1002
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1003
|
+
const dry = jsonResponse(cli([...managedArgs(testCase, assignment), '--dry-run', '--json'], testCase), 18, 'GATE_REFUSED');
|
|
1004
|
+
assert.equal(dry.phase, 'gate');
|
|
1005
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1006
|
+
});
|
|
1007
|
+
check(`G1/G2 opencode (unsandboxed) worker gate "${gate}" is accepted by the profile`, () => {
|
|
1008
|
+
const testCase = makeCase('gate opencode accepted');
|
|
1009
|
+
const assignment = writeAssignment(testCase, { schemaVersion: 1, gates: [{ id: gate, actor: 'worker' }] });
|
|
1010
|
+
const response = jsonResponse(cli([...managedArgs(testCase, assignment, 'opencode'), '--dry-run', '--json'], testCase), 0, 'DRY_RUN_OK');
|
|
1011
|
+
assert.deepEqual(response.gates, { worker: [gate], coordinator: [] });
|
|
1012
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
for (const [label, value, raw] of [
|
|
1017
|
+
['not JSON', undefined, '{not json'],
|
|
1018
|
+
['array root', [], undefined],
|
|
1019
|
+
['wrong schemaVersion', { schemaVersion: 2, gates: [] }, undefined],
|
|
1020
|
+
['unknown top-level key', { schemaVersion: 1, gates: [], extra: true }, undefined],
|
|
1021
|
+
['missing gates', { schemaVersion: 1 }, undefined],
|
|
1022
|
+
['gates not an array', { schemaVersion: 1, gates: 'verify:all' }, undefined],
|
|
1023
|
+
['gate not an object', { schemaVersion: 1, gates: ['verify:all'] }, undefined],
|
|
1024
|
+
['unknown gate key', { schemaVersion: 1, gates: [{ id: 'npm run test:consistency', actor: 'worker', note: 'x' }] }, undefined],
|
|
1025
|
+
['unknown actor', { schemaVersion: 1, gates: [{ id: 'npm run test:consistency', actor: 'reviewer' }] }, undefined],
|
|
1026
|
+
['duplicate gate id', { schemaVersion: 1, gates: [{ id: 'npm run test:consistency', actor: 'worker' }, { id: 'npm run test:consistency', actor: 'coordinator' }] }, undefined],
|
|
1027
|
+
]) {
|
|
1028
|
+
check(`G3 malformed assignment (${label}) -> GATE_ASSIGNMENT_INVALID before spawn`, () => {
|
|
1029
|
+
const testCase = makeCase('gate malformed');
|
|
1030
|
+
const assignment = writeAssignment(testCase, value, raw);
|
|
1031
|
+
const response = jsonResponse(cli([...managedArgs(testCase, assignment), '--json'], testCase), 19, 'GATE_ASSIGNMENT_INVALID');
|
|
1032
|
+
assert.equal(response.phase, 'gate');
|
|
1033
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
check('G3 missing assignment file -> GATE_ASSIGNMENT_INVALID before spawn', () => {
|
|
1037
|
+
const testCase = makeCase('gate missing file');
|
|
1038
|
+
const response = jsonResponse(cli([...managedArgs(testCase, path.join(fixtureRoot, 'no-such-assignment.json')), '--json'], testCase), 19, 'GATE_ASSIGNMENT_INVALID');
|
|
1039
|
+
assert.equal(response.phase, 'gate');
|
|
1040
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
for (const id of ['npm run verify:all', 'verify:all --slow', 'gh pr checks', 'npm run test:unknown', 'node --test']) {
|
|
1044
|
+
check(`G4 unknown gate id "${id}" -> GATE_ASSIGNMENT_INVALID before spawn (either actor)`, () => {
|
|
1045
|
+
for (const actor of ['worker', 'coordinator']) {
|
|
1046
|
+
const testCase = makeCase('gate unknown id');
|
|
1047
|
+
const assignment = writeAssignment(testCase, { schemaVersion: 1, gates: [{ id, actor }] });
|
|
1048
|
+
const response = jsonResponse(cli([...managedArgs(testCase, assignment), '--json'], testCase), 19, 'GATE_ASSIGNMENT_INVALID');
|
|
1049
|
+
assert.ok(response.message.includes(id));
|
|
1050
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// #466 F4: focused node --test operand must be repo-relative and within the supported lexical path grammar.
|
|
1056
|
+
for (const [label, id] of [
|
|
1057
|
+
['absolute POSIX', 'node --test /tmp/outside-repo.js'],
|
|
1058
|
+
['POSIX UNC', 'node --test //server/share/outside.js'],
|
|
1059
|
+
['Windows drive slash', 'node --test C:/outside/test.js'],
|
|
1060
|
+
['Windows drive backslash', 'node --test C:\\outside\\test.js'],
|
|
1061
|
+
['Windows UNC backslash', 'node --test \\\\server\\share\\outside.js'],
|
|
1062
|
+
['leading traversal', 'node --test ../outside.js'],
|
|
1063
|
+
['mid-path traversal', 'node --test ci/../outside.js'],
|
|
1064
|
+
['dot segment', 'node --test ./ci/outside.js'],
|
|
1065
|
+
['empty segment', 'node --test ci//outside.js'],
|
|
1066
|
+
['bare extension', 'node --test .js'],
|
|
1067
|
+
]) {
|
|
1068
|
+
check(`F4 invalid focused node-test operand (${label}) -> GATE_ASSIGNMENT_INVALID on dry-run and normal dispatch`, () => {
|
|
1069
|
+
for (const dryRun of [true, false]) {
|
|
1070
|
+
const testCase = makeCase(`f4 ${label} ${dryRun ? 'dry' : 'live'}`);
|
|
1071
|
+
const admissionDir = path.join(fixtureRoot, `f4-admission-${caseNumber}`);
|
|
1072
|
+
const policy = writeAdmissionPolicy({
|
|
1073
|
+
schemaVersion: 1,
|
|
1074
|
+
dir: admissionDir,
|
|
1075
|
+
pools: { 'codex-f4': { cap: 1 } },
|
|
1076
|
+
routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'codex-f4' }],
|
|
1077
|
+
});
|
|
1078
|
+
const assignment = writeAssignment(testCase, { schemaVersion: 1, gates: [{ id, actor: 'worker' }] });
|
|
1079
|
+
const args = [...managedArgs(testCase, assignment, 'codex', policy), ...(dryRun ? ['--dry-run'] : []), '--json'];
|
|
1080
|
+
const response = jsonResponse(cli(args, testCase), 19, 'GATE_ASSIGNMENT_INVALID');
|
|
1081
|
+
assert.equal(response.phase, 'gate');
|
|
1082
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1083
|
+
assert.equal(fs.existsSync(admissionDir), false, 'refusal must precede admission reservation');
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
check('F4 positive control: repo-relative focused node-test operands + coordinator verify:all accepted', () => {
|
|
1089
|
+
const testCase = makeCase('f4 positive');
|
|
1090
|
+
const assignment = writeAssignment(testCase, {
|
|
1091
|
+
schemaVersion: 1,
|
|
1092
|
+
gates: [
|
|
1093
|
+
{ id: 'node --test ci/mechanism-468-dispatch-cli.test.js', actor: 'worker' },
|
|
1094
|
+
{ id: 'node --test root-test.js', actor: 'worker' },
|
|
1095
|
+
{ id: 'verify:all', actor: 'coordinator' },
|
|
1096
|
+
],
|
|
1097
|
+
});
|
|
1098
|
+
const dry = jsonResponse(cli([...managedArgs(testCase, assignment), '--dry-run', '--json'], testCase), 0, 'DRY_RUN_OK');
|
|
1099
|
+
assert.deepEqual(dry.gates, {
|
|
1100
|
+
worker: ['node --test ci/mechanism-468-dispatch-cli.test.js', 'node --test root-test.js'],
|
|
1101
|
+
coordinator: ['verify:all'],
|
|
1102
|
+
});
|
|
1103
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1106
|
+
for (const gate of ['verify:all', 'verify:all --fast']) {
|
|
1107
|
+
check(`G5 coordinator "${gate}" + focused worker checks -> one C8 attempt, checked report, no coordinator gate run`, () => {
|
|
1108
|
+
const testCase = makeCase('gate coordinator');
|
|
1109
|
+
const assignment = writeAssignment(testCase, { schemaVersion: 1, gates: [...focused, { id: gate, actor: 'coordinator' }] });
|
|
1110
|
+
const result = jsonResponse(cli([...managedArgs(testCase, assignment), '--json'], testCase), 0, 'DONE');
|
|
1111
|
+
assert.deepEqual(result.gates, { worker: focused.map(item => item.id), coordinator: [gate] });
|
|
1112
|
+
assert.equal(fs.readFileSync(result.evidence.report, 'utf8'), 'Fixture completed the packet.\nSTATUS: DONE\n');
|
|
1113
|
+
assert.match(fs.readFileSync(result.evidence.reportWriterLog, 'utf8'), /valid \(STATUS: DONE\)/);
|
|
1114
|
+
assert.ok(result.evidence.readinessLog && result.evidence.runLog && result.evidence.rawOutput);
|
|
1115
|
+
const actualEvents = events(testCase);
|
|
1116
|
+
assert.equal(actualEvents.length, 2, 'one readiness and one execution; the coordinator gate is never run');
|
|
1117
|
+
assert.deepEqual(actualEvents.map(event => event.phase), ['readiness', 'execution']);
|
|
1118
|
+
for (const event of actualEvents) assert.notEqual(event.runner, 'npm');
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
check('G6 managed --dry-run creates no files and spawns no child', () => {
|
|
1123
|
+
const testCase = makeCase('gate dry run');
|
|
1124
|
+
const assignment = writeAssignment(testCase, { schemaVersion: 1, gates: [...focused, { id: 'verify:all', actor: 'coordinator' }] });
|
|
1125
|
+
const response = jsonResponse(cli([...managedArgs(testCase, assignment), '--dry-run', '--json'], testCase), 0, 'DRY_RUN_OK');
|
|
1126
|
+
assert.deepEqual(response.gates, { worker: focused.map(item => item.id), coordinator: ['verify:all'] });
|
|
1127
|
+
assert.equal(response.evidence, undefined);
|
|
1128
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
check('G7 unmanaged invocation carries no gate fields', () => {
|
|
1132
|
+
const testCase = makeCase('gate unmanaged');
|
|
1133
|
+
const dry = jsonResponse(cli([...argsFor(testCase), '--dry-run', '--json'], testCase), 0, 'DRY_RUN_OK');
|
|
1134
|
+
assert.equal(dry.gates, undefined);
|
|
1135
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1136
|
+
});
|
|
1137
|
+
|
|
1138
|
+
// #466 D-scratch: managed C8 per-attempt TMPDIR + lifecycle (rows S1-S8).
|
|
1139
|
+
// In managed mode --scratch names the canonical external ROOT; each attempt gets attempt-* below it.
|
|
1140
|
+
function managedRoot(testCase) {
|
|
1141
|
+
fs.mkdirSync(testCase.scratch, { recursive: true });
|
|
1142
|
+
return testCase.scratch;
|
|
1143
|
+
}
|
|
1144
|
+
function attemptDirs(rootDir) {
|
|
1145
|
+
return fs.readdirSync(rootDir).filter(name => name.startsWith('attempt-'));
|
|
1146
|
+
}
|
|
1147
|
+
function managedAssignment(testCase) {
|
|
1148
|
+
return writeAssignment(testCase, { schemaVersion: 1, gates: [{ id: 'npm run test:consistency', actor: 'worker' }] });
|
|
1149
|
+
}
|
|
1150
|
+
function isInside(parent, child) {
|
|
1151
|
+
const parentReal = path.join(canonicalPath(path.dirname(parent)), path.basename(parent)); // parent may be removed already
|
|
1152
|
+
const rel = path.relative(parentReal, canonicalPath(child));
|
|
1153
|
+
return rel !== '' && !(rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel));
|
|
1154
|
+
}
|
|
1155
|
+
function runManaged(testCase, config = {}, runner = 'codex') {
|
|
1156
|
+
return cli([...managedArgs(testCase, managedAssignment(testCase), runner), '--json'], testCase, config);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
check('S1 managed attempt -> unique attempt dir under external root; child TMPDIR is that dir', () => {
|
|
1160
|
+
const testCase = makeCase('scratch s1');
|
|
1161
|
+
const rootDir = managedRoot(testCase);
|
|
1162
|
+
const response = jsonResponse(runManaged(testCase), 0, 'DONE');
|
|
1163
|
+
const tmpdirs = events(testCase).map(event => event.tmpdir);
|
|
1164
|
+
assert.equal(tmpdirs.length, 2);
|
|
1165
|
+
assert.equal(tmpdirs[0], tmpdirs[1], 'readiness and execution share the attempt dir');
|
|
1166
|
+
assert.notEqual(path.resolve(tmpdirs[0]), path.resolve(rootDir), 'TMPDIR must not be the bare root');
|
|
1167
|
+
assert.equal(path.dirname(tmpdirs[0]), path.resolve(rootDir));
|
|
1168
|
+
assert.match(path.basename(tmpdirs[0]), /^attempt-/);
|
|
1169
|
+
assert.ok(response.evidence.report);
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
for (const [label, rootFor] of [
|
|
1173
|
+
['git repo', () => path.join(worktree, 'managed-root')],
|
|
1174
|
+
['linked worktree', () => path.join(linkedWorktree, 'managed-root')],
|
|
1175
|
+
]) {
|
|
1176
|
+
check(`S2 managed root inside ${label} -> refused before child start; no directory`, () => {
|
|
1177
|
+
const testCase = makeCase('scratch s2');
|
|
1178
|
+
testCase.scratch = rootFor();
|
|
1179
|
+
const response = jsonResponse(runManaged(testCase), 11, 'UNSAFE_SCRATCH');
|
|
1180
|
+
assert.equal(response.phase, 'validation');
|
|
1181
|
+
assertNoRunner(testCase);
|
|
1182
|
+
assert.equal(fs.existsSync(testCase.scratch), false);
|
|
1183
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
check('S3 managed root symlink resolving into a repo -> refused before child start', () => {
|
|
1188
|
+
const testCase = makeCase('scratch s3');
|
|
1189
|
+
const link = path.join(fixtureRoot, `root link ${caseNumber}`);
|
|
1190
|
+
fs.symlinkSync(worktree, link, process.platform === 'win32' ? 'junction' : 'dir');
|
|
1191
|
+
testCase.scratch = path.join(link, 'managed-root');
|
|
1192
|
+
const response = jsonResponse(runManaged(testCase), 11, 'UNSAFE_SCRATCH');
|
|
1193
|
+
assert.equal(response.phase, 'validation');
|
|
1194
|
+
assertNoRunner(testCase);
|
|
1195
|
+
assert.equal(fs.existsSync(path.join(worktree, 'managed-root')), false);
|
|
1196
|
+
const direct = makeCase('scratch s3 link root');
|
|
1197
|
+
direct.scratch = link;
|
|
1198
|
+
jsonResponse(runManaged(direct), 11, 'UNSAFE_SCRATCH');
|
|
1199
|
+
assertNoRunner(direct);
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
// #466 F3: dangling symlink or unresolved symlink chain at root or ancestor refuses before any writes or slot creation.
|
|
1203
|
+
check('F3 dangling symlink and unresolved chain for --scratch and admission.dir -> refused in dry-run and normal dispatch', () => {
|
|
1204
|
+
const danglingIntoRepo = path.join(fixtureRoot, `f3-dangling-repo-${caseNumber}`);
|
|
1205
|
+
const danglingExternal = path.join(fixtureRoot, `f3-dangling-ext-${caseNumber}`);
|
|
1206
|
+
const chainHop2 = path.join(fixtureRoot, `f3-chain-hop2-${caseNumber}`);
|
|
1207
|
+
const chainHop1 = path.join(fixtureRoot, `f3-chain-hop1-${caseNumber}`);
|
|
1208
|
+
const linkType = process.platform === 'win32' ? 'junction' : 'dir';
|
|
1209
|
+
fs.symlinkSync(path.join(worktree, 'nonexistent-sub'), danglingIntoRepo, linkType);
|
|
1210
|
+
fs.symlinkSync(path.join(fixtureRoot, 'nonexistent-ext-target'), danglingExternal, linkType);
|
|
1211
|
+
fs.symlinkSync(path.join(worktree, 'nonexistent-chain-target'), chainHop2, linkType);
|
|
1212
|
+
fs.symlinkSync(chainHop2, chainHop1, linkType);
|
|
1213
|
+
|
|
1214
|
+
const badRoots = [
|
|
1215
|
+
['dangling-into-repo root', danglingIntoRepo],
|
|
1216
|
+
['dangling-into-repo descendant', path.join(danglingIntoRepo, 'child')],
|
|
1217
|
+
['dangling-external root', danglingExternal],
|
|
1218
|
+
['dangling-external descendant', path.join(danglingExternal, 'child')],
|
|
1219
|
+
['unresolved-chain root', chainHop1],
|
|
1220
|
+
['unresolved-chain descendant', path.join(chainHop1, 'child')],
|
|
1221
|
+
];
|
|
1222
|
+
|
|
1223
|
+
for (const [label, badPath] of badRoots) {
|
|
1224
|
+
for (const dryRun of [true, false]) {
|
|
1225
|
+
// Scratch refusal: 11 UNSAFE_SCRATCH before admission slot, scratch, report, or child creation.
|
|
1226
|
+
const sc = makeCase(`f3 scratch ${label} ${dryRun ? 'dry' : 'live'}`);
|
|
1227
|
+
sc.scratch = badPath;
|
|
1228
|
+
const freshAdmissionDir = path.join(fixtureRoot, `f3-sc-adm-${caseNumber}`);
|
|
1229
|
+
const policy = writeAdmissionPolicy({
|
|
1230
|
+
schemaVersion: 1,
|
|
1231
|
+
dir: freshAdmissionDir,
|
|
1232
|
+
pools: { 'codex-f3': { cap: 1 } },
|
|
1233
|
+
routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'codex-f3' }],
|
|
1234
|
+
});
|
|
1235
|
+
const scArgs = [...managedArgs(sc, managedAssignment(sc), 'codex', policy), ...(dryRun ? ['--dry-run'] : []), '--json'];
|
|
1236
|
+
const scRes = jsonResponse(cli(scArgs, sc), 11, 'UNSAFE_SCRATCH');
|
|
1237
|
+
assert.equal(scRes.phase, 'validation', `scratch ${label} dry=${dryRun}`);
|
|
1238
|
+
assertNoRunner(sc);
|
|
1239
|
+
assert.equal(fs.existsSync(sc.report), false);
|
|
1240
|
+
assert.equal(fs.existsSync(freshAdmissionDir), false, `scratch ${label} dry=${dryRun}: must not create admission dir`);
|
|
1241
|
+
|
|
1242
|
+
// Admission dir refusal: 21 ADMISSION_POLICY_INVALID before slot, scratch, report, or child creation.
|
|
1243
|
+
const ac = makeCase(`f3 admission ${label} ${dryRun ? 'dry' : 'live'}`);
|
|
1244
|
+
const badPolicy = writeAdmissionPolicy({
|
|
1245
|
+
schemaVersion: 1,
|
|
1246
|
+
dir: badPath,
|
|
1247
|
+
pools: { 'codex-f3': { cap: 1 } },
|
|
1248
|
+
routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'codex-f3' }],
|
|
1249
|
+
});
|
|
1250
|
+
const acArgs = [...managedArgs(ac, managedAssignment(ac), 'codex', badPolicy), ...(dryRun ? ['--dry-run'] : []), '--json'];
|
|
1251
|
+
const acRes = jsonResponse(cli(acArgs, ac), 21, 'ADMISSION_POLICY_INVALID');
|
|
1252
|
+
assert.equal(acRes.phase, 'admission', `admission ${label} dry=${dryRun}`);
|
|
1253
|
+
assertNoRunner(ac);
|
|
1254
|
+
assertNoScratchOrReport(ac);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
// Positive controls: safe external root and non-existing directory under a safe real parent.
|
|
1259
|
+
const safeParent = path.join(fixtureRoot, `f3-safe-parent-${caseNumber}`);
|
|
1260
|
+
fs.mkdirSync(safeParent, { recursive: true });
|
|
1261
|
+
const posCase = makeCase('f3 positive non-existing under safe parent');
|
|
1262
|
+
posCase.scratch = path.join(safeParent, 'new-scratch-child');
|
|
1263
|
+
const posAdmissionDir = path.join(safeParent, 'new-admission-child');
|
|
1264
|
+
const posPolicy = writeAdmissionPolicy({
|
|
1265
|
+
schemaVersion: 1,
|
|
1266
|
+
dir: posAdmissionDir,
|
|
1267
|
+
pools: { 'codex-f3': { cap: 1 } },
|
|
1268
|
+
routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'codex-f3' }],
|
|
1269
|
+
});
|
|
1270
|
+
const posDry = jsonResponse(cli([...managedArgs(posCase, managedAssignment(posCase), 'codex', posPolicy), '--dry-run', '--json'], posCase), 0, 'DRY_RUN_OK');
|
|
1271
|
+
assert.deepEqual(posDry.admission, { pool: 'codex-f3', cap: 1 });
|
|
1272
|
+
assert.equal(fs.existsSync(posCase.scratch), false);
|
|
1273
|
+
assert.equal(fs.existsSync(posAdmissionDir), false);
|
|
1274
|
+
const posLive = jsonResponse(cli([...managedArgs(posCase, managedAssignment(posCase), 'codex', posPolicy), '--json'], posCase), 0, 'DONE');
|
|
1275
|
+
assert.deepEqual(posLive.admission, { pool: 'codex-f3', cap: 1, slot: 0 });
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
check('S4 two concurrent managed attempts on one root -> distinct attempt dirs', () => {
|
|
1279
|
+
const first = makeCase('scratch s4 a');
|
|
1280
|
+
const second = makeCase('scratch s4 b');
|
|
1281
|
+
second.scratch = first.scratch;
|
|
1282
|
+
const rootDir = managedRoot(first);
|
|
1283
|
+
const assignment = managedAssignment(first);
|
|
1284
|
+
const outputs = [first, second].map((testCase, index) => {
|
|
1285
|
+
const file = path.join(fixtureRoot, `s4 out ${caseNumber} ${index}.json`);
|
|
1286
|
+
const fd = fs.openSync(file, 'w');
|
|
1287
|
+
const child = spawn(process.execPath, [entry, ...managedArgs(testCase, assignment), '--json'], { cwd: root, env: cliEnv(testCase), stdio: ['ignore', fd, fd] });
|
|
1288
|
+
return { testCase, file, child, fd };
|
|
1289
|
+
});
|
|
1290
|
+
const deadline = Date.now() + 20000;
|
|
1291
|
+
const wait = new Int32Array(new SharedArrayBuffer(4));
|
|
1292
|
+
const done = item => { const text = fs.readFileSync(item.file, 'utf8'); return text.endsWith('\n') ? JSON.parse(text) : null; };
|
|
1293
|
+
while (outputs.some(item => !done(item)) && Date.now() < deadline) Atomics.wait(wait, 0, 0, 25);
|
|
1294
|
+
for (const item of outputs) { fs.closeSync(item.fd); item.child.kill('SIGKILL'); }
|
|
1295
|
+
for (const item of outputs) assert.equal(done(item)?.code, 'DONE', fs.readFileSync(item.file, 'utf8'));
|
|
1296
|
+
const dirs = outputs.flatMap(item => events(item.testCase).map(event => event.tmpdir));
|
|
1297
|
+
assert.equal(dirs.length, 4);
|
|
1298
|
+
assert.equal(new Set(dirs).size, 2, `attempts must not share a TMPDIR: ${dirs.join(', ')}`);
|
|
1299
|
+
for (const dir of dirs) assert.equal(path.dirname(dir), path.resolve(rootDir));
|
|
1300
|
+
});
|
|
1301
|
+
|
|
1302
|
+
check('S5 checked DONE -> evidence retained at stable paths outside the run dir, then only its own dir removed', () => {
|
|
1303
|
+
const testCase = makeCase('scratch s5');
|
|
1304
|
+
const rootDir = managedRoot(testCase);
|
|
1305
|
+
const sibling = path.join(rootDir, 'attempt-someone-else');
|
|
1306
|
+
fs.mkdirSync(sibling);
|
|
1307
|
+
fs.writeFileSync(path.join(sibling, 'keep.txt'), 'another attempt\n');
|
|
1308
|
+
const response = jsonResponse(runManaged(testCase), 0, 'DONE');
|
|
1309
|
+
const attempt = events(testCase)[0].tmpdir;
|
|
1310
|
+
assert.equal(fs.existsSync(attempt), false, 'own attempt dir is removed');
|
|
1311
|
+
assert.equal(fs.readFileSync(path.join(sibling, 'keep.txt'), 'utf8'), 'another attempt\n', 'foreign attempt dir is untouched');
|
|
1312
|
+
assert.deepEqual(attemptDirs(rootDir), ['attempt-someone-else']);
|
|
1313
|
+
for (const key of ['readinessOutput', 'readinessLog', 'rawOutput', 'runLog', 'reportWriterLog', 'report']) {
|
|
1314
|
+
assert.ok(response.evidence[key], `evidence.${key} must be reported`);
|
|
1315
|
+
assert.ok(fs.existsSync(response.evidence[key]), `evidence.${key} must exist after cleanup`);
|
|
1316
|
+
assert.equal(isInside(attempt, response.evidence[key]), false, `evidence.${key} must be outside the removed dir`);
|
|
1317
|
+
}
|
|
1318
|
+
assert.match(fs.readFileSync(response.evidence.reportWriterLog, 'utf8'), /valid \(STATUS: DONE\)/);
|
|
1319
|
+
assert.match(fs.readFileSync(response.evidence.rawOutput, 'utf8'), /STATUS: DONE/);
|
|
1320
|
+
assert.equal(fs.readFileSync(response.evidence.report, 'utf8'), 'Fixture completed the packet.\nSTATUS: DONE\n');
|
|
1321
|
+
});
|
|
1322
|
+
|
|
1323
|
+
for (const [label, config, exitCode, code, runner] of [
|
|
1324
|
+
['BLOCKED report', { execution: 'blocked' }, 17, 'WORKER_BLOCKED', 'codex'],
|
|
1325
|
+
['runner failure', { execution: 'exit-failure' }, 15, 'RUN_FAILED', 'codex'],
|
|
1326
|
+
['invalid report', { execution: 'no-status' }, 16, 'REPORT_INVALID', 'codex'],
|
|
1327
|
+
['readiness failure', { readiness: 'ready-failed' }, 12, 'NOT_READY', 'codex'],
|
|
1328
|
+
['opencode BLOCKED report', { execution: 'blocked' }, 17, 'WORKER_BLOCKED', 'opencode'],
|
|
1329
|
+
]) {
|
|
1330
|
+
check(`S6 ${label} -> attempt dir and evidence kept`, () => {
|
|
1331
|
+
const testCase = makeCase('scratch s6');
|
|
1332
|
+
const rootDir = managedRoot(testCase);
|
|
1333
|
+
const response = jsonResponse(runManaged(testCase, config, runner), exitCode, code);
|
|
1334
|
+
const dirs = attemptDirs(rootDir);
|
|
1335
|
+
assert.equal(dirs.length, 1, 'attempt dir is preserved');
|
|
1336
|
+
assert.ok(response.evidence.readinessLog, 'evidence reported');
|
|
1337
|
+
for (const value of Object.values(response.evidence)) assert.ok(fs.existsSync(value));
|
|
1338
|
+
assert.ok(isInside(path.join(rootDir, dirs[0]), response.evidence.readinessLog), 'evidence stays in the kept dir');
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
check('S6 evidence-retention failure on a checked DONE -> attempt dir and evidence kept, nonzero exit', () => {
|
|
1343
|
+
const testCase = makeCase('scratch s6 retention');
|
|
1344
|
+
const rootDir = managedRoot(testCase);
|
|
1345
|
+
fs.writeFileSync(path.join(rootDir, 'retained'), 'a file blocks the retention directory\n');
|
|
1346
|
+
const response = jsonResponse(runManaged(testCase), 20, 'EVIDENCE_RETENTION_FAILED');
|
|
1347
|
+
assert.equal(response.phase, 'retention');
|
|
1348
|
+
const dirs = attemptDirs(rootDir);
|
|
1349
|
+
assert.equal(dirs.length, 1);
|
|
1350
|
+
assert.ok(isInside(path.join(rootDir, dirs[0]), response.evidence.runLog));
|
|
1351
|
+
assert.ok(isInside(path.join(rootDir, dirs[0]), response.evidence.rawOutput));
|
|
1352
|
+
assert.equal(fs.readFileSync(response.evidence.report, 'utf8'), 'Fixture completed the packet.\nSTATUS: DONE\n');
|
|
1353
|
+
});
|
|
1354
|
+
|
|
1355
|
+
check('S7 managed --dry-run -> no root, no attempt dir, no child', () => {
|
|
1356
|
+
const testCase = makeCase('scratch s7');
|
|
1357
|
+
const response = jsonResponse(cli([...managedArgs(testCase, managedAssignment(testCase)), '--dry-run', '--json'], testCase), 0, 'DRY_RUN_OK');
|
|
1358
|
+
assert.equal(response.evidence, undefined);
|
|
1359
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
check('S8 unmanaged DONE is unchanged: TMPDIR is --scratch itself, evidence stays in it, nothing removed', () => {
|
|
1363
|
+
const testCase = makeCase('scratch s8');
|
|
1364
|
+
const response = jsonResponse(cli([...argsFor(testCase), '--json'], testCase), 0, 'DONE');
|
|
1365
|
+
for (const event of events(testCase)) assert.equal(event.tmpdir, testCase.scratch);
|
|
1366
|
+
assert.deepEqual(fs.readdirSync(testCase.scratch).filter(name => name.startsWith('attempt-') || name === 'retained'), []);
|
|
1367
|
+
for (const key of ['readinessLog', 'rawOutput', 'runLog', 'reportWriterLog']) assert.equal(path.dirname(response.evidence[key]), testCase.scratch);
|
|
1368
|
+
const failed = makeCase('scratch s8 failed');
|
|
1369
|
+
jsonResponse(cli([...argsFor(failed), '--json'], failed, { execution: 'blocked' }), 17, 'WORKER_BLOCKED');
|
|
1370
|
+
assert.equal(fs.existsSync(failed.scratch), true);
|
|
1371
|
+
});
|
|
1372
|
+
|
|
1373
|
+
// #466 D-agy: managed C8 agy runner adapter (rows A1-A10).
|
|
1374
|
+
const agyWorkDir = path.join(worktree, '.w');
|
|
1375
|
+
fs.mkdirSync(agyWorkDir, { recursive: true });
|
|
1376
|
+
const agySettings = '{"permissions":{"allow":["command(*)","read_file(*)"]}}';
|
|
1377
|
+
function makeAgyCase(label) {
|
|
1378
|
+
caseNumber += 1;
|
|
1379
|
+
const reportRel = `.w/report-${caseNumber}-${label.replace(/[^A-Za-z0-9_-]+/g, '-')}.md`;
|
|
1380
|
+
return {
|
|
1381
|
+
scratch: path.join(fixtureRoot, `scratch ${caseNumber} ${label}`),
|
|
1382
|
+
report: path.join(worktree, reportRel),
|
|
1383
|
+
reportRel,
|
|
1384
|
+
packetRel: 'packet with spaces.md',
|
|
1385
|
+
log: path.join(fixtureRoot, `runner events ${caseNumber}.jsonl`),
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
function agyArgsFor(testCase, model = 'gemini-4-neon-medium') {
|
|
1389
|
+
return [
|
|
1390
|
+
'--runner', 'agy',
|
|
1391
|
+
'--model', model,
|
|
1392
|
+
'--packet', testCase.packetRel,
|
|
1393
|
+
'--worktree', worktree,
|
|
1394
|
+
'--scratch', testCase.scratch,
|
|
1395
|
+
'--report', testCase.reportRel,
|
|
1396
|
+
];
|
|
1397
|
+
}
|
|
1398
|
+
function assertAgyArgv(argv, model, prompt, timeoutSeconds) {
|
|
1399
|
+
assert.deepEqual(argv, [
|
|
1400
|
+
'-p', prompt,
|
|
1401
|
+
'--model', model,
|
|
1402
|
+
'--mode', 'accept-edits',
|
|
1403
|
+
'--sandbox',
|
|
1404
|
+
'--settings', agySettings,
|
|
1405
|
+
'--print-timeout', `${timeoutSeconds}s`,
|
|
1406
|
+
]);
|
|
1407
|
+
}
|
|
1408
|
+
function assertAgyEvent(event, testCase, phase, model = 'gemini-4-neon-medium') {
|
|
1409
|
+
assert.equal(event.runner, 'agy');
|
|
1410
|
+
assert.equal(event.phase, phase);
|
|
1411
|
+
assertSameCanonicalPath(event.cwd, worktree, 'agy child cwd must resolve to the selected clone');
|
|
1412
|
+
assert.equal(event.stdin, '');
|
|
1413
|
+
assert.equal(event.stdinIsCharacterDevice, true);
|
|
1414
|
+
const expectedPrompt = phase === 'readiness'
|
|
1415
|
+
? 'Reply with the single word READY'
|
|
1416
|
+
: `Execute the packet at ${testCase.packetRel} and write the complete report to ${testCase.reportRel}. Use only paths relative to the current directory.`;
|
|
1417
|
+
assertAgyArgv(event.args, model, expectedPrompt, phase === 'readiness' ? 120 : 2700);
|
|
1418
|
+
if (phase === 'execution') {
|
|
1419
|
+
assert.equal(expectedPrompt.includes(worktree), false, 'agy prompt must use cwd-relative paths');
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
check('A1 agy DONE -> pinned headless argv, cwd = clone, stdin closed, cwd-relative paths, sandbox requested', () => {
|
|
1424
|
+
const testCase = makeAgyCase('agy a1');
|
|
1425
|
+
const args = agyArgsFor(testCase, 'gemini-4-neon-medium');
|
|
1426
|
+
const dryRun = jsonResponse(cli([...args, '--dry-run', '--json'], testCase), 0, 'DRY_RUN_OK');
|
|
1427
|
+
assert.equal(dryRun.runner, 'agy');
|
|
1428
|
+
assert.equal(dryRun.model, 'gemini-4-neon-medium');
|
|
1429
|
+
assert.equal(dryRun.sandbox, 'requested');
|
|
1430
|
+
assertSameCanonicalPath(dryRun.cwd, worktree);
|
|
1431
|
+
assert.equal(dryRun.argv[0], 'agy');
|
|
1432
|
+
const expectedPrompt = `Execute the packet at ${testCase.packetRel} and write the complete report to ${testCase.reportRel}. Use only paths relative to the current directory.`;
|
|
1433
|
+
assertAgyArgv(dryRun.argv.slice(1), 'gemini-4-neon-medium', expectedPrompt, 2700);
|
|
1434
|
+
assertNoRunner(testCase);
|
|
1435
|
+
assertNoScratchOrReport(testCase);
|
|
1436
|
+
|
|
1437
|
+
const assignment = managedAssignment(testCase);
|
|
1438
|
+
const response = jsonResponse(cli([...args, '--assignment', assignment, '--admission-policy', defaultAdmissionPolicy, '--json'], testCase, { readiness: 'ready-host-label' }), 0, 'DONE');
|
|
1439
|
+
assert.equal(response.runner, 'agy');
|
|
1440
|
+
assert.equal(response.model, 'gemini-4-neon-medium');
|
|
1441
|
+
assert.equal(response.sandbox, 'requested');
|
|
1442
|
+
assert.equal(fs.readFileSync(response.evidence.report, 'utf8'), 'Fixture completed the packet.\nSTATUS: DONE\n');
|
|
1443
|
+
const actualEvents = events(testCase);
|
|
1444
|
+
assert.equal(actualEvents.length, 2, 'one readiness and one execution');
|
|
1445
|
+
assertAgyEvent(actualEvents[0], testCase, 'readiness', 'gemini-4-neon-medium');
|
|
1446
|
+
assertAgyEvent(actualEvents[1], testCase, 'execution', 'gemini-4-neon-medium');
|
|
1447
|
+
assert.deepEqual(dryRun.argv, ['agy', ...actualEvents[1].args]);
|
|
1448
|
+
assert.ok(fs.existsSync(response.evidence.runLog));
|
|
1449
|
+
assert.ok(fs.existsSync(response.evidence.readinessLog));
|
|
1450
|
+
});
|
|
1451
|
+
|
|
1452
|
+
check('A1 agy rejects packet or report outside worktree (cwd-relative worker path guard)', () => {
|
|
1453
|
+
const testCase = makeAgyCase('agy outside report');
|
|
1454
|
+
const outsideReport = path.join(reports, `agy-outside-${caseNumber}.md`);
|
|
1455
|
+
const args = agyArgsFor(testCase);
|
|
1456
|
+
args[args.indexOf('--report') + 1] = outsideReport;
|
|
1457
|
+
const response = jsonResponse(cli([...args, '--json'], testCase), 10, 'INVALID_INPUT');
|
|
1458
|
+
assert.equal(response.phase, 'input');
|
|
1459
|
+
assert.match(response.message, /must be inside --worktree for agy/);
|
|
1460
|
+
assertNoRunner(testCase);
|
|
1461
|
+
});
|
|
1462
|
+
|
|
1463
|
+
check('A2 agy valid BLOCKED report -> WORKER_BLOCKED with reason and kept evidence', () => {
|
|
1464
|
+
const testCase = makeAgyCase('agy a2');
|
|
1465
|
+
const assignment = managedAssignment(testCase);
|
|
1466
|
+
const response = jsonResponse(cli([...agyArgsFor(testCase), '--assignment', assignment, '--admission-policy', defaultAdmissionPolicy, '--json'], testCase, { execution: 'blocked' }), 17, 'WORKER_BLOCKED');
|
|
1467
|
+
assert.equal(response.runner, 'agy');
|
|
1468
|
+
assert.equal(response.sandbox, 'requested');
|
|
1469
|
+
assert.match(response.message, /missing evidence/);
|
|
1470
|
+
assert.match(fs.readFileSync(testCase.report, 'utf8'), /STATUS: BLOCKED: missing evidence/);
|
|
1471
|
+
assert.ok(fs.existsSync(response.evidence.runLog));
|
|
1472
|
+
});
|
|
1473
|
+
|
|
1474
|
+
check('A3 agy exit 0 without report (permission-denied log line) -> REPORT_INVALID, log retained', () => {
|
|
1475
|
+
const testCase = makeAgyCase('agy a3');
|
|
1476
|
+
const response = jsonResponse(cli([...agyArgsFor(testCase), '--json'], testCase, { execution: 'permission-denied' }), 16, 'REPORT_INVALID');
|
|
1477
|
+
assert.equal(events(testCase).length, 2);
|
|
1478
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
1479
|
+
assert.ok(response.evidence.runLog && fs.existsSync(response.evidence.runLog));
|
|
1480
|
+
assert.match(fs.readFileSync(response.evidence.runLog, 'utf8'), /jetski: no output produced/);
|
|
1481
|
+
});
|
|
1482
|
+
|
|
1483
|
+
check('A4 agy stale/pre-existing report -> delivery failure (pre-existing and created-during-readiness)', () => {
|
|
1484
|
+
const pre = makeAgyCase('agy a4 pre');
|
|
1485
|
+
fs.writeFileSync(pre.report, 'Old report.\nSTATUS: DONE\n');
|
|
1486
|
+
jsonResponse(cli([...agyArgsFor(pre), '--json'], pre), 10, 'INVALID_INPUT');
|
|
1487
|
+
assertNoRunner(pre);
|
|
1488
|
+
|
|
1489
|
+
const during = makeAgyCase('agy a4 readiness');
|
|
1490
|
+
jsonResponse(cli([...agyArgsFor(during), '--json'], during, { readiness: 'create-stale-report' }), 16, 'REPORT_INVALID');
|
|
1491
|
+
const actualEvents = events(during);
|
|
1492
|
+
assert.equal(actualEvents.length, 1, 'stale report during readiness must block execution');
|
|
1493
|
+
assert.equal(actualEvents[0].phase, 'readiness');
|
|
1494
|
+
});
|
|
1495
|
+
|
|
1496
|
+
// I544: the retired single-line `429 RESOURCE_EXHAUSTED … Resets in …` positive is replaced by the
|
|
1497
|
+
// captured diagnostic pair. Live-backed stderr, fixture exit status; see agy-quota-PROVENANCE.md.
|
|
1498
|
+
check('A5 agy captured Third-party pair -> RUNNER_QUOTA at managed readiness with retained evidence', () => {
|
|
1499
|
+
const ready = makeAgyCase('agy a5 third-party readiness');
|
|
1500
|
+
const rq = jsonResponse(cli(
|
|
1501
|
+
[...agyArgsFor(ready), '--assignment', managedAssignment(ready), '--admission-policy', defaultAdmissionPolicy, '--json'],
|
|
1502
|
+
ready,
|
|
1503
|
+
{ readiness: 'agy-quota-pair', extraEnv: { DISPATCH_FIXTURE_STDERR: thirdPartyPair } },
|
|
1504
|
+
), 13, 'RUNNER_QUOTA');
|
|
1505
|
+
assert.equal(rq.phase, 'readiness');
|
|
1506
|
+
assert.equal(events(ready).length, 1, 'readiness quota starts no execution');
|
|
1507
|
+
assert.equal(rq.evidence.runLog, undefined);
|
|
1508
|
+
const readyLog = fs.readFileSync(rq.evidence.readinessLog, 'utf8');
|
|
1509
|
+
assert.ok(readyLog.includes('[stderr]'));
|
|
1510
|
+
assert.ok(readyLog.includes('error: Third-party quota reached.'));
|
|
1511
|
+
assert.ok(readyLog.includes('"status":"RESOURCE_EXHAUSTED"'));
|
|
1512
|
+
assert.ok(readyLog.includes('"error_code":429'));
|
|
1513
|
+
assert.equal(fs.existsSync(path.join(defaultAdmissionDir, 'agy-shared', 'slot-0.json')), false, 'slot released after readiness quota');
|
|
1514
|
+
});
|
|
1515
|
+
|
|
1516
|
+
check('A5 agy captured Individual pair -> RUNNER_QUOTA at managed execution with retained evidence', () => {
|
|
1517
|
+
const exec = makeAgyCase('agy a5 individual execution');
|
|
1518
|
+
managedRoot(exec);
|
|
1519
|
+
const eq = jsonResponse(cli(
|
|
1520
|
+
[...agyArgsFor(exec), '--assignment', managedAssignment(exec), '--admission-policy', defaultAdmissionPolicy, '--json'],
|
|
1521
|
+
exec,
|
|
1522
|
+
{ execution: 'agy-quota-pair', extraEnv: { DISPATCH_FIXTURE_STDERR: execIndividualPair } },
|
|
1523
|
+
), 13, 'RUNNER_QUOTA');
|
|
1524
|
+
assert.equal(eq.phase, 'execution');
|
|
1525
|
+
assert.equal(events(exec).length, 2, 'one readiness and one execution; no retry');
|
|
1526
|
+
const attempt = events(exec)[0].tmpdir;
|
|
1527
|
+
assert.ok(fs.existsSync(attempt), 'attempt dir and evidence kept on quota failure');
|
|
1528
|
+
assert.ok(isInside(attempt, eq.evidence.runLog));
|
|
1529
|
+
const runLog = fs.readFileSync(eq.evidence.runLog, 'utf8');
|
|
1530
|
+
assert.ok(runLog.includes('[stderr]'));
|
|
1531
|
+
assert.ok(runLog.includes('error: Individual quota reached.'));
|
|
1532
|
+
assert.ok(runLog.includes('"status":"RESOURCE_EXHAUSTED"'));
|
|
1533
|
+
assert.equal(fs.existsSync(exec.report), false, 'quota execution created no fresh report');
|
|
1534
|
+
assert.equal(fs.existsSync(path.join(defaultAdmissionDir, 'agy-shared', 'slot-0.json')), false, 'slot released after execution quota');
|
|
1535
|
+
});
|
|
1536
|
+
|
|
1537
|
+
check('A5 agy direct Individual exit-3 pair -> RUNNER_QUOTA at both phases', () => {
|
|
1538
|
+
// Direct Individual exit 3 (live-backed status) is classified at both phases too.
|
|
1539
|
+
const directReady = makeAgyCase('agy a5 direct individual readiness');
|
|
1540
|
+
const dr = jsonResponse(cli([...agyArgsFor(directReady), '--json'], directReady, {
|
|
1541
|
+
readiness: 'agy-quota-pair', extraEnv: { DISPATCH_FIXTURE_STDERR: individualPair },
|
|
1542
|
+
}), 13, 'RUNNER_QUOTA');
|
|
1543
|
+
assert.equal(dr.phase, 'readiness');
|
|
1544
|
+
assert.equal(events(directReady).length, 1);
|
|
1545
|
+
const directExec = makeAgyCase('agy a5 direct individual execution');
|
|
1546
|
+
const de = jsonResponse(cli([...agyArgsFor(directExec), '--json'], directExec, {
|
|
1547
|
+
execution: 'agy-quota-pair', extraEnv: { DISPATCH_FIXTURE_STDERR: individualPair },
|
|
1548
|
+
}), 13, 'RUNNER_QUOTA');
|
|
1549
|
+
assert.equal(de.phase, 'execution');
|
|
1550
|
+
assert.equal(events(directExec).length, 2);
|
|
1551
|
+
});
|
|
1552
|
+
|
|
1553
|
+
check('A5 agy ambiguous, malformed, partial or unsupported diagnostics keep 12/15', () => {
|
|
1554
|
+
const pair = (errorLine, jsonLine) => `${errorLine}\n${jsonLine}\n`;
|
|
1555
|
+
const businessError = individualErrorLine.replace('Individual quota reached', 'Business quota reached');
|
|
1556
|
+
const controls = [
|
|
1557
|
+
['unsupported pool', pair(businessError, individualJsonLine.replace('Individual quota reached', 'Business quota reached'))],
|
|
1558
|
+
['contradictory pools', pair(individualErrorLine, individualJsonLine.replace('Individual quota reached', 'Third-party quota reached'))],
|
|
1559
|
+
['duplicate error line', `${individualErrorLine}\n${individualErrorLine}\n${individualJsonLine}\n`],
|
|
1560
|
+
['duplicate envelope', `${individualErrorLine}\n${individualJsonLine}\n${individualJsonLine}\n`],
|
|
1561
|
+
['duplicate malformed envelope', `${individualErrorLine}\nAGY_ERROR: not-json\n${individualJsonLine}\n`],
|
|
1562
|
+
['malformed JSON', `${individualErrorLine}\nAGY_ERROR: {"status":"RESOURCE_EXHAUSTED"\n`],
|
|
1563
|
+
['string error_code', pair(individualErrorLine, individualJsonLine.replace('"error_code":429', '"error_code":"429"'))],
|
|
1564
|
+
['wrong status', pair(individualErrorLine, individualJsonLine.replace('"status":"RESOURCE_EXHAUSTED"', '"status":"QUOTA_EXCEEDED"'))],
|
|
1565
|
+
['generic 429', pair('429 Too Many Requests', individualJsonLine)],
|
|
1566
|
+
['quoted 429', pair('Quoted text: 429 RESOURCE_EXHAUSTED: Quota exceeded. Resets in 2h 15m.', individualJsonLine)],
|
|
1567
|
+
['retired single line', retiredAgyQuotaLine],
|
|
1568
|
+
['partial error line', `${individualErrorLine}\n`],
|
|
1569
|
+
['partial envelope', `${individualJsonLine}\n`],
|
|
1570
|
+
['wrong stream', individualJsonLine + '\n'],
|
|
1571
|
+
];
|
|
1572
|
+
for (const [label, stderr] of controls) {
|
|
1573
|
+
const readyTc = makeAgyCase(`agy a5 refusal ready ${label}`);
|
|
1574
|
+
const readyRes = jsonResponse(cli([...agyArgsFor(readyTc), '--json'], readyTc, {
|
|
1575
|
+
readiness: 'agy-quota-pair',
|
|
1576
|
+
extraEnv: {
|
|
1577
|
+
DISPATCH_FIXTURE_STDERR: stderr,
|
|
1578
|
+
...(label === 'wrong stream' ? { DISPATCH_FIXTURE_STDOUT: `${individualErrorLine}\n` } : {}),
|
|
1579
|
+
},
|
|
1580
|
+
}), 12, 'NOT_READY');
|
|
1581
|
+
assert.equal(readyRes.phase, 'readiness', label);
|
|
1582
|
+
assert.equal(events(readyTc).length, 1, label);
|
|
1583
|
+
|
|
1584
|
+
const execTc = makeAgyCase(`agy a5 refusal exec ${label}`);
|
|
1585
|
+
const execRes = jsonResponse(cli([...agyArgsFor(execTc), '--json'], execTc, {
|
|
1586
|
+
execution: 'agy-quota-pair',
|
|
1587
|
+
extraEnv: {
|
|
1588
|
+
DISPATCH_FIXTURE_STDERR: stderr,
|
|
1589
|
+
...(label === 'wrong stream' ? { DISPATCH_FIXTURE_STDOUT: `${individualErrorLine}\n` } : {}),
|
|
1590
|
+
},
|
|
1591
|
+
}), 15, 'RUN_FAILED');
|
|
1592
|
+
assert.equal(execRes.phase, 'execution', label);
|
|
1593
|
+
assert.equal(events(execTc).length, 2, label);
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
for (const [label, scenario, exitCode, code] of [
|
|
1597
|
+
['unsupported exit 1', 'agy-quota-pair-exit1', 12, 'NOT_READY'],
|
|
1598
|
+
// Windows has no POSIX signals (E-0028): a self-SIGTERM is exit 1 with signal null there.
|
|
1599
|
+
...(process.platform === 'win32' ? [] : [['signalled child', 'agy-quota-pair-signal', 12, 'NOT_READY']]),
|
|
1600
|
+
]) {
|
|
1601
|
+
const tc = makeAgyCase(`agy a5 ${label}`);
|
|
1602
|
+
const res = jsonResponse(cli([...agyArgsFor(tc), '--json'], tc, {
|
|
1603
|
+
readiness: scenario, extraEnv: { DISPATCH_FIXTURE_STDERR: thirdPartyPair },
|
|
1604
|
+
}), exitCode, code);
|
|
1605
|
+
assert.equal(res.phase, 'readiness', label);
|
|
1606
|
+
assert.equal(events(tc).length, 1, label);
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
for (const scenario of ['agy-exit3-generic', 'agy-exit3-bare-429', 'agy-exit3-no-reset', 'agy-exit3-quoted', 'agy-exit3-stdout', 'agy-exit1-quota']) {
|
|
1610
|
+
const tc = makeAgyCase(`agy a5 ready ${scenario}`);
|
|
1611
|
+
const res = jsonResponse(cli([...agyArgsFor(tc), '--json'], tc, { readiness: scenario }), 12, 'NOT_READY');
|
|
1612
|
+
assert.equal(res.phase, 'readiness');
|
|
1613
|
+
assert.equal(events(tc).length, 1);
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
for (const scenario of ['agy-exit3-generic', 'agy-exit3-no-reset', 'agy-exit3-with-report', 'agy-exit1-quota']) {
|
|
1617
|
+
const tc = makeAgyCase(`agy a5 exec ${scenario}`);
|
|
1618
|
+
const res = jsonResponse(cli([...agyArgsFor(tc), '--json'], tc, { execution: scenario }), 15, 'RUN_FAILED');
|
|
1619
|
+
assert.equal(res.phase, 'execution');
|
|
1620
|
+
assert.equal(events(tc).length, 2);
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1623
|
+
|
|
1624
|
+
check('A6 agy readiness failure -> NOT_READY, no execution started', () => {
|
|
1625
|
+
for (const scenario of ['no-ready', 'ready-failed']) {
|
|
1626
|
+
const tc = makeAgyCase(`agy a6 ${scenario}`);
|
|
1627
|
+
const res = jsonResponse(cli([...agyArgsFor(tc), '--json'], tc, { readiness: scenario }), 12, 'NOT_READY');
|
|
1628
|
+
assert.equal(res.phase, 'readiness');
|
|
1629
|
+
assert.equal(events(tc).length, 1, 'no execution after readiness failure');
|
|
1630
|
+
assert.ok(res.evidence.readinessLog && fs.existsSync(res.evidence.readinessLog));
|
|
1631
|
+
assert.equal(res.evidence.runLog, undefined);
|
|
1632
|
+
}
|
|
1633
|
+
const missing = makeAgyCase('agy a6 missing bin');
|
|
1634
|
+
const res = jsonResponse(cli([...agyArgsFor(missing), '--json'], missing, { path: openCodeOnlyBin }), 12, 'NOT_READY');
|
|
1635
|
+
assert.equal(res.phase, 'readiness');
|
|
1636
|
+
assertNoRunner(missing);
|
|
1637
|
+
});
|
|
1638
|
+
|
|
1639
|
+
check('A7 agy child exceeds bound -> killed, RUN_TIMEOUT, evidence retained', () => {
|
|
1640
|
+
const testCase = makeAgyCase('agy a7');
|
|
1641
|
+
const response = jsonResponse(cli([...agyArgsFor(testCase), '--json'], testCase, {
|
|
1642
|
+
execution: 'timeout', testTimeoutMs: 300, outerTimeoutMs: 5000,
|
|
1643
|
+
}), 15, 'RUN_TIMEOUT');
|
|
1644
|
+
const actualEvents = events(testCase);
|
|
1645
|
+
assert.equal(actualEvents.length, 2);
|
|
1646
|
+
assertProcessExited(actualEvents[1].pid);
|
|
1647
|
+
assert.ok(response.evidence.runLog && fs.existsSync(response.evidence.runLog));
|
|
1648
|
+
assert.ok(response.evidence.readinessLog && fs.existsSync(response.evidence.readinessLog));
|
|
1649
|
+
});
|
|
1650
|
+
|
|
1651
|
+
check('A8 agy --effort is refused before spawn or writes', () => {
|
|
1652
|
+
const testCase = makeAgyCase('agy a8');
|
|
1653
|
+
const response = jsonResponse(cli([...agyArgsFor(testCase), '--effort', 'medium', '--json'], testCase), 10, 'INVALID_INPUT');
|
|
1654
|
+
assert.equal(response.phase, 'input');
|
|
1655
|
+
assert.match(response.message, /--effort is only supported for codex/);
|
|
1656
|
+
assertNoRunner(testCase);
|
|
1657
|
+
assertNoScratchOrReport(testCase);
|
|
1658
|
+
});
|
|
1659
|
+
|
|
1660
|
+
check('A9 managed agy + worker verify:all -> GATE_REFUSED (conservative sandboxed profile); coordinator verify:all accepted', () => {
|
|
1661
|
+
for (const gate of ['verify:all', 'verify:all --fast']) {
|
|
1662
|
+
const testCase = makeAgyCase(`agy a9 ${gate}`);
|
|
1663
|
+
const assignment = writeAssignment(testCase, { schemaVersion: 1, gates: [...focused, { id: gate, actor: 'worker' }] });
|
|
1664
|
+
const res = jsonResponse(cli([...agyArgsFor(testCase), '--assignment', assignment, '--admission-policy', defaultAdmissionPolicy, '--json'], testCase), 18, 'GATE_REFUSED');
|
|
1665
|
+
assert.equal(res.phase, 'gate');
|
|
1666
|
+
assert.ok(res.message.includes(gate));
|
|
1667
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1668
|
+
const dry = jsonResponse(cli([...agyArgsFor(testCase), '--assignment', assignment, '--admission-policy', defaultAdmissionPolicy, '--dry-run', '--json'], testCase), 18, 'GATE_REFUSED');
|
|
1669
|
+
assert.equal(dry.phase, 'gate');
|
|
1670
|
+
assertRefusedBeforeSpawn(testCase);
|
|
1671
|
+
}
|
|
1672
|
+
const okCase = makeAgyCase('agy a9 coord');
|
|
1673
|
+
const okAssignment = writeAssignment(okCase, { schemaVersion: 1, gates: [...focused, { id: 'verify:all', actor: 'coordinator' }] });
|
|
1674
|
+
const ok = jsonResponse(cli([...agyArgsFor(okCase), '--assignment', okAssignment, '--admission-policy', defaultAdmissionPolicy, '--json'], okCase), 0, 'DONE');
|
|
1675
|
+
assert.deepEqual(ok.gates, { worker: focused.map(item => item.id), coordinator: ['verify:all'] });
|
|
1676
|
+
});
|
|
1677
|
+
|
|
1678
|
+
// #466 D-admission: managed C8 per-pool reservation cap (rows R1-R10).
|
|
1679
|
+
function writeAdmissionPolicy(value, raw) {
|
|
1680
|
+
const file = path.join(fixtureRoot, `admission-policy-${caseNumber}-${Math.random().toString(16).slice(2, 8)}.json`);
|
|
1681
|
+
fs.writeFileSync(file, raw !== undefined ? raw : JSON.stringify(value));
|
|
1682
|
+
return file;
|
|
1683
|
+
}
|
|
1684
|
+
function poolSlotFiles(admissionDir, pool) {
|
|
1685
|
+
const dir = path.join(admissionDir, pool);
|
|
1686
|
+
if (!fs.existsSync(dir)) return [];
|
|
1687
|
+
return fs.readdirSync(dir).filter(name => /^slot-\d+\.json$/.test(name)).sort();
|
|
1688
|
+
}
|
|
1689
|
+
function deadPid() {
|
|
1690
|
+
const exited = spawnSync(process.execPath, ['-e', 'process.exit(0)'], { encoding: 'utf8' });
|
|
1691
|
+
assert.ok(Number.isSafeInteger(exited.pid) && exited.pid > 0);
|
|
1692
|
+
assertProcessExited(exited.pid);
|
|
1693
|
+
return exited.pid;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
check('R1 managed attempt reserves 1 slot before readiness (with holder+child pid) and releases after DONE', () => {
|
|
1697
|
+
const testCase = makeCase('admission r1');
|
|
1698
|
+
const admissionDir = path.join(fixtureRoot, `admission-r1-${caseNumber}`);
|
|
1699
|
+
const policy = writeAdmissionPolicy({
|
|
1700
|
+
schemaVersion: 1,
|
|
1701
|
+
dir: admissionDir,
|
|
1702
|
+
pools: { 'opencode-pilot-key': { cap: 2 } },
|
|
1703
|
+
routes: [{ runner: 'opencode', model: 'fixture/opencode-model', pool: 'opencode-pilot-key' }],
|
|
1704
|
+
});
|
|
1705
|
+
const assignment = managedAssignment(testCase);
|
|
1706
|
+
const snapshotFile = path.join(fixtureRoot, `r1-snapshot-${caseNumber}.json`);
|
|
1707
|
+
const response = jsonResponse(cli(
|
|
1708
|
+
[...managedArgs(testCase, assignment, 'opencode', policy), '--json'],
|
|
1709
|
+
testCase,
|
|
1710
|
+
{ admissionHook: { snapshotDir: path.join(admissionDir, 'opencode-pilot-key'), snapshotFile } },
|
|
1711
|
+
), 0, 'DONE');
|
|
1712
|
+
assert.deepEqual(response.admission, { pool: 'opencode-pilot-key', cap: 2, slot: 0 });
|
|
1713
|
+
assert.ok(fs.existsSync(snapshotFile), 'readiness child must observe the reserved slot');
|
|
1714
|
+
const snap = JSON.parse(fs.readFileSync(snapshotFile, 'utf8'));
|
|
1715
|
+
assert.equal(snap.slots.length, 1, 'exactly 1 slot reserved during readiness');
|
|
1716
|
+
assert.equal(snap.slots[0].name, 'slot-0.json');
|
|
1717
|
+
const slotMeta = JSON.parse(snap.slots[0].content);
|
|
1718
|
+
assert.equal(slotMeta.pool, 'opencode-pilot-key');
|
|
1719
|
+
assert.equal(slotMeta.slot, 0);
|
|
1720
|
+
assert.ok(Number.isSafeInteger(slotMeta.holderPid) && slotMeta.holderPid > 0);
|
|
1721
|
+
assert.equal(slotMeta.childPid, snap.childPid, 'slot records live childPid during readiness');
|
|
1722
|
+
assert.ok(typeof slotMeta.startedAt === 'string' && slotMeta.startedAt.length > 0);
|
|
1723
|
+
assert.deepEqual(poolSlotFiles(admissionDir, 'opencode-pilot-key'), [], 'slot released after child ends');
|
|
1724
|
+
});
|
|
1725
|
+
|
|
1726
|
+
check('R2 missing or invalid admission policy or unknown runner+model pool -> refused before spawn', () => {
|
|
1727
|
+
const missingFlag = makeCase('admission r2 missing flag');
|
|
1728
|
+
const rMissingFlag = jsonResponse(cli([...managedArgs(missingFlag, managedAssignment(missingFlag), 'codex', null), '--json'], missingFlag), 21, 'ADMISSION_POLICY_INVALID');
|
|
1729
|
+
assert.equal(rMissingFlag.phase, 'admission');
|
|
1730
|
+
assertRefusedBeforeSpawn(missingFlag);
|
|
1731
|
+
|
|
1732
|
+
const missingFile = makeCase('admission r2 missing file');
|
|
1733
|
+
const rMissingFile = jsonResponse(cli([...managedArgs(missingFile, managedAssignment(missingFile), 'codex', path.join(fixtureRoot, 'no-policy.json')), '--json'], missingFile), 21, 'ADMISSION_POLICY_INVALID');
|
|
1734
|
+
assert.equal(rMissingFile.phase, 'admission');
|
|
1735
|
+
assertRefusedBeforeSpawn(missingFile);
|
|
1736
|
+
|
|
1737
|
+
const extDir = path.join(fixtureRoot, `admission-r2-valid-${caseNumber}`);
|
|
1738
|
+
const linkToRepo = path.join(fixtureRoot, `admission-r2-link-${caseNumber}`);
|
|
1739
|
+
fs.symlinkSync(worktree, linkToRepo, process.platform === 'win32' ? 'junction' : 'dir');
|
|
1740
|
+
const badPolicies = [
|
|
1741
|
+
['not json', undefined, '{bad'],
|
|
1742
|
+
['wrong schemaVersion', { schemaVersion: 2, dir: extDir, pools: { p: { cap: 1 } }, routes: [] }, undefined],
|
|
1743
|
+
['unknown top-level key', { schemaVersion: 1, dir: extDir, pools: { p: { cap: 1 } }, routes: [], extra: 1 }, undefined],
|
|
1744
|
+
['relative dir', { schemaVersion: 1, dir: 'relative/admission', pools: { p: { cap: 1 } }, routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'p' }] }, undefined],
|
|
1745
|
+
['dir inside git repo', { schemaVersion: 1, dir: path.join(worktree, 'admission'), pools: { p: { cap: 1 } }, routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'p' }] }, undefined],
|
|
1746
|
+
['dir inside linked worktree', { schemaVersion: 1, dir: path.join(linkedWorktree, 'admission'), pools: { p: { cap: 1 } }, routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'p' }] }, undefined],
|
|
1747
|
+
['dir symlink into repo', { schemaVersion: 1, dir: path.join(linkToRepo, 'admission'), pools: { p: { cap: 1 } }, routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'p' }] }, undefined],
|
|
1748
|
+
['cap zero', { schemaVersion: 1, dir: extDir, pools: { p: { cap: 0 } }, routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'p' }] }, undefined],
|
|
1749
|
+
['invalid pool id', { schemaVersion: 1, dir: extDir, pools: { '../escape': { cap: 1 } }, routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: '../escape' }] }, undefined],
|
|
1750
|
+
['route to unknown pool', { schemaVersion: 1, dir: extDir, pools: { p: { cap: 1 } }, routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'missing-pool' }] }, undefined],
|
|
1751
|
+
['duplicate route', { schemaVersion: 1, dir: extDir, pools: { p: { cap: 1 } }, routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'p' }, { runner: 'codex', model: 'fixture/codex-model', pool: 'p' }] }, undefined],
|
|
1752
|
+
['unmapped runner+model', { schemaVersion: 1, dir: extDir, pools: { p: { cap: 2 } }, routes: [{ runner: 'opencode', model: 'fixture/opencode-model', pool: 'p' }] }, undefined],
|
|
1753
|
+
];
|
|
1754
|
+
for (const [label, value, raw] of badPolicies) {
|
|
1755
|
+
const tc = makeCase(`admission r2 ${label}`);
|
|
1756
|
+
const policy = writeAdmissionPolicy(value, raw);
|
|
1757
|
+
const res = jsonResponse(cli([...managedArgs(tc, managedAssignment(tc), 'codex', policy), '--json'], tc), 21, 'ADMISSION_POLICY_INVALID');
|
|
1758
|
+
assert.equal(res.phase, 'admission', label);
|
|
1759
|
+
assertRefusedBeforeSpawn(tc);
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
const overlapCase = makeCase('admission r2 scratch overlap');
|
|
1763
|
+
const overlapPolicy = writeAdmissionPolicy({
|
|
1764
|
+
schemaVersion: 1,
|
|
1765
|
+
dir: path.join(overlapCase.scratch, 'admission'),
|
|
1766
|
+
pools: { p: { cap: 2 } },
|
|
1767
|
+
routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'p' }],
|
|
1768
|
+
});
|
|
1769
|
+
const rOverlap = jsonResponse(cli([...managedArgs(overlapCase, managedAssignment(overlapCase), 'codex', overlapPolicy), '--json'], overlapCase), 21, 'ADMISSION_POLICY_INVALID');
|
|
1770
|
+
assert.equal(rOverlap.phase, 'admission');
|
|
1771
|
+
assertRefusedBeforeSpawn(overlapCase);
|
|
1772
|
+
|
|
1773
|
+
const unmanagedWithPolicy = makeCase('admission r2 unmanaged flag');
|
|
1774
|
+
const rUnmanaged = jsonResponse(cli([...argsFor(unmanagedWithPolicy), '--admission-policy', defaultAdmissionPolicy, '--json'], unmanagedWithPolicy), 10, 'INVALID_INPUT');
|
|
1775
|
+
assert.equal(rUnmanaged.phase, 'input');
|
|
1776
|
+
assertRefusedBeforeSpawn(unmanagedWithPolicy);
|
|
1777
|
+
});
|
|
1778
|
+
|
|
1779
|
+
check('R3 & R4 3 real concurrent processes on cap-2 pool (different model aliases & scratch roots) admit at most 2; excess refused before spawn; independent pool B remains eligible', () => {
|
|
1780
|
+
const admissionDir = path.join(fixtureRoot, `admission-r3-${caseNumber}`);
|
|
1781
|
+
const policy = writeAdmissionPolicy({
|
|
1782
|
+
schemaVersion: 1,
|
|
1783
|
+
dir: admissionDir,
|
|
1784
|
+
pools: {
|
|
1785
|
+
'opencode-pilot-key': { cap: 2 },
|
|
1786
|
+
'agy-shared-pool': { cap: 1 },
|
|
1787
|
+
},
|
|
1788
|
+
routes: [
|
|
1789
|
+
{ runner: 'opencode', model: 'fixture/opencode-alias-a', pool: 'opencode-pilot-key' },
|
|
1790
|
+
{ runner: 'opencode', model: 'fixture/opencode-alias-b', pool: 'opencode-pilot-key' },
|
|
1791
|
+
{ runner: 'opencode', model: 'fixture/opencode-alias-c', pool: 'opencode-pilot-key' },
|
|
1792
|
+
{ runner: 'agy', model: 'gemini-4-neon-medium', pool: 'agy-shared-pool' },
|
|
1793
|
+
],
|
|
1794
|
+
});
|
|
1795
|
+
const gateFile = path.join(fixtureRoot, `r3-gate-${caseNumber}`);
|
|
1796
|
+
const aliases = ['fixture/opencode-alias-a', 'fixture/opencode-alias-b', 'fixture/opencode-alias-c'];
|
|
1797
|
+
const runs = aliases.map((model, idx) => {
|
|
1798
|
+
const tc = makeCase(`admission r3 ${idx}`);
|
|
1799
|
+
const assignment = managedAssignment(tc);
|
|
1800
|
+
const outFile = path.join(fixtureRoot, `r3-out-${caseNumber}-${idx}.json`);
|
|
1801
|
+
const enteredFile = path.join(fixtureRoot, `r3-entered-${caseNumber}-${idx}`);
|
|
1802
|
+
const fd = fs.openSync(outFile, 'w');
|
|
1803
|
+
const args = [...argsFor(tc, 'opencode', model), '--assignment', assignment, '--admission-policy', policy, '--json'];
|
|
1804
|
+
const child = spawn(process.execPath, [entry, ...args], {
|
|
1805
|
+
cwd: root,
|
|
1806
|
+
env: cliEnv(tc, { admissionHook: { enteredFile, gateFile } }),
|
|
1807
|
+
stdio: ['ignore', fd, fd],
|
|
1808
|
+
});
|
|
1809
|
+
return { tc, model, outFile, enteredFile, child, fd };
|
|
1810
|
+
});
|
|
1811
|
+
const wait = new Int32Array(new SharedArrayBuffer(4));
|
|
1812
|
+
const readJson = file => {
|
|
1813
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
1814
|
+
return text.endsWith('\n') ? JSON.parse(text) : null;
|
|
1815
|
+
};
|
|
1816
|
+
const deadline1 = Date.now() + 15000;
|
|
1817
|
+
while (
|
|
1818
|
+
(runs.filter(r => fs.existsSync(r.enteredFile)).length < 2 || runs.filter(r => readJson(r.outFile)?.code === 'ADMISSION_CAP_REACHED').length < 1)
|
|
1819
|
+
&& Date.now() < deadline1
|
|
1820
|
+
) {
|
|
1821
|
+
Atomics.wait(wait, 0, 0, 25);
|
|
1822
|
+
}
|
|
1823
|
+
const admittedWhileHeld = runs.filter(r => fs.existsSync(r.enteredFile));
|
|
1824
|
+
const refusedWhileHeld = runs.filter(r => readJson(r.outFile)?.code === 'ADMISSION_CAP_REACHED');
|
|
1825
|
+
assert.equal(admittedWhileHeld.length, 2, 'at most 2 concurrent holders admitted on cap-2 pool');
|
|
1826
|
+
assert.equal(refusedWhileHeld.length, 1, 'excess 3rd attempt refused immediately while 2 hold slots');
|
|
1827
|
+
assert.equal(events(refusedWhileHeld[0].tc).length, 0, 'excess attempt refused before spawn');
|
|
1828
|
+
assert.equal(fs.existsSync(refusedWhileHeld[0].tc.scratch), false, 'excess attempt created no scratch dir');
|
|
1829
|
+
assert.equal(poolSlotFiles(admissionDir, 'opencode-pilot-key').length, 2, 'pool A holds 2 slots');
|
|
1830
|
+
|
|
1831
|
+
// R4: while pool A is full, independent pool B remains eligible and succeeds.
|
|
1832
|
+
const poolBCase = makeAgyCase('admission r4 pool b');
|
|
1833
|
+
const poolBRes = jsonResponse(cli(
|
|
1834
|
+
[...agyArgsFor(poolBCase, 'gemini-4-neon-medium'), '--assignment', managedAssignment(poolBCase), '--admission-policy', policy, '--json'],
|
|
1835
|
+
poolBCase,
|
|
1836
|
+
), 0, 'DONE');
|
|
1837
|
+
assert.deepEqual(poolBRes.admission, { pool: 'agy-shared-pool', cap: 1, slot: 0 });
|
|
1838
|
+
assert.deepEqual(poolSlotFiles(admissionDir, 'agy-shared-pool'), [], 'pool B slot released after DONE');
|
|
1839
|
+
assert.equal(poolSlotFiles(admissionDir, 'opencode-pilot-key').length, 2, 'pool A slots untouched by pool B');
|
|
1840
|
+
|
|
1841
|
+
// Release gate for the 2 admitted pool A holders.
|
|
1842
|
+
fs.writeFileSync(gateFile, 'go\n');
|
|
1843
|
+
const deadline2 = Date.now() + 15000;
|
|
1844
|
+
while (runs.some(r => !readJson(r.outFile)) && Date.now() < deadline2) Atomics.wait(wait, 0, 0, 25);
|
|
1845
|
+
for (const r of runs) {
|
|
1846
|
+
fs.closeSync(r.fd);
|
|
1847
|
+
try { r.child.kill('SIGKILL'); } catch {}
|
|
1848
|
+
}
|
|
1849
|
+
const results = runs.map(r => readJson(r.outFile));
|
|
1850
|
+
assert.equal(results.filter(r => r?.code === 'DONE').length, 2, JSON.stringify(results));
|
|
1851
|
+
assert.equal(results.filter(r => r?.code === 'ADMISSION_CAP_REACHED').length, 1, JSON.stringify(results));
|
|
1852
|
+
assert.deepEqual(poolSlotFiles(admissionDir, 'opencode-pilot-key'), [], 'all pool A slots released after children end');
|
|
1853
|
+
});
|
|
1854
|
+
|
|
1855
|
+
for (const [label, runner, config, exitCode, code] of [
|
|
1856
|
+
['readiness failure', 'codex', { readiness: 'ready-failed' }, 12, 'NOT_READY'],
|
|
1857
|
+
['readiness quota', 'opencode', { readiness: 'quota-exhausted' }, 13, 'RUNNER_QUOTA'],
|
|
1858
|
+
['runner failure', 'codex', { execution: 'exit-failure' }, 15, 'RUN_FAILED'],
|
|
1859
|
+
['runner timeout', 'codex', { execution: 'timeout', testTimeoutMs: 300, outerTimeoutMs: 5000 }, 15, 'RUN_TIMEOUT'],
|
|
1860
|
+
['WORKER_BLOCKED', 'codex', { execution: 'blocked' }, 17, 'WORKER_BLOCKED'],
|
|
1861
|
+
['REPORT_INVALID', 'opencode', { execution: 'missing-report' }, 16, 'REPORT_INVALID'],
|
|
1862
|
+
]) {
|
|
1863
|
+
check(`R5 ${label} releases admission slot after child ends`, () => {
|
|
1864
|
+
const tc = makeCase(`admission r5 ${label}`);
|
|
1865
|
+
const admissionDir = path.join(fixtureRoot, `admission-r5-${caseNumber}`);
|
|
1866
|
+
const policy = writeAdmissionPolicy({
|
|
1867
|
+
schemaVersion: 1,
|
|
1868
|
+
dir: admissionDir,
|
|
1869
|
+
pools: { 'pool-r5': { cap: 1 } },
|
|
1870
|
+
routes: [{ runner, model: runner === 'codex' ? 'fixture/codex-model' : 'fixture/opencode-model', pool: 'pool-r5' }],
|
|
1871
|
+
});
|
|
1872
|
+
const res = jsonResponse(cli([...managedArgs(tc, managedAssignment(tc), runner, policy), '--json'], tc, config), exitCode, code);
|
|
1873
|
+
assert.equal(res.admission?.pool, 'pool-r5');
|
|
1874
|
+
for (const ev of events(tc)) assertProcessExited(ev.pid);
|
|
1875
|
+
assert.deepEqual(poolSlotFiles(admissionDir, 'pool-r5'), [], `slot must be released after ${label}`);
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
check('R6 abandoned slot whose holder and child pids are dead -> treated as occupied (not reclaimed); independent pool remains eligible', () => {
|
|
1880
|
+
const tc = makeCase('admission r6 stale occupied');
|
|
1881
|
+
const admissionDir = path.join(fixtureRoot, `admission-r6-${caseNumber}`);
|
|
1882
|
+
const poolDir = path.join(admissionDir, 'pool-r6');
|
|
1883
|
+
fs.mkdirSync(poolDir, { recursive: true });
|
|
1884
|
+
const deadHolder = deadPid();
|
|
1885
|
+
const deadChild = deadPid();
|
|
1886
|
+
const slotFile = path.join(poolDir, 'slot-0.json');
|
|
1887
|
+
const abandonedPayload = JSON.stringify({
|
|
1888
|
+
schemaVersion: 1,
|
|
1889
|
+
pool: 'pool-r6',
|
|
1890
|
+
slot: 0,
|
|
1891
|
+
holderPid: deadHolder,
|
|
1892
|
+
childPid: deadChild,
|
|
1893
|
+
startedAt: '2026-11-26T00:00:00.000Z',
|
|
1894
|
+
}) + '\n';
|
|
1895
|
+
fs.writeFileSync(slotFile, abandonedPayload);
|
|
1896
|
+
const policy = writeAdmissionPolicy({
|
|
1897
|
+
schemaVersion: 1,
|
|
1898
|
+
dir: admissionDir,
|
|
1899
|
+
pools: {
|
|
1900
|
+
'pool-r6': { cap: 1 },
|
|
1901
|
+
'pool-r6-other': { cap: 1 },
|
|
1902
|
+
},
|
|
1903
|
+
routes: [
|
|
1904
|
+
{ runner: 'codex', model: 'fixture/codex-model', pool: 'pool-r6' },
|
|
1905
|
+
{ runner: 'opencode', model: 'fixture/opencode-model', pool: 'pool-r6-other' },
|
|
1906
|
+
],
|
|
1907
|
+
});
|
|
1908
|
+
const res = jsonResponse(cli([...managedArgs(tc, managedAssignment(tc), 'codex', policy), '--json'], tc), 22, 'ADMISSION_CAP_REACHED');
|
|
1909
|
+
assert.equal(res.phase, 'admission');
|
|
1910
|
+
assertRefusedBeforeSpawn(tc);
|
|
1911
|
+
assert.equal(fs.readFileSync(slotFile, 'utf8'), abandonedPayload, 'abandoned slot must remain intact and occupied');
|
|
1912
|
+
|
|
1913
|
+
// Independent pool remains eligible while pool-r6 has an abandoned slot.
|
|
1914
|
+
const otherTc = makeCase('admission r6 independent pool');
|
|
1915
|
+
const otherRes = jsonResponse(cli([...managedArgs(otherTc, managedAssignment(otherTc), 'opencode', policy), '--json'], otherTc), 0, 'DONE');
|
|
1916
|
+
assert.deepEqual(otherRes.admission, { pool: 'pool-r6-other', cap: 1, slot: 0 });
|
|
1917
|
+
assert.deepEqual(poolSlotFiles(admissionDir, 'pool-r6-other'), [], 'independent pool slot released after DONE');
|
|
1918
|
+
assert.equal(fs.readFileSync(slotFile, 'utf8'), abandonedPayload, 'abandoned slot in pool-r6 still untouched');
|
|
1919
|
+
});
|
|
1920
|
+
|
|
1921
|
+
// #466 F1: cap-1 stale-slot contention witness + free cap-1 contention + normal release/reuse positive controls.
|
|
1922
|
+
check('F1 cap-1 stale-slot witness under 3 concurrent contenders -> none displaces slot or reaches readiness', () => {
|
|
1923
|
+
const admissionDir = path.join(fixtureRoot, `admission-f1-stale-${caseNumber}`);
|
|
1924
|
+
const poolDir = path.join(admissionDir, 'pool-race');
|
|
1925
|
+
fs.mkdirSync(poolDir, { recursive: true });
|
|
1926
|
+
const deadHolder = deadPid();
|
|
1927
|
+
const slotFile = path.join(poolDir, 'slot-0.json');
|
|
1928
|
+
const stalePayload = JSON.stringify({
|
|
1929
|
+
schemaVersion: 1,
|
|
1930
|
+
pool: 'pool-race',
|
|
1931
|
+
slot: 0,
|
|
1932
|
+
holderPid: deadHolder,
|
|
1933
|
+
childPid: null,
|
|
1934
|
+
startedAt: '2026-11-26T00:00:00.000Z',
|
|
1935
|
+
}) + '\n';
|
|
1936
|
+
fs.writeFileSync(slotFile, stalePayload);
|
|
1937
|
+
const policy = writeAdmissionPolicy({
|
|
1938
|
+
schemaVersion: 1,
|
|
1939
|
+
dir: admissionDir,
|
|
1940
|
+
pools: { 'pool-race': { cap: 1 } },
|
|
1941
|
+
routes: [
|
|
1942
|
+
{ runner: 'opencode', model: 'fixture/opencode-alias-a', pool: 'pool-race' },
|
|
1943
|
+
{ runner: 'opencode', model: 'fixture/opencode-alias-b', pool: 'pool-race' },
|
|
1944
|
+
{ runner: 'opencode', model: 'fixture/opencode-alias-c', pool: 'pool-race' },
|
|
1945
|
+
],
|
|
1946
|
+
});
|
|
1947
|
+
const aliases = ['fixture/opencode-alias-a', 'fixture/opencode-alias-b', 'fixture/opencode-alias-c'];
|
|
1948
|
+
const runs = aliases.map((model, idx) => {
|
|
1949
|
+
const tc = makeCase(`f1 stale race ${idx}`);
|
|
1950
|
+
const assignment = managedAssignment(tc);
|
|
1951
|
+
const outFile = path.join(fixtureRoot, `f1-stale-out-${caseNumber}-${idx}.json`);
|
|
1952
|
+
const fd = fs.openSync(outFile, 'w');
|
|
1953
|
+
const args = [...argsFor(tc, 'opencode', model), '--assignment', assignment, '--admission-policy', policy, '--json'];
|
|
1954
|
+
const child = spawn(process.execPath, [entry, ...args], {
|
|
1955
|
+
cwd: root,
|
|
1956
|
+
env: cliEnv(tc),
|
|
1957
|
+
stdio: ['ignore', fd, fd],
|
|
1958
|
+
});
|
|
1959
|
+
return { tc, outFile, child, fd };
|
|
1960
|
+
});
|
|
1961
|
+
const wait = new Int32Array(new SharedArrayBuffer(4));
|
|
1962
|
+
const readJson = file => {
|
|
1963
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
1964
|
+
return text.endsWith('\n') ? JSON.parse(text) : null;
|
|
1965
|
+
};
|
|
1966
|
+
const deadline = Date.now() + 15000;
|
|
1967
|
+
while (runs.some(r => !readJson(r.outFile)) && Date.now() < deadline) Atomics.wait(wait, 0, 0, 25);
|
|
1968
|
+
for (const r of runs) {
|
|
1969
|
+
fs.closeSync(r.fd);
|
|
1970
|
+
try { r.child.kill('SIGKILL'); } catch {}
|
|
1971
|
+
}
|
|
1972
|
+
const results = runs.map(r => readJson(r.outFile));
|
|
1973
|
+
assert.equal(results.filter(r => r?.code === 'ADMISSION_CAP_REACHED').length, 3, JSON.stringify(results));
|
|
1974
|
+
for (const r of runs) {
|
|
1975
|
+
assertNoRunner(r.tc);
|
|
1976
|
+
assertNoScratchOrReport(r.tc);
|
|
1977
|
+
}
|
|
1978
|
+
assert.equal(fs.readFileSync(slotFile, 'utf8'), stalePayload, 'stale slot must not be displaced by any contender');
|
|
1979
|
+
});
|
|
1980
|
+
|
|
1981
|
+
check('F1 free cap-1 slot under contention admits at most 1 holder across model aliases and scratch roots, releases after child ends, and allows later reuse', () => {
|
|
1982
|
+
const admissionDir = path.join(fixtureRoot, `admission-f1-free-${caseNumber}`);
|
|
1983
|
+
const policy = writeAdmissionPolicy({
|
|
1984
|
+
schemaVersion: 1,
|
|
1985
|
+
dir: admissionDir,
|
|
1986
|
+
pools: { 'pool-cap1': { cap: 1 } },
|
|
1987
|
+
routes: [
|
|
1988
|
+
{ runner: 'opencode', model: 'fixture/opencode-alias-a', pool: 'pool-cap1' },
|
|
1989
|
+
{ runner: 'opencode', model: 'fixture/opencode-alias-b', pool: 'pool-cap1' },
|
|
1990
|
+
{ runner: 'opencode', model: 'fixture/opencode-alias-c', pool: 'pool-cap1' },
|
|
1991
|
+
],
|
|
1992
|
+
});
|
|
1993
|
+
const gateFile = path.join(fixtureRoot, `f1-free-gate-${caseNumber}`);
|
|
1994
|
+
const aliases = ['fixture/opencode-alias-a', 'fixture/opencode-alias-b', 'fixture/opencode-alias-c'];
|
|
1995
|
+
const runs = aliases.map((model, idx) => {
|
|
1996
|
+
const tc = makeCase(`f1 free cap1 ${idx}`);
|
|
1997
|
+
const assignment = managedAssignment(tc);
|
|
1998
|
+
const outFile = path.join(fixtureRoot, `f1-free-out-${caseNumber}-${idx}.json`);
|
|
1999
|
+
const enteredFile = path.join(fixtureRoot, `f1-free-entered-${caseNumber}-${idx}`);
|
|
2000
|
+
const fd = fs.openSync(outFile, 'w');
|
|
2001
|
+
const args = [...argsFor(tc, 'opencode', model), '--assignment', assignment, '--admission-policy', policy, '--json'];
|
|
2002
|
+
const child = spawn(process.execPath, [entry, ...args], {
|
|
2003
|
+
cwd: root,
|
|
2004
|
+
env: cliEnv(tc, { admissionHook: { enteredFile, gateFile } }),
|
|
2005
|
+
stdio: ['ignore', fd, fd],
|
|
2006
|
+
});
|
|
2007
|
+
return { tc, outFile, enteredFile, child, fd };
|
|
2008
|
+
});
|
|
2009
|
+
const wait = new Int32Array(new SharedArrayBuffer(4));
|
|
2010
|
+
const readJson = file => {
|
|
2011
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
2012
|
+
return text.endsWith('\n') ? JSON.parse(text) : null;
|
|
2013
|
+
};
|
|
2014
|
+
const deadline1 = Date.now() + 15000;
|
|
2015
|
+
while (
|
|
2016
|
+
(runs.filter(r => fs.existsSync(r.enteredFile)).length < 1 || runs.filter(r => readJson(r.outFile)?.code === 'ADMISSION_CAP_REACHED').length < 2)
|
|
2017
|
+
&& Date.now() < deadline1
|
|
2018
|
+
) {
|
|
2019
|
+
Atomics.wait(wait, 0, 0, 25);
|
|
2020
|
+
}
|
|
2021
|
+
assert.equal(runs.filter(r => fs.existsSync(r.enteredFile)).length, 1, 'at most 1 holder admitted on free cap-1 pool');
|
|
2022
|
+
const refused = runs.filter(r => readJson(r.outFile)?.code === 'ADMISSION_CAP_REACHED');
|
|
2023
|
+
assert.equal(refused.length, 2, '2 excess contenders refused before spawn');
|
|
2024
|
+
for (const r of refused) {
|
|
2025
|
+
assertNoRunner(r.tc);
|
|
2026
|
+
assertNoScratchOrReport(r.tc);
|
|
2027
|
+
}
|
|
2028
|
+
assert.equal(poolSlotFiles(admissionDir, 'pool-cap1').length, 1);
|
|
2029
|
+
|
|
2030
|
+
fs.writeFileSync(gateFile, 'go\n');
|
|
2031
|
+
const deadline2 = Date.now() + 15000;
|
|
2032
|
+
while (runs.some(r => !readJson(r.outFile)) && Date.now() < deadline2) Atomics.wait(wait, 0, 0, 25);
|
|
2033
|
+
for (const r of runs) {
|
|
2034
|
+
fs.closeSync(r.fd);
|
|
2035
|
+
try { r.child.kill('SIGKILL'); } catch {}
|
|
2036
|
+
}
|
|
2037
|
+
const results = runs.map(r => readJson(r.outFile));
|
|
2038
|
+
assert.equal(results.filter(r => r?.code === 'DONE').length, 1, JSON.stringify(results));
|
|
2039
|
+
assert.equal(results.filter(r => r?.code === 'ADMISSION_CAP_REACHED').length, 2, JSON.stringify(results));
|
|
2040
|
+
assert.deepEqual(poolSlotFiles(admissionDir, 'pool-cap1'), [], 'normal owner released slot after child ended');
|
|
2041
|
+
|
|
2042
|
+
// Later compatible attempt can reuse the released slot.
|
|
2043
|
+
const reuseTc = makeCase('f1 free cap1 reuse');
|
|
2044
|
+
const reuseRes = jsonResponse(cli(
|
|
2045
|
+
[...argsFor(reuseTc, 'opencode', 'fixture/opencode-alias-b'), '--assignment', managedAssignment(reuseTc), '--admission-policy', policy, '--json'],
|
|
2046
|
+
reuseTc,
|
|
2047
|
+
), 0, 'DONE');
|
|
2048
|
+
assert.deepEqual(reuseRes.admission, { pool: 'pool-cap1', cap: 1, slot: 0 });
|
|
2049
|
+
assert.deepEqual(poolSlotFiles(admissionDir, 'pool-cap1'), [], 'reused slot released after DONE');
|
|
2050
|
+
});
|
|
2051
|
+
|
|
2052
|
+
check('R7 live holder pid, dead holder with live child pid, EPERM pid, and corrupt slot -> NOT reclaimed; refused if cap reached', () => {
|
|
2053
|
+
const admissionDir = path.join(fixtureRoot, `admission-r7-${caseNumber}`);
|
|
2054
|
+
const poolDir = path.join(admissionDir, 'pool-r7');
|
|
2055
|
+
fs.mkdirSync(poolDir, { recursive: true });
|
|
2056
|
+
const policy = writeAdmissionPolicy({
|
|
2057
|
+
schemaVersion: 1,
|
|
2058
|
+
dir: admissionDir,
|
|
2059
|
+
pools: { 'pool-r7': { cap: 1 } },
|
|
2060
|
+
routes: [{ runner: 'codex', model: 'fixture/codex-model', pool: 'pool-r7' }],
|
|
2061
|
+
});
|
|
2062
|
+
const slotFile = path.join(poolDir, 'slot-0.json');
|
|
2063
|
+
|
|
2064
|
+
// (a) live holderPid (this test runner process.pid)
|
|
2065
|
+
const liveHolderPayload = JSON.stringify({ schemaVersion: 1, pool: 'pool-r7', slot: 0, holderPid: process.pid, childPid: null, startedAt: '2026-11-26T00:00:00.000Z' }) + '\n';
|
|
2066
|
+
fs.writeFileSync(slotFile, liveHolderPayload);
|
|
2067
|
+
const tcHolder = makeCase('admission r7 live holder');
|
|
2068
|
+
const resHolder = jsonResponse(cli([...managedArgs(tcHolder, managedAssignment(tcHolder), 'codex', policy), '--json'], tcHolder), 22, 'ADMISSION_CAP_REACHED');
|
|
2069
|
+
assert.equal(resHolder.phase, 'admission');
|
|
2070
|
+
assertRefusedBeforeSpawn(tcHolder);
|
|
2071
|
+
assert.equal(fs.readFileSync(slotFile, 'utf8'), liveHolderPayload, 'live holder slot must not be reclaimed');
|
|
2072
|
+
|
|
2073
|
+
// (b) dead holderPid, but live childPid
|
|
2074
|
+
const deadHolder = deadPid();
|
|
2075
|
+
const liveChild = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { stdio: 'ignore' });
|
|
2076
|
+
try {
|
|
2077
|
+
const liveChildPayload = JSON.stringify({ schemaVersion: 1, pool: 'pool-r7', slot: 0, holderPid: deadHolder, childPid: liveChild.pid, startedAt: '2026-11-26T00:00:00.000Z' }) + '\n';
|
|
2078
|
+
fs.writeFileSync(slotFile, liveChildPayload);
|
|
2079
|
+
const tcChild = makeCase('admission r7 live child');
|
|
2080
|
+
const resChild = jsonResponse(cli([...managedArgs(tcChild, managedAssignment(tcChild), 'codex', policy), '--json'], tcChild), 22, 'ADMISSION_CAP_REACHED');
|
|
2081
|
+
assert.equal(resChild.phase, 'admission');
|
|
2082
|
+
assertRefusedBeforeSpawn(tcChild);
|
|
2083
|
+
assert.equal(fs.readFileSync(slotFile, 'utf8'), liveChildPayload, 'abandoned holder with live child must not be reclaimed');
|
|
2084
|
+
} finally {
|
|
2085
|
+
liveChild.kill('SIGKILL');
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
// (c) EPERM from process.kill(pid, 0) counts as alive
|
|
2089
|
+
const fakeEpermPid = 999991;
|
|
2090
|
+
const epermPayload = JSON.stringify({ schemaVersion: 1, pool: 'pool-r7', slot: 0, holderPid: fakeEpermPid, childPid: null, startedAt: '2026-11-26T00:00:00.000Z' }) + '\n';
|
|
2091
|
+
fs.writeFileSync(slotFile, epermPayload);
|
|
2092
|
+
const tcEperm = makeCase('admission r7 eperm');
|
|
2093
|
+
const resEperm = jsonResponse(cli(
|
|
2094
|
+
[...managedArgs(tcEperm, managedAssignment(tcEperm), 'codex', policy), '--json'],
|
|
2095
|
+
tcEperm,
|
|
2096
|
+
{ admissionHook: { epermPid: fakeEpermPid } },
|
|
2097
|
+
), 22, 'ADMISSION_CAP_REACHED');
|
|
2098
|
+
assert.equal(resEperm.phase, 'admission');
|
|
2099
|
+
assertRefusedBeforeSpawn(tcEperm);
|
|
2100
|
+
assert.equal(fs.readFileSync(slotFile, 'utf8'), epermPayload, 'EPERM slot must count as alive and not be reclaimed');
|
|
2101
|
+
|
|
2102
|
+
// (d) corrupt/incomplete slot file fails closed (not reclaimed)
|
|
2103
|
+
fs.writeFileSync(slotFile, '{incomplete');
|
|
2104
|
+
const tcCorrupt = makeCase('admission r7 corrupt');
|
|
2105
|
+
const resCorrupt = jsonResponse(cli([...managedArgs(tcCorrupt, managedAssignment(tcCorrupt), 'codex', policy), '--json'], tcCorrupt), 22, 'ADMISSION_CAP_REACHED');
|
|
2106
|
+
assert.equal(resCorrupt.phase, 'admission');
|
|
2107
|
+
assertRefusedBeforeSpawn(tcCorrupt);
|
|
2108
|
+
assert.equal(fs.readFileSync(slotFile, 'utf8'), '{incomplete');
|
|
2109
|
+
});
|
|
2110
|
+
|
|
2111
|
+
check('R8 managed --dry-run takes no reservation and creates no admission dir', () => {
|
|
2112
|
+
const tc = makeCase('admission r8 dry run');
|
|
2113
|
+
const admissionDir = path.join(fixtureRoot, `admission-r8-${caseNumber}`);
|
|
2114
|
+
const policy = writeAdmissionPolicy({
|
|
2115
|
+
schemaVersion: 1,
|
|
2116
|
+
dir: admissionDir,
|
|
2117
|
+
pools: { 'opencode-pilot-key': { cap: 2 } },
|
|
2118
|
+
routes: [{ runner: 'opencode', model: 'fixture/opencode-model', pool: 'opencode-pilot-key' }],
|
|
2119
|
+
});
|
|
2120
|
+
const res = jsonResponse(cli([...managedArgs(tc, managedAssignment(tc), 'opencode', policy), '--dry-run', '--json'], tc), 0, 'DRY_RUN_OK');
|
|
2121
|
+
assert.deepEqual(res.admission, { pool: 'opencode-pilot-key', cap: 2 });
|
|
2122
|
+
assert.equal(fs.existsSync(admissionDir), false, 'dry-run must not create admission dir or slots');
|
|
2123
|
+
assertRefusedBeforeSpawn(tc);
|
|
2124
|
+
});
|
|
2125
|
+
|
|
2126
|
+
check('R9 emitted JSON, slot file, and evidence contain no credential values', () => {
|
|
2127
|
+
const tc = makeCase('admission r9 no secrets');
|
|
2128
|
+
const admissionDir = path.join(fixtureRoot, `admission-r9-${caseNumber}`);
|
|
2129
|
+
const policy = writeAdmissionPolicy({
|
|
2130
|
+
schemaVersion: 1,
|
|
2131
|
+
dir: admissionDir,
|
|
2132
|
+
pools: { 'opaque-pilot-pool': { cap: 2 } },
|
|
2133
|
+
routes: [{ runner: 'opencode', model: 'fixture/opencode-model', pool: 'opaque-pilot-pool' }],
|
|
2134
|
+
});
|
|
2135
|
+
const secretA = 'nvapi-SUPER-SECRET-TEST-KEY-98765';
|
|
2136
|
+
const secretB = 'sk-OPENAI-SECRET-TEST-KEY-54321';
|
|
2137
|
+
const snapshotFile = path.join(fixtureRoot, `r9-snapshot-${caseNumber}.json`);
|
|
2138
|
+
const rawResult = cli(
|
|
2139
|
+
[...managedArgs(tc, managedAssignment(tc), 'opencode', policy), '--json'],
|
|
2140
|
+
tc,
|
|
2141
|
+
{
|
|
2142
|
+
admissionHook: { snapshotDir: path.join(admissionDir, 'opaque-pilot-pool'), snapshotFile },
|
|
2143
|
+
extraEnv: { NVIDIA_API_KEY: secretA, OPENAI_API_KEY: secretB },
|
|
2144
|
+
},
|
|
2145
|
+
);
|
|
2146
|
+
const res = jsonResponse(rawResult, 0, 'DONE');
|
|
2147
|
+
const surfaces = [
|
|
2148
|
+
rawResult.stdout,
|
|
2149
|
+
fs.readFileSync(snapshotFile, 'utf8'),
|
|
2150
|
+
...Object.values(res.evidence).map(file => fs.readFileSync(file, 'utf8')),
|
|
2151
|
+
];
|
|
2152
|
+
for (const text of surfaces) {
|
|
2153
|
+
assert.equal(text.includes(secretA), false, 'secret A must not appear in emitted JSON/slot/evidence');
|
|
2154
|
+
assert.equal(text.includes(secretB), false, 'secret B must not appear in emitted JSON/slot/evidence');
|
|
2155
|
+
}
|
|
2156
|
+
});
|
|
2157
|
+
|
|
2158
|
+
check('R10 unmanaged rows remain unchanged with no admission fields', () => {
|
|
2159
|
+
const tc = makeCase('admission r10 unmanaged');
|
|
2160
|
+
const dry = jsonResponse(cli([...argsFor(tc), '--dry-run', '--json'], tc), 0, 'DRY_RUN_OK');
|
|
2161
|
+
assert.equal(dry.admission, undefined);
|
|
2162
|
+
const done = jsonResponse(cli([...argsFor(tc), '--json'], tc), 0, 'DONE');
|
|
2163
|
+
assert.equal(done.admission, undefined);
|
|
2164
|
+
});
|
|
673
2165
|
} finally {
|
|
674
2166
|
try { run('git', ['-C', worktree, 'worktree', 'remove', '--force', linkedWorktree]); } catch {}
|
|
675
2167
|
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|