Skip to content

Commit c8f03ea

Browse files
committed
fix(review): bind fixture approval to every scanned endpoint
1 parent e8dfeaf commit c8f03ea

5 files changed

Lines changed: 78 additions & 40 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ checkpoint, and status-only commits are intentionally omitted.
6464

6565
### Fixed
6666

67-
- Classified the explicitly approved autoreview fixture only by its exact full-URI digest and canonical or vendored source path, preserving all scanner gates and value-free audits.
67+
- Classified the explicitly approved autoreview fixture only by its exact full-URI digest and canonical or vendored source path, enforcing the same digest/path/mode policy at every scanned endpoint for all reviewed fixtures while preserving scanner gates and value-free audits.
6868
- Stopped treating pane-local runtime state as stored data while retaining warnings for explicit persistence changes and incomplete storage patches.
6969
- Corrected retained terminal-proof cleanup for independent process-exit and PTY-close events, preserving the original wrapper failure and draining dead-pane capture only after verified cleanup.
7070
- Prevented rejected model inputs from surviving in generated prompt artifacts; retained diagnostics now follow admission with owner-only access, and unused prompt copies are no longer written.

‎README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,10 @@ or its [vendored OpenClaw copy](https://github.com/openclaw/openclaw/blob/136eab
567567
as non-sensitive after a complete scan. Static host policy associates each
568568
exact full-URI SHA-256 with only its approved source paths, requiring a literal
569569
at the reported line of a host-staged Git blob from mode `100644`.
570-
Deduplicated blobs retain the approved paths that established their eligibility.
570+
Deduplicated blobs retain every scanned logical endpoint's path and Git mode,
571+
including mode-only transitions and shared-path aliases. Every captured reference
572+
must qualify under the same digest's exact path and mode `100644` policy before
573+
any source is eligible for classification or an audit notice.
571574
The policy does not trust checkout ignore rules, domain patterns, fixture words,
572575
test names, or unchanged-line inference; no nearby fixture is implicitly approved.
573576
Findings attributed to prompt, schema, diff, additional-input, other-path, or

‎src/agent-input-scan-fixtures.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function reviewedFixtureForSource(source: string, mode: string) {
2828

2929
export interface ReviewedFixtureBlob {
3030
bytes: Buffer;
31-
sources: ReadonlySet<string>;
31+
references: readonly { source: string; mode: string }[];
3232
}
3333

3434
interface ClassifiedFinding {
@@ -120,10 +120,13 @@ export function classifyReviewedFixtureScan(
120120
if (!fixture) return undefined;
121121
const source = object(object(object(finding.SourceMetadata).Data).Filesystem);
122122
const staged = typeof source.file === "string" ? sourceBlobs.get(source.file) : undefined;
123-
const sources = fixture.sources.filter((path) => staged?.sources.has(path));
124123
if (
125124
!staged ||
126-
!sources.length ||
125+
!staged.references.length ||
126+
staged.references.some(
127+
({ source, mode }) =>
128+
reviewedFixtureForSource(source, mode)?.fixtureSha256 !== fixture.fixtureSha256,
129+
) ||
127130
typeof source.line !== "number" ||
128131
!Number.isSafeInteger(source.line) ||
129132
source.line <= 0
@@ -146,6 +149,7 @@ export function classifyReviewedFixtureScan(
146149
return undefined;
147150
const blob = basename(source.file as string);
148151
const key = `${blob}:${source.line}:${finding.DecoderName}`;
152+
const sources = new Set(staged.references.map(({ source }) => source));
149153
for (const path of sources) {
150154
const groupKey = `${digest}:${path}`;
151155
const group = classified.get(groupKey) ?? {

‎src/agent-input-scan.ts‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { fileURLToPath } from "node:url";
2121
import { readReviewGit, reviewMergeBase, type ReviewGitReadOptions } from "./pr-review-evidence.js";
2222
import {
2323
classifyReviewedFixtureScan,
24-
reviewedFixtureForSource,
2524
type ReviewedFixtureBlob,
2625
} from "./agent-input-scan-fixtures.js";
2726

@@ -338,8 +337,7 @@ export function scanAgentInput(options: {
338337
};
339338
}
340339
assertCurrent();
341-
const blobs = new Set<string>();
342-
const fixtureSources = new Map<string, Set<string>>();
340+
const blobs = new Map<string, { source: string; mode: string }[]>();
343341
const endpoints =
344342
source.kind === "snapshot"
345343
? [mergeBase.sha, source.headSha, source.indexTreeSha, source.treeSha]
@@ -384,21 +382,18 @@ export function scanAgentInput(options: {
384382
if (!["100644", "100755", "120000"].includes(mode!))
385383
throw new AgentInputScanError("unsupported_content");
386384
if (!OBJECT_ID.test(oid!)) throw new AgentInputScanError("incomplete_source");
387-
blobs.add(oid!);
388-
const fixture = reviewedFixtureForSource(path, mode!);
389-
if (fixture) {
390-
const sources = fixtureSources.get(oid!) ?? new Set<string>();
391-
sources.add(fixture.source);
392-
fixtureSources.set(oid!, sources);
393-
}
385+
// An OID identifies bytes, not each scanned endpoint's path/mode eligibility.
386+
const references = blobs.get(oid!) ?? [];
387+
references.push({ source: path, mode: mode! });
388+
blobs.set(oid!, references);
394389
}
395390
}
396391
stage(git([...args, "--patch", "--binary", "--full-index", "--"]));
397392
}
398393
// Only live committed checkouts need normalized raw files staged here;
399394
// snapshot objects were already captured and fenced before preparation.
400395
if (source.kind === "committed") assertCurrent();
401-
for (const oid of blobs) {
396+
for (const [oid, references] of blobs) {
402397
const size = Number(git(["cat-file", "-s", oid], 100).toString().trim());
403398
if (!Number.isSafeInteger(size) || size < 0)
404399
throw new AgentInputScanError("incomplete_source");
@@ -411,8 +406,7 @@ export function scanAgentInput(options: {
411406
throw new AgentInputScanError("unsupported_content");
412407
// OID names preserve multiline bytes and make symlinks ordinary scan files.
413408
stage(bytes, oid);
414-
const sources = fixtureSources.get(oid);
415-
if (sources) reviewedFixtureBlobs.set(join(inputDir, oid), { bytes, sources });
409+
reviewedFixtureBlobs.set(join(inputDir, oid), { bytes, references });
416410
}
417411
}
418412
const result = spawnSync(

‎test/agent-input-scan.test.ts‎

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,13 @@ for (const scenario of [
457457
"PLAIN duplicate",
458458
"HTML duplicate",
459459
"shared approved path OIDs",
460-
"shared endpoint OID",
460+
"shared approved and unapproved path OIDs",
461+
"shared endpoint OID 644 to 755",
462+
"shared endpoint OID 755 to 644",
463+
"executable head snapshot",
464+
"executable index snapshot",
465+
"executable worktree snapshot",
466+
"repeated regular snapshot OID",
461467
"canonical autoreview path",
462468
"vendored autoreview path",
463469
"both autoreview paths",
@@ -520,17 +526,19 @@ for (const scenario of [
520526
const files =
521527
scenario === "shared approved path OIDs"
522528
? [...autoreviewSources, ledgerSource]
523-
: scenario === "both autoreview paths"
524-
? autoreviewSources
525-
: [
526-
scenario === "canonical autoreview path"
527-
? autoreviewSources[0]!
528-
: scenario === "vendored autoreview path"
529-
? autoreviewSources[1]!
530-
: scenario === "other file"
531-
? "other.test.ts"
532-
: ledgerSource,
533-
];
529+
: scenario === "shared approved and unapproved path OIDs"
530+
? [ledgerSource, "other.test.ts"]
531+
: scenario === "both autoreview paths"
532+
? autoreviewSources
533+
: [
534+
scenario === "canonical autoreview path"
535+
? autoreviewSources[0]!
536+
: scenario === "vendored autoreview path"
537+
? autoreviewSources[1]!
538+
: scenario === "other file"
539+
? "other.test.ts"
540+
: ledgerSource,
541+
];
534542
const value = scenario === "decoded only" ? uri.replace(":", "&#58;") : uri;
535543
const contents = "// context\n".repeat(40) + JSON.stringify(value) + "\n";
536544
for (const file of files) {
@@ -539,14 +547,40 @@ for (const scenario of [
539547
join(f.cwd, file),
540548
scenario === "diff" ? "// before\n" : "// before\n" + contents,
541549
);
542-
if (scenario === "executable source") chmodSync(join(f.cwd, file), 0o755);
550+
if (scenario === "executable source" || scenario === "shared endpoint OID 755 to 644")
551+
chmodSync(join(f.cwd, file), 0o755);
543552
}
544553
const baseSha = f.commit();
545554
for (const file of files) {
546-
if (scenario === "shared endpoint OID") chmodSync(join(f.cwd, file), 0o755);
555+
if (scenario === "shared endpoint OID 644 to 755" || scenario === "executable head snapshot")
556+
chmodSync(join(f.cwd, file), 0o755);
557+
else if (scenario === "shared endpoint OID 755 to 644") chmodSync(join(f.cwd, file), 0o644);
547558
else writeFileSync(join(f.cwd, file), "// after\n" + contents);
548559
}
549560
const headSha = f.commit();
561+
const modeOnly =
562+
scenario.startsWith("shared endpoint OID") || scenario === "executable head snapshot";
563+
if (modeOnly) {
564+
assert.equal(
565+
f.git("rev-parse", `${baseSha}:${ledgerSource}`),
566+
f.git("rev-parse", `${headSha}:${ledgerSource}`),
567+
);
568+
assert.equal(f.git("diff", baseSha, headSha, "--", ledgerSource).includes(uri), false);
569+
}
570+
if (scenario === "executable head snapshot") {
571+
chmodSync(join(f.cwd, ledgerSource), 0o644);
572+
f.git("add", "--", ledgerSource);
573+
} else if (scenario === "executable index snapshot") {
574+
chmodSync(join(f.cwd, ledgerSource), 0o755);
575+
f.git("add", "--", ledgerSource);
576+
chmodSync(join(f.cwd, ledgerSource), 0o644);
577+
} else if (scenario === "executable worktree snapshot") {
578+
chmodSync(join(f.cwd, ledgerSource), 0o755);
579+
} else if (scenario === "repeated regular snapshot OID") {
580+
writeFileSync(join(f.cwd, ledgerSource), "// before\n" + contents);
581+
f.git("add", "--", ledgerSource);
582+
writeFileSync(join(f.cwd, ledgerSource), "// after\n" + contents);
583+
}
550584
const receipt = join(f.root, "scan-root");
551585
const schemaPath = join(f.root, "schema.json");
552586
if (scenario === "schema") writeFileSync(schemaPath, uri);
@@ -558,7 +592,7 @@ const scenario = ${JSON.stringify(scenario)};
558592
fs.writeFileSync(${JSON.stringify(receipt)}, path.dirname(inputDir));
559593
const parsed = new URL(uri);
560594
const blobs = inputs.filter(({name}) => /^[a-f0-9]{40}$/.test(name));
561-
assert.equal(blobs.length, scenario === 'shared endpoint OID' ? 1 : 2);
595+
assert.equal(blobs.length, ${modeOnly ? 1 : 2});
562596
const findings = inputs.filter(({name, bytes}) =>
563597
(/^[a-f0-9]{40}$/.test(name) && (scenario !== 'diff' || bytes.includes(uri))) ||
564598
(scenario === 'prompt' && name === 'prompt') ||
@@ -607,6 +641,13 @@ process.exit(scenario === 'unexpected successful output' ? 0 : 183);
607641
`,
608642
);
609643
const run = () => {
644+
if (scenario.includes("snapshot")) {
645+
const expected = captureTargetCheckoutBinding(f.cwd);
646+
return withTargetReviewSnapshot(
647+
{ cwd: f.cwd, baseSha, expected, timeoutMs: 30_000 },
648+
f.run,
649+
);
650+
}
610651
const source = { kind: "committed" as const, baseSha, headSha };
611652
if (scenario === "schema" || scenario === "additional") {
612653
scanAgentInput({
@@ -625,8 +666,7 @@ process.exit(scenario === 'unexpected successful output' ? 0 : 183);
625666
"reviewed fixture",
626667
"PLAIN duplicate",
627668
"HTML duplicate",
628-
"shared approved path OIDs",
629-
"shared endpoint OID",
669+
"repeated regular snapshot OID",
630670
].includes(scenario)
631671
) {
632672
assert.equal(run().status, 0);
@@ -651,12 +691,9 @@ process.exit(scenario === 'unexpected successful output' ? 0 : 183);
651691
(sum: number, finding: { occurrences: number }) => sum + finding.occurrences,
652692
0,
653693
),
654-
scenario === "shared endpoint OID" ? 1 : scenario.endsWith("duplicate") ? 3 : 2,
655-
);
656-
assert.equal(
657-
notice.findings.length,
658-
scenario === "shared endpoint OID" ? 1 : scenario === "HTML duplicate" ? 3 : 2,
694+
scenario.endsWith("duplicate") ? 3 : 2,
659695
);
696+
assert.equal(notice.findings.length, scenario === "HTML duplicate" ? 3 : 2);
660697
for (const finding of notice.findings) {
661698
assert.match(finding.blob, /^[a-f0-9]{40}$/);
662699
assert.equal(finding.line, 42);

0 commit comments

Comments
 (0)