From ff03f24b8990920820c3a5c82e0f04030b12cabc Mon Sep 17 00:00:00 2001 From: Lakshmi Tanmay Date: Tue, 20 Oct 2026 00:19:27 +0530 Subject: [PATCH] fix(server): avoid expensive diff minimization in status refreshes --- apps/server/src/vcs/GitVcsDriverCore.test.ts | 48 ++++++++++++++++++++ apps/server/src/vcs/GitVcsDriverCore.ts | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts index f797cc7f1451..59eb6185c182 100644 --- a/apps/server/src/vcs/GitVcsDriverCore.test.ts +++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts @@ -2569,6 +2569,54 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => { }), ); + it.effect("reads Changes totals without minimizing and keeps review diffs minimal", () => + Effect.gen(function* () { + const cwd = yield* makeTmpDir(); + const { initialBranch } = yield* initRepoWithCommit(cwd); + const driver = yield* GitVcsDriver.GitVcsDriver; + yield* git(cwd, ["config", "diff.algorithm", "myers"]); + // Repeated lines make the default and minimal algorithms choose different edits. + const lines = Array.from({ length: 2000 }, (_, index) => index); + yield* writeTextFile( + cwd, + "repeated.txt", + lines.map((index) => `${(index ^ (index >> 3)) % 16}\n`).join(""), + ); + yield* git(cwd, ["add", "."]); + yield* git(cwd, ["commit", "-m", "repeated lines"]); + yield* git(cwd, ["checkout", "-b", "feature/totals"]); + yield* writeTextFile( + cwd, + "repeated.txt", + lines.map((index) => `${(index ^ (index >> 5)) % 16}\n`).join(""), + ); + const defaultStat = yield* git(cwd, ["diff", "--numstat", "HEAD", "--"]); + const minimalStat = yield* git(cwd, ["diff", "--minimal", "--numstat", "HEAD", "--"]); + assert.notEqual(defaultStat, minimalStat); + const [insertions, deletions] = defaultStat.split("\t"); + const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true }); + assert.deepStrictEqual(status.branchChanges, { + baseRef: initialBranch, + insertions: Number(insertions), + deletions: Number(deletions), + }); + + const [additions, removals] = minimalStat.split("\t"); + const preview = yield* driver.getReviewDiffPreview({ cwd }); + assert.deepStrictEqual( + preview.sources.find((source) => source.kind === "branch-range")!.files, + [ + { + path: "repeated.txt", + previousPath: null, + additions: Number(additions), + deletions: Number(removals), + }, + ], + ); + }), + ); + it.effect("reads Changes totals with untracked files when requested", () => Effect.gen(function* () { const cwd = yield* makeTmpDir(); diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts index f3120f5ebefd..b52a6bfea310 100644 --- a/apps/server/src/vcs/GitVcsDriverCore.ts +++ b/apps/server/src/vcs/GitVcsDriverCore.ts @@ -73,7 +73,6 @@ const REVIEW_DIFF_ARGS = [ "--no-color", "--no-ext-diff", "--no-textconv", - "--minimal", ...PATCH_RENDER_PREFIX_ARGS, ]; const STATUS_UPSTREAM_REFRESH_INTERVAL = Duration.seconds(15); @@ -2863,6 +2862,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* const diffArgs = [ ...REVIEW_DIFF_ARGS, + "--minimal", ...(input.ignoreWhitespace ? ["--ignore-all-space"] : []), ]; const readStats = Effect.fn("GitVcsDriver.getReviewDiffPreview.stat")(function* (