fix(FN-2855): scope task diff base to baseCommitSha when branch is null

When a dependency task merges and its branch is deleted, self-healing nulls
the dependent task's baseBranch. Both resolveDiffBase (dashboard) and
resolveTaskDiffBaseRef (merger) defaulted to "main" in that case, widening
the diff range to merge-base(HEAD, main) and surfacing unrelated history —
e.g. FN-2855 reported 108 changed files instead of 16. Skip the merge-base
step when baseBranch is unset and a baseCommitSha is recorded; fall back to
"main" only for legacy tasks lacking both hints.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-28 07:44:04 -07:00
parent 0f40d96e50
commit 49e8da1961
3 changed files with 59 additions and 20 deletions

View File

@@ -60,17 +60,24 @@ export async function resolveDiffBase(
headRef = "HEAD",
runGit: (args: string[], cwd?: string, timeout?: number) => Promise<string> = runGitCommand,
): Promise<string | undefined> {
const baseBranch = task.baseBranch ?? "main";
// When baseBranch was nulled (e.g., upstream dep merged and its branch was
// deleted) but a task-scoped baseCommitSha is still recorded, skip the
// merge-base step so we don't widen the diff range to merge-base(HEAD, main)
// and surface unrelated history. Only fall back to "main" when neither hint
// is available (legacy tasks).
const baseBranch = task.baseBranch?.trim() || (task.baseCommitSha ? undefined : "main");
let mergeBase: string | undefined;
try {
if (baseBranch) {
try {
mergeBase = (await runGit(["merge-base", headRef, baseBranch], cwd, 5000)).trim() || undefined;
try {
mergeBase = (await runGit(["merge-base", headRef, baseBranch], cwd, 5000)).trim() || undefined;
} catch {
mergeBase = (await runGit(["merge-base", headRef, `origin/${baseBranch}`], cwd, 5000)).trim() || undefined;
}
} catch {
mergeBase = (await runGit(["merge-base", headRef, `origin/${baseBranch}`], cwd, 5000)).trim() || undefined;
// base branch may no longer exist locally/remotely
}
} catch {
// base branch may no longer exist locally/remotely
}
// If merge-base equals headRef, the live merge-base would produce an empty