harness-everything 1.2.1 → 1.3.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/CHANGELOG.md +31 -0
- package/benchmarks/results/live-host/agy-2026-11-26-516-read-only/README.md +12 -0
- package/benchmarks/results/live-host/agy-2026-11-26-516-read-only/capture.sanitized.jsonl +5 -0
- package/benchmarks/results/live-host/codex-2026-11-26-488-post-tool-use/README.md +25 -0
- package/benchmarks/results/live-host/codex-2026-11-26-488-post-tool-use/capture.sanitized.jsonl +10 -0
- 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/mechanism-2am-observations-session-import.test.js +1 -0
- package/ci/mechanism-2w-platform-compatibility.test.js +1 -2
- package/ci/mechanism-34-observations.test.js +37 -1
- package/ci/mechanism-397-opencode-observations.test.js +4 -3
- package/ci/mechanism-468-dispatch-cli.test.js +1496 -4
- package/ci/mechanism-516-windows-verify-and-shell.test.js +74 -19
- package/ci/mechanism-548-bigint-identity.test.js +531 -0
- package/ci/mechanism-error-ledger-oracle.test.js +786 -3
- package/ci/mechanism-error-ledger-scan.test.js +981 -0
- package/ci/mechanism-report-writer.test.js +47 -1
- package/ci/mechanism-system-one-cycle.test.js +47 -2
- package/ci/openai-plugin-submission.test.js +26 -8
- package/docs/error-handling/details/c8-dispatch-cli.md +109 -13
- package/docs/openai-plugin.md +6 -10
- package/docs/platform-capabilities.md +15 -0
- package/docs/routing.md +2 -0
- 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/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/kernel-router.js +3 -2
- package/hooks/scripts/state-persist.js +6 -1
- 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/state-persist.js +6 -1
- 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/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +3 -2
- package/sbom.cdx.json +7 -7
- package/scripts/build-openai-submission.js +8 -4
- 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/submission/openai/README.md +9 -14
- package/submission/openai/listing.json +1 -1
- package/submission/openai/test-cases.json +1 -1
|
@@ -53,10 +53,20 @@ function runScript(scriptPath, payload) {
|
|
|
53
53
|
return JSON.parse(res.stdout.trim());
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function
|
|
56
|
+
function hasPwsh(cwd) {
|
|
57
|
+
const result = spawnSync('pwsh', ['-NoProfile', '-NonInteractive', '-Command', 'exit 0'], {
|
|
58
|
+
cwd, timeout: 20000,
|
|
59
|
+
});
|
|
60
|
+
if (result.error?.code === 'ENOENT' && process.env.HARNESS_TEST_PWSH !== '1') return false;
|
|
61
|
+
assert.strictEqual(result.error?.code, undefined, 'PowerShell 7 runtime requires pwsh on PATH');
|
|
62
|
+
assert.strictEqual(result.status, 0, 'PowerShell 7 prerequisite probe failed');
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function runPowerShell(cwd, command, executable = 'pwsh') {
|
|
57
67
|
const env = { ...process.env };
|
|
58
68
|
delete env.NODE_TEST_CONTEXT;
|
|
59
|
-
const res = spawnSync(
|
|
69
|
+
const res = spawnSync(executable, ['-NoProfile', '-NonInteractive', '-Command', command], {
|
|
60
70
|
cwd,
|
|
61
71
|
encoding: 'utf8',
|
|
62
72
|
env,
|
|
@@ -192,10 +202,28 @@ try {
|
|
|
192
202
|
assert.strictEqual(isVerificationCommand(`${changeLocation('.\\pkg')} && ${testCommand}`, { cwd: repo, root: repo }), true);
|
|
193
203
|
}
|
|
194
204
|
|
|
205
|
+
const pkg = path.join(repo, 'pkg');
|
|
206
|
+
if (process.platform === 'win32') {
|
|
207
|
+
const fixture = path.join(pkg, 'verify.test.js');
|
|
208
|
+
fs.writeFileSync(fixture, 'require("node:test")("failing verifier", () => { throw Error("fixture failure"); });\n');
|
|
209
|
+
const failure = runPowerShell(pkg, testCommand, 'powershell.exe');
|
|
210
|
+
assert.strictEqual(failure.status, 1, failure.stderr);
|
|
211
|
+
assert.match(failure.stdout, /fixture failure/);
|
|
212
|
+
assert.ok(!postShell(repo, 'winps-plain', testCommand, failure.status, pkg).lastVerifyAt);
|
|
213
|
+
|
|
214
|
+
fs.writeFileSync(fixture, 'require("node:test")("passing verifier", () => {});\n');
|
|
215
|
+
const success = runPowerShell(pkg, testCommand, 'powershell.exe');
|
|
216
|
+
assert.strictEqual(success.status, 0, success.stderr);
|
|
217
|
+
assert.match(success.stdout, /passing verifier/);
|
|
218
|
+
assert.ok(postShell(repo, 'winps-plain', testCommand, success.status, pkg).lastVerifyAt);
|
|
219
|
+
console.log('Windows PowerShell plain verifier: real exit 0 and 1 propagated through packaged PostToolUse.');
|
|
220
|
+
}
|
|
221
|
+
|
|
195
222
|
let successfulExit = 0;
|
|
196
223
|
let failedExit = 1;
|
|
197
224
|
let wildcardExit = 0;
|
|
198
|
-
|
|
225
|
+
const wantsPwsh = process.platform === 'win32' || process.env.HARNESS_TEST_PWSH === '1';
|
|
226
|
+
if (wantsPwsh && hasPwsh(repo)) {
|
|
199
227
|
fs.writeFileSync(path.join(repo, 'verify.test.js'), 'require("node:test")("root verifier", () => {});\n');
|
|
200
228
|
fs.writeFileSync(path.join(repo, 'pkg', 'verify.test.js'), 'require("node:test")("package verifier", () => {});\n');
|
|
201
229
|
fs.writeFileSync(path.join(repo, 'pkg1', 'verify.test.js'), 'require("node:test")("wildcard verifier", () => {});\n');
|
|
@@ -223,6 +251,8 @@ try {
|
|
|
223
251
|
const literal = runPowerShell(repo, literalBracketsPrelude);
|
|
224
252
|
assert.strictEqual(literal.status, 0, literal.stderr);
|
|
225
253
|
assert.match(literal.stdout, /literal verifier/);
|
|
254
|
+
} else {
|
|
255
|
+
console.log('Skipped 5 PowerShell 7 runtime cases: ' + (wantsPwsh ? 'pwsh unavailable' : 'pwsh runtime lane not requested'));
|
|
226
256
|
}
|
|
227
257
|
|
|
228
258
|
for (const cmd of [
|
|
@@ -280,23 +310,41 @@ try {
|
|
|
280
310
|
|
|
281
311
|
// 5. End-to-end packaged AGY hooks: read-only PowerShell doesn't trigger false Stop;
|
|
282
312
|
// A successful, contained Set-Location verifier allows Stop.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
runScript(
|
|
290
|
-
conversationId:
|
|
291
|
-
workspacePaths: [repo],
|
|
292
|
-
toolCall: { name: 'run_command', args: { CommandLine: 'agy plugin list --json', Cwd: repo } },
|
|
313
|
+
git(repo, ['add', '.']);
|
|
314
|
+
git(repo, ['commit', '-m', 'seed verifier fixtures']);
|
|
315
|
+
const liveReadOnly = [
|
|
316
|
+
'git grep -n "mechanism-516"',
|
|
317
|
+
'$PSVersionTable.PSVersion; Get-Command pwsh -ErrorAction SilentlyContinue',
|
|
318
|
+
];
|
|
319
|
+
const stop = conversationId => runScript(PACKAGED_STOP, {
|
|
320
|
+
conversationId, workspacePaths: [repo], terminationReason: 'NO_TOOL_CALL',
|
|
293
321
|
});
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
322
|
+
for (const [index, command] of [
|
|
323
|
+
'Get-ChildItem | Select-Object Name', 'agy plugin list --json', ...liveReadOnly,
|
|
324
|
+
].entries()) {
|
|
325
|
+
const conversationId = 'win-readonly-' + index;
|
|
326
|
+
assert.ok(!git(repo, ['status', '--short']), 'read-only fixture requires a clean workspace');
|
|
327
|
+
const handoff = postShell(repo, conversationId, command);
|
|
328
|
+
assert.ok(!handoff.lastEditAt, command);
|
|
329
|
+
assert.ok(!handoff.lastVerifyAt, command);
|
|
330
|
+
assert.deepStrictEqual(stop(conversationId), { decision: 'allow' });
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
for (const [index, command] of [
|
|
334
|
+
'git grep -O "mechanism-516"',
|
|
335
|
+
'git grep --open-files-in-pager "mechanism-516"',
|
|
336
|
+
'git grep --textconv "mechanism-516"',
|
|
337
|
+
'git grep -n "mechanism-516" > output.txt',
|
|
338
|
+
'git grep -n "$(Get-Content file)"',
|
|
339
|
+
'git grep -n "mechanism-516"; git status',
|
|
340
|
+
'Get-ChildItem | ForEach-Object { Remove-Item $_.FullName }',
|
|
341
|
+
liveReadOnly[1] + '; git status',
|
|
342
|
+
].entries()) {
|
|
343
|
+
assert.notStrictEqual(classifyShell(command), 'read-only', command);
|
|
344
|
+
const handoff = postShell(repo, 'win-unknown-' + index, command);
|
|
345
|
+
assert.ok(handoff.lastEditAt, command);
|
|
346
|
+
assert.ok(!handoff.lastVerifyAt, command);
|
|
347
|
+
}
|
|
300
348
|
|
|
301
349
|
const convEditVerify = 'win-edit-verify-' + Date.now();
|
|
302
350
|
const target = path.join(repo, 'README.md');
|
|
@@ -307,6 +355,13 @@ try {
|
|
|
307
355
|
toolCall: { name: 'write_file', args: { Path: target, Content: 'edited\n' } },
|
|
308
356
|
});
|
|
309
357
|
const afterEdit = readHandoff(repo, convEditVerify);
|
|
358
|
+
for (const command of liveReadOnly) {
|
|
359
|
+
const pending = postShell(repo, convEditVerify, command);
|
|
360
|
+
assert.strictEqual(pending.lastEditAt, afterEdit.lastEditAt, command);
|
|
361
|
+
assert.strictEqual(pending.lastVerifyAt, afterEdit.lastVerifyAt, command);
|
|
362
|
+
}
|
|
363
|
+
assert.strictEqual(stop(convEditVerify).decision, 'continue');
|
|
364
|
+
assert.deepStrictEqual(stop(convEditVerify), { decision: 'allow' });
|
|
310
365
|
for (const exitCode of [undefined, '0']) {
|
|
311
366
|
const unverified = postShell(repo, convEditVerify, verifyInPkg, exitCode);
|
|
312
367
|
assert.strictEqual(unverified.lastEditAt, afterEdit.lastEditAt);
|
|
@@ -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
|
+
});
|