harness-everything 1.1.1 → 1.2.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 +1 -1
- package/CHANGELOG.md +18 -0
- package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/README.md +32 -0
- package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/claude-records.json +1 -0
- package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/codex-hook-trace.txt +24 -0
- package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/opencode-records.json +1 -0
- package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/probe.sh +16 -0
- package/ci/mechanism-496-local-error-store.test.js +188 -5
- package/ci/mechanism-498-local-store-promote.test.js +402 -0
- package/ci/mechanism-498-local-store-scan.test.js +582 -0
- package/error-ledger-bootstrap/SKILL.md +1 -1
- package/error-ledger-bootstrap/references/workflow.md +15 -1
- package/error-ledger-bootstrap/scripts/promote.js +145 -9
- package/error-ledger-bootstrap/scripts/scan.js +394 -3
- package/hooks/scripts/lib/local-errors.js +24 -7
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/lib/local-errors.js +24 -7
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +1 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +15 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +145 -9
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +394 -3
- package/sbom.cdx.json +7 -7
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const assert = require('node:assert/strict');
|
|
5
|
+
const childProcess = require('node:child_process');
|
|
6
|
+
const crypto = require('node:crypto');
|
|
7
|
+
const fs = require('node:fs');
|
|
8
|
+
const os = require('node:os');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const localErrors = require('../hooks/scripts/lib/local-errors');
|
|
11
|
+
const { render } = require('../scripts/errors-sync');
|
|
12
|
+
|
|
13
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
14
|
+
const SCANNER = path.join(ROOT, 'error-ledger-bootstrap', 'scripts', 'scan.js');
|
|
15
|
+
const PROMOTER = path.join(ROOT, 'error-ledger-bootstrap', 'scripts', 'promote.js');
|
|
16
|
+
const SYNC = path.join(ROOT, 'scripts', 'errors-sync.js');
|
|
17
|
+
const ERRORS = path.join('.agents', 'harness-everything', 'errors');
|
|
18
|
+
const TMP = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'harness-498-promote-')));
|
|
19
|
+
const STORE = path.join(TMP, 'store');
|
|
20
|
+
const HOME = path.join(TMP, 'home');
|
|
21
|
+
const PRIVATE = {
|
|
22
|
+
provisionalId: 'provisional-parser-one',
|
|
23
|
+
lesson: 'PRIVATE_LESSON_SENTINEL',
|
|
24
|
+
cue: 'PRIVATE_CUE_SENTINEL',
|
|
25
|
+
issueUrl: 'https://private.example/PRIVATE_URL_SENTINEL'
|
|
26
|
+
};
|
|
27
|
+
const WRITER_ENV = isolatedEnv({ HARNESS_OBSERVATIONS_DIR: STORE, HOME, USERPROFILE: HOME });
|
|
28
|
+
|
|
29
|
+
function isolatedEnv(overrides = {}) {
|
|
30
|
+
const env = { ...process.env, ...overrides, GIT_CONFIG_NOSYSTEM: '1' };
|
|
31
|
+
for (const name of ['HARNESS_WORKSPACE_ROOT', 'CLAUDE_PROJECT_DIR', 'CODEX_PROJECT_DIR', 'HARNESS_SYSTEM_ONE_MODE']) {
|
|
32
|
+
delete env[name];
|
|
33
|
+
}
|
|
34
|
+
return env;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function write(file, bytes) {
|
|
38
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
39
|
+
fs.writeFileSync(file, bytes);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function git(root, args, extraEnv = {}) {
|
|
43
|
+
const result = childProcess.spawnSync('git', ['-C', root, ...args], {
|
|
44
|
+
encoding: 'utf8',
|
|
45
|
+
env: isolatedEnv({
|
|
46
|
+
GIT_AUTHOR_NAME: 'Promotion Fixture', GIT_AUTHOR_EMAIL: 'fixture@example.invalid',
|
|
47
|
+
GIT_COMMITTER_NAME: 'Promotion Fixture', GIT_COMMITTER_EMAIL: 'fixture@example.invalid',
|
|
48
|
+
...extraEnv
|
|
49
|
+
}),
|
|
50
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
51
|
+
});
|
|
52
|
+
assert.ifError(result.error);
|
|
53
|
+
assert.equal(result.status, 0, `git ${args.join(' ')} failed: ${result.stderr}`);
|
|
54
|
+
return result.stdout.trim();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function hash(bytes) {
|
|
58
|
+
return crypto.createHash('sha256').update(bytes).digest('hex');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function treeDigest(directory, excludeLock = false) {
|
|
62
|
+
const entries = fs.readdirSync(directory).sort()
|
|
63
|
+
.filter(name => !(excludeLock && name === '.promote.lock'))
|
|
64
|
+
.map(name => [name, hash(fs.readFileSync(path.join(directory, name)))]);
|
|
65
|
+
return hash(JSON.stringify(entries));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function createTarget(name) {
|
|
69
|
+
const root = fs.realpathSync.native(fs.mkdtempSync(path.join(TMP, `${name}-`)));
|
|
70
|
+
const errorsDir = path.join(root, ERRORS);
|
|
71
|
+
write(path.join(errorsDir, 'E-0001-fixture.md'), [
|
|
72
|
+
'---', 'id: E-0001', 'signature: fixture', 'class: test-coupling',
|
|
73
|
+
'title: Promotion fixture', 'scope: in', 'status: lesson', 'sites: []',
|
|
74
|
+
'violates: Fixture contract', 'mechanism_ref: null', 'episodes: []', '---',
|
|
75
|
+
'', '## Cue', '', 'A synthetic target ledger.', '', '## Lesson', '', 'Keep this fixture isolated.', ''
|
|
76
|
+
].join('\n'));
|
|
77
|
+
write(path.join(errorsDir, 'index.jsonl'), render(root));
|
|
78
|
+
write(path.join(root, 'README.md'), '# Promotion fixture\n');
|
|
79
|
+
write(path.join(root, 'src', 'parser.js'), 'module.exports = value => value;\n');
|
|
80
|
+
write(path.join(root, 'ci', 'parser.test.js'), "require('../src/parser');\n");
|
|
81
|
+
git(root, ['init', '-q']);
|
|
82
|
+
git(root, ['config', 'user.name', 'Promotion Fixture']);
|
|
83
|
+
git(root, ['config', 'user.email', 'fixture@example.invalid']);
|
|
84
|
+
git(root, ['config', 'commit.gpgsign', 'false']);
|
|
85
|
+
const epoch = Date.parse('2026-11-25T00:00:00.000Z');
|
|
86
|
+
function commit(subject, seconds, content) {
|
|
87
|
+
write(path.join(root, 'src', 'parser.js'), content);
|
|
88
|
+
git(root, ['add', '-A']);
|
|
89
|
+
const date = new Date(epoch + seconds * 1000).toISOString();
|
|
90
|
+
git(root, ['commit', '-q', '-m', subject], { GIT_AUTHOR_DATE: date, GIT_COMMITTER_DATE: date });
|
|
91
|
+
}
|
|
92
|
+
git(root, ['add', '-A']);
|
|
93
|
+
const seedDate = new Date(epoch).toISOString();
|
|
94
|
+
git(root, ['commit', '-q', '-m', 'chore: seed promotion fixture'], {
|
|
95
|
+
GIT_AUTHOR_DATE: seedDate, GIT_COMMITTER_DATE: seedDate
|
|
96
|
+
});
|
|
97
|
+
commit('fix: preserve parser boundary', 1, 'module.exports = value => value == null ? "" : value;\n');
|
|
98
|
+
commit('fix: handle parser edge case', 2, 'module.exports = value => String(value ?? "");\n');
|
|
99
|
+
return { root, errorsDir };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function scan(target, destination = 'harness') {
|
|
103
|
+
const out = path.join(TMP, `report-${crypto.randomBytes(5).toString('hex')}`);
|
|
104
|
+
fs.mkdirSync(out);
|
|
105
|
+
const result = childProcess.spawnSync(process.execPath, [
|
|
106
|
+
SCANNER, '--root', target.root, '--no-memory', '--hide-ledger',
|
|
107
|
+
'--source', 'local-store', '--destination', destination, '--out', out, '--json'
|
|
108
|
+
], {
|
|
109
|
+
cwd: ROOT,
|
|
110
|
+
encoding: 'utf8',
|
|
111
|
+
env: isolatedEnv({ HARNESS_OBSERVATIONS_DIR: STORE, HOME, USERPROFILE: HOME })
|
|
112
|
+
});
|
|
113
|
+
assert.ifError(result.error);
|
|
114
|
+
assert.equal(result.status, 0, `scanner exit ${result.status}; stderr: ${result.stderr}`);
|
|
115
|
+
const envelope = JSON.parse(result.stdout);
|
|
116
|
+
const reportFile = envelope.reportJson;
|
|
117
|
+
const report = JSON.parse(fs.readFileSync(reportFile, 'utf8'));
|
|
118
|
+
const localSource = report.sources.find(source => source.type === 'local-store');
|
|
119
|
+
const candidate = report.candidates.find(item => item.sources.some(source => source.type === 'local-store'));
|
|
120
|
+
const gitCandidate = report.candidates.find(item => item.sources.some(source => source.type === 'git' || source.type === 'doc'));
|
|
121
|
+
assert.equal(localSource.status, 'used', 'positive control: scanner reads a valid, workspace-bound store row');
|
|
122
|
+
assert.ok(candidate, 'real scanner emits the local lead');
|
|
123
|
+
assert.equal(candidate.signature, 'parser-edge-case');
|
|
124
|
+
assert.ok(gitCandidate, 'real target history supplies a separate repeated-fix candidate');
|
|
125
|
+
return { target, reportFile, report, localSource, candidate, gitCandidate };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function addLocalLead(target, destination) {
|
|
129
|
+
const result = localErrors.addProvisionalLesson({
|
|
130
|
+
workspaceRoot: target.root,
|
|
131
|
+
destination,
|
|
132
|
+
provisionalId: PRIVATE.provisionalId,
|
|
133
|
+
signature: 'parser-edge-case',
|
|
134
|
+
match: { actions: [{ tool: 'shell', executable: 'git', subcommand: 'commit' }] },
|
|
135
|
+
lesson: PRIVATE.lesson,
|
|
136
|
+
cue: PRIVATE.cue,
|
|
137
|
+
issueUrl: PRIVATE.issueUrl
|
|
138
|
+
}, { env: WRITER_ENV });
|
|
139
|
+
assert.ok(['appended', 'duplicate'].includes(result.status), `local-store fixture write failed: ${result.status}`);
|
|
140
|
+
return result.record;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function saveReport(fixture) {
|
|
144
|
+
fixture.reportBytes = Buffer.from(`${JSON.stringify(fixture.report, null, 2)}\n`);
|
|
145
|
+
fs.writeFileSync(fixture.reportFile, fixture.reportBytes);
|
|
146
|
+
return fixture.reportBytes;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function bindCorroboratingCommit(fixture) {
|
|
150
|
+
const source = fixture.gitCandidate.sources.find(item => ['git', 'doc'].includes(item.type) && /^[a-f0-9]{40}$/i.test(item.sha));
|
|
151
|
+
assert.ok(source, 'positive control: a scanner Git/doc source has a real commit SHA');
|
|
152
|
+
git(fixture.target.root, ['cat-file', '-e', `${source.sha}^{commit}`]);
|
|
153
|
+
fixture.candidate.sites = [...new Set([...fixture.candidate.sites, ...fixture.gitCandidate.sites])].sort();
|
|
154
|
+
fixture.candidate.sources.push(source);
|
|
155
|
+
fixture.candidate.sources.sort((left, right) => `${left.type}:${left.sha || left.ref}`.localeCompare(`${right.type}:${right.sha || right.ref}`));
|
|
156
|
+
fixture.candidate.domain = fixture.candidate.sites[0].split('/')[0];
|
|
157
|
+
fixture.candidate.id = hash(JSON.stringify([
|
|
158
|
+
'error-candidate', fixture.candidate.sites,
|
|
159
|
+
fixture.candidate.sources.map(item => `${item.type}:${item.sha || item.ref}`)
|
|
160
|
+
])).slice(0, 20);
|
|
161
|
+
saveReport(fixture);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function prepared(name, corroborate = true, destination = 'harness') {
|
|
165
|
+
const target = createTarget(name);
|
|
166
|
+
addLocalLead(target, destination);
|
|
167
|
+
const fixture = scan(target, destination);
|
|
168
|
+
fixture.destination = destination;
|
|
169
|
+
if (corroborate) bindCorroboratingCommit(fixture);
|
|
170
|
+
else saveReport(fixture);
|
|
171
|
+
fixture.localRef = fixture.candidate.sources.find(item => item.type === 'local-store').ref;
|
|
172
|
+
return fixture;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function approvalFor(fixture, changes = {}) {
|
|
176
|
+
return {
|
|
177
|
+
schemaVersion: 1,
|
|
178
|
+
candidateId: fixture.candidate.id,
|
|
179
|
+
reportSha256: hash(fs.readFileSync(fixture.reportFile)),
|
|
180
|
+
targetRoot: fixture.target.root,
|
|
181
|
+
destination: fixture.destination,
|
|
182
|
+
approvedBy: 'fixture-owner',
|
|
183
|
+
approvedAt: '2026-11-25T12:00:00.000Z',
|
|
184
|
+
record: {
|
|
185
|
+
signature: fixture.candidate.signature,
|
|
186
|
+
class: 'test-coupling',
|
|
187
|
+
title: 'Parser boundary regression',
|
|
188
|
+
violates: 'The parser preserves the approved token boundary.',
|
|
189
|
+
scope: 'in',
|
|
190
|
+
status: 'lesson',
|
|
191
|
+
sites: ['src/parser.js'],
|
|
192
|
+
sourcesNote: 'The repeated target commits corroborate this local lead.'
|
|
193
|
+
},
|
|
194
|
+
...changes
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function saveApproval(fixture, approval, name = 'approval.json') {
|
|
199
|
+
const file = path.join(TMP, `${path.basename(fixture.target.root)}-${name}`);
|
|
200
|
+
write(file, `${JSON.stringify(approval, null, 2)}\n`);
|
|
201
|
+
return file;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function invoke(fixture, approvalFile, extraEnv = {}) {
|
|
205
|
+
return childProcess.spawnSync(process.execPath, [
|
|
206
|
+
PROMOTER, '--target', fixture.target.root, '--report', fixture.reportFile,
|
|
207
|
+
'--approval', approvalFile, '--harness', ROOT, '--json'
|
|
208
|
+
], {
|
|
209
|
+
cwd: ROOT,
|
|
210
|
+
encoding: 'utf8',
|
|
211
|
+
env: isolatedEnv({ HARNESS_OBSERVATIONS_DIR: STORE, HOME, USERPROFILE: HOME, ...extraEnv })
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function resultFor(run, status, label) {
|
|
216
|
+
assert.ifError(run.error);
|
|
217
|
+
assert.equal(run.status, status, `${label}: promote exited ${run.status}; stderr: ${run.stderr}; stdout: ${run.stdout}`);
|
|
218
|
+
assert.equal(run.stderr.trim(), '', `${label}: JSON result is on stdout`);
|
|
219
|
+
return JSON.parse(run.stdout);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function refuse(fixture, approvalFile, label, diagnostic, extraEnv = {}) {
|
|
223
|
+
const before = treeDigest(fixture.target.errorsDir);
|
|
224
|
+
const result = resultFor(invoke(fixture, approvalFile, extraEnv), 2, label);
|
|
225
|
+
assert.equal(result.ok, false, `${label}: refusal result is explicit`);
|
|
226
|
+
assert.match(result.error, diagnostic, `${label}: refusal explains the contract violation`);
|
|
227
|
+
assert.equal(treeDigest(fixture.target.errorsDir), before, `${label}: SHA-256 ledger-tree digest is unchanged`);
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function promoteControl(fixture, approvalFile, label) {
|
|
232
|
+
const reportBefore = fs.readFileSync(fixture.reportFile);
|
|
233
|
+
const before = fs.readdirSync(fixture.target.errorsDir).filter(name => /^E-\d{4}-.*\.md$/.test(name)).sort();
|
|
234
|
+
const result = resultFor(invoke(fixture, approvalFile), 0, `${label} positive control`);
|
|
235
|
+
assert.deepEqual(result, {
|
|
236
|
+
ok: true, id: 'E-0002',
|
|
237
|
+
file: path.posix.join(...ERRORS.split(path.sep), 'E-0002-parser-edge-case.md'),
|
|
238
|
+
indexUpdated: true
|
|
239
|
+
}, `${label}: only one new E-ID is allocated`);
|
|
240
|
+
const after = fs.readdirSync(fixture.target.errorsDir).filter(name => /^E-\d{4}-.*\.md$/.test(name)).sort();
|
|
241
|
+
assert.deepEqual(after, [...before, 'E-0002-parser-edge-case.md'].sort(), `${label}: intended destination ledger gets one record`);
|
|
242
|
+
const record = fs.readFileSync(path.join(fixture.target.errorsDir, 'E-0002-parser-edge-case.md'), 'utf8');
|
|
243
|
+
assert.ok(record.includes(fixture.gitCandidate.sources.find(item => ['git', 'doc'].includes(item.type)).sha),
|
|
244
|
+
`${label}: the corroborating target commit reaches the promoted record`);
|
|
245
|
+
assert.doesNotMatch(record, /p-local-|w-local-|PRIVATE_LESSON_SENTINEL|PRIVATE_CUE_SENTINEL|PRIVATE_URL_SENTINEL|issueUrl|workspaceKey|provisionalId/,
|
|
246
|
+
`${label}: opaque refs and private store fields stay out of committed text`);
|
|
247
|
+
assert.equal(fs.readFileSync(path.join(fixture.target.errorsDir, 'index.jsonl'), 'utf8'), render(fixture.target.root),
|
|
248
|
+
`${label}: destination index matches the canonical renderer`);
|
|
249
|
+
assert.deepEqual(fs.readFileSync(fixture.reportFile), reportBefore, `${label}: promotion leaves approved report bytes unchanged`);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function duplicateInjection(fixture, wholeRule = false) {
|
|
253
|
+
const marker = path.join(TMP, `${path.basename(fixture.target.root)}-lock-ledger.sha`);
|
|
254
|
+
const hook = path.join(TMP, `${path.basename(fixture.target.root)}-lock-injection.js`);
|
|
255
|
+
const config = {
|
|
256
|
+
promoteScript: PROMOTER,
|
|
257
|
+
targetRoot: fixture.target.root,
|
|
258
|
+
errorsDir: fixture.target.errorsDir,
|
|
259
|
+
lockPath: path.join(fixture.target.errorsDir, '.promote.lock'),
|
|
260
|
+
recordPath: path.join(fixture.target.errorsDir, `E-0002-${wholeRule ? 'same-rule-other-signature' : 'parser-edge-case'}.md`),
|
|
261
|
+
indexPath: path.join(fixture.target.errorsDir, 'index.jsonl'),
|
|
262
|
+
syncScript: SYNC,
|
|
263
|
+
marker
|
|
264
|
+
};
|
|
265
|
+
const record = [
|
|
266
|
+
'---', 'id: E-0002', `signature: ${wholeRule ? 'same-rule-other-signature' : 'parser-edge-case'}`, 'class: test-coupling',
|
|
267
|
+
'title: Added after local-store scan', 'scope: in', 'status: lesson',
|
|
268
|
+
...(wholeRule ? ['match:', ' actions:', ' - tool: shell', ' executable: git', ' subcommand: commit'] : []),
|
|
269
|
+
'sites:', ' - src/parser.js', 'violates: Duplicate class control',
|
|
270
|
+
'mechanism_ref: null', 'episodes: []', '---', '', '## Cue', '', 'A duplicate control.',
|
|
271
|
+
'', '## Lesson', '', 'This record was inserted after scan and after lock acquisition.', ''
|
|
272
|
+
].join('\n');
|
|
273
|
+
const hookText = [
|
|
274
|
+
"const fs = require('node:fs');",
|
|
275
|
+
"const path = require('node:path');",
|
|
276
|
+
"const crypto = require('node:crypto');",
|
|
277
|
+
`const config = ${JSON.stringify(config)};`,
|
|
278
|
+
`const record = ${JSON.stringify(record)};`,
|
|
279
|
+
'const originalOpenSync = fs.openSync.bind(fs);',
|
|
280
|
+
'const originalWriteFileSync = fs.writeFileSync.bind(fs);',
|
|
281
|
+
'let injected = false;',
|
|
282
|
+
'fs.openSync = function (file, ...args) {',
|
|
283
|
+
' const fd = originalOpenSync(file, ...args);',
|
|
284
|
+
' if (!injected && process.argv[1] === config.promoteScript && path.resolve(String(file)) === config.lockPath) {',
|
|
285
|
+
' injected = true;',
|
|
286
|
+
" originalWriteFileSync(config.recordPath, record, { flag: 'wx' });",
|
|
287
|
+
' const index = require(config.syncScript).render(config.targetRoot);',
|
|
288
|
+
' originalWriteFileSync(config.indexPath, index);',
|
|
289
|
+
" const rows = fs.readdirSync(config.errorsDir).filter(name => name !== '.promote.lock').sort().map(name => [name, crypto.createHash('sha256').update(fs.readFileSync(path.join(config.errorsDir, name))).digest('hex')]);",
|
|
290
|
+
" originalWriteFileSync(config.marker, crypto.createHash('sha256').update(JSON.stringify(rows)).digest('hex'));",
|
|
291
|
+
' }',
|
|
292
|
+
' return fd;',
|
|
293
|
+
'};', ''
|
|
294
|
+
].join('\n');
|
|
295
|
+
write(hook, hookText);
|
|
296
|
+
return { marker, recordPath: config.recordPath, nodeOptions: `--require="${hook.replace(/\\/g, '/')}"` };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
const positive = prepared('positive-control');
|
|
301
|
+
assert.ok(positive.candidate.sources.some(source => source.type === 'local-store'));
|
|
302
|
+
assert.ok(positive.candidate.sources.some(source => ['git', 'doc'].includes(source.type)),
|
|
303
|
+
'positive control: local ref and real commit are bound to the same approved candidate');
|
|
304
|
+
assert.equal(positive.localSource.destination, 'harness');
|
|
305
|
+
assert.match(positive.localSource.workspaceRef, /^w-local-[a-f0-9]{64}$/);
|
|
306
|
+
const validApproval = saveApproval(positive, approvalFor(positive));
|
|
307
|
+
promoteControl(positive, validApproval, 'same-candidate corroboration');
|
|
308
|
+
|
|
309
|
+
const projectDestination = prepared('project-destination', true, 'project');
|
|
310
|
+
assert.equal(projectDestination.localSource.destination, 'project');
|
|
311
|
+
promoteControl(projectDestination, saveApproval(projectDestination, approvalFor(projectDestination)),
|
|
312
|
+
'project destination binding');
|
|
313
|
+
|
|
314
|
+
const missingApproval = prepared('missing-approval');
|
|
315
|
+
refuse(missingApproval, path.join(TMP, 'not-created-approval.json'), 'missing approval', /approval cannot be read/);
|
|
316
|
+
promoteControl(missingApproval, saveApproval(missingApproval, approvalFor(missingApproval)), 'missing approval');
|
|
317
|
+
|
|
318
|
+
const wrongApproval = prepared('wrong-approval');
|
|
319
|
+
const wrong = approvalFor(wrongApproval);
|
|
320
|
+
wrong.reportSha256 = '0'.repeat(64);
|
|
321
|
+
refuse(wrongApproval, saveApproval(wrongApproval, wrong), 'wrong approval digest', /report SHA-256/);
|
|
322
|
+
promoteControl(wrongApproval, saveApproval(wrongApproval, approvalFor(wrongApproval)), 'wrong approval digest');
|
|
323
|
+
|
|
324
|
+
const editedReport = prepared('edited-report');
|
|
325
|
+
const approved = saveApproval(editedReport, approvalFor(editedReport));
|
|
326
|
+
const reportBytes = fs.readFileSync(editedReport.reportFile);
|
|
327
|
+
fs.appendFileSync(editedReport.reportFile, ' ');
|
|
328
|
+
refuse(editedReport, approved, 'edited report', /report SHA-256/);
|
|
329
|
+
fs.writeFileSync(editedReport.reportFile, reportBytes);
|
|
330
|
+
promoteControl(editedReport, approved, 'edited report');
|
|
331
|
+
|
|
332
|
+
const wrongWorkspace = prepared('wrong-workspace');
|
|
333
|
+
const boundReport = fs.readFileSync(wrongWorkspace.reportFile);
|
|
334
|
+
wrongWorkspace.localSource.workspaceRef = `w-local-${'0'.repeat(64)}`;
|
|
335
|
+
saveReport(wrongWorkspace);
|
|
336
|
+
const wrongWorkspaceApproval = saveApproval(wrongWorkspace, approvalFor(wrongWorkspace));
|
|
337
|
+
refuse(wrongWorkspace, wrongWorkspaceApproval, 'wrong workspace binding', /workspace.*(?:match|target)|workspace binding/i);
|
|
338
|
+
fs.writeFileSync(wrongWorkspace.reportFile, boundReport);
|
|
339
|
+
wrongWorkspace.report = JSON.parse(boundReport.toString('utf8'));
|
|
340
|
+
wrongWorkspace.localSource = wrongWorkspace.report.sources.find(source => source.type === 'local-store');
|
|
341
|
+
wrongWorkspace.candidate = wrongWorkspace.report.candidates.find(item => item.id === JSON.parse(boundReport.toString('utf8')).candidates.find(candidate => candidate.sources.some(source => source.type === 'local-store')).id);
|
|
342
|
+
promoteControl(wrongWorkspace, saveApproval(wrongWorkspace, approvalFor(wrongWorkspace)), 'wrong workspace binding');
|
|
343
|
+
|
|
344
|
+
const wrongDestination = prepared('wrong-destination');
|
|
345
|
+
const projectApproval = saveApproval(wrongDestination, approvalFor(wrongDestination, { destination: 'project' }));
|
|
346
|
+
refuse(wrongDestination, projectApproval, 'wrong destination approval', /destination/);
|
|
347
|
+
promoteControl(wrongDestination, saveApproval(wrongDestination, approvalFor(wrongDestination)), 'wrong destination approval');
|
|
348
|
+
|
|
349
|
+
const unknownDestination = prepared('unknown-destination');
|
|
350
|
+
const goodReport = fs.readFileSync(unknownDestination.reportFile);
|
|
351
|
+
unknownDestination.localSource.destination = 'unknown';
|
|
352
|
+
for (const source of unknownDestination.candidate.sources.filter(item => item.type === 'local-store')) source.destination = 'unknown';
|
|
353
|
+
saveReport(unknownDestination);
|
|
354
|
+
const unknownApproval = saveApproval(unknownDestination, approvalFor(unknownDestination, { destination: 'unknown' }));
|
|
355
|
+
refuse(unknownDestination, unknownApproval, 'unknown destination', /destination/);
|
|
356
|
+
fs.writeFileSync(unknownDestination.reportFile, goodReport);
|
|
357
|
+
unknownDestination.report = JSON.parse(goodReport.toString('utf8'));
|
|
358
|
+
unknownDestination.localSource = unknownDestination.report.sources.find(source => source.type === 'local-store');
|
|
359
|
+
unknownDestination.candidate = unknownDestination.report.candidates.find(item => item.sources.some(source => source.type === 'local-store'));
|
|
360
|
+
promoteControl(unknownDestination, saveApproval(unknownDestination, approvalFor(unknownDestination)), 'unknown destination');
|
|
361
|
+
|
|
362
|
+
const localOnly = prepared('local-only', false);
|
|
363
|
+
assert.ok(localOnly.gitCandidate, 'negative control: a similar durable Git candidate exists elsewhere in the report');
|
|
364
|
+
assert.ok(!localOnly.candidate.sources.some(source => ['git', 'doc'].includes(source.type)),
|
|
365
|
+
'negative control: the selected local candidate itself has no durable source');
|
|
366
|
+
assert.ok(!fs.readFileSync(localOnly.reportFile, 'utf8').includes(PRIVATE.issueUrl), 'stored issue URL stays private to the store');
|
|
367
|
+
refuse(localOnly, saveApproval(localOnly, approvalFor(localOnly)), 'local-only evidence including issue URL', /durable source evidence/);
|
|
368
|
+
bindCorroboratingCommit(localOnly);
|
|
369
|
+
promoteControl(localOnly, saveApproval(localOnly, approvalFor(localOnly)), 'local-only evidence including issue URL');
|
|
370
|
+
|
|
371
|
+
const duplicateAfterScan = prepared('duplicate-after-scan');
|
|
372
|
+
const duplicateApproval = saveApproval(duplicateAfterScan, approvalFor(duplicateAfterScan));
|
|
373
|
+
const injection = duplicateInjection(duplicateAfterScan);
|
|
374
|
+
const raced = resultFor(invoke(duplicateAfterScan, duplicateApproval, { NODE_OPTIONS: injection.nodeOptions }), 2,
|
|
375
|
+
'duplicate added after scan while promotion lock is acquired');
|
|
376
|
+
assert.equal(raced.ok, false);
|
|
377
|
+
assert.match(raced.error, /duplicate class|exact dedupe/i,
|
|
378
|
+
'lock-time recheck identifies the newly added exact class');
|
|
379
|
+
assert.equal(treeDigest(duplicateAfterScan.target.errorsDir, true), fs.readFileSync(injection.marker, 'utf8'),
|
|
380
|
+
'after the concurrent duplicate insertion, the refusal makes zero further ledger writes');
|
|
381
|
+
fs.rmSync(injection.recordPath);
|
|
382
|
+
write(path.join(duplicateAfterScan.target.errorsDir, 'index.jsonl'), render(duplicateAfterScan.target.root));
|
|
383
|
+
promoteControl(duplicateAfterScan, duplicateApproval, 'locked dedupe recheck');
|
|
384
|
+
|
|
385
|
+
const wholeRuleDuplicate = prepared('whole-rule-after-scan');
|
|
386
|
+
const wholeRuleApproval = saveApproval(wholeRuleDuplicate, approvalFor(wholeRuleDuplicate));
|
|
387
|
+
const wholeRuleInjection = duplicateInjection(wholeRuleDuplicate, true);
|
|
388
|
+
const wholeRuleResult = resultFor(invoke(wholeRuleDuplicate, wholeRuleApproval,
|
|
389
|
+
{ NODE_OPTIONS: wholeRuleInjection.nodeOptions }), 2, 'whole-rule duplicate added after scan under the lock');
|
|
390
|
+
assert.equal(wholeRuleResult.ok, false);
|
|
391
|
+
assert.match(wholeRuleResult.error, /duplicate class|exact dedupe/i,
|
|
392
|
+
'lock-time recheck catches the same exact rule under a different signature');
|
|
393
|
+
assert.equal(treeDigest(wholeRuleDuplicate.target.errorsDir, true), fs.readFileSync(wholeRuleInjection.marker, 'utf8'),
|
|
394
|
+
'whole-rule refusal makes zero further ledger writes after the concurrent insertion');
|
|
395
|
+
fs.rmSync(wholeRuleInjection.recordPath);
|
|
396
|
+
write(path.join(wholeRuleDuplicate.target.errorsDir, 'index.jsonl'), render(wholeRuleDuplicate.target.root));
|
|
397
|
+
promoteControl(wholeRuleDuplicate, wholeRuleApproval, 'locked whole-rule dedupe recheck');
|
|
398
|
+
|
|
399
|
+
console.log('PASS local-store promotion binds workspace, destination, corroboration, approval, and locked dedupe');
|
|
400
|
+
} finally {
|
|
401
|
+
fs.rmSync(TMP, { recursive: true, force: true });
|
|
402
|
+
}
|