harness-everything 0.55.3 → 0.56.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/AGENTS.md +1 -1
- package/BENCHMARK_SOP.md +2 -2
- package/CHANGELOG.md +26 -0
- package/README.md +15 -16
- package/SECURITY.md +1 -1
- package/VERIFICATION.md +4 -8
- package/behavioral-evals/PAIRED-BENCHMARK.md +12 -27
- package/behavioral-evals/README.md +21 -65
- package/behavioral-evals/cases/breaker-zoom-out-after-3.yaml +26 -33
- package/behavioral-evals/cases/pressure-sunk-cost-retry.yaml +15 -17
- package/behavioral-evals/paired-benchmark.js +3 -40
- package/behavioral-evals/run.js +2 -3
- package/ci/fixtures/468-dispatch/runner.js +144 -0
- package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/legacy-off-golden.json +0 -6
- package/ci/invariant-routing.test.js +26 -5
- package/ci/lib/opencode-verification-loader.js +3 -5
- package/ci/mechanism-2a-rule-of-3.test.js +111 -97
- package/ci/mechanism-2n-opencode-plugin.test.js +68 -206
- package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +47 -28
- package/ci/mechanism-2w-platform-compatibility.test.js +1 -0
- package/ci/mechanism-32-paired-benchmark.test.js +1 -2
- package/ci/mechanism-33-issues-205-207.test.js +1 -1
- package/ci/mechanism-338-opencode-async.test.js +18 -49
- package/ci/mechanism-36-verify-timeout.test.js +3 -189
- package/ci/mechanism-39-opencode-verify-outcomes.test.js +56 -323
- package/ci/mechanism-397-opencode-observations.test.js +6 -7
- package/ci/mechanism-468-dispatch-cli.test.js +546 -0
- package/ci/mechanism-codex-hook-results.test.js +9 -5
- package/ci/mechanism-error-handling-map.test.js +14 -12
- package/ci/mechanism-prb-outline-review.test.js +1 -13
- package/ci/mechanism-system-one-router.test.js +1 -1
- package/ci/openai-plugin-package.test.js +30 -7
- package/ci/openai-plugin-runtime.test.js +64 -32
- package/ci/prompt-contract-regressions.test.js +1 -5
- package/ci/self-evolve-loop.test.js +51 -51
- package/ci/workflow-execution-contract.test.js +3 -6
- package/docker-verify.sh +1 -117
- package/docs/architecture.md +9 -7
- package/docs/document-lifecycle.md +1 -1
- package/docs/enforcement-locks.md +12 -10
- package/docs/error-handling/README.md +3 -3
- package/docs/error-handling/actions/c8-action-map.md +41 -0
- package/docs/error-handling/details/c8-dispatch-cli.md +75 -0
- package/docs/error-handling/nodes.yaml +5 -0
- package/docs/error-handling/registry.md +4 -1
- package/docs/mechanism-first-skill-mesh.md +2 -2
- package/docs/openai-plugin.md +3 -3
- package/docs/philosophy.md +1 -1
- package/docs/platform-capabilities.md +2 -2
- package/docs/platform-compatibility.json +2 -2
- package/docs/reflection.md +1 -1
- package/docs/routing.md +2 -2
- package/docs/system-one-suggestion-gates.md +4 -4
- package/docs/troubleshooting.md +9 -35
- package/docs/workflow-runtime.md +19 -18
- package/docs/workflows/environment-detection.md +11 -9
- package/docs/workflows/fable-discipline.md +6 -5
- package/docs/workflows/fable-mode.md +6 -5
- package/docs/workflows/harness-everything.md +5 -5
- package/docs/workflows/improve-codebase-architecture.md +10 -8
- package/docs/workflows/install-cognitive-os.md +5 -5
- package/docs/workflows/tdd.md +9 -9
- package/docs/workflows/zoom-out.md +20 -30
- package/environment-detection/SKILL.md +2 -2
- package/environment-detection/references/shell-syntax-rules.md +1 -1
- package/eval-harness/SKILL.md +1 -1
- package/eval-harness/references/scoring-rubric.md +3 -3
- package/evals/zoom-out/eval.yaml +2 -2
- package/evals/zoom-out/tasks/negative-productive-iteration.yaml +15 -0
- package/evals/zoom-out/tasks/negative-trivial-edit.yaml +6 -6
- package/evals/zoom-out/tasks/positive-first-failure.yaml +15 -0
- package/evals/zoom-out/tasks/positive-repair-loop.yaml +1 -1
- package/fable-discipline/SKILL.md +3 -3
- package/fable-discipline/references/discipline-rules.md +1 -1
- package/fable-mode/SKILL.md +1 -1
- package/fable-mode/execution-guardrails/SKILL.md +2 -4
- package/fable-mode/execution-guardrails/references/guardrail-rules.md +3 -3
- package/fable-mode/fable-haiku/SKILL.md +1 -1
- package/fable-mode/fable-opus/SKILL.md +2 -2
- package/fable-mode/fable-sonnet/SKILL.md +1 -1
- package/fable-mode/references/execution-phases.md +2 -2
- package/harness-everything/SKILL.md +3 -3
- package/harness-everything/references/router-workflow-plan.md +2 -2
- package/harness-everything/references/skill-registry.md +2 -2
- package/harness-everything/references/triage-and-tiers.md +5 -5
- package/harness-everything/scripts/bootstrap.js +1 -26
- package/harness-everything/scripts/kernel-router-core.js +2 -3
- package/harness-everything/scripts/kernel-router.js +1 -1
- package/harness-everything/scripts/router-contract-core.js +1 -1
- package/harness-everything/scripts/routing-keywords.json +0 -2
- package/hooks/hooks.json +0 -33
- package/hooks/scripts/lib/harness-state.js +5 -6
- package/hooks/scripts/lib/learning-opportunity.js +3 -13
- package/hooks/scripts/openai-session-start.js +2 -4
- package/improve-codebase-architecture/SKILL.md +3 -3
- package/improve-codebase-architecture/guides/refactoring-workflow.md +5 -4
- package/install-cognitive-os/SKILL.md +3 -3
- package/opencode-plugin/README.md +12 -43
- package/opencode-plugin/index.mjs +21 -368
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +2 -4
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/hooks.json +0 -14
- package/plugins/harness-everything/hooks/scripts/lib/harness-state.js +5 -6
- package/plugins/harness-everything/hooks/scripts/lib/learning-opportunity.js +3 -13
- package/plugins/harness-everything/hooks/scripts/lib/workspace.js +2 -2
- package/plugins/harness-everything/hooks/scripts/openai-session-start.js +2 -4
- package/plugins/harness-everything/hooks/session-start.js +2 -4
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/scripts/lib/advisory-text.js +2 -2
- package/plugins/harness-everything/scripts/lib/workspace.js +2 -2
- package/plugins/harness-everything/skills/environment-detection/SKILL.md +2 -2
- package/plugins/harness-everything/skills/environment-detection/references/shell-syntax-rules.md +1 -1
- package/plugins/harness-everything/skills/eval-harness/SKILL.md +1 -1
- package/plugins/harness-everything/skills/eval-harness/references/scoring-rubric.md +3 -3
- package/plugins/harness-everything/skills/fable-discipline/SKILL.md +3 -3
- package/plugins/harness-everything/skills/fable-discipline/references/discipline-rules.md +1 -1
- package/plugins/harness-everything/skills/fable-mode/SKILL.md +1 -1
- package/plugins/harness-everything/skills/fable-mode/execution-guardrails/SKILL.md +2 -4
- package/plugins/harness-everything/skills/fable-mode/execution-guardrails/references/guardrail-rules.md +3 -3
- package/plugins/harness-everything/skills/fable-mode/fable-haiku/SKILL.md +1 -1
- package/plugins/harness-everything/skills/fable-mode/fable-opus/SKILL.md +2 -2
- package/plugins/harness-everything/skills/fable-mode/fable-sonnet/SKILL.md +1 -1
- package/plugins/harness-everything/skills/fable-mode/references/execution-phases.md +2 -2
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +3 -3
- package/plugins/harness-everything/skills/harness-everything/references/router-workflow-plan.md +2 -2
- package/plugins/harness-everything/skills/harness-everything/references/skill-registry.md +2 -2
- package/plugins/harness-everything/skills/harness-everything/references/triage-and-tiers.md +5 -5
- package/plugins/harness-everything/skills/harness-everything/scripts/bootstrap.js +1 -26
- package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router-core.js +2 -3
- package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/router-contract-core.js +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +0 -2
- package/plugins/harness-everything/skills/improve-codebase-architecture/SKILL.md +3 -3
- package/plugins/harness-everything/skills/improve-codebase-architecture/guides/refactoring-workflow.md +5 -4
- package/plugins/harness-everything/skills/install-cognitive-os/SKILL.md +3 -3
- package/plugins/harness-everything/skills/self-evolve/SKILL.md +1 -1
- package/plugins/harness-everything/skills/self-evolve/references/memory-resolution.md +3 -3
- package/plugins/harness-everything/skills/self-evolve/schemas/lesson-candidate.schema.json +4 -1
- package/plugins/harness-everything/skills/self-evolve/scripts/lesson-candidate.js +1 -0
- package/plugins/harness-everything/skills/skill-creator/SKILL.md +1 -1
- package/plugins/harness-everything/skills/skill-creator/references/quality-checklist.md +1 -1
- package/plugins/harness-everything/skills/skill-creator/references/quality-principles.md +4 -4
- package/plugins/harness-everything/skills/tdd/SKILL.md +2 -2
- package/plugins/harness-everything/skills/tdd/references/core-discipline.md +3 -5
- package/plugins/harness-everything/skills/todo-driven-workflow/SKILL.md +2 -2
- package/plugins/harness-everything/skills/zoom-out/SKILL.md +14 -26
- package/plugins/harness-everything/skills/zoom-out/references/circuit-breaker.md +18 -62
- package/references/platform-advisory-template.md +3 -9
- package/sbom.cdx.json +7 -7
- package/scripts/dispatch.js +340 -0
- package/scripts/lib/advisory-text.js +2 -2
- package/scripts/lib/workspace.js +2 -2
- package/self-evolve/SKILL.md +1 -1
- package/self-evolve/references/memory-resolution.md +3 -3
- package/self-evolve/schemas/lesson-candidate.schema.json +4 -1
- package/self-evolve/scripts/lesson-candidate.js +1 -0
- package/skill-creator/SKILL.md +1 -1
- package/skill-creator/references/quality-checklist.md +1 -1
- package/skill-creator/references/quality-principles.md +4 -4
- package/submission/openai/test-cases.json +5 -5
- package/tdd/SKILL.md +2 -2
- package/tdd/references/core-discipline.md +3 -5
- package/todo-driven-workflow/SKILL.md +2 -2
- package/zoom-out/SKILL.md +14 -26
- package/zoom-out/references/circuit-breaker.md +18 -62
- package/behavioral-evals/opencode-hardlock-live.js +0 -17
- package/behavioral-evals/opencode-reflection-gate-live.js +0 -342
- package/ci/mechanism-31-opencode-hardlock-evidence.test.js +0 -82
- package/evals/zoom-out/tasks/negative-first-edge-case-review.yaml +0 -16
- package/evals/zoom-out/tasks/positive-repeated-failure.yaml +0 -15
- package/hooks/scripts/reset-circuit-breaker.js +0 -30
- package/hooks/scripts/rule-of-3-tracker.js +0 -165
- package/hooks/scripts/rule-of-3.js +0 -171
- package/plugins/harness-everything/hooks/scripts/reset-circuit-breaker.js +0 -30
- package/plugins/harness-everything/hooks/scripts/rule-of-3-tracker.js +0 -165
- package/plugins/harness-everything/hooks/scripts/rule-of-3.js +0 -171
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const { spawnSync } = require('node:child_process');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
|
|
9
|
+
const root = path.resolve(__dirname, '..');
|
|
10
|
+
const entry = path.join(root, 'scripts', 'dispatch.js');
|
|
11
|
+
const fixtureRunner = path.join(__dirname, 'fixtures', '468-dispatch', 'runner.js');
|
|
12
|
+
const tempParent = process.env.TMPDIR || os.tmpdir();
|
|
13
|
+
const rootReal = fs.realpathSync.native(root);
|
|
14
|
+
const tempRelative = path.relative(rootReal, fs.realpathSync.native(path.resolve(tempParent)));
|
|
15
|
+
assert.ok(tempRelative === '..' || tempRelative.startsWith(`..${path.sep}`) || path.isAbsolute(tempRelative), 'test TMPDIR must be outside the repository');
|
|
16
|
+
|
|
17
|
+
function canonicalPath(file) {
|
|
18
|
+
const resolved = fs.realpathSync.native(file);
|
|
19
|
+
return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function assertSameCanonicalPath(actual, expected, message) {
|
|
23
|
+
assert.equal(canonicalPath(actual), canonicalPath(expected), message);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const fixtureRoot = fs.mkdtempSync(path.join(tempParent, '468-dispatch-p2-'));
|
|
27
|
+
const repositoryParent = path.join(fixtureRoot, 'repository parent');
|
|
28
|
+
const worktree = path.join(repositoryParent, 'worktree with spaces');
|
|
29
|
+
const linkedWorktree = path.join(repositoryParent, 'linked worktree');
|
|
30
|
+
const symlinkedParent = path.join(fixtureRoot, 'symlinked parent');
|
|
31
|
+
const reports = path.join(fixtureRoot, 'reports with spaces');
|
|
32
|
+
const runnerBin = path.join(fixtureRoot, 'runner bin');
|
|
33
|
+
const openCodeOnlyBin = path.join(fixtureRoot, 'opencode only bin');
|
|
34
|
+
const packet = path.join(worktree, 'packet with spaces.md');
|
|
35
|
+
const failures = [];
|
|
36
|
+
const passed = [];
|
|
37
|
+
let caseNumber = 0;
|
|
38
|
+
|
|
39
|
+
function run(command, args, options = {}) {
|
|
40
|
+
const result = spawnSync(command, args, { encoding: 'utf8', ...options });
|
|
41
|
+
assert.equal(result.error, undefined, result.error?.message);
|
|
42
|
+
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function makeRepository() {
|
|
47
|
+
fs.mkdirSync(repositoryParent, { recursive: true });
|
|
48
|
+
fs.mkdirSync(worktree);
|
|
49
|
+
run('git', ['init', '--quiet', worktree]);
|
|
50
|
+
run('git', ['-C', worktree, 'config', 'user.name', 'Dispatch Fixture']);
|
|
51
|
+
run('git', ['-C', worktree, 'config', 'user.email', 'dispatch-fixture@example.invalid']);
|
|
52
|
+
fs.writeFileSync(packet, 'P2 fixture packet\n');
|
|
53
|
+
run('git', ['-C', worktree, 'add', 'packet with spaces.md']);
|
|
54
|
+
run('git', ['-C', worktree, 'commit', '--quiet', '-m', 'fixture']);
|
|
55
|
+
run('git', ['-C', worktree, 'worktree', 'add', '--quiet', '--detach', linkedWorktree, 'HEAD']);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function linkNodeExecutable(bin, name) {
|
|
59
|
+
const executable = path.join(bin, process.platform === 'win32' ? `${name}.exe` : name);
|
|
60
|
+
if (process.platform === 'win32') {
|
|
61
|
+
try { fs.linkSync(process.execPath, executable); } catch { fs.copyFileSync(process.execPath, executable); }
|
|
62
|
+
} else fs.symlinkSync(process.execPath, executable);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function makeRunnerPath() {
|
|
66
|
+
fs.mkdirSync(runnerBin);
|
|
67
|
+
fs.mkdirSync(openCodeOnlyBin);
|
|
68
|
+
for (const name of ['codex', 'opencode']) linkNodeExecutable(runnerBin, name);
|
|
69
|
+
linkNodeExecutable(openCodeOnlyBin, 'opencode');
|
|
70
|
+
fs.copyFileSync(fixtureRunner, path.join(worktree, 'exec'));
|
|
71
|
+
fs.copyFileSync(fixtureRunner, path.join(worktree, 'run'));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function makeCase(label) {
|
|
75
|
+
caseNumber += 1;
|
|
76
|
+
return {
|
|
77
|
+
scratch: path.join(fixtureRoot, `scratch ${caseNumber} ${label}`),
|
|
78
|
+
report: path.join(reports, `report ${caseNumber} ${label}.md`),
|
|
79
|
+
log: path.join(fixtureRoot, `runner events ${caseNumber}.jsonl`),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function argsFor(testCase, runner = 'codex', model = runner === 'codex' ? 'fixture/codex-model' : 'fixture/opencode-model') {
|
|
84
|
+
return [
|
|
85
|
+
'--runner', runner,
|
|
86
|
+
'--model', model,
|
|
87
|
+
'--packet', packet,
|
|
88
|
+
'--worktree', worktree,
|
|
89
|
+
'--scratch', testCase.scratch,
|
|
90
|
+
'--report', testCase.report,
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function cli(args, testCase, config = {}) {
|
|
95
|
+
const env = {
|
|
96
|
+
...process.env,
|
|
97
|
+
PATH: config.path || runnerBin,
|
|
98
|
+
TMPDIR: testCase.scratch,
|
|
99
|
+
NODE_ENV: 'test',
|
|
100
|
+
DISPATCH_TEST_TIMEOUT_MS: String(config.testTimeoutMs || 750),
|
|
101
|
+
DISPATCH_FIXTURE_LOG: testCase.log,
|
|
102
|
+
DISPATCH_FIXTURE_REPORT_PATH: testCase.report,
|
|
103
|
+
DISPATCH_FIXTURE_READINESS: config.readiness || 'ready',
|
|
104
|
+
DISPATCH_FIXTURE_EXECUTION: config.execution || 'done',
|
|
105
|
+
};
|
|
106
|
+
delete env.HARNESS_SYSTEM_ONE_MODE;
|
|
107
|
+
const result = spawnSync(process.execPath, [entry, ...args], {
|
|
108
|
+
cwd: root,
|
|
109
|
+
env,
|
|
110
|
+
encoding: 'utf8',
|
|
111
|
+
input: 'parent stdin must not reach the runner\n',
|
|
112
|
+
timeout: config.outerTimeoutMs || 15000,
|
|
113
|
+
});
|
|
114
|
+
if (result.error?.code === 'ETIMEDOUT') {
|
|
115
|
+
for (const event of events(testCase)) {
|
|
116
|
+
try { process.kill(event.pid, 'SIGKILL'); } catch {}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function jsonResponse(result, exitCode, code) {
|
|
123
|
+
assert.equal(result.error, undefined, result.error?.message);
|
|
124
|
+
assert.equal(result.status, exitCode, result.stderr || result.stdout);
|
|
125
|
+
assert.equal(result.stderr, '');
|
|
126
|
+
assert.equal(result.stdout.trim().split(/\r?\n/).length, 1, result.stdout);
|
|
127
|
+
const response = JSON.parse(result.stdout);
|
|
128
|
+
assert.equal(response.code, code);
|
|
129
|
+
assert.equal(response.ok, exitCode === 0);
|
|
130
|
+
return response;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function events(testCase) {
|
|
134
|
+
if (!fs.existsSync(testCase.log)) return [];
|
|
135
|
+
return fs.readFileSync(testCase.log, 'utf8').trim().split(/\r?\n/).filter(Boolean).map(line => JSON.parse(line));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function check(name, body) {
|
|
139
|
+
try {
|
|
140
|
+
body();
|
|
141
|
+
passed.push(name);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
failures.push(`${name}: ${error.message}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function assertNoRunner(testCase) {
|
|
148
|
+
assert.deepEqual(events(testCase), []);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function assertNoScratchOrReport(testCase) {
|
|
152
|
+
assert.equal(fs.existsSync(testCase.scratch), false);
|
|
153
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function assertEvent(event, testCase, runner, phase, model = runner === 'codex' ? 'fixture/codex-model' : 'fixture/opencode-model') {
|
|
157
|
+
assert.equal(event.runner, runner);
|
|
158
|
+
assert.equal(event.phase, phase);
|
|
159
|
+
assertSameCanonicalPath(event.cwd, worktree, 'child cwd must resolve to the requested worktree');
|
|
160
|
+
assert.equal(event.tmpdir, testCase.scratch);
|
|
161
|
+
assert.equal(event.stdin, '');
|
|
162
|
+
assert.equal(event.stdinIsCharacterDevice, true);
|
|
163
|
+
assert.equal(event.args[event.args.indexOf('-m') + 1], model);
|
|
164
|
+
assert.equal(event.args.at(-1), phase === 'readiness'
|
|
165
|
+
? 'Reply exactly with READY.'
|
|
166
|
+
: `Execute the packet at ${packet} and ${runner === 'codex' ? 'return the complete report body.' : `write the complete report to ${testCase.report}.`}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function assertProcessExited(pid) {
|
|
170
|
+
let error;
|
|
171
|
+
try { process.kill(pid, 0); } catch (cause) { error = cause; }
|
|
172
|
+
assert.equal(error?.code, 'ESRCH', `child process ${pid} is still running`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function removeOption(args, option) {
|
|
176
|
+
const index = args.indexOf(option);
|
|
177
|
+
if (index >= 0) args.splice(index, 2);
|
|
178
|
+
return args;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function assertNoExecutionAfterReadinessFailure(testCase, runner, response, model = runner === 'codex' ? 'fixture/codex-model' : 'fixture/opencode-model') {
|
|
182
|
+
assert.equal(typeof response.code, 'string');
|
|
183
|
+
assert.equal(typeof response.ok, 'boolean');
|
|
184
|
+
assert.equal(response.phase, 'readiness');
|
|
185
|
+
assert.equal(response.runner, runner);
|
|
186
|
+
assert.equal(response.model, model);
|
|
187
|
+
assert.deepEqual(Object.keys(response).sort(), ['code', 'evidence', 'message', 'model', 'ok', 'phase', 'runner'].sort());
|
|
188
|
+
const actualEvents = events(testCase);
|
|
189
|
+
assert.equal(actualEvents.length, 1, 'refusal must make one readiness call and no execution or fallback call');
|
|
190
|
+
assertEvent(actualEvents[0], testCase, runner, 'readiness', model);
|
|
191
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
192
|
+
assert.ok(response.evidence?.readinessLog, 'refusal should retain readiness evidence');
|
|
193
|
+
for (const key of ['runLog', 'rawOutput', 'reportWriterLog']) {
|
|
194
|
+
assert.equal(response.evidence[key], undefined, `${key} must not be created before a successful readiness check`);
|
|
195
|
+
}
|
|
196
|
+
const files = fs.readdirSync(testCase.scratch);
|
|
197
|
+
assert.equal(files.some(file => /(?:raw\.txt|run\.log|report-writer\.log)$/.test(file)), false);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function assertReadinessRefusal(testCase, runner, response, model = runner === 'codex' ? 'fixture/codex-model' : 'fixture/opencode-model') {
|
|
201
|
+
assert.equal(response.message, 'Readiness failed. Keep the available child evidence.');
|
|
202
|
+
assertNoExecutionAfterReadinessFailure(testCase, runner, response, model);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function runSuccessAndArgvMatch(runner, requestedModel = runner === 'codex' ? 'fixture/codex-model' : 'fixture/opencode-model') {
|
|
206
|
+
const testCase = makeCase(`${runner} success`);
|
|
207
|
+
const model = requestedModel.trim();
|
|
208
|
+
const args = argsFor(testCase, runner, requestedModel);
|
|
209
|
+
const dryRun = jsonResponse(cli([...args, '--dry-run', '--json'], testCase), 0, 'DRY_RUN_OK');
|
|
210
|
+
assert.equal(dryRun.model, model);
|
|
211
|
+
assert.equal(dryRun.argv[dryRun.argv.indexOf('-m') + 1], model);
|
|
212
|
+
assertSameCanonicalPath(dryRun.cwd, worktree, 'dry-run cwd must resolve to the requested worktree');
|
|
213
|
+
assert.equal(dryRun.argv[0], runner);
|
|
214
|
+
assertNoRunner(testCase);
|
|
215
|
+
assertNoScratchOrReport(testCase);
|
|
216
|
+
|
|
217
|
+
const result = jsonResponse(cli([...args, '--json'], testCase), 0, 'DONE');
|
|
218
|
+
assert.equal(result.runner, runner);
|
|
219
|
+
assert.equal(result.model, model);
|
|
220
|
+
assert.equal(fs.existsSync(testCase.scratch), true);
|
|
221
|
+
assert.equal(fs.readFileSync(result.evidence.report, 'utf8'), 'Fixture completed the packet.\nSTATUS: DONE\n');
|
|
222
|
+
const actualEvents = events(testCase);
|
|
223
|
+
assert.equal(actualEvents.length, 2, 'one readiness and one execution; no retry or fallback');
|
|
224
|
+
for (const event of actualEvents) assertEvent(event, testCase, runner, event.phase, model);
|
|
225
|
+
const observedArgv = [actualEvents[1].runner, ...actualEvents[1].args];
|
|
226
|
+
if (runner === 'codex') {
|
|
227
|
+
const outputIndex = observedArgv.indexOf('-o') + 1;
|
|
228
|
+
assert.ok(outputIndex > 0);
|
|
229
|
+
assert.equal(path.dirname(observedArgv[outputIndex]), testCase.scratch);
|
|
230
|
+
observedArgv[outputIndex] = dryRun.argv[outputIndex];
|
|
231
|
+
assert.match(dryRun.argv[outputIndex], /<run-id>/);
|
|
232
|
+
}
|
|
233
|
+
assert.deepEqual(dryRun.argv, observedArgv);
|
|
234
|
+
assertSameCanonicalPath(dryRun.cwd, actualEvents[1].cwd, 'dry-run and child cwd must identify the same directory');
|
|
235
|
+
if (runner === 'codex') {
|
|
236
|
+
const writerLog = fs.readFileSync(result.evidence.reportWriterLog, 'utf8');
|
|
237
|
+
assert.ok(writerLog.includes(`Wrote ${testCase.report}`));
|
|
238
|
+
assert.ok(writerLog.includes('valid (STATUS: DONE)'));
|
|
239
|
+
} else {
|
|
240
|
+
assert.match(fs.readFileSync(result.evidence.reportWriterLog, 'utf8'), /valid \(STATUS: DONE\)/);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function runReportInvalidCase(runner, scenario) {
|
|
245
|
+
const testCase = makeCase(`${runner} ${scenario}`);
|
|
246
|
+
const response = jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, { execution: scenario }), 16, 'REPORT_INVALID');
|
|
247
|
+
assert.equal(events(testCase).length, 2, 'no execution retry or runner fallback');
|
|
248
|
+
for (const event of events(testCase)) assert.equal(event.runner, runner);
|
|
249
|
+
assert.equal(fs.existsSync(testCase.report), runner === 'opencode' && scenario !== 'missing-report');
|
|
250
|
+
return response;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
makeRepository();
|
|
254
|
+
makeRunnerPath();
|
|
255
|
+
fs.mkdirSync(reports);
|
|
256
|
+
fs.mkdirSync(path.join(fixtureRoot, `${path.basename(worktree)}-sibling`));
|
|
257
|
+
fs.symlinkSync(repositoryParent, symlinkedParent, process.platform === 'win32' ? 'junction' : 'dir');
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
check('HELP human and JSON', () => {
|
|
261
|
+
const testCase = makeCase('help');
|
|
262
|
+
const human = cli(['--help'], testCase);
|
|
263
|
+
assert.equal(human.status, 0, human.stderr);
|
|
264
|
+
assert.match(human.stdout, /Usage:.*dispatch/);
|
|
265
|
+
assert.equal(human.stderr, '');
|
|
266
|
+
const json = jsonResponse(cli(['--json', '--help'], testCase), 0, 'HELP');
|
|
267
|
+
assert.match(json.message, /--runner <codex\|opencode>/);
|
|
268
|
+
assertNoRunner(testCase);
|
|
269
|
+
assertNoScratchOrReport(testCase);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
for (const args of [['--json', '--bad-option'], ['--bad-option', '--json']]) {
|
|
273
|
+
check(`INVALID_INPUT JSON ordering ${args[0]}`, () => {
|
|
274
|
+
const testCase = makeCase('invalid option');
|
|
275
|
+
const response = jsonResponse(cli(args, testCase), 10, 'INVALID_INPUT');
|
|
276
|
+
assert.equal(response.phase, 'input');
|
|
277
|
+
assertNoRunner(testCase);
|
|
278
|
+
assertNoScratchOrReport(testCase);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
for (const option of ['--runner', '--model', '--packet']) {
|
|
283
|
+
check(`INVALID_INPUT missing ${option}`, () => {
|
|
284
|
+
const testCase = makeCase(`missing ${option}`);
|
|
285
|
+
const response = jsonResponse(cli([...removeOption(argsFor(testCase), option), '--json'], testCase), 10, 'INVALID_INPUT');
|
|
286
|
+
assert.equal(response.phase, 'input');
|
|
287
|
+
assertNoRunner(testCase);
|
|
288
|
+
assertNoScratchOrReport(testCase);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
check('INVALID_INPUT rejects a report path that is already occupied', () => {
|
|
293
|
+
const testCase = makeCase('preexisting report');
|
|
294
|
+
fs.writeFileSync(testCase.report, 'Old report.\nSTATUS: DONE\n');
|
|
295
|
+
jsonResponse(cli([...argsFor(testCase), '--json'], testCase), 10, 'INVALID_INPUT');
|
|
296
|
+
assertNoRunner(testCase);
|
|
297
|
+
assert.equal(fs.existsSync(testCase.scratch), false);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
check('INVALID_INPUT rejects a non-Git worktree', () => {
|
|
301
|
+
const testCase = makeCase('invalid worktree');
|
|
302
|
+
const invalidWorktree = path.join(fixtureRoot, 'invalid worktree');
|
|
303
|
+
fs.mkdirSync(path.join(invalidWorktree, '.git'), { recursive: true });
|
|
304
|
+
const args = argsFor(testCase);
|
|
305
|
+
args[args.indexOf('--worktree') + 1] = invalidWorktree;
|
|
306
|
+
jsonResponse(cli([...args, '--json'], testCase), 10, 'INVALID_INPUT');
|
|
307
|
+
assertNoRunner(testCase);
|
|
308
|
+
assertNoScratchOrReport(testCase);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
check('UNSAFE_SCRATCH refuses a repository descendant', () => {
|
|
312
|
+
const testCase = makeCase('repo scratch');
|
|
313
|
+
const scratch = path.join(worktree, 'scratch');
|
|
314
|
+
const args = argsFor(testCase);
|
|
315
|
+
args[args.indexOf('--scratch') + 1] = scratch;
|
|
316
|
+
jsonResponse(cli([...args, '--json'], testCase), 11, 'UNSAFE_SCRATCH');
|
|
317
|
+
assertNoRunner(testCase);
|
|
318
|
+
assert.equal(fs.existsSync(scratch), false);
|
|
319
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
check('UNSAFE_SCRATCH refuses a linked-worktree .git file ancestor', () => {
|
|
323
|
+
const testCase = makeCase('linked worktree scratch');
|
|
324
|
+
assert.equal(fs.statSync(path.join(linkedWorktree, '.git')).isFile(), true);
|
|
325
|
+
const args = argsFor(testCase);
|
|
326
|
+
args[args.indexOf('--scratch') + 1] = path.join(linkedWorktree, 'scratch');
|
|
327
|
+
jsonResponse(cli([...args, '--json'], testCase), 11, 'UNSAFE_SCRATCH');
|
|
328
|
+
assertNoRunner(testCase);
|
|
329
|
+
assert.equal(fs.existsSync(path.join(linkedWorktree, 'scratch')), false);
|
|
330
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
check('UNSAFE_SCRATCH resolves a symlinked ancestor before checking Git roots', () => {
|
|
334
|
+
const testCase = makeCase('symlinked ancestor');
|
|
335
|
+
const args = argsFor(testCase);
|
|
336
|
+
args[args.indexOf('--scratch') + 1] = path.join(symlinkedParent, path.basename(worktree), 'scratch');
|
|
337
|
+
jsonResponse(cli([...args, '--json'], testCase), 11, 'UNSAFE_SCRATCH');
|
|
338
|
+
assertNoRunner(testCase);
|
|
339
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
check('external sibling-prefix scratch remains outside the worktree', () => {
|
|
343
|
+
const testCase = makeCase('sibling prefix');
|
|
344
|
+
const args = argsFor(testCase);
|
|
345
|
+
const siblingScratch = path.join(fixtureRoot, `${path.basename(worktree)}-sibling`, 'scratch');
|
|
346
|
+
args[args.indexOf('--scratch') + 1] = siblingScratch;
|
|
347
|
+
const response = jsonResponse(cli([...args, '--dry-run', '--json'], testCase), 0, 'DRY_RUN_OK');
|
|
348
|
+
assertSameCanonicalPath(response.cwd, worktree);
|
|
349
|
+
assertNoRunner(testCase);
|
|
350
|
+
assert.equal(fs.existsSync(siblingScratch), false);
|
|
351
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
check('path.win32 cross-drive control is exercised through the real entry', () => {
|
|
355
|
+
const relative = path.win32.relative('C:\\repo', 'D:\\scratch\\dispatch');
|
|
356
|
+
assert.equal(path.win32.isAbsolute(relative), true);
|
|
357
|
+
assert.equal(path.win32.resolve('C:\\repo', relative), 'D:\\scratch\\dispatch');
|
|
358
|
+
const testCase = makeCase('cross-drive scratch');
|
|
359
|
+
const worktreeRoot = path.win32.parse(canonicalPath(worktree)).root;
|
|
360
|
+
const currentDrive = /^([A-Za-z]:)/.exec(worktreeRoot)?.[1].toUpperCase() || 'C:';
|
|
361
|
+
const otherDrive = currentDrive === 'C:' ? 'D:' : 'C:';
|
|
362
|
+
const crossDriveScratch = `${otherDrive}\\468-dispatch-p2\\scratch`;
|
|
363
|
+
const args = argsFor(testCase);
|
|
364
|
+
args[args.indexOf('--scratch') + 1] = crossDriveScratch;
|
|
365
|
+
const expected = process.platform === 'win32' ? ['0', 'DRY_RUN_OK'] : ['11', 'UNSAFE_SCRATCH'];
|
|
366
|
+
const response = jsonResponse(cli([...args, '--dry-run', '--json'], testCase), Number(expected[0]), expected[1]);
|
|
367
|
+
if (process.platform === 'win32') assertSameCanonicalPath(response.cwd, worktree);
|
|
368
|
+
assertNoRunner(testCase);
|
|
369
|
+
assert.equal(fs.existsSync(crossDriveScratch), false);
|
|
370
|
+
assertNoScratchOrReport(testCase);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
check('cwd oracle accepts the selected linked worktree and rejects a different directory', () => {
|
|
374
|
+
const testCase = makeCase('different cwd control');
|
|
375
|
+
const args = argsFor(testCase);
|
|
376
|
+
args[args.indexOf('--packet') + 1] = 'packet with spaces.md';
|
|
377
|
+
args[args.indexOf('--worktree') + 1] = linkedWorktree;
|
|
378
|
+
const response = jsonResponse(cli([...args, '--dry-run', '--json'], testCase), 0, 'DRY_RUN_OK');
|
|
379
|
+
assertSameCanonicalPath(response.cwd, linkedWorktree);
|
|
380
|
+
assert.notEqual(canonicalPath(response.cwd), canonicalPath(worktree));
|
|
381
|
+
assertNoRunner(testCase);
|
|
382
|
+
assertNoScratchOrReport(testCase);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
for (const runner of ['codex', 'opencode']) {
|
|
386
|
+
check(`${runner} real entry succeeds and dry-run argv/cwd match execution`, () => runSuccessAndArgvMatch(runner));
|
|
387
|
+
check(`${runner} reports one trimmed model across dry-run, both runner calls, and run JSON`, () => {
|
|
388
|
+
runSuccessAndArgvMatch(runner, ` ${runner === 'codex' ? 'fixture/codex-model' : 'fixture/opencode-model'} `);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
check(`${runner} supported provider text on successful READY does not refuse`, () => {
|
|
392
|
+
const testCase = makeCase(`${runner} provider text on success`);
|
|
393
|
+
const response = jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, {
|
|
394
|
+
readiness: 'ready-with-provider-rate', execution: 'done-with-quota-prose',
|
|
395
|
+
}), 0, 'DONE');
|
|
396
|
+
assert.match(fs.readFileSync(response.evidence.readinessLog, 'utf8'), /Provider request failed with HTTP 429/);
|
|
397
|
+
const actualEvents = events(testCase);
|
|
398
|
+
assert.equal(actualEvents.length, 2);
|
|
399
|
+
assertEvent(actualEvents[0], testCase, runner, 'readiness');
|
|
400
|
+
assertEvent(actualEvents[1], testCase, runner, 'execution');
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
for (const scenario of ['no-ready', 'ready-failed', 'stdout-provider-rate', 'wrong-envelope', 'quoted-provider-rate', 'local-http-429', 'invalid-quota', 'bare-429', 'provider-rate-with-extra-text', 'provider-timeout',
|
|
404
|
+
// Windows has no POSIX signals: a self-SIGTERM reports exit 1 with signal null, so the signal row only exists off win32.
|
|
405
|
+
...(process.platform === 'win32' ? [] : ['signal-provider-rate'])]) {
|
|
406
|
+
check(`${runner} readiness ${scenario} -> NOT_READY`, () => {
|
|
407
|
+
const testCase = makeCase(`${runner} ${scenario}`);
|
|
408
|
+
const response = jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, { readiness: scenario }), 12, 'NOT_READY');
|
|
409
|
+
assertReadinessRefusal(testCase, runner, response);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
for (const scenario of ['rate-limit-and-quota', 'quota-and-rate-limit']) {
|
|
414
|
+
check(`${runner} readiness ${scenario} -> NOT_READY regardless of diagnostic order`, () => {
|
|
415
|
+
const testCase = makeCase(`${runner} ${scenario}`);
|
|
416
|
+
const response = jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, { readiness: scenario }), 12, 'NOT_READY');
|
|
417
|
+
const readinessLog = fs.readFileSync(response.evidence.readinessLog, 'utf8');
|
|
418
|
+
assert.ok(readinessLog.includes('Provider request failed with HTTP 429'));
|
|
419
|
+
assert.ok(readinessLog.includes('Free usage limit reached'));
|
|
420
|
+
assertReadinessRefusal(testCase, runner, response);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
check(`${runner} validated padded model is retained in readiness failure JSON`, () => {
|
|
425
|
+
const testCase = makeCase(`${runner} padded model refusal`);
|
|
426
|
+
const model = runner === 'codex' ? 'fixture/codex-model' : 'fixture/opencode-model';
|
|
427
|
+
const response = jsonResponse(cli([...argsFor(testCase, runner, ` ${model} `), '--json'], testCase, {
|
|
428
|
+
readiness: 'invalid-quota',
|
|
429
|
+
}), 12, 'NOT_READY');
|
|
430
|
+
assert.equal(response.model, model);
|
|
431
|
+
assertReadinessRefusal(testCase, runner, response, model);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
check(`${runner} readiness timeout -> NOT_READY and child exited`, () => {
|
|
435
|
+
const testCase = makeCase(`${runner} readiness timeout`);
|
|
436
|
+
const response = jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, {
|
|
437
|
+
readiness: 'timeout', testTimeoutMs: 300, outerTimeoutMs: 5000,
|
|
438
|
+
}), 12, 'NOT_READY');
|
|
439
|
+
const actualEvents = events(testCase);
|
|
440
|
+
assertReadinessRefusal(testCase, runner, response);
|
|
441
|
+
assertProcessExited(actualEvents[0].pid);
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
for (const { scenario, code, message, cause } of [
|
|
445
|
+
{ scenario: 'rate-limited', code: 'RUNNER_RATE_LIMITED', message: 'Reduce concurrency on the affected key or retry later.', cause: 'Provider request failed with HTTP 429: {"status":429,"title":"Too Many Requests"}' },
|
|
446
|
+
{ scenario: 'quota-exhausted', code: 'RUNNER_QUOTA', message: 'Select an authorized runner or model with available quota.', cause: 'Free usage limit reached. Free models work in OpenCode (https://opencode.ai); subscribe to OpenCode Go to keep going: https://opencode.ai/go' },
|
|
447
|
+
]) {
|
|
448
|
+
const evidence = runner === 'codex' ? ' (fixture-only)' : ' (OpenCode envelope live-traced)';
|
|
449
|
+
check(`${runner}${evidence} ${scenario} -> ${code} without fallback`, () => {
|
|
450
|
+
const testCase = makeCase(`${runner} ${scenario}`);
|
|
451
|
+
const response = jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, { readiness: scenario }), 13, code);
|
|
452
|
+
assert.equal(response.message, message);
|
|
453
|
+
assert.match(fs.readFileSync(response.evidence.readinessLog, 'utf8'), /\u001b\[91m\u001b\[1m/);
|
|
454
|
+
assert.ok(fs.readFileSync(response.evidence.readinessLog, 'utf8').includes(cause));
|
|
455
|
+
assertNoExecutionAfterReadinessFailure(testCase, runner, response);
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
check(`${runner} execution failure -> RUN_FAILED with no retry/fallback`, () => {
|
|
460
|
+
const testCase = makeCase(`${runner} run failed`);
|
|
461
|
+
const response = jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, { execution: 'exit-failure' }), 15, 'RUN_FAILED');
|
|
462
|
+
const actualEvents = events(testCase);
|
|
463
|
+
assert.equal(actualEvents.length, 2);
|
|
464
|
+
assert.ok(actualEvents.every(event => event.runner === runner));
|
|
465
|
+
assert.equal(fs.existsSync(response.evidence.runLog), true);
|
|
466
|
+
if (runner === 'codex') assert.equal(fs.existsSync(response.evidence.rawOutput), true);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
check(`${runner} execution timeout -> RUN_TIMEOUT and child exited`, () => {
|
|
470
|
+
const testCase = makeCase(`${runner} run timeout`);
|
|
471
|
+
jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, {
|
|
472
|
+
execution: 'timeout', testTimeoutMs: 300, outerTimeoutMs: 5000,
|
|
473
|
+
}), 15, 'RUN_TIMEOUT');
|
|
474
|
+
const actualEvents = events(testCase);
|
|
475
|
+
assert.equal(actualEvents.length, 2);
|
|
476
|
+
assert.ok(actualEvents.every(event => event.runner === runner));
|
|
477
|
+
assertProcessExited(actualEvents[1].pid);
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
check(`${runner} valid BLOCKED report -> WORKER_BLOCKED with reason`, () => {
|
|
481
|
+
const testCase = makeCase(`${runner} blocked`);
|
|
482
|
+
const response = jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, { execution: 'blocked' }), 17, 'WORKER_BLOCKED');
|
|
483
|
+
assert.match(response.message, /missing evidence/);
|
|
484
|
+
assert.match(fs.readFileSync(testCase.report, 'utf8'), /STATUS: BLOCKED: missing evidence/);
|
|
485
|
+
assert.match(fs.readFileSync(response.evidence.reportWriterLog, 'utf8'), /valid \(STATUS: BLOCKED: missing evidence\)/);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
check(`${runner} report created during readiness is stale and rejected before run`, () => {
|
|
489
|
+
const testCase = makeCase(`${runner} stale report`);
|
|
490
|
+
jsonResponse(cli([...argsFor(testCase, runner), '--json'], testCase, { readiness: 'create-stale-report' }), 16, 'REPORT_INVALID');
|
|
491
|
+
const actualEvents = events(testCase);
|
|
492
|
+
assert.equal(actualEvents.length, 1, 'stale report must not be accepted as a fresh run result');
|
|
493
|
+
assert.equal(actualEvents[0].phase, 'readiness');
|
|
494
|
+
assert.equal(fs.readFileSync(testCase.report, 'utf8'), 'Stale report.\nSTATUS: DONE\n');
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
check('missing selected Codex executable -> NOT_READY without OpenCode fallback', () => {
|
|
499
|
+
const testCase = makeCase('missing codex executable');
|
|
500
|
+
const response = jsonResponse(cli([...argsFor(testCase, 'codex'), '--json'], testCase, { path: openCodeOnlyBin }), 12, 'NOT_READY');
|
|
501
|
+
assert.equal(response.message, 'Readiness failed. Keep the available child evidence.');
|
|
502
|
+
assertNoRunner(testCase);
|
|
503
|
+
assert.equal(fs.existsSync(testCase.report), false);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
check('Codex raw output with terminal host label is accepted and writer strips label', () => {
|
|
507
|
+
const testCase = makeCase('Codex host label');
|
|
508
|
+
const response = jsonResponse(cli([...argsFor(testCase), '--json'], testCase, { execution: 'raw-label' }), 0, 'DONE');
|
|
509
|
+
assert.equal(fs.readFileSync(testCase.report, 'utf8'), 'Fixture completed the packet.\nSTATUS: DONE\n');
|
|
510
|
+
assert.match(fs.readFileSync(response.evidence.reportWriterLog, 'utf8'), /stripped the terminal host label/);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
for (const scenario of ['missing-raw', 'no-status', 'multiple-status', 'bad-label']) {
|
|
514
|
+
check(`Codex ${scenario} -> REPORT_INVALID`, () => runReportInvalidCase('codex', scenario));
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
for (const scenario of ['missing-report', 'malformed-report']) {
|
|
518
|
+
check(`OpenCode ${scenario} -> REPORT_INVALID`, () => runReportInvalidCase('opencode', scenario));
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
check('INTERNAL_ERROR is one terminal outcome when evidence storage fails', () => {
|
|
522
|
+
const testCase = makeCase('internal error');
|
|
523
|
+
const response = jsonResponse(cli([...argsFor(testCase), '--json'], testCase, { readiness: 'remove-scratch' }), 1, 'INTERNAL_ERROR');
|
|
524
|
+
assert.equal(response.phase, 'application');
|
|
525
|
+
assert.equal(events(testCase).length, 1);
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
check('entry usage mentions every option used by the CLI contract', () => {
|
|
529
|
+
const testCase = makeCase('usage options');
|
|
530
|
+
const response = jsonResponse(cli(['--help', '--json'], testCase), 0, 'HELP');
|
|
531
|
+
for (const option of ['--runner', '--model', '--packet', '--worktree', '--scratch', '--report', '--dry-run', '--json', '--help']) {
|
|
532
|
+
assert.ok(response.message.includes(option), `usage is missing ${option}`);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
} finally {
|
|
536
|
+
try { run('git', ['-C', worktree, 'worktree', 'remove', '--force', linkedWorktree]); } catch {}
|
|
537
|
+
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (failures.length) {
|
|
541
|
+
console.error(`RED matrix rows: ${failures.length}/${passed.length + failures.length} failed`);
|
|
542
|
+
for (const failure of failures) console.error(`- ${failure}`);
|
|
543
|
+
process.exitCode = 1;
|
|
544
|
+
} else {
|
|
545
|
+
console.log(`mechanism-468-dispatch-cli: ${passed.length} P2 matrix rows passed`);
|
|
546
|
+
}
|
|
@@ -11,6 +11,9 @@ const pluginRoot = path.join(root, 'plugins', 'harness-everything');
|
|
|
11
11
|
const manifest = require('../plugins/harness-everything/hooks/hooks.json');
|
|
12
12
|
const { getSessionDir, getStateRoot } = require('../hooks/scripts/lib/harness-state');
|
|
13
13
|
|
|
14
|
+
assert.doesNotMatch(JSON.stringify(manifest.hooks), /rule-of-3(?:-tracker)?\.js|reset-circuit-breaker\.js/,
|
|
15
|
+
'packaged Codex hooks must not register retired breaker entry points');
|
|
16
|
+
|
|
14
17
|
function registeredHook(event, script) {
|
|
15
18
|
const handler = manifest.hooks[event].flatMap(group => group.hooks)
|
|
16
19
|
.find(hook => hook.command.includes('/' + script + '"'));
|
|
@@ -61,22 +64,22 @@ try {
|
|
|
61
64
|
}));
|
|
62
65
|
function read(file) { return JSON.parse(fs.readFileSync(file, 'utf8')); }
|
|
63
66
|
function post(response) {
|
|
64
|
-
for (const script of ['state-persist.js', '
|
|
67
|
+
for (const script of ['state-persist.js', 'contract-test.js']) {
|
|
65
68
|
hook('PostToolUse', script, { ...shell, tool_response: response });
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
const handoff = path.join(session, 'handoff-state.json');
|
|
70
|
-
const tracker = path.join(session, 'rule-of-3-state.json');
|
|
71
73
|
post({ exit_code: 1, stderr: 'test failed' });
|
|
72
74
|
assert.equal(read(handoff).status, 'failed');
|
|
73
|
-
assert.equal(
|
|
75
|
+
assert.equal(fs.existsSync(path.join(session, 'rule-of-3-state.json')), false,
|
|
76
|
+
'failure result capture must not create retired breaker state');
|
|
74
77
|
assert.equal(read(contract).status, 'fail');
|
|
75
78
|
function evidenceSnapshot() {
|
|
76
79
|
// Test commands can themselves write files, so the edit timestamp is
|
|
77
80
|
// independent of whether the host confirmed success.
|
|
78
81
|
const { lastEditAt, ...verification } = read(handoff);
|
|
79
|
-
return [verification, ...[
|
|
82
|
+
return [verification, ...[contract, evidence].map(read)];
|
|
80
83
|
}
|
|
81
84
|
const snapshots = evidenceSnapshot();
|
|
82
85
|
|
|
@@ -91,7 +94,8 @@ try {
|
|
|
91
94
|
post({ exitCode: 0, stderr: 'benign test warning' });
|
|
92
95
|
assert.equal(read(handoff).status, 'idle');
|
|
93
96
|
assert.ok(read(handoff).lastVerifyAt > 0);
|
|
94
|
-
assert.equal(
|
|
97
|
+
assert.equal(fs.existsSync(path.join(session, 'rule-of-3-state.json')), false,
|
|
98
|
+
'successful result capture must not create retired breaker state');
|
|
95
99
|
assert.equal(read(contract).status, 'pass');
|
|
96
100
|
|
|
97
101
|
const priorEdit = read(handoff).lastEditAt;
|
|
@@ -118,6 +118,7 @@ test('check rejects dropped, extra and reversed links with actionable diagnostic
|
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
test('new then set-status then check preserves identities and detects later drift', () => {
|
|
121
|
+
const alias = 'I';
|
|
121
122
|
const dir = fs.mkdtempSync(path.join(TEMP, 'walk-'));
|
|
122
123
|
const mapPath = path.join(dir, 'nodes.yaml');
|
|
123
124
|
const diagramPath = path.join(dir, 'README.md');
|
|
@@ -126,36 +127,37 @@ test('new then set-status then check preserves identities and detects later drif
|
|
|
126
127
|
fs.copyFileSync(CANONICAL_DIAGRAM, diagramPath);
|
|
127
128
|
const before = yaml.load(originalMap);
|
|
128
129
|
|
|
129
|
-
const created = invoke({ mapPath, diagramPath }, 'new', '--alias',
|
|
130
|
+
const created = invoke({ mapPath, diagramPath }, 'new', '--alias', alias, '--name', 'New "Action"', '--date', '20261118');
|
|
130
131
|
assert.equal(created.status, 0, output(created));
|
|
131
132
|
const id = created.stdout.trim();
|
|
132
133
|
assert.match(id, /^ERR-20261118-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
|
|
133
134
|
const afterNewText = fs.readFileSync(mapPath, 'utf8');
|
|
134
|
-
const actionBlock = new RegExp(
|
|
135
|
+
const actionBlock = new RegExp(` ${alias}:\\r?\\n identifier: ${id}\\r?\\n name: .*\\r?\\n status: proposed\\r?\\n`);
|
|
135
136
|
assert.equal(afterNewText.replace(actionBlock, ''), originalMap);
|
|
136
137
|
const afterNew = yaml.load(afterNewText);
|
|
137
|
-
assert.equal(afterNew.actions.
|
|
138
|
-
assert.equal(afterNew.actions.
|
|
139
|
-
assert.equal(afterNew.actions.
|
|
138
|
+
assert.equal(afterNew.actions[alias].identifier, id);
|
|
139
|
+
assert.equal(afterNew.actions[alias].name, 'New "Action"');
|
|
140
|
+
assert.equal(afterNew.actions[alias].status, 'proposed');
|
|
140
141
|
assert.ok(!Object.values(before.actions).some(action => action.identifier === id));
|
|
141
|
-
for (const
|
|
142
|
+
for (const existingAlias of Object.keys(before.actions)) assert.equal(afterNew.actions[existingAlias].identifier, before.actions[existingAlias].identifier);
|
|
142
143
|
assert.match(fs.readFileSync(mapPath, 'utf8'), /# A-G are drawing-local aliases, NOT identity or ordered numbering\./);
|
|
143
|
-
fs.writeFileSync(diagramPath, fs.readFileSync(diagramPath, 'utf8').replace(' OPEN --> Z((End))',
|
|
144
|
+
fs.writeFileSync(diagramPath, fs.readFileSync(diagramPath, 'utf8').replace(' OPEN --> Z((End))', ` OPEN --> Z((End))\n ${alias}["New Action"]`));
|
|
144
145
|
|
|
145
146
|
const statusBefore = fs.readFileSync(mapPath, 'utf8');
|
|
146
147
|
const changed = invoke({ mapPath, diagramPath }, 'set-status', '--id', id, '--status', 'accepted');
|
|
147
148
|
assert.equal(changed.status, 0, output(changed));
|
|
148
149
|
const statusAfter = fs.readFileSync(mapPath, 'utf8');
|
|
149
|
-
|
|
150
|
-
assert.
|
|
151
|
-
assert.equal(
|
|
150
|
+
const selectedStatus = new RegExp(`(^ ${alias}:\\r?\\n(?:^ [^\\r\\n]*\\r?\\n)*?^ status: )proposed(\\r?$)`, 'm');
|
|
151
|
+
assert.match(statusBefore, selectedStatus);
|
|
152
|
+
assert.equal(statusAfter, statusBefore.replace(selectedStatus, '$1accepted$2'));
|
|
153
|
+
assert.equal(yaml.load(statusAfter).actions[alias].status, 'accepted');
|
|
152
154
|
|
|
153
155
|
const valid = invoke({ mapPath, diagramPath }, 'check');
|
|
154
156
|
assert.equal(valid.status, 0, output(valid));
|
|
155
|
-
fs.writeFileSync(mapPath, statusAfter.replace('{ from: A, to: B }',
|
|
157
|
+
fs.writeFileSync(mapPath, statusAfter.replace('{ from: A, to: B }', `{ from: A, to: ${alias} }`));
|
|
156
158
|
const drift = invoke({ mapPath, diagramPath }, 'check');
|
|
157
159
|
assert.notEqual(drift.status, 0, output(drift));
|
|
158
|
-
assert.match(output(drift),
|
|
160
|
+
assert.match(output(drift), new RegExp(`missing.*A.*B|extra.*A.*${alias}`, 'i'));
|
|
159
161
|
});
|
|
160
162
|
|
|
161
163
|
test('new rejects a duplicate alias without changing any input bytes', () => {
|