harness-everything 0.52.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 +38 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/README.md +7 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-probe.js +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-trace-2026-11-15.jsonl +4 -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-2n-opencode-plugin.test.js +1 -1
- package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +18 -3
- package/ci/mechanism-338-opencode-async.test.js +20 -3
- package/ci/mechanism-341-opencode-lane.test.js +7 -1
- package/ci/mechanism-349-ci-change-scope.test.js +78 -57
- package/ci/mechanism-397-cycle-import.test.js +414 -0
- package/ci/mechanism-397-host-acceptance.test.js +119 -0
- package/ci/mechanism-397-opencode-observations.test.js +1922 -0
- 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/mechanism-system-one-curves.test.js +17 -0
- package/ci/mechanism-system-one-cycle.test.js +621 -2
- 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 +16 -7
- package/docs/system-one-cycle.md +12 -3
- package/docs/system-one-observations.md +35 -4
- package/hooks/scripts/codex-user-prompt.js +2 -3
- package/hooks/scripts/lib/observations.js +5 -3
- package/opencode-plugin/README.md +22 -8
- package/opencode-plugin/index.mjs +424 -44
- 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/hooks/scripts/lib/observations.js +5 -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
- package/scripts/system-one-curves.js +154 -14
- package/scripts/system-one-cycle/collect.js +20 -3
- package/scripts/system-one-cycle/common.js +39 -1
- package/scripts/system-one-cycle/evaluate.js +8 -5
- package/scripts/system-one-cycle.js +7 -2
- package/scripts/system-one-observations-export.js +29 -0
- package/scripts/system-one-observations-import-store.js +128 -0
|
@@ -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
|
+
});
|
|
@@ -122,6 +122,23 @@ test('one successful run appends exactly one history line', t => {
|
|
|
122
122
|
assert.deepEqual(JSON.parse(lines[1]), second.curves);
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
+
test('446 H2: empty, LF, and CRLF histories append readable rows without rewriting prior bytes', t => {
|
|
126
|
+
const f = fixture(t);
|
|
127
|
+
const first = f.run({ version: 'v0', val: validityRows([['invalid', 0.8], ['actionable', 0.2]]) });
|
|
128
|
+
const initial = fs.readFileSync(f.history, 'utf8');
|
|
129
|
+
assert.ok(initial.endsWith('\n'));
|
|
130
|
+
assert.equal(initial.split(/\r?\n/).filter(Boolean).length, 1, 'an empty history gets no leading record');
|
|
131
|
+
|
|
132
|
+
const crlfPrefix = `${JSON.stringify(first.curves)}\r\n`;
|
|
133
|
+
fs.writeFileSync(f.history, crlfPrefix);
|
|
134
|
+
const second = f.run({ version: 'v1', val: validityRows([['invalid', 0.7], ['actionable', 0.3]]) });
|
|
135
|
+
const combined = fs.readFileSync(f.history, 'utf8');
|
|
136
|
+
assert.ok(combined.startsWith(crlfPrefix), 'CRLF history bytes remain unchanged');
|
|
137
|
+
assert.deepEqual(combined.split(/\r?\n/).filter(Boolean).map(line => JSON.parse(line).version), ['v0', 'v1']);
|
|
138
|
+
assert.ok(combined.endsWith('\n'));
|
|
139
|
+
assert.deepEqual(JSON.parse(combined.split(/\r?\n/).filter(Boolean)[1]), second.curves);
|
|
140
|
+
});
|
|
141
|
+
|
|
125
142
|
test('intent curves keep reference-only unclassified scores but never use them as the selected option', t => {
|
|
126
143
|
const f = fixture(t, { stage: 'intent', options: ['fix', 'unclassified'], referenceOnly: ['unclassified'] });
|
|
127
144
|
const { curves, trend } = f.run({ val: [
|