harness-everything 0.54.1 → 0.55.1
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 +2 -1
- package/CHANGELOG.md +23 -0
- package/README.md +1 -0
- package/ci/mechanism-2ao-plugin-sync.test.js +18 -2
- package/ci/mechanism-349-ci-change-scope.test.js +68 -7
- package/ci/mechanism-check-packet-write-set.test.js +13 -3
- package/ci/mechanism-error-ledger-oracle.test.js +222 -0
- package/ci/mechanism-error-ledger-promote.test.js +520 -0
- package/ci/mechanism-error-ledger-scan.test.js +640 -0
- package/ci/mechanism-errors-sync-root.test.js +215 -0
- package/ci/openai-plugin-package.test.js +1 -1
- package/docs/error-handling/README.md +5 -5
- package/docs/error-handling/details/e0002-report-writer.md +25 -27
- package/docs/error-handling/registry.md +1 -1
- package/docs/workflows/error-ledger-bootstrap.md +23 -0
- package/error-ledger-bootstrap/SKILL.md +33 -0
- package/error-ledger-bootstrap/references/workflow.md +79 -0
- package/error-ledger-bootstrap/scripts/promote.js +613 -0
- package/error-ledger-bootstrap/scripts/scan.js +654 -0
- package/evals/error-ledger-bootstrap/eval.yaml +26 -0
- package/evals/error-ledger-bootstrap/tasks/negative-error-handling-map.yaml +16 -0
- package/evals/error-ledger-bootstrap/tasks/negative-trigger.yaml +16 -0
- package/evals/error-ledger-bootstrap/tasks/positive-trigger.yaml +15 -0
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/references/skill-registry.md +1 -0
- package/harness-everything/scripts/routing-keywords.json +11 -0
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +33 -0
- package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +79 -0
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +613 -0
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +654 -0
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/references/skill-registry.md +1 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +11 -0
- package/sbom.cdx.json +7 -7
- package/scripts/error-ledger-oracle.js +257 -0
- package/scripts/errors-sync.js +175 -12
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const assert = require('node:assert/strict');
|
|
5
|
+
const crypto = require('node:crypto');
|
|
6
|
+
const childProcess = require('node:child_process');
|
|
7
|
+
const fs = require('node:fs');
|
|
8
|
+
const os = require('node:os');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const { render } = require('../scripts/errors-sync');
|
|
11
|
+
const { isWithin } = require('../error-ledger-bootstrap/scripts/promote');
|
|
12
|
+
|
|
13
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
14
|
+
const SCRIPT = path.join(ROOT, 'error-ledger-bootstrap', 'scripts', 'promote.js');
|
|
15
|
+
const SYNC = path.join(ROOT, 'scripts', 'errors-sync.js');
|
|
16
|
+
const SCANNER = path.join(ROOT, 'error-ledger-bootstrap', 'scripts', 'scan.js');
|
|
17
|
+
const ERRORS = path.join('.agents', 'harness-everything', 'errors');
|
|
18
|
+
const TMP = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'error ledger promote ')));
|
|
19
|
+
const HOME = path.join(TMP, 'synthetic-home');
|
|
20
|
+
const MEMORY = path.join(HOME, 'private.md');
|
|
21
|
+
const MEMORY_BODY = 'PRIVATE MEMORY BODY SENTINEL';
|
|
22
|
+
|
|
23
|
+
function write(file, value) {
|
|
24
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
25
|
+
fs.writeFileSync(file, value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function git(repo, args, env = {}) {
|
|
29
|
+
return childProcess.execFileSync('git', ['-C', repo, ...args], {
|
|
30
|
+
encoding: 'utf8',
|
|
31
|
+
env: { ...process.env, GIT_CONFIG_NOSYSTEM: '1', HUSKY: '0', ...env },
|
|
32
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
33
|
+
}).trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function createTarget(name = 'target') {
|
|
37
|
+
const root = fs.realpathSync.native(fs.mkdtempSync(path.join(TMP, `${name} `)));
|
|
38
|
+
const errorsDir = path.join(root, ERRORS);
|
|
39
|
+
fs.mkdirSync(errorsDir, { recursive: true });
|
|
40
|
+
write(path.join(errorsDir, 'E-0001-fixture.md'), [
|
|
41
|
+
'---', 'id: E-0001', 'signature: fixture', 'class: test',
|
|
42
|
+
'scope: in', 'status: lesson', '---',
|
|
43
|
+
'## Cue', '', 'A synthetic target record.', '',
|
|
44
|
+
'## Lesson', '', 'Keep the synthetic ledger isolated.', ''
|
|
45
|
+
].join('\n'));
|
|
46
|
+
fs.writeFileSync(path.join(errorsDir, 'index.jsonl'), render(root));
|
|
47
|
+
write(path.join(root, 'src', 'parser.js'), 'module.exports = value => value;\n');
|
|
48
|
+
write(path.join(root, 'src', 'renderer.js'), 'module.exports = value => value;\n');
|
|
49
|
+
write(path.join(root, 'ci', 'parser.test.js'), "require('../src/parser');\n");
|
|
50
|
+
git(root, ['init', '-q']);
|
|
51
|
+
git(root, ['config', 'user.name', 'Promotion Fixture']);
|
|
52
|
+
git(root, ['config', 'user.email', 'fixture@example.invalid']);
|
|
53
|
+
git(root, ['config', 'commit.gpgsign', 'false']);
|
|
54
|
+
const fixedDate = Date.parse('2024-01-02T03:04:05.000Z');
|
|
55
|
+
function commit(subject, seconds, text, site = 'src/parser.js') {
|
|
56
|
+
write(path.join(root, site), text);
|
|
57
|
+
git(root, ['add', '-A']);
|
|
58
|
+
const date = new Date(fixedDate + seconds * 1000).toISOString();
|
|
59
|
+
git(root, ['commit', '-q', '-m', subject], {
|
|
60
|
+
GIT_AUTHOR_DATE: date,
|
|
61
|
+
GIT_COMMITTER_DATE: date
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
git(root, ['add', '-A']);
|
|
65
|
+
const seedDate = new Date(fixedDate).toISOString();
|
|
66
|
+
git(root, ['commit', '-q', '-m', 'feat: seed parser fixture'], {
|
|
67
|
+
GIT_AUTHOR_DATE: seedDate,
|
|
68
|
+
GIT_COMMITTER_DATE: seedDate
|
|
69
|
+
});
|
|
70
|
+
commit('fix: preserve parser boundary', 1, 'module.exports = value => value == null ? "" : value;\n');
|
|
71
|
+
commit('fix: handle parser edge case', 2, 'module.exports = value => String(value ?? "");\n');
|
|
72
|
+
commit('fix: preserve renderer boundary', 3, 'module.exports = value => value == null ? "" : value;\n', 'src/renderer.js');
|
|
73
|
+
commit('fix: handle renderer edge case', 4, 'module.exports = value => String(value ?? "");\n', 'src/renderer.js');
|
|
74
|
+
return { root, errorsDir };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function makeReport(targetRoot) {
|
|
78
|
+
fs.mkdirSync(HOME, { recursive: true });
|
|
79
|
+
write(MEMORY, [
|
|
80
|
+
'---', 'type: feedback', 'title: PRIVATE MEMORY SENTINEL', '---',
|
|
81
|
+
'## Cue', '', 'A local note about src/parser.js.', '',
|
|
82
|
+
'## Lesson', '', `${MEMORY_BODY}`, ''
|
|
83
|
+
].join('\n'));
|
|
84
|
+
const out = path.join(TMP, `reports-${path.basename(targetRoot)}`);
|
|
85
|
+
const env = { ...process.env, HOME, USERPROFILE: HOME, GIT_CONFIG_NOSYSTEM: '1' };
|
|
86
|
+
delete env.HARNESS_SYSTEM_ONE_MODE;
|
|
87
|
+
const scan = childProcess.spawnSync(process.execPath, [
|
|
88
|
+
SCANNER, '--root', targetRoot, '--out', out, '--memory', MEMORY,
|
|
89
|
+
'--home', HOME, '--hide-ledger', '--json'
|
|
90
|
+
], { cwd: ROOT, encoding: 'utf8', env });
|
|
91
|
+
assert.ifError(scan.error);
|
|
92
|
+
assert.equal(scan.status, 0, `scanner exit ${scan.status}; stderr: ${scan.stderr}`);
|
|
93
|
+
const payload = JSON.parse(scan.stdout);
|
|
94
|
+
const report = fs.readFileSync(payload.reportJson, 'utf8');
|
|
95
|
+
const reportJson = JSON.parse(report);
|
|
96
|
+
const selected = reportJson.candidates.find(candidate => candidate.sites.includes('src/parser.js') &&
|
|
97
|
+
candidate.sources.some(source => source.type === 'git'));
|
|
98
|
+
const memoryCandidate = reportJson.candidates.find(candidate => candidate.sources.some(source => source.type === 'memory'));
|
|
99
|
+
assert.ok(selected, 'the real scanner report includes the repeated-fix Git candidate');
|
|
100
|
+
assert.ok(memoryCandidate, 'the real scanner report includes the local memory candidate');
|
|
101
|
+
return { reportFile: payload.reportJson, reportJson, selected, memoryCandidate };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function approvalFor(targetRoot, reportFile, candidateId, changes = {}) {
|
|
105
|
+
const reportBytes = fs.readFileSync(reportFile);
|
|
106
|
+
return {
|
|
107
|
+
schemaVersion: 1,
|
|
108
|
+
candidateId,
|
|
109
|
+
reportSha256: crypto.createHash('sha256').update(reportBytes).digest('hex'),
|
|
110
|
+
targetRoot,
|
|
111
|
+
approvedBy: 'fixture-owner',
|
|
112
|
+
approvedAt: '2026-11-19T12:00:00.000Z',
|
|
113
|
+
record: {
|
|
114
|
+
signature: 'parser-edge-case',
|
|
115
|
+
class: 'test-coupling',
|
|
116
|
+
title: 'Parser edge case regressed',
|
|
117
|
+
violates: 'The parser preserves the approved token boundary.',
|
|
118
|
+
scope: 'in',
|
|
119
|
+
status: 'lesson',
|
|
120
|
+
sites: ['src/parser.js'],
|
|
121
|
+
sourcesNote: 'Review confirms the parser token boundary regression.'
|
|
122
|
+
},
|
|
123
|
+
...changes
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function writeApproval(value, file = path.join(TMP, 'approval.json')) {
|
|
128
|
+
write(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
129
|
+
return file;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function invoke(target, report, approval, harness = ROOT, extraEnv = {}) {
|
|
133
|
+
const env = { ...process.env, ...extraEnv };
|
|
134
|
+
delete env.HARNESS_SYSTEM_ONE_MODE;
|
|
135
|
+
return childProcess.spawnSync(process.execPath, [
|
|
136
|
+
SCRIPT, '--target', target, '--report', report,
|
|
137
|
+
'--approval', approval, '--harness', harness, '--json'
|
|
138
|
+
], { cwd: ROOT, encoding: 'utf8', env });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function resultFor(run, status) {
|
|
142
|
+
assert.ifError(run.error);
|
|
143
|
+
assert.equal(run.status, status, `promote exit ${run.status}; expected ${status}; stderr: ${run.stderr}`);
|
|
144
|
+
assert.equal(run.stderr.trim(), '', 'JSON mode returns its result on stdout');
|
|
145
|
+
return JSON.parse(run.stdout);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function snapshot(directory) {
|
|
149
|
+
return Object.fromEntries(fs.readdirSync(directory).sort().map(name => [
|
|
150
|
+
name,
|
|
151
|
+
fs.readFileSync(path.join(directory, name)).toString('base64')
|
|
152
|
+
]));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function seedFixture() {
|
|
156
|
+
const target = createTarget();
|
|
157
|
+
const report = makeReport(target.root);
|
|
158
|
+
const approval = writeApproval(approvalFor(fs.realpathSync.native(target.root), report.reportFile, report.selected.id));
|
|
159
|
+
return { ...target, ...report, report: report.reportFile, approval };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function updateCandidate(fixture, candidateId, update) {
|
|
163
|
+
const report = JSON.parse(fs.readFileSync(fixture.report, 'utf8'));
|
|
164
|
+
const candidate = report.candidates.find(item => item.id === candidateId);
|
|
165
|
+
assert.ok(candidate, `candidate ${candidateId} exists in the fixture report`);
|
|
166
|
+
update(candidate, report);
|
|
167
|
+
write(fixture.report, `${JSON.stringify(report, null, 2)}\n`);
|
|
168
|
+
fixture.reportJson = report;
|
|
169
|
+
return candidate;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function approveCandidate(fixture, candidateId, filename) {
|
|
173
|
+
return writeApproval(approvalFor(fs.realpathSync.native(fixture.root), fixture.report, candidateId),
|
|
174
|
+
path.join(TMP, filename));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function runSync(targetRoot, check = true) {
|
|
178
|
+
return childProcess.spawnSync(process.execPath, [SYNC, ...(check ? ['--check'] : []), '--root', targetRoot], {
|
|
179
|
+
cwd: ROOT, encoding: 'utf8', env: { ...process.env, GIT_CONFIG_NOSYSTEM: '1' }
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function makeHarness(name, syncSource) {
|
|
184
|
+
const harness = path.join(TMP, name);
|
|
185
|
+
fs.mkdirSync(path.join(harness, 'scripts'), { recursive: true });
|
|
186
|
+
if (syncSource !== null) write(path.join(harness, 'scripts', 'errors-sync.js'), syncSource);
|
|
187
|
+
return harness;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function addFakeYaml(harness) {
|
|
191
|
+
const moduleDir = path.join(harness, 'node_modules', 'js-yaml');
|
|
192
|
+
write(path.join(moduleDir, 'package.json'), JSON.stringify({ name: 'js-yaml', main: 'index.js' }));
|
|
193
|
+
write(path.join(moduleDir, 'index.js'), 'module.exports = {};\n');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function makeSyncHarness(name, afterWrite, duringRollback = '') {
|
|
197
|
+
const source = [
|
|
198
|
+
"const childProcess = require('node:child_process');",
|
|
199
|
+
"const fs = require('node:fs');",
|
|
200
|
+
"const path = require('node:path');",
|
|
201
|
+
`const canonicalSync = ${JSON.stringify(SYNC)};`,
|
|
202
|
+
'module.exports = require(canonicalSync);',
|
|
203
|
+
...(duringRollback ? [
|
|
204
|
+
'const renderIndex = module.exports.render;',
|
|
205
|
+
'module.exports.render = function (root) {',
|
|
206
|
+
duringRollback,
|
|
207
|
+
' return renderIndex(root);',
|
|
208
|
+
'};'
|
|
209
|
+
] : []),
|
|
210
|
+
'if (require.main === module) {',
|
|
211
|
+
' const args = process.argv.slice(2);',
|
|
212
|
+
" if (args.includes('--check')) { process.stderr.write('injected final check failure\\n'); process.exit(1); }",
|
|
213
|
+
" const result = childProcess.spawnSync(process.execPath, [canonicalSync, ...args], { encoding: 'utf8' });",
|
|
214
|
+
' if (result.stdout) process.stdout.write(result.stdout);',
|
|
215
|
+
' if (result.stderr) process.stderr.write(result.stderr);',
|
|
216
|
+
' if (result.status !== 0) process.exit(result.status || 1);',
|
|
217
|
+
afterWrite,
|
|
218
|
+
'}', ''
|
|
219
|
+
].join('\n');
|
|
220
|
+
const harness = makeHarness(name, source);
|
|
221
|
+
addFakeYaml(harness);
|
|
222
|
+
return harness;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
// The whole happy path uses the real CLI and target-root sync implementation.
|
|
227
|
+
const success = seedFixture();
|
|
228
|
+
success.selected = updateCandidate(success, success.selected.id, candidate => {
|
|
229
|
+
candidate.title = 'PRIVATE MEMORY TITLE SENTINEL';
|
|
230
|
+
candidate.sources.push({ type: 'memory', ref: 'PRIVATE MEMORY REF SENTINEL', title: 'PRIVATE MEMORY TITLE SENTINEL' });
|
|
231
|
+
});
|
|
232
|
+
success.approval = approveCandidate(success, success.selected.id, 'success-approval.json');
|
|
233
|
+
const unselectedApproval = writeApproval(
|
|
234
|
+
approvalFor(fs.realpathSync.native(success.root), success.report, success.memoryCandidate.id),
|
|
235
|
+
path.join(TMP, 'unselected-approval.json')
|
|
236
|
+
);
|
|
237
|
+
assert.equal(JSON.parse(fs.readFileSync(unselectedApproval, 'utf8')).candidateId, success.memoryCandidate.id,
|
|
238
|
+
'the fixture includes a separately approved candidate that is not selected for this promotion');
|
|
239
|
+
const originalReport = fs.readFileSync(success.report);
|
|
240
|
+
const promoted = resultFor(invoke(success.root, success.report, success.approval), 0);
|
|
241
|
+
assert.deepEqual(Object.keys(promoted).sort(), ['file', 'id', 'indexUpdated', 'ok']);
|
|
242
|
+
assert.deepEqual(promoted, {
|
|
243
|
+
ok: true,
|
|
244
|
+
id: 'E-0002',
|
|
245
|
+
file: path.posix.join(...ERRORS.split(path.sep), 'E-0002-parser-edge-case.md'),
|
|
246
|
+
indexUpdated: true
|
|
247
|
+
});
|
|
248
|
+
const promotedFile = path.join(success.errorsDir, 'E-0002-parser-edge-case.md');
|
|
249
|
+
const record = fs.readFileSync(promotedFile, 'utf8');
|
|
250
|
+
assert.match(record, /\bid: "E-0002"/);
|
|
251
|
+
assert.match(record, /\bsignature: "parser-edge-case"/);
|
|
252
|
+
for (const source of success.selected.sources.filter(item => item.type === 'git')) {
|
|
253
|
+
assert.ok(record.includes(source.sha), `durable commit ${source.sha} is cited in the record`);
|
|
254
|
+
}
|
|
255
|
+
assert.match(record, /repo\/src\/parser\.js/);
|
|
256
|
+
const approvedRecord = JSON.parse(fs.readFileSync(success.approval, 'utf8')).record;
|
|
257
|
+
assert.ok(record.includes(approvedRecord.title), 'record title comes from the owner-approved payload');
|
|
258
|
+
assert.ok(record.includes(approvedRecord.sourcesNote), 'record lesson comes from the owner-approved payload');
|
|
259
|
+
assert.doesNotMatch(record, /PRIVATE MEMORY SENTINEL|PRIVATE MEMORY REF SENTINEL|PRIVATE MEMORY TITLE SENTINEL/,
|
|
260
|
+
'memory source refs and titles are never promoted');
|
|
261
|
+
assert.doesNotMatch(record, new RegExp(`${MEMORY_BODY}|home\\/private\\.md|\\/Users\\/|\\/private\\/tmp`),
|
|
262
|
+
'promotion writes approved content and durable sources, never local memory or absolute paths');
|
|
263
|
+
assert.deepEqual(fs.readFileSync(success.report), originalReport, 'promotion never edits the report');
|
|
264
|
+
assert.equal(JSON.parse(fs.readFileSync(success.report, 'utf8')).candidates.length, success.reportJson.candidates.length,
|
|
265
|
+
'approved-but-unselected candidates remain in the report');
|
|
266
|
+
assert.equal(fs.readFileSync(path.join(success.errorsDir, 'index.jsonl'), 'utf8'), render(success.root),
|
|
267
|
+
'the promoted index has byte parity with the canonical renderer');
|
|
268
|
+
assert.doesNotMatch(fs.readFileSync(path.join(success.errorsDir, 'index.jsonl'), 'utf8'),
|
|
269
|
+
/PRIVATE MEMORY SENTINEL|PRIVATE MEMORY REF SENTINEL|PRIVATE MEMORY TITLE SENTINEL/,
|
|
270
|
+
'the promoted index contains no memory source refs or titles');
|
|
271
|
+
assert.equal(runSync(success.root).status, 0, 'errors-sync --root --check accepts the promoted index');
|
|
272
|
+
|
|
273
|
+
const memoryOnly = seedFixture();
|
|
274
|
+
updateCandidate(memoryOnly, memoryOnly.memoryCandidate.id, candidate => {
|
|
275
|
+
candidate.sites = ['src/parser.js'];
|
|
276
|
+
candidate.sources = [{ type: 'memory', ref: 'PRIVATE MEMORY REF SENTINEL', title: 'PRIVATE MEMORY TITLE SENTINEL' }];
|
|
277
|
+
});
|
|
278
|
+
const memoryApproval = approveCandidate(memoryOnly, memoryOnly.memoryCandidate.id, 'memory-only-approval.json');
|
|
279
|
+
const memoryBefore = snapshot(memoryOnly.errorsDir);
|
|
280
|
+
const memoryResult = resultFor(invoke(memoryOnly.root, memoryOnly.report, memoryApproval), 2);
|
|
281
|
+
assert.equal(memoryResult.ok, false, 'memory-only candidate evidence is refused despite a valid-looking site');
|
|
282
|
+
assert.match(memoryResult.error, /durable source evidence/, 'private-only refusal explains the missing durable evidence');
|
|
283
|
+
assert.deepEqual(snapshot(memoryOnly.errorsDir), memoryBefore, 'private-only refusal writes no E-record or index changes');
|
|
284
|
+
|
|
285
|
+
const instructionOnly = seedFixture();
|
|
286
|
+
updateCandidate(instructionOnly, instructionOnly.selected.id, candidate => {
|
|
287
|
+
candidate.sites = ['src/parser.js'];
|
|
288
|
+
candidate.sources = [{ type: 'instruction', ref: 'repo/AGENTS.md', title: 'PRIVATE INSTRUCTION TITLE SENTINEL' }];
|
|
289
|
+
});
|
|
290
|
+
const instructionApproval = approveCandidate(instructionOnly, instructionOnly.selected.id, 'instruction-only-approval.json');
|
|
291
|
+
const instructionBefore = snapshot(instructionOnly.errorsDir);
|
|
292
|
+
const instructionResult = resultFor(invoke(instructionOnly.root, instructionOnly.report, instructionApproval), 2);
|
|
293
|
+
assert.equal(instructionResult.ok, false, 'instruction-only candidate evidence is refused');
|
|
294
|
+
assert.deepEqual(snapshot(instructionOnly.errorsDir), instructionBefore, 'instruction-only refusal writes no E-record');
|
|
295
|
+
|
|
296
|
+
const missingSite = seedFixture();
|
|
297
|
+
updateCandidate(missingSite, missingSite.selected.id, candidate => { candidate.sites = ['src/not-present.js']; });
|
|
298
|
+
const missingSiteApproval = approveCandidate(missingSite, missingSite.selected.id, 'missing-site-approval.json');
|
|
299
|
+
const missingSiteBefore = snapshot(missingSite.errorsDir);
|
|
300
|
+
const missingSiteResult = resultFor(invoke(missingSite.root, missingSite.report, missingSiteApproval), 2);
|
|
301
|
+
assert.equal(missingSiteResult.ok, false, 'candidate sites must resolve to existing files in the target repo');
|
|
302
|
+
assert.match(missingSiteResult.error, /existing target-repository file/, 'site refusal identifies the invalid target path');
|
|
303
|
+
assert.deepEqual(snapshot(missingSite.errorsDir), missingSiteBefore, 'unverified site refusal writes no E-record');
|
|
304
|
+
|
|
305
|
+
const unverifiedApprovalSite = seedFixture();
|
|
306
|
+
const unverifiedApproval = JSON.parse(fs.readFileSync(unverifiedApprovalSite.approval, 'utf8'));
|
|
307
|
+
unverifiedApproval.record.sites = ['src/not-present.js'];
|
|
308
|
+
const unverifiedApprovalFile = writeApproval(unverifiedApproval, path.join(TMP, 'unverified-approval-site.json'));
|
|
309
|
+
const unverifiedApprovalBefore = snapshot(unverifiedApprovalSite.errorsDir);
|
|
310
|
+
const unverifiedApprovalResult = resultFor(invoke(unverifiedApprovalSite.root, unverifiedApprovalSite.report,
|
|
311
|
+
unverifiedApprovalFile), 2);
|
|
312
|
+
assert.equal(unverifiedApprovalResult.ok, false, 'approved record sites must also exist inside the target repo');
|
|
313
|
+
assert.deepEqual(snapshot(unverifiedApprovalSite.errorsDir), unverifiedApprovalBefore,
|
|
314
|
+
'a nonexistent approved site writes no E-record');
|
|
315
|
+
|
|
316
|
+
const successSnapshot = snapshot(success.errorsDir);
|
|
317
|
+
assert.equal(resultFor(invoke(success.root, success.report, success.approval), 2).ok, false,
|
|
318
|
+
'the same approval cannot be promoted twice');
|
|
319
|
+
assert.deepEqual(snapshot(success.errorsDir), successSnapshot, 'a repeat leaves the existing record and index unchanged');
|
|
320
|
+
|
|
321
|
+
const locked = seedFixture();
|
|
322
|
+
const lockFile = path.join(locked.errorsDir, '.promote.lock');
|
|
323
|
+
write(lockFile, 'active promotion\n');
|
|
324
|
+
const lockedBefore = snapshot(locked.errorsDir);
|
|
325
|
+
assert.equal(resultFor(invoke(locked.root, locked.report, locked.approval), 2).ok, false,
|
|
326
|
+
'a concurrent or stale promotion lock is refused');
|
|
327
|
+
assert.deepEqual(snapshot(locked.errorsDir), lockedBefore, 'a refused run never removes another promotion lock');
|
|
328
|
+
|
|
329
|
+
const missingCandidate = seedFixture();
|
|
330
|
+
const absentApproval = approvalFor(fs.realpathSync.native(missingCandidate.root), missingCandidate.report,
|
|
331
|
+
'11111111111111111111');
|
|
332
|
+
const absentFile = writeApproval(absentApproval);
|
|
333
|
+
const absentBefore = snapshot(missingCandidate.errorsDir);
|
|
334
|
+
assert.equal(resultFor(invoke(missingCandidate.root, missingCandidate.report, absentFile), 2).ok, false,
|
|
335
|
+
'an approval for a missing report candidate is refused');
|
|
336
|
+
assert.deepEqual(snapshot(missingCandidate.errorsDir), absentBefore, 'unknown candidate refusal writes nothing');
|
|
337
|
+
|
|
338
|
+
const changedReport = seedFixture();
|
|
339
|
+
fs.appendFileSync(changedReport.report, ' ');
|
|
340
|
+
const changedBefore = snapshot(changedReport.errorsDir);
|
|
341
|
+
assert.equal(resultFor(invoke(changedReport.root, changedReport.report, changedReport.approval), 2).ok, false,
|
|
342
|
+
'a report changed after approval is refused');
|
|
343
|
+
assert.deepEqual(snapshot(changedReport.errorsDir), changedBefore, 'report digest refusal writes nothing');
|
|
344
|
+
|
|
345
|
+
const wrongTarget = seedFixture();
|
|
346
|
+
const wrongTargetApproval = writeApproval(approvalFor(path.join(TMP, 'different-target'), wrongTarget.report, wrongTarget.selected.id));
|
|
347
|
+
const wrongTargetBefore = snapshot(wrongTarget.errorsDir);
|
|
348
|
+
assert.equal(resultFor(invoke(wrongTarget.root, wrongTarget.report, wrongTargetApproval), 2).ok, false,
|
|
349
|
+
'approval for a different target root is refused');
|
|
350
|
+
assert.deepEqual(snapshot(wrongTarget.errorsDir), wrongTargetBefore, 'target mismatch writes nothing');
|
|
351
|
+
|
|
352
|
+
const symlinkTarget = seedFixture();
|
|
353
|
+
const externalErrors = path.join(TMP, 'external-errors');
|
|
354
|
+
fs.renameSync(symlinkTarget.errorsDir, externalErrors);
|
|
355
|
+
fs.mkdirSync(path.dirname(symlinkTarget.errorsDir), { recursive: true });
|
|
356
|
+
fs.symlinkSync(externalErrors, symlinkTarget.errorsDir, process.platform === 'win32' ? 'junction' : 'dir');
|
|
357
|
+
const externalBefore = snapshot(externalErrors);
|
|
358
|
+
assert.equal(resultFor(invoke(symlinkTarget.root, symlinkTarget.report, symlinkTarget.approval), 2).ok, false,
|
|
359
|
+
'an errors directory that resolves outside the target is refused');
|
|
360
|
+
assert.deepEqual(snapshot(externalErrors), externalBefore, 'symlink escape refusal leaves its target unchanged');
|
|
361
|
+
|
|
362
|
+
const internalSymlinkErrors = seedFixture();
|
|
363
|
+
const internalErrors = path.join(internalSymlinkErrors.root, '.private-ledger-storage');
|
|
364
|
+
fs.renameSync(internalSymlinkErrors.errorsDir, internalErrors);
|
|
365
|
+
fs.symlinkSync(internalErrors, internalSymlinkErrors.errorsDir, process.platform === 'win32' ? 'junction' : 'dir');
|
|
366
|
+
const internalBefore = snapshot(internalErrors);
|
|
367
|
+
const internalRefused = resultFor(invoke(internalSymlinkErrors.root, internalSymlinkErrors.report,
|
|
368
|
+
internalSymlinkErrors.approval), 1);
|
|
369
|
+
assert.equal(internalRefused.ok, false, 'the canonical sync refuses a symlinked errors directory even when it stays inside the target');
|
|
370
|
+
assert.deepEqual(snapshot(internalErrors), internalBefore, 'rejected symlink target leaves no new E-record or changed index');
|
|
371
|
+
|
|
372
|
+
const missingErrors = fs.realpathSync.native(fs.mkdtempSync(path.join(TMP, 'missing errors ')));
|
|
373
|
+
git(missingErrors, ['init', '-q']);
|
|
374
|
+
const missingApproval = writeApproval(approvalFor(missingErrors, success.report, success.selected.id));
|
|
375
|
+
assert.equal(resultFor(invoke(missingErrors, success.report, missingApproval), 2).ok, false,
|
|
376
|
+
'a target without its existing errors directory is refused');
|
|
377
|
+
assert.equal(fs.existsSync(path.join(missingErrors, '.agents')), false, 'promotion never creates the missing ledger directory');
|
|
378
|
+
|
|
379
|
+
const noSync = seedFixture();
|
|
380
|
+
const unavailableHarness = makeHarness('missing-sync-harness', null);
|
|
381
|
+
const noSyncBefore = snapshot(noSync.errorsDir);
|
|
382
|
+
const noSyncResult = resultFor(invoke(noSync.root, noSync.report, noSync.approval, unavailableHarness), 2);
|
|
383
|
+
assert.equal(noSyncResult.ok, false,
|
|
384
|
+
'a Harness checkout without errors-sync.js is refused before writing');
|
|
385
|
+
assert.match(noSyncResult.error, /pass --harness to a trusted Harness checkout/,
|
|
386
|
+
'missing sync tool explains how to recover locally');
|
|
387
|
+
assert.deepEqual(snapshot(noSync.errorsDir), noSyncBefore, 'unavailable sync tool leaves the ledger untouched');
|
|
388
|
+
|
|
389
|
+
const noDependency = seedFixture();
|
|
390
|
+
const missingDependencyHarness = makeHarness('missing-dependency-harness', 'process.exit(0);\n');
|
|
391
|
+
const noDependencyBefore = snapshot(noDependency.errorsDir);
|
|
392
|
+
const noDependencyResult = resultFor(invoke(noDependency.root, noDependency.report, noDependency.approval, missingDependencyHarness), 2);
|
|
393
|
+
assert.equal(noDependencyResult.ok, false,
|
|
394
|
+
'a Harness checkout without resolvable js-yaml is refused before writing');
|
|
395
|
+
assert.match(noDependencyResult.error, /install its Node dependencies/,
|
|
396
|
+
'missing dependency explains how to recover locally');
|
|
397
|
+
assert.deepEqual(snapshot(noDependency.errorsDir), noDependencyBefore, 'dependency preflight writes nothing');
|
|
398
|
+
|
|
399
|
+
const syncFailure = seedFixture();
|
|
400
|
+
const failingHarness = makeSyncHarness('failing-sync-harness', '');
|
|
401
|
+
const beforeFailure = snapshot(syncFailure.errorsDir);
|
|
402
|
+
const syncFailureResult = resultFor(invoke(syncFailure.root, syncFailure.report, syncFailure.approval, failingHarness), 1);
|
|
403
|
+
assert.equal(syncFailureResult.ok, false, 'a failed final check after atomic index replacement is reported as a failure');
|
|
404
|
+
assert.deepEqual(snapshot(syncFailure.errorsDir), beforeFailure,
|
|
405
|
+
`rollback recognizes its own replacement, removes the new record, and restores prior index bytes: ${syncFailureResult.error}`);
|
|
406
|
+
assert.equal(runSync(syncFailure.root).status, 0, 'the target index remains current after rollback');
|
|
407
|
+
|
|
408
|
+
const rollbackContention = seedFixture();
|
|
409
|
+
const secondCandidate = rollbackContention.reportJson.candidates.find(candidate =>
|
|
410
|
+
candidate.id !== rollbackContention.selected.id && candidate.sources.some(source => source.type === 'git'));
|
|
411
|
+
assert.ok(secondCandidate, 'the real scanner fixture supplies two distinct durable candidates');
|
|
412
|
+
const approvalB = writeApproval(approvalFor(fs.realpathSync.native(rollbackContention.root),
|
|
413
|
+
rollbackContention.report, secondCandidate.id, {
|
|
414
|
+
record: {
|
|
415
|
+
signature: 'renderer-rollback-contention',
|
|
416
|
+
class: 'test-coupling',
|
|
417
|
+
title: 'Renderer rollback contention',
|
|
418
|
+
violates: 'The renderer promotion waits for rollback recovery.',
|
|
419
|
+
scope: 'in',
|
|
420
|
+
status: 'lesson',
|
|
421
|
+
sites: ['src/renderer.js'],
|
|
422
|
+
sourcesNote: 'The renderer record is independently approved for the rollback contention control.'
|
|
423
|
+
}
|
|
424
|
+
}), path.join(TMP, 'rollback-b-approval.json'));
|
|
425
|
+
const contentionProbeFile = path.join(TMP, 'rollback-contention-probe.json');
|
|
426
|
+
const contentionResultFile = path.join(TMP, 'rollback-contention-result.json');
|
|
427
|
+
write(contentionProbeFile, JSON.stringify({
|
|
428
|
+
args: [SCRIPT, '--target', rollbackContention.root, '--report', rollbackContention.report,
|
|
429
|
+
'--approval', approvalB, '--harness', ROOT, '--json'],
|
|
430
|
+
cwd: ROOT,
|
|
431
|
+
resultFile: contentionResultFile
|
|
432
|
+
}));
|
|
433
|
+
const duringRollback = [
|
|
434
|
+
" const probe = JSON.parse(fs.readFileSync(process.env.PROMOTION_ROLLBACK_PROBE, 'utf8'));",
|
|
435
|
+
" const errorsDir = path.join(root, '.agents', 'harness-everything', 'errors');",
|
|
436
|
+
' const state = () => ({',
|
|
437
|
+
" records: Object.fromEntries(fs.readdirSync(errorsDir).filter(name => name.startsWith('E-') && name.endsWith('.md')).sort().map(name => [name, fs.readFileSync(path.join(errorsDir, name)).toString('base64')])),",
|
|
438
|
+
" index: fs.readFileSync(path.join(errorsDir, 'index.jsonl')).toString('base64'),",
|
|
439
|
+
" lock: fs.existsSync(path.join(errorsDir, '.promote.lock'))",
|
|
440
|
+
' });',
|
|
441
|
+
' const before = state();',
|
|
442
|
+
" const expectedIndex = Buffer.from(renderIndex(root)).toString('base64');",
|
|
443
|
+
" const attempt = childProcess.spawnSync(process.execPath, probe.args, { cwd: probe.cwd, encoding: 'utf8' });",
|
|
444
|
+
' const after = state();',
|
|
445
|
+
" fs.writeFileSync(probe.resultFile, JSON.stringify({ before, after, expectedIndex, attempt: { status: attempt.status, stdout: attempt.stdout, stderr: attempt.stderr, error: attempt.error && attempt.error.message } }));"
|
|
446
|
+
].join('\n');
|
|
447
|
+
const contentionHarness = makeSyncHarness('rollback-contention-harness', '', duringRollback);
|
|
448
|
+
const beforeContention = snapshot(rollbackContention.errorsDir);
|
|
449
|
+
const rollbackAResult = resultFor(invoke(rollbackContention.root, rollbackContention.report,
|
|
450
|
+
rollbackContention.approval, contentionHarness, { PROMOTION_ROLLBACK_PROBE: contentionProbeFile }), 1);
|
|
451
|
+
assert.equal(rollbackAResult.ok, false, 'A reports its injected final check failure');
|
|
452
|
+
assert.match(rollbackAResult.error, /injected final check failure/);
|
|
453
|
+
const contention = JSON.parse(fs.readFileSync(contentionResultFile, 'utf8'));
|
|
454
|
+
assert.ok(Object.hasOwn(contention.before.records, 'E-0002-parser-edge-case.md'),
|
|
455
|
+
'A published its record before rollback began');
|
|
456
|
+
assert.equal(contention.before.index, contention.expectedIndex,
|
|
457
|
+
'A published the replacement index before rollback began');
|
|
458
|
+
assert.equal(contention.attempt.status, 2, 'B is refused while A is rolling back');
|
|
459
|
+
const refusedB = JSON.parse(contention.attempt.stdout);
|
|
460
|
+
assert.equal(refusedB.ok, false);
|
|
461
|
+
assert.match(refusedB.error, /another promotion is active or a stale \.promote\.lock remains/,
|
|
462
|
+
'B receives the active-lock refusal');
|
|
463
|
+
assert.equal(contention.before.lock, true, 'A still owns the lock before the contention attempt');
|
|
464
|
+
assert.deepEqual(contention.after, contention.before,
|
|
465
|
+
'B leaves the record bytes, index bytes, and active lock unchanged');
|
|
466
|
+
assert.deepEqual(snapshot(rollbackContention.errorsDir), beforeContention,
|
|
467
|
+
'A removes its record and restores the original index after B is refused');
|
|
468
|
+
assert.equal(fs.existsSync(path.join(rollbackContention.errorsDir, '.promote.lock')), false,
|
|
469
|
+
'A releases its lock after rollback completes');
|
|
470
|
+
assert.equal(fs.readdirSync(rollbackContention.errorsDir).some(name =>
|
|
471
|
+
name.startsWith('.index.jsonl.') && name.endsWith('.tmp')), false,
|
|
472
|
+
'rollback leaves no temporary index');
|
|
473
|
+
assert.equal(runSync(rollbackContention.root).status, 0,
|
|
474
|
+
'canonical errors-sync --check passes after A recovery');
|
|
475
|
+
|
|
476
|
+
const retryB = resultFor(invoke(rollbackContention.root, rollbackContention.report, approvalB), 0);
|
|
477
|
+
assert.equal(retryB.id, 'E-0002', 'B can promote after A recovery');
|
|
478
|
+
assert.equal(fs.existsSync(path.join(rollbackContention.errorsDir, 'E-0002-renderer-rollback-contention.md')), true,
|
|
479
|
+
'the retry publishes only B approved record');
|
|
480
|
+
assert.equal(fs.existsSync(path.join(rollbackContention.errorsDir, 'E-0002-parser-edge-case.md')), false,
|
|
481
|
+
'A record remains rolled back');
|
|
482
|
+
assert.deepEqual(fs.readdirSync(rollbackContention.errorsDir)
|
|
483
|
+
.filter(name => name.startsWith('E-') && name.endsWith('.md')).sort(),
|
|
484
|
+
['E-0001-fixture.md', 'E-0002-renderer-rollback-contention.md'],
|
|
485
|
+
'the recovered ledger contains only B approved record');
|
|
486
|
+
assert.equal(fs.readFileSync(path.join(rollbackContention.errorsDir, 'index.jsonl'), 'utf8'),
|
|
487
|
+
render(rollbackContention.root), 'B retry leaves byte parity with the canonical renderer');
|
|
488
|
+
assert.equal(runSync(rollbackContention.root).status, 0,
|
|
489
|
+
'canonical errors-sync --check passes after B retry');
|
|
490
|
+
|
|
491
|
+
const unrelatedReplacement = seedFixture();
|
|
492
|
+
const unrelatedHarness = makeSyncHarness('unrelated-sync-harness', [
|
|
493
|
+
" const root = args[args.indexOf('--root') + 1];",
|
|
494
|
+
" const index = path.join(root, '.agents/harness-everything/errors/index.jsonl');",
|
|
495
|
+
" const replacement = `${index}.replacement`;",
|
|
496
|
+
" fs.writeFileSync(replacement, 'unrelated writer bytes\\n');",
|
|
497
|
+
' fs.renameSync(replacement, index);'
|
|
498
|
+
].join('\n'));
|
|
499
|
+
const unrelatedRecord = path.join(unrelatedReplacement.errorsDir, 'E-0002-parser-edge-case.md');
|
|
500
|
+
const unrelatedResult = resultFor(invoke(unrelatedReplacement.root, unrelatedReplacement.report,
|
|
501
|
+
unrelatedReplacement.approval, unrelatedHarness), 1);
|
|
502
|
+
assert.match(unrelatedResult.error, /recovery needed/, 'unowned index replacement reports actionable recovery');
|
|
503
|
+
assert.equal(fs.readFileSync(path.join(unrelatedReplacement.errorsDir, 'index.jsonl'), 'utf8'),
|
|
504
|
+
'unrelated writer bytes\n', 'rollback preserves an unrelated index replacement');
|
|
505
|
+
assert.equal(fs.existsSync(unrelatedRecord), false, 'rollback removes only the owned new E-record');
|
|
506
|
+
|
|
507
|
+
const win32 = path.win32;
|
|
508
|
+
const outside = win32.relative('C:\\repo', 'D:\\temp\\file.md');
|
|
509
|
+
assert.ok(win32.isAbsolute(outside), 'cross-drive relative paths are absolute on Windows');
|
|
510
|
+
assert.equal(isWithin('C:\\repo', 'D:\\temp\\file.md', win32), false,
|
|
511
|
+
'cross-drive paths must not be mistaken for a leading-dotdot escape');
|
|
512
|
+
assert.equal(isWithin('C:\\repo', 'C:\\repo\\..cache\\lesson.md', win32), true,
|
|
513
|
+
'a child beginning with two dots is not a parent path segment');
|
|
514
|
+
assert.equal(isWithin('C:\\repo', 'C:\\repo2\\lesson.md', win32), false,
|
|
515
|
+
'a sibling with a shared string prefix remains outside');
|
|
516
|
+
|
|
517
|
+
console.log('PASS error-ledger promotion is approval-bound, non-overwriting, and recoverable');
|
|
518
|
+
} finally {
|
|
519
|
+
fs.rmSync(TMP, { recursive: true, force: true });
|
|
520
|
+
}
|