fix: repair conflict diff check failures
This commit is contained in:
1 parent
57b2c22a00
commit
54fc6ee494
2 files changed
+62
-4
No files matched your search
@@ -164,8 +164,8 @@ export async function resolvePullRequestConflicts(
|
|||||||
await writeKnowledgeScratch(snapshot, knowledge);
|
await writeKnowledgeScratch(snapshot, knowledge);
|
||||||
const beforeAgent = await inventorySnapshot(snapshot);
|
const beforeAgent = await inventorySnapshot(snapshot);
|
||||||
await runGooseAgent(buildConflictPrompt(params, conflictFiles), snapshot);
|
await runGooseAgent(buildConflictPrompt(params, conflictFiles), snapshot);
|
||||||
const afterAgent = await inventorySnapshot(snapshot);
|
let afterAgent = await inventorySnapshot(snapshot);
|
||||||
const agentChanges = diffSnapshotInventories(beforeAgent, afterAgent);
|
let agentChanges = diffSnapshotInventories(beforeAgent, afterAgent);
|
||||||
if (agentChanges.length === 0) {
|
if (agentChanges.length === 0) {
|
||||||
throw new Error("goose did not modify any files while resolving conflicts.");
|
throw new Error("goose did not modify any files while resolving conflicts.");
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,44 @@ export async function resolvePullRequestConflicts(
|
|||||||
if (remaining.length > 0) {
|
if (remaining.length > 0) {
|
||||||
throw new Error(`goose left unresolved conflicts in: ${remaining.join(", ")}`);
|
throw new Error(`goose left unresolved conflicts in: ${remaining.join(", ")}`);
|
||||||
}
|
}
|
||||||
await runCommand("git", ["diff", "--check", "--cached"], worktree, gitEnv);
|
let diffCheck = await runCommandAllowFailure(
|
||||||
|
"git",
|
||||||
|
["diff", "--check", "--cached"],
|
||||||
|
worktree,
|
||||||
|
gitEnv
|
||||||
|
);
|
||||||
|
if (diffCheck.code !== 0) {
|
||||||
|
const previousAgent = afterAgent;
|
||||||
|
await runGooseAgent(buildDiffCheckRepairPrompt(commandFailureOutput(diffCheck)), snapshot);
|
||||||
|
afterAgent = await inventorySnapshot(snapshot);
|
||||||
|
const correctionChanges = diffSnapshotInventories(previousAgent, afterAgent);
|
||||||
|
if (correctionChanges.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
`git diff --check failed and goose did not correct the reported files: ${commandFailureOutput(diffCheck)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await applySnapshotChanges(snapshot, worktree, correctionChanges, afterAgent);
|
||||||
|
await assertConflictMarkersRemoved(worktree, conflictFiles);
|
||||||
|
await runCommand("git", ["add", "-A"], worktree, gitEnv);
|
||||||
|
const remainingAfterCorrection = splitNullSeparated(
|
||||||
|
await runCommand("git", ["diff", "--name-only", "--diff-filter=U", "-z"], worktree, gitEnv)
|
||||||
|
);
|
||||||
|
if (remainingAfterCorrection.length > 0) {
|
||||||
|
throw new Error(
|
||||||
|
`goose reintroduced unresolved conflicts while correcting diff issues: ${remainingAfterCorrection.join(", ")}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
diffCheck = await runCommandAllowFailure(
|
||||||
|
"git",
|
||||||
|
["diff", "--check", "--cached"],
|
||||||
|
worktree,
|
||||||
|
gitEnv
|
||||||
|
);
|
||||||
|
if (diffCheck.code !== 0) {
|
||||||
|
throw new Error(`git diff --check failed after goose correction: ${commandFailureOutput(diffCheck)}`);
|
||||||
|
}
|
||||||
|
agentChanges = diffSnapshotInventories(beforeAgent, afterAgent);
|
||||||
|
}
|
||||||
|
|
||||||
const finalDiff = await runCommand(
|
const finalDiff = await runCommand(
|
||||||
"git",
|
"git",
|
||||||
@@ -333,6 +370,9 @@ export function describeConflictResolutionFailure(error: unknown): string {
|
|||||||
if (message.includes("final goose confirmation rejected") || message.includes("validation command")) {
|
if (message.includes("final goose confirmation rejected") || message.includes("validation command")) {
|
||||||
return "goose produced a candidate resolution, but the configured validation or final safety confirmation rejected it. No commit was pushed.";
|
return "goose produced a candidate resolution, but the configured validation or final safety confirmation rejected it. No commit was pushed.";
|
||||||
}
|
}
|
||||||
|
if (message.includes("git diff --check failed")) {
|
||||||
|
return "The candidate resolution still contained Git whitespace or conflict-marker errors after one automatic correction pass. No commit was pushed.";
|
||||||
|
}
|
||||||
return "goose could not safely complete and validate the conflict resolution. The Actions log contains the exact failure stage, and no commit was pushed.";
|
return "goose could not safely complete and validate the conflict resolution. The Actions log contains the exact failure stage, and no commit was pushed.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,6 +419,16 @@ function buildConflictPrompt(
|
|||||||
].join("\n");
|
].join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildDiffCheckRepairPrompt(checkOutput: string): string {
|
||||||
|
return [
|
||||||
|
"Correct the current conflict-resolution workspace so the host Git diff check passes.",
|
||||||
|
"Change only the files and lines needed to address the reported whitespace or conflict-marker diagnostics. Preserve the resolved behavior and do not add features, refactor unrelated code, or modify repository knowledge.",
|
||||||
|
"Inspect the affected files directly, apply the corrections, and return a concise summary. Do not commit or push.",
|
||||||
|
"Host git diff --check diagnostics:",
|
||||||
|
checkOutput.slice(0, 12_000)
|
||||||
|
].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
async function confirmFinalResolution(input: {
|
async function confirmFinalResolution(input: {
|
||||||
pullNumber: number;
|
pullNumber: number;
|
||||||
baseBranch: string;
|
baseBranch: string;
|
||||||
@@ -576,11 +626,15 @@ async function runCommand(
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const result = await runCommandAllowFailure(command, args, cwd, extraEnv);
|
const result = await runCommandAllowFailure(command, args, cwd, extraEnv);
|
||||||
if (result.code !== 0) {
|
if (result.code !== 0) {
|
||||||
throw new Error(`${command} exited with code ${result.code}: ${result.stderr.trim()}`);
|
throw new Error(`${command} exited with code ${result.code}: ${commandFailureOutput(result)}`);
|
||||||
}
|
}
|
||||||
return result.stdout;
|
return result.stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function commandFailureOutput(result: { stdout: string; stderr: string }): string {
|
||||||
|
return [result.stderr.trim(), result.stdout.trim()].filter(Boolean).join("\n").slice(0, 20_000) || "no output";
|
||||||
|
}
|
||||||
|
|
||||||
async function runCommandAllowFailure(
|
async function runCommandAllowFailure(
|
||||||
command: string,
|
command: string,
|
||||||
args: string[],
|
args: string[],
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ test("conflict failures are actionable without exposing raw command output", ()
|
|||||||
describeConflictResolutionFailure(new Error("Committer identity unknown")),
|
describeConflictResolutionFailure(new Error("Committer identity unknown")),
|
||||||
/no bot committer identity/
|
/no bot committer identity/
|
||||||
);
|
);
|
||||||
|
assert.match(
|
||||||
|
describeConflictResolutionFailure(new Error("git diff --check failed after goose correction")),
|
||||||
|
/automatic correction pass/
|
||||||
|
);
|
||||||
assert.match(
|
assert.match(
|
||||||
describeConflictResolutionFailure(new Error("rejected: stale info")),
|
describeConflictResolutionFailure(new Error("rejected: stale info")),
|
||||||
/Run \/conflict again/
|
/Run \/conflict again/
|
||||||
|
|||||||
Reference in new issue
Block a user