fix: support minimax large multi-hunk patches

This commit is contained in:
Codex
2026-06-03 10:12:16 +00:00
parent 1d542d82b5
commit d012fe9a5e
2 changed files with 116 additions and 12 deletions
@@ -734,6 +734,86 @@ export async function runSshArgvGuidanceContract(): Promise<JsonRecord> {
assertCondition(!largeV2.commands.some((command) => command.includes("write-b64-append")), "v2 should keep the single stdin write as the normal large-file fast path", largeV2.commands);
assertCondition(largeV2.commands.filter((command) => command.startsWith("read-b64-block")).length <= 2, "v2 large-file verified read should use coarse chunks, not many tiny SSH calls", largeV2.commands);
const repeatedLargeLines = Array.from({ length: 1200 }, (_, index) => `repeat target ${String(index).padStart(4, "0")}`);
repeatedLargeLines[899] = "same marker";
repeatedLargeLines[1099] = "same marker";
const unifiedHeaderLineRangeV2 = await applyPatchV2FixtureAttempt([
"*** Begin Patch",
"*** Update File: repeated-large.txt",
"@@ -1100,1 +1100,1 @@",
"-same marker",
"+same marker patched",
"*** End Patch",
"",
].join("\n"), {
"repeated-large.txt": `${repeatedLargeLines.join("\n")}\n`,
}, { stderrOutput: true });
assertCondition(unifiedHeaderLineRangeV2.exitCode === 0 && unifiedHeaderLineRangeV2.error === null, "v2 should accept unified-diff hunk headers with a hint", unifiedHeaderLineRangeV2);
const unifiedLines = unifiedHeaderLineRangeV2.files["repeated-large.txt"]?.split("\n") ?? [];
assertCondition(unifiedLines[899] === "same marker" && unifiedLines[1099] === "same marker patched", "v2 should use unified header old line number to avoid patching the first repeated match", {
line900: unifiedLines[899],
line1100: unifiedLines[1099],
stderr: unifiedHeaderLineRangeV2.stderr,
});
assertCondition(unifiedHeaderLineRangeV2.stderr.includes("accepted unified-diff hunk header in repeated-large.txt"), "v2 unified header compatibility should emit a canonical syntax hint", unifiedHeaderLineRangeV2.stderr);
const manyLines = Array.from({ length: 6200 }, (_, index) => {
if (index === 4) return "HEAD old";
if (index === 3099) return "MIDDLE old";
if (index === 6194) return "TAIL old";
return `ROW-${String(index + 1).padStart(5, "0")} keep`;
});
const largeMultiMixedV2 = await applyPatchV2FixtureAttempt([
"*** Begin Patch",
"*** Update File: big-multi.txt",
"@@ -5,1 +5,1 @@",
"-HEAD old",
"+HEAD new",
"@@ -3100,1 +3100,2 @@",
"-MIDDLE old",
"+MIDDLE new",
"+MIDDLE inserted",
"@@ -6195,1 +6196,1 @@",
"-TAIL old",
"+TAIL new",
"*** Add File: nested/compat-created.txt",
"@@",
"first",
"+ ",
"+last",
"*** Delete File: stale.txt",
"@@",
"-stale",
"*** End Patch",
"",
].join("\n"), {
"big-multi.txt": `${manyLines.join("\n")}\n`,
"stale.txt": "stale\n",
}, { stderrOutput: true });
assertCondition(largeMultiMixedV2.exitCode === 0 && largeMultiMixedV2.error === null, "v2 should apply large multi-hunk mixed compatibility patches", largeMultiMixedV2);
const bigMulti = largeMultiMixedV2.files["big-multi.txt"]?.split("\n") ?? [];
assertCondition(
bigMulti[4] === "HEAD new"
&& bigMulti[3099] === "MIDDLE new"
&& bigMulti[3100] === "MIDDLE inserted"
&& bigMulti[6195] === "TAIL new"
&& bigMulti[0] === "ROW-00001 keep"
&& bigMulti[6200] === "ROW-06200 keep"
&& bigMulti.length === 6202,
"v2 should preserve distant untouched lines while applying multiple large-file hunks",
{ head: bigMulti.slice(0, 6), middle: bigMulti.slice(3098, 3102), tail: bigMulti.slice(6194, 6201) },
);
assertCondition(largeMultiMixedV2.files["nested/compat-created.txt"] === "first\n\nlast\n", "v2 mixed compatibility Add File should preserve intended blank line", largeMultiMixedV2);
assertCondition(largeMultiMixedV2.files["stale.txt"] === undefined, "v2 mixed compatibility Delete File should delete stale files", largeMultiMixedV2);
assertCondition(
largeMultiMixedV2.stderr.includes("accepted unified-diff hunk header in big-multi.txt")
&& largeMultiMixedV2.stderr.includes("accepted MiniMax-style @@ inside Add File nested/compat-created.txt")
&& largeMultiMixedV2.stderr.includes("ignored extra MiniMax-style hunk/body lines after Delete File stale.txt"),
"v2 mixed compatibility patch should emit hints for every non-canonical form",
largeMultiMixedV2.stderr,
);
assertCondition(largeMultiMixedV2.commands.some((command) => command.startsWith("write-b64-stdin big-multi.txt")), "v2 large multi-hunk file should use stdin write path", largeMultiMixedV2.commands);
const multiChunkTailV2 = await applyPatchV2ActualShellFixtureAttempt([
"*** Begin Patch",
"*** Update File: two_chunks.txt",