Inherit verified path selection and snapshot runner regression fixes

This commit is contained in:
Michael D'Angelo
2026-11-10 18:16:04 -08:00
3 changed files with 32 additions and 24 deletions
+15 -5
View File
@@ -1601,7 +1601,7 @@ interface CliDependencies {
// Apply coordinator-owned Git bindings after native shell environment filtering.
const snapshotCredentialName =
/(?:^|_)(?:TOKEN|PASSWORD|SECRET|CREDENTIALS?|AUTHORIZATION|(?:API|ACCESS|SECRET|PRIVATE)_KEY|AUTH_SOCK)(?:_FILE)?$/iu;
const PATCH_GIT_ENVIRONMENT_RUNNER = `
export const PATCH_GIT_ENVIRONMENT_RUNNER = `
const { spawn } = require("node:child_process");
const { readSync, writeSync } = require("node:fs");
const [headerLength, command, ...args] = process.argv.slice(1);
@@ -9881,14 +9881,20 @@ async function prepareSavedPatchPublication(
before: SavedPatchTrees,
after: SavedPatchTrees,
) {
const changes = paths.length
? await diff(before.tree, after.tree, paths)
: new Map<string, string>();
// A move may be reported under its new name. Include its deleted source
// only if the full turn contains exactly one removal and one addition
// of the same mode and object. Never select neighboring directory leaves.
const previous = new Map<string, string>();
const turn = await diff(before.tree, after.tree, ["."], previous);
// Git emits root-relative byte paths. Use the exact directory-entry names
// accepted by finding verification, including descendants of a selected directory.
const changes = new Map(
[...turn].filter(([path]) =>
paths.some(
(selected) => path === selected || path.startsWith(selected + "/"),
),
),
);
const filtered = (path: string) =>
before.filteredInputs?.has(path) || after.filteredInputs?.has(path);
for (const path of turn.keys()) {
@@ -14166,7 +14172,11 @@ async function runFindingPatches(
!(base instanceof Map)
) {
const reason = await options.publication.verified.record(
selectedFiles,
files.map((file) =>
relativePatchPath(rootKey, resolve(repositoryKey, file))
.split(sep)
.join("/"),
),
base,
observed,
);
@@ -1,22 +1,12 @@
import { afterEach, expect, test } from "bun:test";
import { spawn } from "node:child_process";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { PATCH_GIT_ENVIRONMENT_RUNNER as runner } from "../src/cli.js";
import { createTemporaryDirectories } from "./support/temporary-directories.js";
const fixtures = createTemporaryDirectories(true);
afterEach(fixtures.cleanup);
const source = await readFile(
new URL("../src/cli.ts", import.meta.url),
"utf8",
);
const declaration = source.match(
/const PATCH_GIT_ENVIRONMENT_RUNNER = (`[\s\S]*?`);/u,
);
expect(declaration).not.toBeNull();
const runner = new Function(`return ${declaration![1]};`)() as string;
function bindingFrame(environment: Record<string, string> = {}): Buffer {
return Buffer.from(JSON.stringify({ bindings: Object.entries(environment) }));
}
@@ -75,7 +75,10 @@ for (const kind of [
nestedGit("add", "-f", "local.txt");
nestedGit("commit", "-m", "Synthetic nested content");
}
const blocked = copied && kind !== "directory link";
const copiedPrivateContent = copied && kind !== "directory link";
const blocked = copiedPrivateContent || kind === "scrubbed";
const assessed =
kind === "scrubbed" || (kind === "untracked" && !copied);
expect(git("status", "--porcelain=v1", "--untracked-files=all")).toBe(
kind.startsWith("ignored") ? "" : "?? nested/",
);
@@ -92,7 +95,7 @@ for (const kind of [
"patch",
"--scan",
"scan-1",
...(kind === "scrubbed" ? ["--assess-patch-risk"] : []),
...(assessed ? ["--assess-patch-risk"] : []),
"--create-pr",
"--json",
],
@@ -115,10 +118,11 @@ for (const kind of [
output!.appServer!.prompt.includes("immutable patch artifact")
) {
assessments++;
await writeFile(
join(directory, "selected.txt"),
"Synthetic scrubbed working copy\n",
);
if (kind === "scrubbed")
await writeFile(
join(directory, "selected.txt"),
"Synthetic scrubbed working copy\n",
);
output!.stdout.write(patchRiskAssessment().report);
return 0;
}
@@ -150,7 +154,11 @@ for (const kind of [
blocked ? { pushes: 0, creations: 0 } : { pushes: 1, creations: 1 },
);
if (blocked) {
expect(outcome.stderr).toContain("pre-existing");
expect(outcome.stderr).toContain(
copiedPrivateContent
? "pre-existing"
: "working tree differs from the verified changes",
);
expect(git("rev-parse", "HEAD")).toBe(head);
expect(await readFile(join(directory, ".git", "index"))).toEqual(
index!,
@@ -170,7 +178,7 @@ for (const kind of [
configuration,
);
expect(await readFile(source, "utf8")).toBe(content);
expect(assessments).toBe(kind === "scrubbed" ? 1 : 0);
expect(assessments).toBe(assessed ? 1 : 0);
expect(await readFile(join(directory, "selected.txt"), "utf8")).toBe(
kind === "scrubbed"
? "Synthetic scrubbed working copy\n"