Skip to content

Commit 5087c40

Browse files
committed
test(proof): pass metadata probe paths as data
Static generated Node programs and explicit path data replace avoidable source interpolation. The network-denial preload is independently self-tested.
1 parent 5e4c897 commit 5087c40

3 files changed

Lines changed: 103 additions & 27 deletions

File tree

‎docs/proof/report-front-matter/README.md‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ part of this procedure.
9494
[runtime-proof.mjs](runtime-proof.mjs) executes **13 scenarios per mode**. The
9595
expectation mode is explicit, with no source-symbol detection.
9696

97-
| Scenarios | Baseline expectation | Candidate expectation |
98-
| --- | --- | --- |
99-
| Ordinary and fenced quoted header keys (2) | Intake exits 2; `none` invents a blocker; required packet is suppressed | Intake succeeds; `none` yields false/null; required decision survives exactly |
100-
| Body heading, header comments, header list, body list, single/repeated delimited body-only keys (6) | All remain readable | All remain readable |
101-
| Genuine competing owned-key record containing comments/list entries (1) | Intake rejects ambiguous ref; decision blocks with no packet | Same guarded rejection |
102-
| Eligible F/missing legacy-rating selector (1) | Selects `322` | Selects `322` |
103-
| Missing ratings with body lookalikes: no legacy sections, F/missing legacy sections, fenced lookalikes plus legacy sections (3) | Selects nothing | Selects nothing |
97+
| Scenarios | Baseline expectation | Candidate expectation |
98+
| ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
99+
| Ordinary and fenced quoted header keys (2) | Intake exits 2; `none` invents a blocker; required packet is suppressed | Intake succeeds; `none` yields false/null; required decision survives exactly |
100+
| Body heading, header comments, header list, body list, single/repeated delimited body-only keys (6) | All remain readable | All remain readable |
101+
| Genuine competing owned-key record containing comments/list entries (1) | Intake rejects ambiguous ref; decision blocks with no packet | Same guarded rejection |
102+
| Eligible F/missing legacy-rating selector (1) | Selects `322` | Selects `322` |
103+
| Missing ratings with body lookalikes: no legacy sections, F/missing legacy sections, fenced lookalikes plus legacy sections (3) | Selects nothing | Selects nothing |
104104

105105
The six benign structural cases are positive controls on both versions, not
106106
failures attributed to the original bug. F/missing legacy ratings are valid
@@ -114,19 +114,28 @@ The actual intake invocation uses `create-job --from-report` with synthetic
114114
check the original subject, question, rationale, options, and owner. Selector
115115
cases invoke actual `workflow-utils proposed-item-numbers` against a flat
116116
synthetic `records/.../items` directory. Each mode expects 22 application
117-
invocations, one GitHub-command tripwire self-check, and 136 baseline / 150
117+
invocations, two tripwire self-checks (GitHub command and network denial), and 138 baseline / 152
118118
candidate assertions. These counts are expectations, not an execution receipt.
119119

120120
## Boundaries and output
121121

122-
Children receive a credential-free allowlist. `gh`, `codex`, and `claude`
123-
tripwires reject execution; the GitHub tripwire is self-tested and its log is
124-
cleared before measuring application behavior. A Node preload denies fetch,
125-
HTTP(S), and socket connections. Assertions require zero subsequent command or
126-
network attempts, no jobs written, and unchanged selector records.
122+
Children receive a credential-free allowlist. Static `gh`, `codex`, and `claude`
123+
tripwires and the static network-denial preload read their log pathname from the
124+
child-only `CLAWSWEEPER_PROOF_DENIED_LOG` environment value. The command names
125+
remain an explicit allowlist. Decision probes receive module and report paths
126+
as arguments; runtime paths are never inserted into generated JavaScript.
127+
128+
The central spawn helper passes the preload through explicit Node `--require`
129+
arguments. It denies fetch, HTTP(S), and socket connections. Independent self-checks
130+
require the GitHub command's rejection and a fetch to `https://example.invalid`
131+
to fail with the known network-denial error and log entry. Both self-check logs
132+
are cleared before measuring application behavior. Assertions require zero
133+
subsequent command or network attempts, no jobs written, and unchanged selector
134+
records.
127135

128136
Generated manifests bind source IDs, archive hashes, source/dist hashes, driver
129-
and fixture hashes, exact argv and argv hashes, observations, and toolchain.
137+
and fixture hashes, complete argv (including the preload) and argv hashes,
138+
the non-secret child environment, observations, and toolchain.
130139
Build/runtime logs and manifests stay in the caller's output directory, outside
131140
committed source. Publish only inspected normalized observations in the PR body
132141
after fresh execution and record provider/image/lease separately.

‎docs/proof/report-front-matter/run-proof.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ try {
196196
);
197197
const result = JSON.parse(output);
198198
assert.equal(result.scenarios, 13);
199-
assert.equal(result.assertions, mode === "baseline" ? 136 : 150);
199+
assert.equal(result.assertions, mode === "baseline" ? 138 : 152);
200+
assert.equal(result.tripwireSelfChecks, 2);
201+
assert.equal(result.applicationInvocations, 22);
200202
assert.deepEqual(sourceHashes(source), before, `${mode} source changed during execution`);
201203
assert.deepEqual(
202204
dependencyHashes(),

‎docs/proof/report-front-matter/runtime-proof.mjs‎

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
writeFileSync,
1616
} from "node:fs";
1717
import { dirname, join, resolve } from "node:path";
18-
import { pathToFileURL } from "node:url";
1918

2019
const args = Object.fromEntries(
2120
Array.from({ length: (process.argv.length - 2) / 2 }, (_, index) => [
@@ -44,18 +43,35 @@ const deniedLog = join(proofRoot, "denied-commands.log");
4443
for (const command of ["gh", "codex", "claude"]) {
4544
writeFileSync(
4645
join(tripwireDir, command),
47-
`#!${process.execPath}\nrequire('node:fs').appendFileSync(${JSON.stringify(deniedLog)}, '${command} denied\\n'); process.exit(97);\n`,
46+
String.raw`#!/usr/bin/env node
47+
const command = require('node:path').basename(process.argv[1]);
48+
require('node:assert/strict').ok(['gh', 'codex', 'claude'].includes(command));
49+
require('node:fs').appendFileSync(process.env.CLAWSWEEPER_PROOF_DENIED_LOG, command + ' denied\n');
50+
process.exit(97);
51+
`,
4852
{ mode: 0o755 },
4953
);
5054
}
5155
const denyNetwork = join(proofRoot, "deny-network.cjs");
5256
writeFileSync(
5357
denyNetwork,
54-
`const deny = () => { require('node:fs').appendFileSync(${JSON.stringify(deniedLog)}, 'network denied\\n'); throw new Error('Synthetic proof denies network'); }; globalThis.fetch = deny; require('node:net').Socket.prototype.connect = deny; for (const name of ['node:http', 'node:https']) { const module = require(name); module.request = deny; module.get = deny; } require('node:module').syncBuiltinESMExports();\n`,
58+
String.raw`const deny = () => {
59+
require('node:fs').appendFileSync(process.env.CLAWSWEEPER_PROOF_DENIED_LOG, 'network denied\n');
60+
throw new Error('Synthetic proof denies network');
61+
};
62+
globalThis.fetch = deny;
63+
require('node:net').Socket.prototype.connect = deny;
64+
for (const name of ['node:http', 'node:https']) {
65+
const module = require(name);
66+
module.request = deny;
67+
module.get = deny;
68+
}
69+
require('node:module').syncBuiltinESMExports();
70+
`,
5571
);
5672
const childEnv = {
5773
PATH: [tripwireDir, dirname(process.execPath), "/usr/bin", "/bin"].join(":"),
58-
NODE_OPTIONS: `--require=${denyNetwork}`,
74+
CLAWSWEEPER_PROOF_DENIED_LOG: deniedLog,
5975
CI: "1",
6076
};
6177
const commands = [];
@@ -66,7 +82,8 @@ function equal(actual, wanted, label) {
6682
assert.deepEqual(actual, wanted, label);
6783
}
6884
function run(name, argv) {
69-
const result = spawnSync(process.execPath, argv, {
85+
const nodeArgs = ["--require", denyNetwork, ...argv];
86+
const result = spawnSync(process.execPath, nodeArgs, {
7087
cwd: proofRoot,
7188
env: childEnv,
7289
encoding: "utf8",
@@ -76,8 +93,8 @@ function run(name, argv) {
7693
writeFileSync(join(proofRoot, `${name}.stderr`), result.stderr);
7794
commands.push({
7895
name,
79-
argv: [process.execPath, ...argv],
80-
argvSha256: hash(JSON.stringify([process.execPath, ...argv])),
96+
argv: [process.execPath, ...nodeArgs],
97+
argvSha256: hash(JSON.stringify([process.execPath, ...nodeArgs])),
8198
cwd: proofRoot,
8299
exitCode: result.status,
83100
});
@@ -87,6 +104,17 @@ const tripwireCheck = run("tripwire-self-check", [join(tripwireDir, "gh")]);
87104
equal(tripwireCheck.status, 97, "the GitHub tripwire executes and denies commands");
88105
equal(readFileSync(deniedLog, "utf8"), "gh denied\n", "the GitHub tripwire records attempts");
89106
unlinkSync(deniedLog);
107+
const networkCheck = run("network-self-check", ["--eval", 'fetch("https://example.invalid");']);
108+
equal(
109+
{
110+
exitCode: networkCheck.status,
111+
deniedError: networkCheck.stderr.includes("Error: Synthetic proof denies network"),
112+
},
113+
{ exitCode: 1, deniedError: true },
114+
"the application preload rejects fetch with its known denial error",
115+
);
116+
equal(readFileSync(deniedLog, "utf8"), "network denied\n", "the network tripwire records attempts");
117+
unlinkSync(deniedLog);
90118
const requiredDecision = {
91119
required: true,
92120
kind: "manual_review",
@@ -208,9 +236,28 @@ for (const { name, markdown, required, baselinePoisoned } of [
208236
const probe = join(proofRoot, `${name}-decisions.mjs`);
209237
writeFileSync(
210238
probe,
211-
`import { readFileSync } from 'node:fs';\nimport { maintainerDecisionBlocksClose, buildDecisionPacketFromReport } from ${JSON.stringify(pathToFileURL(join(root, "dist/decision-packets.js")).href)};\nconst none = readFileSync(${JSON.stringify(reportPath)}, 'utf8'); const required = readFileSync(${JSON.stringify(requiredPath)}, 'utf8');\nconsole.log(JSON.stringify({ noneBlocked: maintainerDecisionBlocksClose(none), nonePacket: buildDecisionPacketFromReport(none), requiredBlocked: maintainerDecisionBlocksClose(required), requiredPacket: buildDecisionPacketFromReport(required, { generatedAt: '2026-08-30T00:00:00.000Z', reportPath: 'records/openclaw-clawsweeper/items/321.md' }) }));\n`,
239+
`import { readFileSync } from 'node:fs';
240+
import { pathToFileURL } from 'node:url';
241+
const { maintainerDecisionBlocksClose, buildDecisionPacketFromReport } = await import(pathToFileURL(process.argv[2]).href);
242+
const none = readFileSync(process.argv[3], 'utf8');
243+
const required = readFileSync(process.argv[4], 'utf8');
244+
console.log(JSON.stringify({
245+
noneBlocked: maintainerDecisionBlocksClose(none),
246+
nonePacket: buildDecisionPacketFromReport(none),
247+
requiredBlocked: maintainerDecisionBlocksClose(required),
248+
requiredPacket: buildDecisionPacketFromReport(required, {
249+
generatedAt: '2026-08-30T00:00:00.000Z',
250+
reportPath: 'records/openclaw-clawsweeper/items/321.md'
251+
})
252+
}));
253+
`,
212254
);
213-
const decisions = run(`decisions-${name}`, [probe]);
255+
const decisions = run(`decisions-${name}`, [
256+
probe,
257+
join(root, "dist/decision-packets.js"),
258+
reportPath,
259+
requiredPath,
260+
]);
214261
equal(decisions.status, 0, `${name}: decision export invocation`);
215262
const result = JSON.parse(decisions.stdout);
216263
equal(result.noneBlocked, poisoned, `${name}: no invented maintainer blocker`);
@@ -261,9 +308,21 @@ equal(existsSync(join(proofRoot, "jobs")), false, "competing record writes no jo
261308
const competingProbe = join(proofRoot, "competing-decisions.mjs");
262309
writeFileSync(
263310
competingProbe,
264-
`import { readFileSync } from 'node:fs';\nimport { maintainerDecisionBlocksClose, buildDecisionPacketFromReport } from ${JSON.stringify(pathToFileURL(join(root, "dist/decision-packets.js")).href)};\nconst markdown = readFileSync(${JSON.stringify(competingPath)}, 'utf8');\nconsole.log(JSON.stringify({ blocked: maintainerDecisionBlocksClose(markdown), packet: buildDecisionPacketFromReport(markdown) }));\n`,
311+
`import { readFileSync } from 'node:fs';
312+
import { pathToFileURL } from 'node:url';
313+
const { maintainerDecisionBlocksClose, buildDecisionPacketFromReport } = await import(pathToFileURL(process.argv[2]).href);
314+
const markdown = readFileSync(process.argv[3], 'utf8');
315+
console.log(JSON.stringify({
316+
blocked: maintainerDecisionBlocksClose(markdown),
317+
packet: buildDecisionPacketFromReport(markdown)
318+
}));
319+
`,
265320
);
266-
const competingDecisions = run("decisions-competing-comment-list", [competingProbe]);
321+
const competingDecisions = run("decisions-competing-comment-list", [
322+
competingProbe,
323+
join(root, "dist/decision-packets.js"),
324+
competingPath,
325+
]);
267326
equal(competingDecisions.status, 0, "competing record decision exports execute");
268327
const competingResult = JSON.parse(competingDecisions.stdout);
269328
equal(
@@ -355,6 +414,8 @@ const sourcePaths = [
355414
"src/repair/create-job.ts",
356415
"src/repair/workflow-utils.ts",
357416
];
417+
const tripwireSelfChecks = commands.filter(({ name }) => name.endsWith("-self-check")).length;
418+
const applicationInvocations = commands.length - tripwireSelfChecks;
358419
const manifest = {
359420
expected,
360421
assertions,
@@ -376,7 +437,9 @@ const manifest = {
376437
commands,
377438
observations,
378439
githubReads: 0,
379-
tripwireSelfChecks: 1,
440+
tripwireSelfChecks,
441+
applicationInvocations,
442+
childEnvironment: childEnv,
380443
networkAttempts: 0,
381444
jobsCreated: 0,
382445
environment:
@@ -391,6 +454,8 @@ console.log(
391454
expected,
392455
assertions,
393456
scenarios: observations.length,
457+
tripwireSelfChecks,
458+
applicationInvocations,
394459
githubReads: 0,
395460
jobsCreated: 0,
396461
manifest: join(proofRoot, "manifest.json"),

0 commit comments

Comments
 (0)