mirror of
https://github.com/openai/codex-security.git
synced 2026-11-25 12:35:54 +08:00
Validate sparse publication paths and tolerate absent optional LFS configuration
This commit is contained in:
@@ -12525,7 +12525,13 @@ async function createPatchPullRequest(
|
||||
indexCommand(true),
|
||||
(stage) =>
|
||||
stage(
|
||||
["--literal-pathspecs", "add", "--dry-run", ...stageArguments],
|
||||
[
|
||||
"--literal-pathspecs",
|
||||
"add",
|
||||
"--dry-run",
|
||||
"--sparse",
|
||||
...stageArguments,
|
||||
],
|
||||
stageInput,
|
||||
),
|
||||
indexSelection,
|
||||
|
||||
@@ -1695,6 +1695,7 @@ export async function capturePatchGitControls(
|
||||
"--null",
|
||||
"--show-scope",
|
||||
"--show-origin",
|
||||
"--default=",
|
||||
"--get",
|
||||
"lfs.storage",
|
||||
]).catch((error: unknown) => {
|
||||
@@ -1732,7 +1733,10 @@ export async function capturePatchGitControls(
|
||||
const lfs = absolute
|
||||
? configured
|
||||
: join(common.replace(/\n$/u, ""), configured);
|
||||
const userSelected = await userSelectedConfig(scope, origin, checkout);
|
||||
// Git reports a supplied default as command-line configuration. Only an
|
||||
// actual nonempty setting can authorize a cache outside this checkout.
|
||||
const userSelected =
|
||||
!!value && (await userSelectedConfig(scope, origin, checkout));
|
||||
pendingStoragePaths.push({ path: lfs, userSelected });
|
||||
}
|
||||
let tracked: Buffer;
|
||||
|
||||
@@ -125,13 +125,13 @@ test.each([
|
||||
const inventory = calls.filter(
|
||||
({ args }) => args.includes("config") && !args.includes("--git-path"),
|
||||
);
|
||||
expect(inventory.some(({ args }) => args.includes("--list"))).toBe(true);
|
||||
expect(inventory.some(({ args }) => args.includes("--get-regexp"))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(inventory.some(({ args }) => args.includes("--type=path"))).toBe(
|
||||
true,
|
||||
);
|
||||
const origins = inventory.filter(({ args }) => args.includes("--list"));
|
||||
expect(origins.length).toBeGreaterThan(0);
|
||||
for (const { args } of origins) {
|
||||
expect(args).toContain("--includes");
|
||||
expect(args).toContain("--show-origin");
|
||||
expect(args).toContain("--show-scope");
|
||||
}
|
||||
const lfsLookups = inventory.filter(
|
||||
({ args }) => args.at(-1) === "lfs.storage",
|
||||
);
|
||||
|
||||
@@ -27,7 +27,62 @@ const runCommand: typeof runGitRepositoryCommand = (
|
||||
? "[]"
|
||||
: "https://github.example.test/example/repository/pull/1";
|
||||
|
||||
test.skipIf(process.platform === "win32")(
|
||||
test.each(["issue", "saved"] as const)(
|
||||
"publishes a materialized tracked file outside the sparse checkout for a %s patch",
|
||||
async (mode) => {
|
||||
const { directory, git, remote } = await publicationRepository(fixtures);
|
||||
const outside = join(directory, "outside");
|
||||
const file = join(outside, "finding.ts");
|
||||
await mkdir(outside);
|
||||
await writeFile(file, "original\n");
|
||||
git("add", "outside/finding.ts");
|
||||
git("commit", "-m", "Add tracked source outside the cone");
|
||||
const parent = git("rev-parse", "HEAD");
|
||||
git("sparse-checkout", "set", "--cone", "src");
|
||||
expect(git("ls-files", "-t", "outside/finding.ts")).toBe(
|
||||
"S outside/finding.ts",
|
||||
);
|
||||
await expect(readFile(file)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await mkdir(outside, { recursive: true });
|
||||
await writeFile(file, "original\n");
|
||||
const selection =
|
||||
mode === "issue" ? ["Synthetic issue"] : ["--scan", "scan-1"];
|
||||
const result = await runWorkflow(
|
||||
["patch", ...selection, "--create-pr", "--json"],
|
||||
{
|
||||
currentDirectory: directory,
|
||||
onWorkbench: () =>
|
||||
savedScan(resultWithFindings(["high"]), "scan-1", directory),
|
||||
onRepositoryCommand: runCommand,
|
||||
onCodex: async (_args, output) => {
|
||||
await writeFile(file, "fixed\n");
|
||||
output!.stdout.write(
|
||||
mode === "issue"
|
||||
? "Fixed the issue."
|
||||
: JSON.stringify({
|
||||
patches: [
|
||||
{
|
||||
occurrenceId: "occ_1",
|
||||
status: "verified",
|
||||
files: ["outside/finding.ts"],
|
||||
verification: "Checked the edited file.",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
return 0;
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
const remoteGit = repositoryGit(remote);
|
||||
const tip = remoteGit("for-each-ref", "--format=%(objectname)");
|
||||
expect(remoteGit("show", `${tip}:outside/finding.ts`)).toBe("fixed");
|
||||
expect(remoteGit("rev-parse", `${tip}^`)).toBe(parent);
|
||||
},
|
||||
);
|
||||
|
||||
test.skipIf(process.platform !== "linux")(
|
||||
"publishes both supplied-issue edits when a raw path has a Unicode alias",
|
||||
async () => {
|
||||
const { directory, git, remote } = await publicationRepository(fixtures);
|
||||
|
||||
@@ -518,7 +518,7 @@ describe("scan and patch workflow", () => {
|
||||
] as const)(
|
||||
"completes required patch output (status %i, failure %p)",
|
||||
async (codexStatus, failOutput, expectedStatus) => {
|
||||
const directory = await fixtures.create("patch-required-output-");
|
||||
const { directory } = await createPublicationRepository(fixtures);
|
||||
const report = "Synthetic patch report: café → fixed.\n";
|
||||
const started = Promise.withResolvers<(error?: Error) => void>();
|
||||
const stdout = new Writable({
|
||||
@@ -533,39 +533,39 @@ describe("scan and patch workflow", () => {
|
||||
: undefined;
|
||||
const stderr = capture();
|
||||
let patched = false;
|
||||
let laterCommands = 0;
|
||||
let laterSnapshots = 0;
|
||||
const operation = main(
|
||||
["patch", "Synthetic finding"],
|
||||
stdout,
|
||||
stderr.stream,
|
||||
dependencies({
|
||||
currentDirectory: directory,
|
||||
onCodex: (_args, output) => {
|
||||
onCodex: async (_args, output) => {
|
||||
await writeFile(join(directory, "src/finding-1.ts"), "fixed\n");
|
||||
output?.stdout.write(report);
|
||||
patched = true;
|
||||
return codexStatus;
|
||||
},
|
||||
onRepositoryCommand: (_command, args, _repository, options) => {
|
||||
if (patched) laterCommands++;
|
||||
if (options?.encoding === "base64") return "";
|
||||
if (args.includes("--show-toplevel")) return directory;
|
||||
return args.includes("--name-only") ? "synthetic.ts\0" : "tree";
|
||||
onRepositoryCommand: (command, args, repository, options) => {
|
||||
if (patched && options?.patchSnapshot !== undefined)
|
||||
laterSnapshots++;
|
||||
return runGitRepositoryCommand(command, args, repository, options);
|
||||
},
|
||||
}),
|
||||
);
|
||||
const complete = await started.promise;
|
||||
const commandsBeforeCompletion = laterCommands;
|
||||
const snapshotsBeforeCompletion = laterSnapshots;
|
||||
complete(failOutput ? failure : undefined);
|
||||
expect(await operation).toBe(expectedStatus);
|
||||
expect(commandsBeforeCompletion).toBe(0);
|
||||
expect(await operation, stderr.text()).toBe(expectedStatus);
|
||||
expect(snapshotsBeforeCompletion).toBe(0);
|
||||
expect(patched).toBe(true);
|
||||
if (failOutput) {
|
||||
expect(await emitted).toBe(failure);
|
||||
expect(laterCommands).toBe(0);
|
||||
expect(laterSnapshots).toBe(0);
|
||||
expect(stderr.text()).toContain(failure.message);
|
||||
expect(stderr.text()).not.toContain("Patch applied.");
|
||||
} else {
|
||||
expect(laterCommands).toBeGreaterThan(0);
|
||||
expect(laterSnapshots).toBeGreaterThan(0);
|
||||
expect(stderr.text()).toContain("Patch applied. Files changed: 1.");
|
||||
expect(stdout.writableEnded).toBe(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user