harness-everything 1.2.2 → 1.3.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 +29 -0
- package/ci/archive/325-prep/README.md +9 -2
- package/ci/archive/325-prep/doc-reconciliation-red.js +34 -8
- package/ci/fixtures/468-dispatch/agy-quota-PROVENANCE.md +19 -0
- package/ci/fixtures/468-dispatch/agy-quota-direct-individual.stderr +2 -0
- package/ci/fixtures/468-dispatch/agy-quota-direct-third-party.stderr +2 -0
- package/ci/fixtures/468-dispatch/agy-quota-exec-individual.log +3 -0
- package/ci/fixtures/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
- package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
- package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
- package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
- package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
- package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
- package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
- package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
- package/ci/fixtures/stop/fail-session-writes.js +109 -0
- package/ci/fixtures/workflow-contract/cases.json +3355 -0
- package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
- package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
- package/ci/mechanism-2an-workflow-replay.test.js +324 -0
- package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
- package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
- package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
- package/ci/mechanism-325-3b-preparation.test.js +208 -49
- package/ci/mechanism-325-3b-s1-review.test.js +20 -828
- package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
- package/ci/mechanism-325-f3-derived-views.test.js +140 -0
- package/ci/mechanism-341-opencode-lane.test.js +164 -284
- package/ci/mechanism-35-verification-contract.test.js +246 -0
- package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
- package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
- package/ci/mechanism-397-opencode-observations.test.js +151 -18
- package/ci/mechanism-468-dispatch-cli.test.js +1496 -4
- package/ci/mechanism-548-bigint-identity.test.js +531 -0
- package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
- package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
- package/ci/mechanism-553-p3-plan-start.test.js +212 -0
- package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
- package/ci/mechanism-553-stop.test.js +427 -0
- package/ci/mechanism-553-t2a-derive.test.js +110 -0
- package/ci/mechanism-553-t2c-derive.test.js +94 -0
- package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
- package/ci/mechanism-error-ledger-oracle.test.js +786 -3
- package/ci/mechanism-error-ledger-scan.test.js +981 -0
- package/ci/mechanism-outline-sanitizer.test.js +0 -8
- package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
- package/ci/mechanism-prb-outline-review.test.js +101 -3283
- package/ci/mechanism-report-writer.test.js +45 -0
- package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
- package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
- package/docs/doc-workflow-reconciliation.md +17 -2
- package/docs/document-lifecycle.md +6 -2
- package/docs/error-handling/details/c8-dispatch-cli.md +109 -13
- package/docs/platform-capabilities.md +35 -5
- package/error-ledger-bootstrap/SKILL.md +1 -1
- package/error-ledger-bootstrap/references/workflow.md +42 -7
- package/error-ledger-bootstrap/scripts/promote.js +8 -6
- package/error-ledger-bootstrap/scripts/scan.js +525 -12
- package/hooks/hooks.json +0 -46
- package/hooks/scripts/lib/workflow-obligations.js +0 -55
- package/hooks/scripts/state-persist.js +7 -95
- package/hooks/scripts/workflow-disposition.js +0 -2
- package/hooks/scripts/workflow-stop-gate.js +17 -30
- package/opencode-plugin/index.mjs +6 -70
- 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/workflow-obligations.js +0 -55
- package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
- package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
- package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
- 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 +42 -7
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +8 -6
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +525 -12
- package/sbom.cdx.json +7 -7
- package/scripts/dispatch.js +499 -87
- package/scripts/error-ledger-oracle.js +521 -27
- package/scripts/errors-sync.js +4 -3
- package/scripts/report-writer.js +4 -3
- package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
- package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
- package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
- package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
- package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
- package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
- package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
- package/ci/lib/doc-reconciliation-file-spy.js +0 -23
- package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
- package/ci/lib/doc-reconciliation-replay.js +0 -104
- package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
- package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
- package/ci/mechanism-325-3b-s1.test.js +0 -188
- package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
- package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
- package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
- package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
- package/ci/mechanism-325-f4-invariants.test.js +0 -606
- package/ci/mechanism-325-f4-projections.test.js +0 -392
- package/ci/mechanism-325-f4-qualification.test.js +0 -228
- package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
- package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
- package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
- package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
- package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
- package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
- package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
- package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
- package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
- package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
- package/hooks/scripts/w6-state-operations.js +0 -239
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
- package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
- package/scripts/system-one-eval-laya.js +0 -112
- /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
- /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { spawnSync } = require('node:child_process');
|
|
8
|
+
const { test } = require('node:test');
|
|
9
|
+
const acorn = require('acorn');
|
|
10
|
+
const walk = require('acorn-walk');
|
|
11
|
+
|
|
12
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
13
|
+
const REPORT_WRITER = path.join(ROOT, 'scripts', 'report-writer.js');
|
|
14
|
+
const ERRORS_SYNC = path.join(ROOT, 'scripts', 'errors-sync.js');
|
|
15
|
+
const LARGE = 2n ** 60n;
|
|
16
|
+
|
|
17
|
+
function canonical(file) {
|
|
18
|
+
return fs.realpathSync.native ? fs.realpathSync.native(file) : fs.realpathSync(file);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function tempDir(t, prefix) {
|
|
22
|
+
const dir = fs.mkdtempSync(path.join(canonical(os.tmpdir()), prefix));
|
|
23
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
24
|
+
return dir;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function runNode(args, { preload, cwd = ROOT, env = process.env } = {}) {
|
|
28
|
+
return spawnSync(process.execPath, [...(preload ? ['-r', preload] : []), ...args], {
|
|
29
|
+
cwd,
|
|
30
|
+
env,
|
|
31
|
+
encoding: 'utf8',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function writeStatPreload(file, body) {
|
|
36
|
+
fs.writeFileSync(file, body, 'utf8');
|
|
37
|
+
return file;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
test('548 report-writer allows distinct files whose 64-bit dev/ino collide as Number (#546 witness)', t => {
|
|
41
|
+
assert.equal(Number(LARGE), Number(LARGE + 1n), 'fixture IDs must collide when converted to Number');
|
|
42
|
+
|
|
43
|
+
const dir = tempDir(t, 'harness-548-report-');
|
|
44
|
+
const raw = path.join(dir, 'raw.txt');
|
|
45
|
+
const output = path.join(dir, 'report.md');
|
|
46
|
+
fs.writeFileSync(raw, 'First\nSTATUS: DONE\n');
|
|
47
|
+
fs.writeFileSync(output, 'Previous\nSTATUS: DONE\n');
|
|
48
|
+
|
|
49
|
+
for (const scenario of ['distinct-ino', 'distinct-dev', 'same-alias']) {
|
|
50
|
+
fs.writeFileSync(output, 'Previous\nSTATUS: DONE\n');
|
|
51
|
+
const preload = writeStatPreload(path.join(dir, `preload-${scenario}.cjs`), `
|
|
52
|
+
'use strict';
|
|
53
|
+
const fs = require('node:fs');
|
|
54
|
+
const path = require('node:path');
|
|
55
|
+
const norm = p => {
|
|
56
|
+
const resolved = path.resolve(String(p));
|
|
57
|
+
return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
58
|
+
};
|
|
59
|
+
const rawKey = norm(${JSON.stringify(raw)});
|
|
60
|
+
const outKey = norm(${JSON.stringify(output)});
|
|
61
|
+
const large = ${LARGE}n;
|
|
62
|
+
const scenario = ${JSON.stringify(scenario)};
|
|
63
|
+
const origStatSync = fs.statSync;
|
|
64
|
+
fs.statSync = function (file, options) {
|
|
65
|
+
const result = origStatSync.call(this, file, options);
|
|
66
|
+
const key = norm(file);
|
|
67
|
+
if (key === rawKey || key === outKey) {
|
|
68
|
+
const isOut = key === outKey;
|
|
69
|
+
const conv = value => (options && options.bigint ? value : Number(value));
|
|
70
|
+
result.ino = conv(large + (isOut && scenario === 'distinct-ino' ? 1n : 0n));
|
|
71
|
+
result.dev = conv(large + (isOut && scenario === 'distinct-dev' ? 1n : 0n));
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
`);
|
|
76
|
+
|
|
77
|
+
const result = runNode(
|
|
78
|
+
[REPORT_WRITER, 'write', '--output', output, '--status', 'DONE', '--from-codex-output', raw],
|
|
79
|
+
{ preload }
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (scenario === 'same-alias') {
|
|
83
|
+
assert.notEqual(result.status, 0, 'true alias must still be rejected');
|
|
84
|
+
assert.match(result.stderr, /report-writer: output aliases an input file/);
|
|
85
|
+
assert.equal(fs.readFileSync(output, 'utf8'), 'Previous\nSTATUS: DONE\n');
|
|
86
|
+
} else {
|
|
87
|
+
assert.equal(result.status, 0, `${scenario} failed: ${result.stderr || result.stdout}`);
|
|
88
|
+
assert.equal(fs.readFileSync(output, 'utf8'), 'First\nSTATUS: DONE\n');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('548 report-writer rejects a zero-inode parent-directory alias and preserves the raw input', t => {
|
|
94
|
+
const dir = tempDir(t, 'harness-548-alias-');
|
|
95
|
+
const files = path.join(dir, 'files');
|
|
96
|
+
fs.mkdirSync(files);
|
|
97
|
+
const raw = path.join(files, 'raw.txt');
|
|
98
|
+
const aliasDir = path.join(dir, 'alias-dir');
|
|
99
|
+
const aliased = path.join(aliasDir, 'raw.txt');
|
|
100
|
+
fs.symlinkSync(files, aliasDir, process.platform === 'win32' ? 'junction' : 'dir');
|
|
101
|
+
const rawBytes = Buffer.from('First\n');
|
|
102
|
+
fs.writeFileSync(raw, rawBytes);
|
|
103
|
+
|
|
104
|
+
// Simulate a stat backend that reports inode zero for Number and bigint stats alike.
|
|
105
|
+
const preload = writeStatPreload(path.join(dir, 'preload-zero-ino.cjs'), `
|
|
106
|
+
'use strict';
|
|
107
|
+
const fs = require('node:fs');
|
|
108
|
+
const path = require('node:path');
|
|
109
|
+
const norm = p => {
|
|
110
|
+
const resolved = path.resolve(String(p));
|
|
111
|
+
return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
112
|
+
};
|
|
113
|
+
const rawKey = norm(${JSON.stringify(raw)});
|
|
114
|
+
const aliasKey = norm(${JSON.stringify(aliased)});
|
|
115
|
+
const origStatSync = fs.statSync;
|
|
116
|
+
fs.statSync = function (file, options) {
|
|
117
|
+
const result = origStatSync.call(this, file, options);
|
|
118
|
+
const key = norm(file);
|
|
119
|
+
if (key === rawKey || key === aliasKey) {
|
|
120
|
+
result.ino = options && options.bigint ? 0n : 0;
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
};
|
|
124
|
+
`);
|
|
125
|
+
|
|
126
|
+
const result = runNode(
|
|
127
|
+
[REPORT_WRITER, 'write', '--output', aliased, '--status', 'DONE', '--from-codex-output', raw],
|
|
128
|
+
{ preload }
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
assert.notEqual(result.status, 0, 'zero-inode directory alias must be rejected');
|
|
132
|
+
assert.match(result.stderr, /report-writer: output aliases an input file/);
|
|
133
|
+
assert.deepEqual(fs.readFileSync(raw), rawBytes, 'raw input bytes must be preserved');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('548 errors-sync detects a swapped index whose 64-bit ino collides as Number', t => {
|
|
137
|
+
assert.equal(Number(LARGE), Number(LARGE + 1n), 'fixture IDs must collide when converted to Number');
|
|
138
|
+
|
|
139
|
+
const root = tempDir(t, 'harness-548-errors-sync-');
|
|
140
|
+
const errorsDir = path.join(root, '.agents', 'harness-everything', 'errors');
|
|
141
|
+
fs.mkdirSync(errorsDir, { recursive: true });
|
|
142
|
+
fs.writeFileSync(path.join(errorsDir, 'E-0001-sample.md'), [
|
|
143
|
+
'---',
|
|
144
|
+
'id: E-0001',
|
|
145
|
+
'signature: sample-error',
|
|
146
|
+
'class: test',
|
|
147
|
+
'title: "Sample"',
|
|
148
|
+
'scope: in',
|
|
149
|
+
'status: open',
|
|
150
|
+
'---',
|
|
151
|
+
'',
|
|
152
|
+
'Body.',
|
|
153
|
+
'',
|
|
154
|
+
].join('\n'));
|
|
155
|
+
|
|
156
|
+
const initial = runNode([ERRORS_SYNC, '--root', root]);
|
|
157
|
+
assert.equal(initial.status, 0, initial.stderr || initial.stdout);
|
|
158
|
+
const indexFile = path.join(errorsDir, 'index.jsonl');
|
|
159
|
+
assert.equal(fs.existsSync(indexFile), true);
|
|
160
|
+
|
|
161
|
+
// Control: consistent bigint identity (> MAX_SAFE_INTEGER) passes both write and --check.
|
|
162
|
+
const samePreload = writeStatPreload(path.join(root, 'preload-same.cjs'), `
|
|
163
|
+
'use strict';
|
|
164
|
+
const fs = require('node:fs');
|
|
165
|
+
const path = require('node:path');
|
|
166
|
+
const norm = p => {
|
|
167
|
+
const resolved = path.resolve(String(p));
|
|
168
|
+
return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
169
|
+
};
|
|
170
|
+
const indexKey = norm(${JSON.stringify(indexFile)});
|
|
171
|
+
const large = ${LARGE}n;
|
|
172
|
+
const origLstat = fs.lstatSync;
|
|
173
|
+
const origFstat = fs.fstatSync;
|
|
174
|
+
const origOpen = fs.openSync;
|
|
175
|
+
const indexFds = new Set();
|
|
176
|
+
fs.openSync = function (file, ...rest) {
|
|
177
|
+
const fd = origOpen.call(this, file, ...rest);
|
|
178
|
+
if (norm(file) === indexKey) indexFds.add(fd);
|
|
179
|
+
return fd;
|
|
180
|
+
};
|
|
181
|
+
fs.lstatSync = function (file, options) {
|
|
182
|
+
const res = origLstat.call(this, file, options);
|
|
183
|
+
if (norm(file) === indexKey) {
|
|
184
|
+
const conv = value => (options && options.bigint ? value : Number(value));
|
|
185
|
+
res.dev = conv(large);
|
|
186
|
+
res.ino = conv(large);
|
|
187
|
+
}
|
|
188
|
+
return res;
|
|
189
|
+
};
|
|
190
|
+
fs.fstatSync = function (fd, options) {
|
|
191
|
+
const res = origFstat.call(this, fd, options);
|
|
192
|
+
if (indexFds.has(fd)) {
|
|
193
|
+
const conv = value => (options && options.bigint ? value : Number(value));
|
|
194
|
+
res.dev = conv(large);
|
|
195
|
+
res.ino = conv(large);
|
|
196
|
+
}
|
|
197
|
+
return res;
|
|
198
|
+
};
|
|
199
|
+
`);
|
|
200
|
+
const sameWrite = runNode([ERRORS_SYNC, '--root', root], { preload: samePreload });
|
|
201
|
+
assert.equal(sameWrite.status, 0, `same-identity write failed: ${sameWrite.stderr || sameWrite.stdout}`);
|
|
202
|
+
const sameCheck = runNode([ERRORS_SYNC, '--check', '--root', root], { preload: samePreload });
|
|
203
|
+
assert.equal(sameCheck.status, 0, `same-identity check failed: ${sameCheck.stderr || sameCheck.stdout}`);
|
|
204
|
+
|
|
205
|
+
// Regression: lstatSync reports large, fstatSync reports large + 1n (Number-equal, BigInt-distinct).
|
|
206
|
+
const swapPreload = writeStatPreload(path.join(root, 'preload-swap.cjs'), `
|
|
207
|
+
'use strict';
|
|
208
|
+
const fs = require('node:fs');
|
|
209
|
+
const path = require('node:path');
|
|
210
|
+
const norm = p => {
|
|
211
|
+
const resolved = path.resolve(String(p));
|
|
212
|
+
return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
213
|
+
};
|
|
214
|
+
const indexKey = norm(${JSON.stringify(indexFile)});
|
|
215
|
+
const large = ${LARGE}n;
|
|
216
|
+
const origLstat = fs.lstatSync;
|
|
217
|
+
const origFstat = fs.fstatSync;
|
|
218
|
+
const origOpen = fs.openSync;
|
|
219
|
+
const indexFds = new Set();
|
|
220
|
+
fs.openSync = function (file, ...rest) {
|
|
221
|
+
const fd = origOpen.call(this, file, ...rest);
|
|
222
|
+
if (norm(file) === indexKey) indexFds.add(fd);
|
|
223
|
+
return fd;
|
|
224
|
+
};
|
|
225
|
+
fs.lstatSync = function (file, options) {
|
|
226
|
+
const res = origLstat.call(this, file, options);
|
|
227
|
+
if (norm(file) === indexKey) {
|
|
228
|
+
const conv = value => (options && options.bigint ? value : Number(value));
|
|
229
|
+
res.dev = conv(large);
|
|
230
|
+
res.ino = conv(large);
|
|
231
|
+
}
|
|
232
|
+
return res;
|
|
233
|
+
};
|
|
234
|
+
fs.fstatSync = function (fd, options) {
|
|
235
|
+
const res = origFstat.call(this, fd, options);
|
|
236
|
+
if (indexFds.has(fd)) {
|
|
237
|
+
const conv = value => (options && options.bigint ? value : Number(value));
|
|
238
|
+
res.dev = conv(large);
|
|
239
|
+
res.ino = conv(large + 1n);
|
|
240
|
+
}
|
|
241
|
+
return res;
|
|
242
|
+
};
|
|
243
|
+
`);
|
|
244
|
+
const swapCheck = runNode([ERRORS_SYNC, '--check', '--root', root], { preload: swapPreload });
|
|
245
|
+
assert.notEqual(swapCheck.status, 0, 'swapped index with Number-colliding 64-bit ino must be rejected');
|
|
246
|
+
assert.match(swapCheck.stderr, /target index changed while it was being read/);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// --- Guard: every non-test JS `.ino` access must originate from a `{ bigint: true }` stat call ---
|
|
250
|
+
|
|
251
|
+
const STAT_METHODS = new Set(['statSync', 'lstatSync', 'fstatSync']);
|
|
252
|
+
const EXCLUDED_DIRS = new Set(['.git', '.w', 'node_modules', 'ci', 'evals', 'benchmarks', 'behavioral-evals']);
|
|
253
|
+
|
|
254
|
+
function listNonTestJsFiles(dir, out = []) {
|
|
255
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
256
|
+
if (entry.isDirectory()) {
|
|
257
|
+
if (EXCLUDED_DIRS.has(entry.name)) continue;
|
|
258
|
+
listNonTestJsFiles(path.join(dir, entry.name), out);
|
|
259
|
+
} else if (entry.isFile() && /\.(?:js|mjs|cjs)$/.test(entry.name)) {
|
|
260
|
+
out.push(path.join(dir, entry.name));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function isStatCall(node) {
|
|
267
|
+
return node && node.type === 'CallExpression'
|
|
268
|
+
&& node.callee.type === 'MemberExpression'
|
|
269
|
+
&& !node.callee.computed
|
|
270
|
+
&& node.callee.property.type === 'Identifier'
|
|
271
|
+
&& STAT_METHODS.has(node.callee.property.name);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function hasBigIntTrueOption(callNode) {
|
|
275
|
+
const opts = callNode.arguments[1];
|
|
276
|
+
if (!opts || opts.type !== 'ObjectExpression') return false;
|
|
277
|
+
return opts.properties.some(prop =>
|
|
278
|
+
prop.type === 'Property'
|
|
279
|
+
&& !prop.computed
|
|
280
|
+
&& ((prop.key.type === 'Identifier' && prop.key.name === 'bigint')
|
|
281
|
+
|| (prop.key.type === 'Literal' && prop.key.value === 'bigint'))
|
|
282
|
+
&& prop.value.type === 'Literal'
|
|
283
|
+
&& prop.value.value === true
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function parseProgram(source, file) {
|
|
288
|
+
const clean = source.startsWith('#!') ? `//${source.slice(2)}` : source;
|
|
289
|
+
try {
|
|
290
|
+
return acorn.parse(clean, { ecmaVersion: 'latest', sourceType: 'script', locations: true });
|
|
291
|
+
} catch (_) {
|
|
292
|
+
return acorn.parse(clean, { ecmaVersion: 'latest', sourceType: 'module', locations: true });
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function findNonBigIntInoViolations(source, label) {
|
|
297
|
+
if (!source.includes('.ino')) return [];
|
|
298
|
+
const ast = parseProgram(source, label);
|
|
299
|
+
|
|
300
|
+
// Collect function declarations and expressions by name, plus per-scope variable bindings.
|
|
301
|
+
const functions = new Map();
|
|
302
|
+
const callsByName = new Map();
|
|
303
|
+
const bindingsByScope = new Map(); // scopeNode -> Map<varName, Expression[]>
|
|
304
|
+
const parentOf = new Map();
|
|
305
|
+
|
|
306
|
+
function recordBinding(scopeNode, name, expr) {
|
|
307
|
+
if (!bindingsByScope.has(scopeNode)) bindingsByScope.set(scopeNode, new Map());
|
|
308
|
+
const map = bindingsByScope.get(scopeNode);
|
|
309
|
+
if (!map.has(name)) map.set(name, []);
|
|
310
|
+
if (expr) map.get(name).push(expr);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function isFnNode(node) {
|
|
314
|
+
return node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression';
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function isScopeNode(node) {
|
|
318
|
+
return node.type === 'Program' || node.type === 'BlockStatement' || isFnNode(node);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function nearestScope(ancestors) {
|
|
322
|
+
return [...ancestors].reverse().find(isScopeNode) || ast;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function enclosingFn(ancestors) {
|
|
326
|
+
return [...ancestors].reverse().find(isFnNode) || ast;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function enclosingScope(ancestors) {
|
|
330
|
+
return [...ancestors].slice(0, -1).reverse().find(isScopeNode) || ast;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Pass 1: build scope tree, function table, and variable declarations.
|
|
334
|
+
walk.ancestor(ast, {
|
|
335
|
+
FunctionDeclaration(node, ancestors) {
|
|
336
|
+
if (node.id) functions.set(node.id.name, node);
|
|
337
|
+
parentOf.set(node, enclosingScope(ancestors));
|
|
338
|
+
},
|
|
339
|
+
BlockStatement(node, ancestors) {
|
|
340
|
+
parentOf.set(node, enclosingScope(ancestors));
|
|
341
|
+
},
|
|
342
|
+
FunctionExpression(node, ancestors) {
|
|
343
|
+
parentOf.set(node, enclosingScope(ancestors));
|
|
344
|
+
},
|
|
345
|
+
ArrowFunctionExpression(node, ancestors) {
|
|
346
|
+
parentOf.set(node, enclosingScope(ancestors));
|
|
347
|
+
},
|
|
348
|
+
VariableDeclarator(node, ancestors) {
|
|
349
|
+
if (node.id.type !== 'Identifier') return;
|
|
350
|
+
const decl = ancestors[ancestors.length - 2];
|
|
351
|
+
const scope = decl && decl.kind === 'var' ? enclosingFn(ancestors) : nearestScope(ancestors);
|
|
352
|
+
recordBinding(scope, node.id.name, node.init || null);
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// Pass 2: attach assignments to their declaring lexical scope and index calls.
|
|
357
|
+
walk.ancestor(ast, {
|
|
358
|
+
AssignmentExpression(node, ancestors) {
|
|
359
|
+
if (node.left.type !== 'Identifier') return;
|
|
360
|
+
const fn = enclosingFn(ancestors);
|
|
361
|
+
let cursor = nearestScope(ancestors);
|
|
362
|
+
while (cursor) {
|
|
363
|
+
if (bindingsByScope.get(cursor)?.has(node.left.name)) {
|
|
364
|
+
recordBinding(cursor, node.left.name, node.right);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (cursor === fn) break;
|
|
368
|
+
cursor = parentOf.get(cursor);
|
|
369
|
+
}
|
|
370
|
+
recordBinding(fn, node.left.name, node.right);
|
|
371
|
+
},
|
|
372
|
+
CallExpression(node, ancestors) {
|
|
373
|
+
if (node.callee.type === 'Identifier') {
|
|
374
|
+
if (!callsByName.has(node.callee.name)) callsByName.set(node.callee.name, []);
|
|
375
|
+
callsByName.get(node.callee.name).push({ call: node, scope: nearestScope(ancestors), fn: enclosingFn(ancestors) });
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
function isNullLiteral(expr) {
|
|
381
|
+
return expr && expr.type === 'Literal' && expr.value === null;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function verifyExpr(expr, scopeNode, fnNode, propPath, seen) {
|
|
385
|
+
if (!expr) return { ok: false, reason: 'missing initializer' };
|
|
386
|
+
const key = `${expr.start}:${expr.end}:${propPath.join('.')}`;
|
|
387
|
+
if (seen.has(key)) return { ok: true };
|
|
388
|
+
seen.add(key);
|
|
389
|
+
|
|
390
|
+
if (isNullLiteral(expr)) return { ok: true };
|
|
391
|
+
|
|
392
|
+
if (isStatCall(expr)) {
|
|
393
|
+
if (propPath.length !== 0) return { ok: false, reason: 'unexpected property chain on stat call' };
|
|
394
|
+
return hasBigIntTrueOption(expr)
|
|
395
|
+
? { ok: true }
|
|
396
|
+
: { ok: false, reason: `${expr.callee.property.name}() without { bigint: true } at line ${expr.loc.start.line}` };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (expr.type === 'ObjectExpression' && propPath.length > 0) {
|
|
400
|
+
const [head, ...rest] = propPath;
|
|
401
|
+
const prop = expr.properties.find(p =>
|
|
402
|
+
p.type === 'Property' && !p.computed
|
|
403
|
+
&& ((p.key.type === 'Identifier' && p.key.name === head)
|
|
404
|
+
|| (p.key.type === 'Literal' && p.key.value === head))
|
|
405
|
+
);
|
|
406
|
+
if (!prop) return { ok: false, reason: `object literal missing property ${head}` };
|
|
407
|
+
return verifyExpr(prop.value, scopeNode, fnNode, rest, seen);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (expr.type === 'Identifier') {
|
|
411
|
+
return verifyIdentifier(expr.name, scopeNode, fnNode, propPath, seen);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (expr.type === 'MemberExpression' && !expr.computed && expr.property.type === 'Identifier') {
|
|
415
|
+
return verifyExpr(expr.object, scopeNode, fnNode, [expr.property.name, ...propPath], seen);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (expr.type === 'CallExpression' && expr.callee.type === 'Identifier') {
|
|
419
|
+
const targetFn = functions.get(expr.callee.name);
|
|
420
|
+
if (!targetFn) return { ok: false, reason: `untraced call ${expr.callee.name}()` };
|
|
421
|
+
const returns = [];
|
|
422
|
+
walk.ancestor(targetFn.body, {
|
|
423
|
+
ReturnStatement(ret, ancestors) {
|
|
424
|
+
if (ret.argument) returns.push({ arg: ret.argument, scope: nearestScope(ancestors) });
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
if (!returns.length) return { ok: false, reason: `${expr.callee.name}() has no return value` };
|
|
428
|
+
let verifiedStat = false;
|
|
429
|
+
for (const ret of returns) {
|
|
430
|
+
if (isNullLiteral(ret.arg)) continue;
|
|
431
|
+
const check = verifyExpr(ret.arg, ret.scope, targetFn, propPath, seen);
|
|
432
|
+
if (!check.ok) return check;
|
|
433
|
+
verifiedStat = true;
|
|
434
|
+
}
|
|
435
|
+
return verifiedStat ? { ok: true } : { ok: false, reason: `${expr.callee.name}() only returns null` };
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return { ok: false, reason: `untraced expression (${expr.type}) at line ${expr.loc.start.line}` };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function verifyIdentifier(name, scopeNode, fnNode, propPath, seen) {
|
|
442
|
+
const key = `id:${scopeNode.start}:${name}:${propPath.join('.')}`;
|
|
443
|
+
if (seen.has(key)) return { ok: true };
|
|
444
|
+
seen.add(key);
|
|
445
|
+
|
|
446
|
+
// Walk lexical scopes up to fnNode (inclusive).
|
|
447
|
+
let cursor = scopeNode;
|
|
448
|
+
while (cursor) {
|
|
449
|
+
const bindings = bindingsByScope.get(cursor)?.get(name);
|
|
450
|
+
if (bindings && bindings.length > 0) {
|
|
451
|
+
let verified = false;
|
|
452
|
+
for (const expr of bindings) {
|
|
453
|
+
if (isNullLiteral(expr)) continue;
|
|
454
|
+
const check = verifyExpr(expr, cursor, fnNode, propPath, seen);
|
|
455
|
+
if (!check.ok) return check;
|
|
456
|
+
verified = true;
|
|
457
|
+
}
|
|
458
|
+
return verified ? { ok: true } : { ok: false, reason: `${name} only assigned null` };
|
|
459
|
+
}
|
|
460
|
+
if (cursor === fnNode) break;
|
|
461
|
+
cursor = parentOf.get(cursor);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// Check if identifier is a parameter of fnNode; trace all call sites.
|
|
465
|
+
if (fnNode.params) {
|
|
466
|
+
const paramIndex = fnNode.params.findIndex(p => p.type === 'Identifier' && p.name === name);
|
|
467
|
+
if (paramIndex !== -1 && fnNode.id) {
|
|
468
|
+
const callSites = callsByName.get(fnNode.id.name) || [];
|
|
469
|
+
if (!callSites.length) return { ok: false, reason: `parameter ${name} of ${fnNode.id.name}() has no call sites` };
|
|
470
|
+
for (const { call, scope, fn } of callSites) {
|
|
471
|
+
const arg = call.arguments[paramIndex];
|
|
472
|
+
const check = verifyExpr(arg, scope, fn, propPath, seen);
|
|
473
|
+
if (!check.ok) return check;
|
|
474
|
+
}
|
|
475
|
+
return { ok: true };
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return { ok: false, reason: `untraced identifier ${name}` };
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const violations = [];
|
|
483
|
+
walk.ancestor(ast, {
|
|
484
|
+
MemberExpression(node, ancestors) {
|
|
485
|
+
if (node.computed || node.property.type !== 'Identifier' || node.property.name !== 'ino') return;
|
|
486
|
+
const scopeNode = nearestScope(ancestors);
|
|
487
|
+
const fnNode = enclosingFn(ancestors);
|
|
488
|
+
const check = verifyExpr(node.object, scopeNode, fnNode, [], new Set());
|
|
489
|
+
if (!check.ok) {
|
|
490
|
+
violations.push(`${label}:${node.loc.start.line}: ${check.reason}`);
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
return violations;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
test('548 guard: every non-test JS .ino access comes from a { bigint: true } stat', () => {
|
|
498
|
+
// Self-check: guard must reject a new Number-ino comparison and accept a bigint one.
|
|
499
|
+
const badSample = `
|
|
500
|
+
const fs = require('node:fs');
|
|
501
|
+
function same(a, b) {
|
|
502
|
+
const x = fs.statSync(a);
|
|
503
|
+
const y = fs.statSync(b);
|
|
504
|
+
return x.dev === y.dev && x.ino === y.ino;
|
|
505
|
+
}
|
|
506
|
+
`;
|
|
507
|
+
const goodSample = `
|
|
508
|
+
const fs = require('node:fs');
|
|
509
|
+
function same(a, b) {
|
|
510
|
+
const x = fs.statSync(a, { bigint: true });
|
|
511
|
+
const y = fs.statSync(b, { bigint: true });
|
|
512
|
+
return x.ino > 0n && x.dev === y.dev && x.ino === y.ino;
|
|
513
|
+
}
|
|
514
|
+
`;
|
|
515
|
+
assert.ok(findNonBigIntInoViolations(badSample, 'bad.js').length > 0, 'guard must fail on Number-ino comparison');
|
|
516
|
+
assert.deepEqual(findNonBigIntInoViolations(goodSample, 'good.js'), [], 'guard must accept bigint-ino comparison');
|
|
517
|
+
|
|
518
|
+
const files = listNonTestJsFiles(ROOT).sort();
|
|
519
|
+
const checkedWithIno = [];
|
|
520
|
+
const violations = [];
|
|
521
|
+
for (const file of files) {
|
|
522
|
+
const source = fs.readFileSync(file, 'utf8');
|
|
523
|
+
if (!source.includes('.ino')) continue;
|
|
524
|
+
const rel = path.relative(ROOT, file).replace(/\\/g, '/');
|
|
525
|
+
checkedWithIno.push(rel);
|
|
526
|
+
violations.push(...findNonBigIntInoViolations(source, rel));
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
assert.ok(checkedWithIno.length >= 4, `expected to inspect inventoried .ino files; found ${checkedWithIno.length}`);
|
|
530
|
+
assert.deepEqual(violations, [], `non-bigint .ino stat usage found:\n${violations.join('\n')}`);
|
|
531
|
+
});
|