harness-everything 0.53.0 → 0.54.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 +3 -1
- package/CHANGELOG.md +18 -0
- package/bin/cli.js +1 -0
- package/ci/invariant-routing.test.js +22 -3
- package/ci/mechanism-2al-codex-hooks-compat.test.js +56 -2
- package/ci/mechanism-349-ci-change-scope.test.js +78 -57
- package/ci/mechanism-397-cycle-import.test.js +18 -3
- package/ci/mechanism-check-packet-write-set.test.js +232 -0
- package/ci/mechanism-codex-prompt-pass-through.test.js +8 -4
- package/ci/mechanism-error-handling-map.test.js +219 -0
- package/ci/mechanism-report-writer.test.js +335 -0
- package/ci/router-workflow-plan.test.js +50 -7
- package/docs/architecture.md +4 -3
- package/docs/error-handling/README.md +250 -0
- package/docs/error-handling/actions/c1-action-map.md +89 -0
- package/docs/error-handling/actions/c2-action-map.md +22 -0
- package/docs/error-handling/actions/c3-action-map.md +26 -0
- package/docs/error-handling/actions/c5-action-map.md +31 -0
- package/docs/error-handling/actions/c6-action-map.md +37 -0
- package/docs/error-handling/actions/c7-action-map.md +18 -0
- package/docs/error-handling/actions/e0002-action-map.md +101 -0
- package/docs/error-handling/activity.puml +84 -0
- package/docs/error-handling/details/c1-authority-conformance.md +93 -0
- package/docs/error-handling/details/c2-test-root-containment.md +35 -0
- package/docs/error-handling/details/c3-mode-ownership.md +50 -0
- package/docs/error-handling/details/c5-host-replay-contract.md +40 -0
- package/docs/error-handling/details/c6-packet-briefing.md +65 -0
- package/docs/error-handling/details/c7-write-set-check.md +54 -0
- package/docs/error-handling/details/e0002-capture-evidence.md +93 -0
- package/docs/error-handling/details/e0002-report-writer.md +116 -0
- package/docs/error-handling/nodes.yaml +44 -0
- package/docs/error-handling/registry.md +59 -0
- package/docs/error-handling/templates/packet-briefing.md +45 -0
- package/docs/platform-capabilities.md +3 -1
- package/hooks/scripts/codex-user-prompt.js +2 -3
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +2 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/codex-user-prompt.js +2 -3
- package/plugins/harness-everything/plugin.json +1 -1
- package/sbom.cdx.json +7 -7
- package/scripts/check-packet-write-set.js +155 -0
- package/scripts/codex-hooks-compat.js +46 -5
- package/scripts/error-handling-map.js +288 -0
- package/scripts/report-writer.js +261 -0
|
@@ -42,7 +42,7 @@ fs.writeFileSync(stubRouter, [
|
|
|
42
42
|
"process.stdin.on('end', () => {",
|
|
43
43
|
" const fs = require('fs');",
|
|
44
44
|
" fs.writeFileSync(process.env.STUB_ROUTER_MARKER, input, 'utf8');",
|
|
45
|
-
" process.stdout.write('STUB_ROUTER_MARKER');",
|
|
45
|
+
" process.stdout.write('[Tier Routing Pre-check] STUB_ROUTER_MARKER');",
|
|
46
46
|
" process.exit(0);",
|
|
47
47
|
"});",
|
|
48
48
|
"process.stdin.on('error', () => process.exit(0));",
|
|
@@ -83,12 +83,16 @@ for (const testCase of cases) {
|
|
|
83
83
|
const marker = fs.readFileSync(markerFile, 'utf8');
|
|
84
84
|
check(marker === inputText, `${testCase.name}: router received the original payload unchanged`);
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
assert.deepStrictEqual(JSON.parse(result.stdout), {
|
|
87
|
+
hookSpecificOutput: {
|
|
88
|
+
hookEventName: 'UserPromptSubmit',
|
|
89
|
+
additionalContext: '[Tier Routing Pre-check] STUB_ROUTER_MARKER',
|
|
90
|
+
},
|
|
91
|
+
}, `${testCase.name}: bracketed router output reaches the host as valid hook JSON`);
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
// Cleanup
|
|
91
95
|
try { fs.rmSync(tempRoot, { recursive: true, force: true }); } catch (_) {}
|
|
92
96
|
|
|
93
97
|
console.log(`\n${failed === 0 ? 'PASS' : 'FAIL'}: codex prompt pass-through (${failed} failure${failed === 1 ? '' : 's'})`);
|
|
94
|
-
process.exit(failed === 0 ? 0 : 1);
|
|
98
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const { after, test } = require('node:test');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { spawnSync } = require('node:child_process');
|
|
9
|
+
const yaml = require('js-yaml');
|
|
10
|
+
|
|
11
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
12
|
+
const CLI = path.join(ROOT, 'scripts', 'error-handling-map.js');
|
|
13
|
+
const TEMP = fs.mkdtempSync(path.join(os.tmpdir(), 'error-handling-map-'));
|
|
14
|
+
const CANONICAL_MAP = path.join(ROOT, 'docs', 'error-handling', 'nodes.yaml');
|
|
15
|
+
const CANONICAL_DIAGRAM = path.join(ROOT, 'docs', 'error-handling', 'README.md');
|
|
16
|
+
const ID_A = 'ERR-20261112-a82f647f-c0b1-4c6c-b90b-fb2221fe66bd';
|
|
17
|
+
const ID_B = 'ERR-20261112-da72e7fa-a37c-48ab-81b9-a678673a7324';
|
|
18
|
+
const ID_C = 'ERR-20261112-ffbb1b17-edb3-4adb-92ff-df76ad8f101c';
|
|
19
|
+
|
|
20
|
+
const sampleMap = ({ links = ' - { from: A, to: B }', identifierB = ID_B } = {}) => [
|
|
21
|
+
'# Keep this comment through every mutation.',
|
|
22
|
+
'schema: concept-v0',
|
|
23
|
+
'scope: error-handling',
|
|
24
|
+
'actions:',
|
|
25
|
+
' A:',
|
|
26
|
+
' identifier: ' + ID_A,
|
|
27
|
+
' name: Capture',
|
|
28
|
+
' status: proposed',
|
|
29
|
+
' B:',
|
|
30
|
+
' identifier: ' + identifierB,
|
|
31
|
+
' name: Triage',
|
|
32
|
+
' status: proposed',
|
|
33
|
+
' C:',
|
|
34
|
+
' identifier: ' + ID_C,
|
|
35
|
+
' name: Identify',
|
|
36
|
+
' status: retired',
|
|
37
|
+
'links:' + (links === '' ? ' []' : ''),
|
|
38
|
+
...(links ? [links] : []),
|
|
39
|
+
'',
|
|
40
|
+
].join('\n');
|
|
41
|
+
|
|
42
|
+
const fence = String.fromCharCode(96).repeat(3);
|
|
43
|
+
const sampleDiagram = [
|
|
44
|
+
'# View 1',
|
|
45
|
+
'## View 1 — Overall UML Activity Diagram',
|
|
46
|
+
'',
|
|
47
|
+
fence + 'mermaid',
|
|
48
|
+
'flowchart TD',
|
|
49
|
+
' A["Renamed Capture"] --> MODE{"Decision"}',
|
|
50
|
+
' A --> MODE',
|
|
51
|
+
' MODE -->|yes| B((Renamed Triage))',
|
|
52
|
+
' MODE{"Reused alias label"} --> B',
|
|
53
|
+
fence,
|
|
54
|
+
'',
|
|
55
|
+
'## View 2 — ignored by check',
|
|
56
|
+
fence + 'mermaid',
|
|
57
|
+
'flowchart TD',
|
|
58
|
+
' A --> C',
|
|
59
|
+
fence,
|
|
60
|
+
'',
|
|
61
|
+
].join('\n');
|
|
62
|
+
|
|
63
|
+
function makeFixture({ map = sampleMap(), diagram = sampleDiagram } = {}) {
|
|
64
|
+
const dir = fs.mkdtempSync(path.join(TEMP, 'case-'));
|
|
65
|
+
const mapPath = path.join(dir, 'nodes.yaml');
|
|
66
|
+
const diagramPath = path.join(dir, 'README.md');
|
|
67
|
+
fs.writeFileSync(mapPath, map);
|
|
68
|
+
fs.writeFileSync(diagramPath, diagram);
|
|
69
|
+
return { dir, mapPath, diagramPath };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function invoke(fixture, ...args) {
|
|
73
|
+
return spawnSync(process.execPath, [CLI, ...args, '--map', fixture.mapPath, '--diagram', fixture.diagramPath], {
|
|
74
|
+
cwd: ROOT,
|
|
75
|
+
encoding: 'utf8',
|
|
76
|
+
timeout: 5000,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function output(result) {
|
|
81
|
+
return (result.stdout || '') + '\n' + (result.stderr || result.error?.message || '');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function assertRejectedUnchanged(fixture, args, diagnostic) {
|
|
85
|
+
const before = fs.readFileSync(fixture.mapPath);
|
|
86
|
+
const result = invoke(fixture, ...args);
|
|
87
|
+
assert.notEqual(result.status, 0, output(result));
|
|
88
|
+
assert.match(output(result), diagnostic);
|
|
89
|
+
assert.deepEqual(fs.readFileSync(fixture.mapPath), before);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
after(() => fs.rmSync(TEMP, { recursive: true, force: true }));
|
|
93
|
+
|
|
94
|
+
test('check accepts the canonical map from the normal repository path', () => {
|
|
95
|
+
const result = spawnSync(process.execPath, [CLI, 'check'], { cwd: ROOT, encoding: 'utf8', timeout: 5000 });
|
|
96
|
+
assert.equal(result.status, 0, output(result));
|
|
97
|
+
assert.match(result.stdout, /OK.*Action link/i);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('check derives Action links through non-Action nodes and ignores renamed or reused labels', () => {
|
|
101
|
+
const fixture = makeFixture();
|
|
102
|
+
const result = invoke(fixture, 'check');
|
|
103
|
+
assert.equal(result.status, 0, output(result));
|
|
104
|
+
assert.match(result.stdout, /OK.*Action link/i);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('check rejects dropped, extra and reversed links with actionable diagnostics', () => {
|
|
108
|
+
for (const [links, diagnostics] of [
|
|
109
|
+
['', [/missing.*A.*B/i]],
|
|
110
|
+
[' - { from: A, to: B }\n - { from: A, to: C }', [/extra.*A.*C/i]],
|
|
111
|
+
[' - { from: B, to: A }', [/missing.*A.*B/i, /extra.*B.*A/i]],
|
|
112
|
+
]) {
|
|
113
|
+
const fixture = makeFixture({ map: sampleMap({ links }) });
|
|
114
|
+
const result = invoke(fixture, 'check');
|
|
115
|
+
assert.notEqual(result.status, 0, output(result));
|
|
116
|
+
for (const diagnostic of diagnostics) assert.match(output(result), diagnostic);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('new then set-status then check preserves identities and detects later drift', () => {
|
|
121
|
+
const dir = fs.mkdtempSync(path.join(TEMP, 'walk-'));
|
|
122
|
+
const mapPath = path.join(dir, 'nodes.yaml');
|
|
123
|
+
const diagramPath = path.join(dir, 'README.md');
|
|
124
|
+
const originalMap = fs.readFileSync(CANONICAL_MAP, 'utf8');
|
|
125
|
+
fs.writeFileSync(mapPath, originalMap);
|
|
126
|
+
fs.copyFileSync(CANONICAL_DIAGRAM, diagramPath);
|
|
127
|
+
const before = yaml.load(originalMap);
|
|
128
|
+
|
|
129
|
+
const created = invoke({ mapPath, diagramPath }, 'new', '--alias', 'H', '--name', 'New "Action"', '--date', '20261118');
|
|
130
|
+
assert.equal(created.status, 0, output(created));
|
|
131
|
+
const id = created.stdout.trim();
|
|
132
|
+
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
|
+
const afterNewText = fs.readFileSync(mapPath, 'utf8');
|
|
134
|
+
const actionBlock = new RegExp(' H:\\r?\\n identifier: ' + id + '\\r?\\n name: .*\\r?\\n status: proposed\\r?\\n');
|
|
135
|
+
assert.equal(afterNewText.replace(actionBlock, ''), originalMap);
|
|
136
|
+
const afterNew = yaml.load(afterNewText);
|
|
137
|
+
assert.equal(afterNew.actions.H.identifier, id);
|
|
138
|
+
assert.equal(afterNew.actions.H.name, 'New "Action"');
|
|
139
|
+
assert.equal(afterNew.actions.H.status, 'proposed');
|
|
140
|
+
assert.ok(!Object.values(before.actions).some(action => action.identifier === id));
|
|
141
|
+
for (const alias of Object.keys(before.actions)) assert.equal(afterNew.actions[alias].identifier, before.actions[alias].identifier);
|
|
142
|
+
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))', ' OPEN --> Z((End))\n H["New Action"]'));
|
|
144
|
+
|
|
145
|
+
const statusBefore = fs.readFileSync(mapPath, 'utf8');
|
|
146
|
+
const changed = invoke({ mapPath, diagramPath }, 'set-status', '--id', id, '--status', 'accepted');
|
|
147
|
+
assert.equal(changed.status, 0, output(changed));
|
|
148
|
+
const statusAfter = fs.readFileSync(mapPath, 'utf8');
|
|
149
|
+
assert.equal((statusAfter.match(/status: accepted/g) || []).length, 1);
|
|
150
|
+
assert.equal(statusAfter.replace(' status: accepted', ' status: proposed'), statusBefore);
|
|
151
|
+
assert.equal(yaml.load(statusAfter).actions.H.status, 'accepted');
|
|
152
|
+
|
|
153
|
+
const valid = invoke({ mapPath, diagramPath }, 'check');
|
|
154
|
+
assert.equal(valid.status, 0, output(valid));
|
|
155
|
+
fs.writeFileSync(mapPath, statusAfter.replace('{ from: A, to: B }', '{ from: A, to: H }'));
|
|
156
|
+
const drift = invoke({ mapPath, diagramPath }, 'check');
|
|
157
|
+
assert.notEqual(drift.status, 0, output(drift));
|
|
158
|
+
assert.match(output(drift), /missing.*A.*B|extra.*A.*H/i);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('new rejects a duplicate alias without changing any input bytes', () => {
|
|
162
|
+
const fixture = makeFixture();
|
|
163
|
+
assertRejectedUnchanged(fixture, ['new', '--alias', 'A', '--name', 'Duplicate'], /already exists.*A/i);
|
|
164
|
+
const invalidDate = makeFixture();
|
|
165
|
+
assertRejectedUnchanged(invalidDate, ['new', '--alias', 'H', '--name', 'Invalid date', '--date', '20260230'], /invalid date.*20260230/i);
|
|
166
|
+
const dangling = makeFixture({ map: sampleMap({ links: ' - { from: A, to: Z }' }) });
|
|
167
|
+
assertRejectedUnchanged(dangling, ['new', '--alias', 'H', '--name', 'Must not write'], /unknown Action alias: Z/i);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('new and set-status preserve CRLF input', () => {
|
|
171
|
+
const fixture = makeFixture({
|
|
172
|
+
map: sampleMap().replace(/\n/g, '\r\n'),
|
|
173
|
+
diagram: sampleDiagram.replace(fence + '\n\n## View 2', ' D["New Action"]\n' + fence + '\n\n## View 2').replace(/\n/g, '\r\n'),
|
|
174
|
+
});
|
|
175
|
+
const created = invoke(fixture, 'new', '--alias', 'D', '--name', 'New action', '--date', '20261118');
|
|
176
|
+
assert.equal(created.status, 0, output(created));
|
|
177
|
+
const createdMap = fs.readFileSync(fixture.mapPath, 'utf8');
|
|
178
|
+
assert.doesNotMatch(createdMap, /(^|[^\r])\n/);
|
|
179
|
+
const changed = invoke(fixture, 'set-status', '--id', created.stdout.trim(), '--status', 'accepted');
|
|
180
|
+
assert.equal(changed.status, 0, output(changed));
|
|
181
|
+
assert.doesNotMatch(fs.readFileSync(fixture.mapPath, 'utf8'), /(^|[^\r])\n/);
|
|
182
|
+
const checked = invoke(fixture, 'check');
|
|
183
|
+
assert.equal(checked.status, 0, output(checked));
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('set-status changes only the selected Action status line', () => {
|
|
187
|
+
const fixture = makeFixture();
|
|
188
|
+
const before = fs.readFileSync(fixture.mapPath, 'utf8');
|
|
189
|
+
const result = invoke(fixture, 'set-status', '--id', ID_A.toUpperCase(), '--status', 'accepted');
|
|
190
|
+
assert.equal(result.status, 0, output(result));
|
|
191
|
+
const after = fs.readFileSync(fixture.mapPath, 'utf8');
|
|
192
|
+
assert.equal(after.replace(' status: accepted', ' status: proposed'), before);
|
|
193
|
+
const parsed = yaml.load(after);
|
|
194
|
+
assert.equal(parsed.actions.A.status, 'accepted');
|
|
195
|
+
assert.equal(parsed.actions.B.status, 'proposed');
|
|
196
|
+
assert.equal(parsed.actions.C.status, 'retired');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('set-status rejects unknown identifiers and invalid statuses without changing bytes', () => {
|
|
200
|
+
const unknown = makeFixture();
|
|
201
|
+
assertRejectedUnchanged(unknown, ['set-status', '--id', 'ERR-20261118-missing', '--status', 'accepted'], /no Action.*identifier/i);
|
|
202
|
+
const invalid = makeFixture();
|
|
203
|
+
assertRejectedUnchanged(invalid, ['set-status', '--id', ID_A, '--status', 'pending'], /invalid status.*pending/i);
|
|
204
|
+
const duplicate = makeFixture({ map: sampleMap({ identifierB: ID_A.toUpperCase() }) });
|
|
205
|
+
assertRejectedUnchanged(duplicate, ['set-status', '--id', ID_A, '--status', 'accepted'], /duplicate.*identifier/i);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('check rejects duplicate identities and dangling link endpoints', () => {
|
|
209
|
+
const duplicate = makeFixture({ map: sampleMap({ identifierB: ID_A.toUpperCase() }) });
|
|
210
|
+
const duplicateResult = invoke(duplicate, 'check');
|
|
211
|
+
assert.notEqual(duplicateResult.status, 0, output(duplicateResult));
|
|
212
|
+
assert.match(output(duplicateResult), /duplicate.*identifier/i);
|
|
213
|
+
|
|
214
|
+
const dangling = makeFixture({ map: sampleMap({ links: ' - { from: A, to: Z }' }) });
|
|
215
|
+
const danglingResult = invoke(dangling, 'check');
|
|
216
|
+
assert.notEqual(danglingResult.status, 0, output(danglingResult));
|
|
217
|
+
assert.match(output(danglingResult), /unknown.*alias.*Z/i);
|
|
218
|
+
});
|
|
219
|
+
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { spawnSync } = require('node:child_process');
|
|
8
|
+
const { test } = require('node:test');
|
|
9
|
+
|
|
10
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
11
|
+
const CLI = path.join(ROOT, 'scripts', 'report-writer.js');
|
|
12
|
+
|
|
13
|
+
function tempDir(t) {
|
|
14
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-report-writer-'));
|
|
15
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
16
|
+
return dir;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function run(args, { preload, env = process.env } = {}) {
|
|
20
|
+
return spawnSync(process.execPath, [...(preload ? ['-r', preload] : []), CLI, ...args], {
|
|
21
|
+
cwd: ROOT,
|
|
22
|
+
env,
|
|
23
|
+
encoding: 'utf8',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function assertOk(result) {
|
|
28
|
+
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function assertRejected(result, message) {
|
|
32
|
+
assert.notEqual(result.status, 0, result.stdout);
|
|
33
|
+
assert.match(result.stderr, /report-writer:/);
|
|
34
|
+
if (message) assert.match(result.stderr, message);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function writeArgs(output, status, mode, ...extra) {
|
|
38
|
+
return ['write', '--output', output, '--status', status, ...mode, ...extra];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readbackHook(dir) {
|
|
42
|
+
const hook = path.join(dir, 'fail-readback.cjs');
|
|
43
|
+
fs.writeFileSync(hook, `
|
|
44
|
+
const fs = require('node:fs');
|
|
45
|
+
const path = require('node:path');
|
|
46
|
+
const readFileSync = fs.readFileSync;
|
|
47
|
+
fs.readFileSync = function (file, ...args) {
|
|
48
|
+
const actual = path.resolve(String(file));
|
|
49
|
+
const target = path.resolve(process.env.REPORT_WRITER_FAIL_PATH);
|
|
50
|
+
const mode = process.env.REPORT_WRITER_FAIL_MODE;
|
|
51
|
+
const staged = path.dirname(actual) === path.dirname(target)
|
|
52
|
+
&& path.basename(actual).startsWith('.' + path.basename(target) + '.')
|
|
53
|
+
&& path.basename(actual).endsWith('.tmp');
|
|
54
|
+
if ((mode === 'staged' && staged) || (mode === 'published' && actual === target)) {
|
|
55
|
+
const error = new Error('controlled read-back failure');
|
|
56
|
+
error.code = 'EIO';
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
return readFileSync.call(this, file, ...args);
|
|
60
|
+
};
|
|
61
|
+
`);
|
|
62
|
+
return hook;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
test('writes DONE from --context and the checker accepts the exact artifact', t => {
|
|
66
|
+
const dir = tempDir(t);
|
|
67
|
+
const output = path.join(dir, 'report.md');
|
|
68
|
+
const result = run(writeArgs(output, 'DONE', ['--context', 'Summary\nEvidence']))
|
|
69
|
+
assertOk(result);
|
|
70
|
+
assert.equal(fs.readFileSync(output, 'utf8'), 'Summary\nEvidence\nSTATUS: DONE\n');
|
|
71
|
+
assertOk(run(['check', '--file', output]));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('preserves body-file CRLF bytes and accepts numeric zero status', t => {
|
|
75
|
+
const dir = tempDir(t);
|
|
76
|
+
const body = path.join(dir, 'body.md');
|
|
77
|
+
const output = path.join(dir, 'report.md');
|
|
78
|
+
fs.writeFileSync(body, 'First\r\nSecond\r\n');
|
|
79
|
+
assertOk(run(writeArgs(output, '0', ['--body-file', body])));
|
|
80
|
+
assert.equal(fs.readFileSync(output, 'utf8'), 'First\r\nSecond\r\nSTATUS: DONE\r\n');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('writes BLOCKED with a nonempty single-line reason', t => {
|
|
84
|
+
const dir = tempDir(t);
|
|
85
|
+
const output = path.join(dir, 'report.md');
|
|
86
|
+
assertOk(run(writeArgs(output, 'BLOCKED', ['--context', 'Work stopped'], '--reason', 'verification unavailable')));
|
|
87
|
+
assert.equal(fs.readFileSync(output, 'utf8'), 'Work stopped\nSTATUS: BLOCKED: verification unavailable\n');
|
|
88
|
+
assertOk(run(['check', '--file', output]));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('maps a nonzero status and repeated --error values to one reason line', t => {
|
|
92
|
+
const dir = tempDir(t);
|
|
93
|
+
const output = path.join(dir, 'report.md');
|
|
94
|
+
assertOk(run(writeArgs(output, '2', ['--context', 'Work stopped'], '--error', 'build failed', '--error', 'required gate unavailable')));
|
|
95
|
+
assert.equal(fs.readFileSync(output, 'utf8'), 'Work stopped\nSTATUS: BLOCKED: build failed; required gate unavailable\n');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('revises an existing artifact as one complete report', t => {
|
|
99
|
+
const dir = tempDir(t);
|
|
100
|
+
const output = path.join(dir, 'report.md');
|
|
101
|
+
fs.writeFileSync(output, 'Old body\nSTATUS: DONE\n');
|
|
102
|
+
assertOk(run(writeArgs(output, 'BLOCKED', ['--context', 'New body'], '--reason', 'gate failed')));
|
|
103
|
+
assert.equal(fs.readFileSync(output, 'utf8'), 'New body\nSTATUS: BLOCKED: gate failed\n');
|
|
104
|
+
assertOk(run(['check', '--file', output]));
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('imports a raw Codex report without altering its source', t => {
|
|
108
|
+
const dir = tempDir(t);
|
|
109
|
+
const raw = path.join(dir, 'raw.txt');
|
|
110
|
+
const output = path.join(dir, 'report.md');
|
|
111
|
+
const rawBytes = Buffer.from('Summary\r\nEvidence\r\nSTATUS: DONE\r\n');
|
|
112
|
+
fs.writeFileSync(raw, rawBytes);
|
|
113
|
+
const result = run(writeArgs(output, '0', ['--from-codex-output', raw]));
|
|
114
|
+
assertOk(result);
|
|
115
|
+
assert.doesNotMatch(result.stderr, /stripped.*host label/i);
|
|
116
|
+
assert.deepEqual(fs.readFileSync(raw), rawBytes);
|
|
117
|
+
assert.equal(fs.readFileSync(output, 'utf8'), rawBytes.toString('utf8'));
|
|
118
|
+
assertOk(run(['check', '--file', output]));
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('strips only one valid terminal host label and reports the extraction', t => {
|
|
122
|
+
const dir = tempDir(t);
|
|
123
|
+
const raw = path.join(dir, 'raw.txt');
|
|
124
|
+
const output = path.join(dir, 'report.md');
|
|
125
|
+
const rawBytes = Buffer.from('Summary\nSTATUS: DONE\n<!-- harness-label {"v":1,"validity":"actionable"} -->\n');
|
|
126
|
+
fs.writeFileSync(raw, rawBytes);
|
|
127
|
+
const result = run(writeArgs(output, 'DONE', ['--from-codex-output', raw]));
|
|
128
|
+
assertOk(result);
|
|
129
|
+
assert.match(result.stderr, /stripped.*host label/i);
|
|
130
|
+
assert.deepEqual(fs.readFileSync(raw), rawBytes);
|
|
131
|
+
assert.equal(fs.readFileSync(output, 'utf8'), 'Summary\nSTATUS: DONE\n');
|
|
132
|
+
assertOk(run(['check', '--file', output]));
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('assembles a DONE report from raw body text without STATUS', t => {
|
|
136
|
+
const dir = tempDir(t);
|
|
137
|
+
const raw = path.join(dir, 'raw.txt');
|
|
138
|
+
const output = path.join(dir, 'report.md');
|
|
139
|
+
const rawBytes = Buffer.from('Summary\r\nEvidence\r\n');
|
|
140
|
+
fs.writeFileSync(raw, rawBytes);
|
|
141
|
+
|
|
142
|
+
const result = run(writeArgs(output, 'DONE', ['--from-codex-output', raw]));
|
|
143
|
+
|
|
144
|
+
assertOk(result);
|
|
145
|
+
assert.doesNotMatch(result.stderr, /stripped.*host label/i);
|
|
146
|
+
assert.deepEqual(fs.readFileSync(raw), rawBytes);
|
|
147
|
+
assert.deepEqual(fs.readFileSync(output), Buffer.from('Summary\r\nEvidence\r\nSTATUS: DONE\r\n'));
|
|
148
|
+
assertOk(run(['check', '--file', output]));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('assembles BLOCKED from a raw body, blank line, and one EOF host label', t => {
|
|
152
|
+
const dir = tempDir(t);
|
|
153
|
+
const raw = path.join(dir, 'raw.txt');
|
|
154
|
+
const output = path.join(dir, 'report.md');
|
|
155
|
+
const rawBytes = Buffer.from('Summary\n\nEvidence\n\n<!-- harness-label {"v":1,"validity":"actionable","tier":"tier2","intents":["test"],"workflow":"iterative-single","skills":[]} -->');
|
|
156
|
+
const body = rawBytes.subarray(0, rawBytes.lastIndexOf(Buffer.from('<!-- harness-label')));
|
|
157
|
+
fs.writeFileSync(raw, rawBytes);
|
|
158
|
+
|
|
159
|
+
const result = run(writeArgs(output, 'BLOCKED', ['--from-codex-output', raw], '--reason', 'verification unavailable'));
|
|
160
|
+
|
|
161
|
+
assertOk(result);
|
|
162
|
+
assert.match(result.stderr, /stripped.*host label/i);
|
|
163
|
+
assert.deepEqual(fs.readFileSync(raw), rawBytes);
|
|
164
|
+
assert.deepEqual(fs.readFileSync(output), Buffer.concat([body, Buffer.from('STATUS: BLOCKED: verification unavailable\n')]));
|
|
165
|
+
assertOk(run(['check', '--file', output]));
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('rejects embedded STATUS in body without changing an existing target', t => {
|
|
169
|
+
const dir = tempDir(t);
|
|
170
|
+
const output = path.join(dir, 'report.md');
|
|
171
|
+
const before = Buffer.from('Keep this report\nSTATUS: DONE\n');
|
|
172
|
+
fs.writeFileSync(output, before);
|
|
173
|
+
const result = run(writeArgs(output, 'DONE', ['--context', 'Summary\nSTATUS: DONE']));
|
|
174
|
+
assertRejected(result, /STATUS/);
|
|
175
|
+
assert.deepEqual(fs.readFileSync(output), before);
|
|
176
|
+
assert.deepEqual(fs.readdirSync(dir), ['report.md']);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('rejects label markers and malformed or duplicate body controls without creating an artifact', t => {
|
|
180
|
+
const dir = tempDir(t);
|
|
181
|
+
const output = path.join(dir, 'report.md');
|
|
182
|
+
for (const body of [
|
|
183
|
+
'Summary <!-- harness-label {"v":1} -->',
|
|
184
|
+
'STATUS: broken',
|
|
185
|
+
'STATUS: DONE\nSTATUS: DONE',
|
|
186
|
+
]) {
|
|
187
|
+
assertRejected(run(writeArgs(output, 'DONE', ['--context', body])));
|
|
188
|
+
assert.equal(fs.existsSync(output), false);
|
|
189
|
+
}
|
|
190
|
+
assert.deepEqual(fs.readdirSync(dir), []);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('rejects missing, blank, multiline, or unused outcome reasons without changing the target', t => {
|
|
194
|
+
const dir = tempDir(t);
|
|
195
|
+
const output = path.join(dir, 'report.md');
|
|
196
|
+
const before = Buffer.from('Existing\nSTATUS: DONE\n');
|
|
197
|
+
fs.writeFileSync(output, before);
|
|
198
|
+
const cases = [
|
|
199
|
+
['BLOCKED', ['--context', 'body']],
|
|
200
|
+
['1', ['--context', 'body'], '--reason', ' '],
|
|
201
|
+
['BLOCKED', ['--context', 'body'], '--reason', 'line one\nline two'],
|
|
202
|
+
['DONE', ['--context', 'body'], '--reason', 'not used'],
|
|
203
|
+
['DONE\nSTATUS: BLOCKED: injected', ['--context', 'body']],
|
|
204
|
+
];
|
|
205
|
+
for (const [status, mode, ...extra] of cases) {
|
|
206
|
+
assertRejected(run(writeArgs(output, status, mode, ...extra)));
|
|
207
|
+
assert.deepEqual(fs.readFileSync(output), before);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('rejects mismatched, malformed, duplicate, or trailing Codex controls and preserves both files', t => {
|
|
212
|
+
const dir = tempDir(t);
|
|
213
|
+
const raw = path.join(dir, 'raw.txt');
|
|
214
|
+
const output = path.join(dir, 'report.md');
|
|
215
|
+
const before = Buffer.from('Keep this report\nSTATUS: DONE\n');
|
|
216
|
+
fs.writeFileSync(output, before);
|
|
217
|
+
const invalidRaw = [
|
|
218
|
+
['Summary\nSTATUS: BLOCKED: wrong reason\n', 'DONE'],
|
|
219
|
+
['Summary\nSTATUS: BLOCKED: wrong reason\n', 'BLOCKED', '--reason', 'expected reason'],
|
|
220
|
+
['Summary\nSTATUS: FINISHED\n', 'DONE'],
|
|
221
|
+
['Summary\nSTATUS: malformed\nSTATUS: DONE\n', 'DONE'],
|
|
222
|
+
['Summary\nSTATUS: DONE\nSTATUS: DONE\n', 'DONE'],
|
|
223
|
+
['Summary\nSTATUS: DONE\n\n', 'DONE'],
|
|
224
|
+
['Summary\nSTATUS: DONE\ntext after status\n', 'DONE'],
|
|
225
|
+
['Summary\nSTATUS: DONE\n\n<!-- harness-label {"v":1} -->', 'DONE'],
|
|
226
|
+
['Summary\nSTATUS: DONE\ntext\n<!-- harness-label {"v":1} -->', 'DONE'],
|
|
227
|
+
['Summary\nSTATUS: DONE\n<!-- harness-label {bad json} -->\n', 'DONE'],
|
|
228
|
+
['Summary\nSTATUS: DONE\n<!-- harness-label [] -->\n', 'DONE'],
|
|
229
|
+
['Summary\nSTATUS: DONE\n<!-- harness-label {"v":1} -->\n<!-- harness-label {"v":1} -->\n', 'DONE'],
|
|
230
|
+
['Summary\nSTATUS: DONE\n<!-- harness-label {"v":1} -->\ntrailing text', 'DONE'],
|
|
231
|
+
['Summary <!-- harness-label {"v":1} -->\nSTATUS: DONE\n', 'DONE'],
|
|
232
|
+
];
|
|
233
|
+
for (const [contents, status, ...extra] of invalidRaw) {
|
|
234
|
+
const rawBytes = Buffer.from(contents);
|
|
235
|
+
fs.writeFileSync(raw, rawBytes);
|
|
236
|
+
assertRejected(run(writeArgs(output, status, ['--from-codex-output', raw], ...extra)));
|
|
237
|
+
assert.deepEqual(fs.readFileSync(raw), rawBytes);
|
|
238
|
+
assert.deepEqual(fs.readFileSync(output), before);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
fs.rmSync(output);
|
|
242
|
+
fs.writeFileSync(raw, 'Summary\nSTATUS: BLOCKED: wrong reason\n');
|
|
243
|
+
assertRejected(run(writeArgs(output, 'BLOCKED', ['--from-codex-output', raw], '--reason', 'expected reason')));
|
|
244
|
+
assert.equal(fs.existsSync(output), false);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('rejects raw-input/output aliases', t => {
|
|
248
|
+
const dir = tempDir(t);
|
|
249
|
+
const raw = path.join(dir, 'raw.txt');
|
|
250
|
+
const before = Buffer.from('Summary\nSTATUS: DONE\n');
|
|
251
|
+
fs.writeFileSync(raw, before);
|
|
252
|
+
assertRejected(run(writeArgs(raw, 'DONE', ['--from-codex-output', raw])), /alias/i);
|
|
253
|
+
assert.deepEqual(fs.readFileSync(raw), before);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test('rejects a body-file/output alias before replacing the source', t => {
|
|
257
|
+
const dir = tempDir(t);
|
|
258
|
+
const body = path.join(dir, 'body.md');
|
|
259
|
+
const before = Buffer.from('Summary');
|
|
260
|
+
fs.writeFileSync(body, before);
|
|
261
|
+
assertRejected(run(writeArgs(body, 'DONE', ['--body-file', body])), /alias/i);
|
|
262
|
+
assert.deepEqual(fs.readFileSync(body), before);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('requires exactly one body mode and rejects conflicting reason flags', t => {
|
|
266
|
+
const dir = tempDir(t);
|
|
267
|
+
const output = path.join(dir, 'report.md');
|
|
268
|
+
assertRejected(run(['write', '--output', output, '--status', 'DONE']));
|
|
269
|
+
assertRejected(run(['write', '--output', output, '--status', 'DONE', '--context', 'body', '--body-file', 'body.md']));
|
|
270
|
+
assertRejected(run(writeArgs(output, 'BLOCKED', ['--context', 'body'], '--reason', 'one', '--error', 'two')));
|
|
271
|
+
assert.equal(fs.existsSync(output), false);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test('check accepts one terminal status with LF or CRLF and rejects other control layouts', t => {
|
|
275
|
+
const dir = tempDir(t);
|
|
276
|
+
const file = path.join(dir, 'report.md');
|
|
277
|
+
for (const valid of ['Summary\nSTATUS: DONE', 'Summary\nSTATUS: DONE\n', 'Summary\r\nSTATUS: BLOCKED: reason\r\n']) {
|
|
278
|
+
fs.writeFileSync(file, valid);
|
|
279
|
+
assertOk(run(['check', '--file', file]));
|
|
280
|
+
}
|
|
281
|
+
for (const invalid of [
|
|
282
|
+
'Summary',
|
|
283
|
+
'Summary\nSTATUS: DONE\n\n',
|
|
284
|
+
'Summary\nSTATUS: DONE\ntrailing',
|
|
285
|
+
'Summary\nSTATUS: DONE\nSTATUS: DONE',
|
|
286
|
+
'Summary\nSTATUS: BLOCKED: ',
|
|
287
|
+
'Summary\nSTATUS: FINISHED',
|
|
288
|
+
'Summary\nSTATUS: DONE\n<!-- harness-label {"v":1} -->',
|
|
289
|
+
'<!-- harness-label {"v":1} -->\nSummary\nSTATUS: DONE',
|
|
290
|
+
]) {
|
|
291
|
+
fs.writeFileSync(file, invalid);
|
|
292
|
+
assertRejected(run(['check', '--file', file]));
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('returns actionable errors for missing input and a bad output path', t => {
|
|
297
|
+
const dir = tempDir(t);
|
|
298
|
+
const missingBody = path.join(dir, 'missing.md');
|
|
299
|
+
const badOutput = path.join(dir, 'missing-parent', 'report.md');
|
|
300
|
+
assertRejected(run(writeArgs(path.join(dir, 'report.md'), 'DONE', ['--body-file', missingBody])), /read|open|ENOENT/i);
|
|
301
|
+
assertRejected(run(writeArgs(badOutput, 'DONE', ['--context', 'Summary'])), /write|publish|ENOENT|directory/i);
|
|
302
|
+
assert.equal(fs.existsSync(path.dirname(badOutput)), false);
|
|
303
|
+
assert.deepEqual(fs.readdirSync(dir), []);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test('a staged read-back failure leaves an existing report byte-identical and removes staging data', t => {
|
|
307
|
+
const dir = tempDir(t);
|
|
308
|
+
const output = path.join(dir, 'report.md');
|
|
309
|
+
const before = Buffer.from('Existing\nSTATUS: DONE\n');
|
|
310
|
+
fs.writeFileSync(output, before);
|
|
311
|
+
const hook = readbackHook(dir);
|
|
312
|
+
const result = run(writeArgs(output, 'DONE', ['--context', 'New body']), {
|
|
313
|
+
preload: hook,
|
|
314
|
+
env: { ...process.env, REPORT_WRITER_FAIL_PATH: output, REPORT_WRITER_FAIL_MODE: 'staged' },
|
|
315
|
+
});
|
|
316
|
+
assertRejected(result, /controlled read-back failure/);
|
|
317
|
+
assert.deepEqual(fs.readFileSync(output), before);
|
|
318
|
+
assert.deepEqual(fs.readdirSync(dir).sort(), ['fail-readback.cjs', 'report.md']);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test('a published read-back failure is nonzero and keeps raw evidence intact', t => {
|
|
322
|
+
const dir = tempDir(t);
|
|
323
|
+
const raw = path.join(dir, 'raw.txt');
|
|
324
|
+
const output = path.join(dir, 'report.md');
|
|
325
|
+
const rawBytes = Buffer.from('Summary\nSTATUS: DONE\n');
|
|
326
|
+
fs.writeFileSync(raw, rawBytes);
|
|
327
|
+
const hook = readbackHook(dir);
|
|
328
|
+
const result = run(writeArgs(output, 'DONE', ['--from-codex-output', raw]), {
|
|
329
|
+
preload: hook,
|
|
330
|
+
env: { ...process.env, REPORT_WRITER_FAIL_PATH: output, REPORT_WRITER_FAIL_MODE: 'published' },
|
|
331
|
+
});
|
|
332
|
+
assertRejected(result, /published.*verify|read-back/i);
|
|
333
|
+
assert.deepEqual(fs.readFileSync(raw), rawBytes);
|
|
334
|
+
assert.equal(fs.readFileSync(output, 'utf8'), 'Summary\nSTATUS: DONE\n');
|
|
335
|
+
});
|