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,232 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const crypto = require('node:crypto');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { execFileSync, spawnSync } = require('node:child_process');
|
|
9
|
+
const { test } = require('node:test');
|
|
10
|
+
|
|
11
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
12
|
+
const CHECKER_SOURCE = path.join(ROOT, 'scripts', 'check-packet-write-set.js');
|
|
13
|
+
const FIXED_DATE = '2000-01-01T00:00:00Z';
|
|
14
|
+
|
|
15
|
+
function isOutside(root, target, pathApi = path) {
|
|
16
|
+
const relative = pathApi.relative(root, target);
|
|
17
|
+
return relative.startsWith('..') || pathApi.isAbsolute(relative);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
assert.equal(isOutside('D:\\repo', 'C:\\tmp\\fixture', path.win32), true, 'cross-drive fixtures are outside');
|
|
21
|
+
assert.equal(isOutside('D:\\repo', path.win32.join('D:\\repo', 'fixture'), path.win32), false, 'same-drive children are inside');
|
|
22
|
+
|
|
23
|
+
function gitEnv(tempRoot) {
|
|
24
|
+
const env = { ...process.env };
|
|
25
|
+
for (const key of Object.keys(env)) {
|
|
26
|
+
if (key.startsWith('GIT_')) delete env[key];
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
...env,
|
|
30
|
+
GIT_CONFIG_NOSYSTEM: '1',
|
|
31
|
+
GIT_CONFIG_GLOBAL: path.join(tempRoot, 'empty-global-config'),
|
|
32
|
+
GIT_OPTIONAL_LOCKS: '0',
|
|
33
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
34
|
+
GIT_AUTHOR_NAME: 'Packet Fixture',
|
|
35
|
+
GIT_AUTHOR_EMAIL: 'packet-fixture@example.test',
|
|
36
|
+
GIT_COMMITTER_NAME: 'Packet Fixture',
|
|
37
|
+
GIT_COMMITTER_EMAIL: 'packet-fixture@example.test',
|
|
38
|
+
GIT_AUTHOR_DATE: FIXED_DATE,
|
|
39
|
+
GIT_COMMITTER_DATE: FIXED_DATE,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function runGit(repo, tempRoot, args) {
|
|
44
|
+
return execFileSync('git', ['-C', repo, ...args], { env: gitEnv(tempRoot) });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function gitText(repo, tempRoot, ...args) {
|
|
48
|
+
return runGit(repo, tempRoot, args).toString('utf8').trim();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function write(repo, relativePath, content) {
|
|
52
|
+
const file = path.join(repo, ...relativePath.split('/'));
|
|
53
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
54
|
+
fs.writeFileSync(file, content);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function commitAll(repo, tempRoot, message) {
|
|
58
|
+
runGit(repo, tempRoot, ['add', '--all']);
|
|
59
|
+
runGit(repo, tempRoot, ['commit', '--quiet', '-m', message]);
|
|
60
|
+
return gitText(repo, tempRoot, 'rev-parse', 'HEAD');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function makeRepo(t) {
|
|
64
|
+
assert.ok(fs.existsSync(CHECKER_SOURCE), 'checker entry point must be available to the fixture invocation');
|
|
65
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'packet write set fixture '));
|
|
66
|
+
assert.ok(isOutside(ROOT, tempRoot), 'throwaway git repository is outside the checkout');
|
|
67
|
+
const repo = path.join(tempRoot, 'repo with spaces');
|
|
68
|
+
fs.mkdirSync(repo, { recursive: true });
|
|
69
|
+
execFileSync('git', ['init', '--quiet', repo], { env: gitEnv(tempRoot) });
|
|
70
|
+
t.after(() => fs.rmSync(tempRoot, { recursive: true, force: true }));
|
|
71
|
+
return { repo, tempRoot };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function runChecker(repo, tempRoot, { base, head, allow = [], allowFile } = {}) {
|
|
75
|
+
const args = [CHECKER_SOURCE, '--base', base];
|
|
76
|
+
if (head) args.push('--head', head);
|
|
77
|
+
for (const pattern of allow) args.push('--allow', pattern);
|
|
78
|
+
if (allowFile) args.push('--allow-file', allowFile);
|
|
79
|
+
const result = spawnSync(process.execPath, args, {
|
|
80
|
+
cwd: repo,
|
|
81
|
+
encoding: 'utf8',
|
|
82
|
+
env: gitEnv(tempRoot),
|
|
83
|
+
});
|
|
84
|
+
assert.equal(result.error, undefined, result.error && result.error.message);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function outOfSetPaths(result) {
|
|
89
|
+
return result.stdout.split(/\r?\n/).filter(line => line.startsWith('OUT_OF_SET '))
|
|
90
|
+
.map(line => JSON.parse(line.slice('OUT_OF_SET '.length)));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function snapshotTree(root) {
|
|
94
|
+
const files = {};
|
|
95
|
+
function visit(directory) {
|
|
96
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
97
|
+
const file = path.join(directory, entry.name);
|
|
98
|
+
const relative = path.relative(root, file).split(path.sep).join('/');
|
|
99
|
+
if (entry.isDirectory()) visit(file);
|
|
100
|
+
else if (entry.isSymbolicLink()) files[relative] = `link:${fs.readlinkSync(file)}`;
|
|
101
|
+
else files[relative] = crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
visit(root);
|
|
105
|
+
return files;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
test('allows matching globs and allow files without accepting similar prefixes', t => {
|
|
109
|
+
const { repo, tempRoot } = makeRepo(t);
|
|
110
|
+
write(repo, 'docs/guide.md', 'before\n');
|
|
111
|
+
write(repo, 'docs-extra/guide.md', 'before\n');
|
|
112
|
+
const unusualPath = process.platform === 'win32' ? 'docs/space and [guide].md' : 'docs/space and\n[guide].md';
|
|
113
|
+
const base = commitAll(repo, tempRoot, 'baseline');
|
|
114
|
+
|
|
115
|
+
write(repo, 'docs/guide.md', 'after\n');
|
|
116
|
+
write(repo, unusualPath, 'new\n');
|
|
117
|
+
write(repo, 'docs-extra/guide.md', 'after\n');
|
|
118
|
+
const head = commitAll(repo, tempRoot, 'change docs');
|
|
119
|
+
|
|
120
|
+
const partial = runChecker(repo, tempRoot, { base, head, allow: ['docs/**'] });
|
|
121
|
+
assert.equal(partial.status, 1, partial.stderr);
|
|
122
|
+
assert.deepEqual(outOfSetPaths(partial), ['docs-extra/guide.md']);
|
|
123
|
+
|
|
124
|
+
const allowFile = path.join(tempRoot, 'allow patterns.txt');
|
|
125
|
+
fs.writeFileSync(allowFile, 'docs/**\r\ndocs-extra/guide.md\r\n');
|
|
126
|
+
const allowed = runChecker(repo, tempRoot, { base, head, allowFile });
|
|
127
|
+
assert.equal(allowed.status, 0, allowed.stderr);
|
|
128
|
+
assert.deepEqual(outOfSetPaths(allowed), []);
|
|
129
|
+
assert.ok(allowed.stdout.includes(`ALLOWED ${JSON.stringify(unusualPath)}`));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('rejects a deleted path unless the deleted endpoint is allowed', t => {
|
|
133
|
+
const { repo, tempRoot } = makeRepo(t);
|
|
134
|
+
write(repo, 'docs/delete-me.md', 'before\n');
|
|
135
|
+
const base = commitAll(repo, tempRoot, 'baseline');
|
|
136
|
+
fs.rmSync(path.join(repo, 'docs', 'delete-me.md'));
|
|
137
|
+
const head = commitAll(repo, tempRoot, 'delete path');
|
|
138
|
+
|
|
139
|
+
const rejected = runChecker(repo, tempRoot, { base, head, allow: ['docs/other.md'] });
|
|
140
|
+
assert.equal(rejected.status, 1, rejected.stderr);
|
|
141
|
+
assert.deepEqual(outOfSetPaths(rejected), ['docs/delete-me.md']);
|
|
142
|
+
const allowed = runChecker(repo, tempRoot, { base, head, allow: ['docs/delete-me.md'] });
|
|
143
|
+
assert.equal(allowed.status, 0, allowed.stderr);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('checks both endpoints of a committed rename across the write-set boundary', t => {
|
|
147
|
+
const { repo, tempRoot } = makeRepo(t);
|
|
148
|
+
write(repo, 'approved/old.txt', 'content\n');
|
|
149
|
+
const base = commitAll(repo, tempRoot, 'baseline');
|
|
150
|
+
fs.mkdirSync(path.join(repo, 'outside'), { recursive: true });
|
|
151
|
+
runGit(repo, tempRoot, ['mv', 'approved/old.txt', 'outside/new.txt']);
|
|
152
|
+
const head = commitAll(repo, tempRoot, 'move across boundary');
|
|
153
|
+
|
|
154
|
+
const oldAllowed = runChecker(repo, tempRoot, { base, head, allow: ['approved/**'] });
|
|
155
|
+
assert.equal(oldAllowed.status, 1, oldAllowed.stderr);
|
|
156
|
+
assert.deepEqual(outOfSetPaths(oldAllowed), ['outside/new.txt']);
|
|
157
|
+
const newAllowed = runChecker(repo, tempRoot, { base, head, allow: ['outside/**'] });
|
|
158
|
+
assert.equal(newAllowed.status, 1, newAllowed.stderr);
|
|
159
|
+
assert.deepEqual(outOfSetPaths(newAllowed), ['approved/old.txt']);
|
|
160
|
+
const bothAllowed = runChecker(repo, tempRoot, { base, head, allow: ['approved/**', 'outside/**'] });
|
|
161
|
+
assert.equal(bothAllowed.status, 0, bothAllowed.stderr);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('checks staged, unstaged, untracked and staged-rename paths without mutating the worktree', t => {
|
|
165
|
+
const { repo, tempRoot } = makeRepo(t);
|
|
166
|
+
write(repo, '.gitignore', 'ignored/**\n');
|
|
167
|
+
write(repo, 'tracked.txt', 'before\n');
|
|
168
|
+
write(repo, 'move/old.txt', 'content\n');
|
|
169
|
+
const base = commitAll(repo, tempRoot, 'baseline');
|
|
170
|
+
|
|
171
|
+
write(repo, 'tracked.txt', 'after\n');
|
|
172
|
+
write(repo, 'staged.txt', 'staged\n');
|
|
173
|
+
runGit(repo, tempRoot, ['add', '--', 'staged.txt']);
|
|
174
|
+
fs.mkdirSync(path.join(repo, 'generated'), { recursive: true });
|
|
175
|
+
runGit(repo, tempRoot, ['mv', 'move/old.txt', 'generated/moved.txt']);
|
|
176
|
+
write(repo, 'generated/untracked.json', '{"generated":true}\n');
|
|
177
|
+
write(repo, 'ignored/output.log', 'ignored\n');
|
|
178
|
+
const before = snapshotTree(repo);
|
|
179
|
+
|
|
180
|
+
const partial = runChecker(repo, tempRoot, { base, allow: ['staged.txt'] });
|
|
181
|
+
assert.equal(partial.status, 1, partial.stderr);
|
|
182
|
+
assert.deepEqual(outOfSetPaths(partial), [
|
|
183
|
+
'generated/moved.txt',
|
|
184
|
+
'generated/untracked.json',
|
|
185
|
+
'move/old.txt',
|
|
186
|
+
'tracked.txt',
|
|
187
|
+
]);
|
|
188
|
+
assert.ok(!partial.stdout.includes('ignored/output.log'), 'ignored untracked output is excluded');
|
|
189
|
+
|
|
190
|
+
const explicitHead = runChecker(repo, tempRoot, { base, head: 'HEAD', allow: ['staged.txt'] });
|
|
191
|
+
assert.equal(explicitHead.status, 1, explicitHead.stderr);
|
|
192
|
+
assert.deepEqual(outOfSetPaths(explicitHead), outOfSetPaths(partial));
|
|
193
|
+
|
|
194
|
+
const allAllowed = runChecker(repo, tempRoot, {
|
|
195
|
+
base,
|
|
196
|
+
allow: ['generated/**', 'move/**', 'staged.txt', 'tracked.txt'],
|
|
197
|
+
});
|
|
198
|
+
assert.equal(allAllowed.status, 0, allAllowed.stderr);
|
|
199
|
+
assert.deepEqual(snapshotTree(repo), before, 'checker leaves files and Git metadata byte-identical');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('compares only the requested commits when --head is not the worktree HEAD', t => {
|
|
203
|
+
const { repo, tempRoot } = makeRepo(t);
|
|
204
|
+
write(repo, 'base.txt', 'base\n');
|
|
205
|
+
const base = commitAll(repo, tempRoot, 'baseline');
|
|
206
|
+
write(repo, 'allowed.txt', 'in requested head\n');
|
|
207
|
+
const head = commitAll(repo, tempRoot, 'requested head');
|
|
208
|
+
write(repo, 'later.txt', 'after requested head\n');
|
|
209
|
+
commitAll(repo, tempRoot, 'worktree HEAD');
|
|
210
|
+
write(repo, 'dirty.txt', 'uncommitted\n');
|
|
211
|
+
|
|
212
|
+
const result = runChecker(repo, tempRoot, { base, head, allow: ['allowed.txt'] });
|
|
213
|
+
assert.equal(result.status, 0, result.stderr);
|
|
214
|
+
assert.deepEqual(outOfSetPaths(result), []);
|
|
215
|
+
assert.match(result.stdout, /commits only/i);
|
|
216
|
+
assert.doesNotMatch(result.stdout, /later\.txt|dirty\.txt/);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('returns usage errors for an unknown base and a missing allow list', t => {
|
|
220
|
+
const { repo, tempRoot } = makeRepo(t);
|
|
221
|
+
write(repo, 'tracked.txt', 'base\n');
|
|
222
|
+
const base = commitAll(repo, tempRoot, 'baseline');
|
|
223
|
+
|
|
224
|
+
const badBase = runChecker(repo, tempRoot, { base: 'missing-base', allow: ['tracked.txt'] });
|
|
225
|
+
assert.equal(badBase.status, 2);
|
|
226
|
+
assert.match(badBase.stderr, /base|commit|revision/i);
|
|
227
|
+
|
|
228
|
+
const missingAllow = spawnSync(process.execPath, [
|
|
229
|
+
CHECKER_SOURCE, '--base', base,
|
|
230
|
+
], { cwd: repo, encoding: 'utf8', env: gitEnv(tempRoot) });
|
|
231
|
+
assert.equal(missingAllow.status, 2);
|
|
232
|
+
});
|
|
@@ -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
|
+
|