authorgravatar for saiansh2525@gmail.comYash Singh <saiansh2525@gmail.com> 2026-09-22 19:40:40-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-22 19:40:40-05:00
logf22331240ed1a97fae560e314bffb75fe39db8ca
treef6b8bb582f8ff130b223703aaee373e3a6bb3107
parent5821b778fd29e9c5b6945f4e7150f92d19a0a3da
signature Signed by PGP key B5690EEEBB952194

fix(server): generate PR diffs from branch changes (#13170)


2 files changed, 22 insertions(+), 5 deletions(-)

apps/server/src/git/GitManager.test.ts+16-1
...@@ -4071,7 +4071,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {...@@ -4071,7 +4071,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
4071 }),4071 }),
4072 );4072 );
40734073
4074 it.effect("generates PR content against the remote base when the local base is stale", () =>4074 it.effect("generates PR content from branch changes when the remote base advances", () =>
4075 Effect.gen(function* () {4075 Effect.gen(function* () {
4076 const repoDir = yield* makeTempDir("t3code-git-manager-");4076 const repoDir = yield* makeTempDir("t3code-git-manager-");
4077 yield* initRepo(repoDir);4077 yield* initRepo(repoDir);
...@@ -4103,7 +4103,15 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {...@@ -4103,7 +4103,15 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
4103 yield* runGit(repoDir, ["push", "-u", "origin", "feature/remote-base"]);4103 yield* runGit(repoDir, ["push", "-u", "origin", "feature/remote-base"]);
4104 yield* runGit(repoDir, ["config", "branch.feature/remote-base.gh-merge-base", "main"]);4104 yield* runGit(repoDir, ["config", "branch.feature/remote-base.gh-merge-base", "main"]);
41054105
4106 NodeFS.writeFileSync(NodePath.join(peerDir, "later-main.txt"), "unrelated\n");
4107 yield* runGit(peerDir, ["add", "later-main.txt"]);
4108 yield* runGit(peerDir, ["commit", "-m", "Later main commit"]);
4109 yield* runGit(peerDir, ["push", "origin", "main"]);
4110 yield* runGit(repoDir, ["fetch", "origin"]);
4111
4106 let generatedCommitSummary = "";4112 let generatedCommitSummary = "";
4113 let generatedDiffSummary = "";
4114 let generatedDiffPatch = "";
4107 const { manager } = yield* makeManager({4115 const { manager } = yield* makeManager({
4108 ghScenario: {4116 ghScenario: {
4109 prListSequence: ["[]", "[]"],4117 prListSequence: ["[]", "[]"],
...@@ -4111,6 +4119,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {...@@ -4111,6 +4119,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
4111 textGeneration: {4119 textGeneration: {
4112 generatePrContent: (input) => {4120 generatePrContent: (input) => {
4113 generatedCommitSummary = input.commitSummary;4121 generatedCommitSummary = input.commitSummary;
4122 generatedDiffSummary = input.diffSummary;
4123 generatedDiffPatch = input.diffPatch;
4114 return Effect.succeed({ title: "Feature PR", body: "Feature body" });4124 return Effect.succeed({ title: "Feature PR", body: "Feature body" });
4115 },4125 },
4116 },4126 },
...@@ -4124,6 +4134,11 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {...@@ -4124,6 +4134,11 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
4124 expect(result.pr.status).toBe("created");4134 expect(result.pr.status).toBe("created");
4125 expect(generatedCommitSummary).toContain("Feature commit");4135 expect(generatedCommitSummary).toContain("Feature commit");
4126 expect(generatedCommitSummary).not.toContain("Remote base commit");4136 expect(generatedCommitSummary).not.toContain("Remote base commit");
4137 expect(generatedCommitSummary).not.toContain("Later main commit");
4138 expect(generatedDiffSummary).toContain("feature.txt");
4139 expect(generatedDiffSummary).not.toContain("later-main.txt");
4140 expect(generatedDiffPatch).toContain("feature.txt");
4141 expect(generatedDiffPatch).not.toContain("later-main.txt");
4127 }),4142 }),
4128 );4143 );
41294144
apps/server/src/vcs/GitVcsDriverCore.ts+6-4
...@@ -2285,13 +2285,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*...@@ -2285,13 +2285,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2285 const readRangeContext: GitVcsDriver.GitVcsDriver["Service"]["readRangeContext"] = Effect.fn(2285 const readRangeContext: GitVcsDriver.GitVcsDriver["Service"]["readRangeContext"] = Effect.fn(
2286 "readRangeContext",2286 "readRangeContext",
2287 )(function* (cwd, baseRef) {2287 )(function* (cwd, baseRef) {
2288 const range = `${baseRef}..HEAD`;2288 const commitRange = `${baseRef}..HEAD`;
2289 // PR diffs start at the common ancestor when the base branch has advanced.
2290 const diffRange = `${baseRef}...HEAD`;
2289 const [commitSummary, diffSummary, diffPatch] = yield* Effect.all(2291 const [commitSummary, diffSummary, diffPatch] = yield* Effect.all(
2290 [2292 [
2291 runGitStdoutWithOptions(2293 runGitStdoutWithOptions(
2292 "GitVcsDriver.readRangeContext.log",2294 "GitVcsDriver.readRangeContext.log",
2293 cwd,2295 cwd,
2294 ["log", "--oneline", range],2296 ["log", "--oneline", commitRange],
2295 {2297 {
2296 maxOutputBytes: RANGE_COMMIT_SUMMARY_MAX_OUTPUT_BYTES,2298 maxOutputBytes: RANGE_COMMIT_SUMMARY_MAX_OUTPUT_BYTES,
2297 appendTruncationMarker: true,2299 appendTruncationMarker: true,
...@@ -2300,7 +2302,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*...@@ -2300,7 +2302,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2300 runGitStdoutWithOptions(2302 runGitStdoutWithOptions(
2301 "GitVcsDriver.readRangeContext.diffStat",2303 "GitVcsDriver.readRangeContext.diffStat",
2302 cwd,2304 cwd,
2303 ["diff", "--stat", range],2305 ["diff", "--stat", diffRange],
2304 {2306 {
2305 maxOutputBytes: RANGE_DIFF_SUMMARY_MAX_OUTPUT_BYTES,2307 maxOutputBytes: RANGE_DIFF_SUMMARY_MAX_OUTPUT_BYTES,
2306 appendTruncationMarker: true,2308 appendTruncationMarker: true,
...@@ -2309,7 +2311,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*...@@ -2309,7 +2311,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2309 runGitStdoutWithOptions(2311 runGitStdoutWithOptions(
2310 "GitVcsDriver.readRangeContext.diffPatch",2312 "GitVcsDriver.readRangeContext.diffPatch",
2311 cwd,2313 cwd,
2312 ["diff", "--no-ext-diff", "--patch", "--minimal", range],2314 ["diff", "--no-ext-diff", "--patch", "--minimal", diffRange],
2313 {2315 {
2314 maxOutputBytes: RANGE_DIFF_PATCH_MAX_OUTPUT_BYTES,2316 maxOutputBytes: RANGE_DIFF_PATCH_MAX_OUTPUT_BYTES,
2315 appendTruncationMarker: true,2317 appendTruncationMarker: true,