TypeScript
fix(server): allow large git status metadata (#25207)
maria1e3e3a8dfd87
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.tsindex 47b3f3a62b7..cbc3efcc3b4 100644--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts@@ -1003,6 +1003,45 @@ describe("rejected git refs", () => {});it.layer(layerTest)("GitVcsDriver core integration", (it) => {+ it.effect("keeps large change sets available for status and commit preparation", () =>+ Effect.gen(function* () {+ const cwd = yield* makeTmpDir();+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const driver = yield* GitVcsDriver.GitVcsDriver;+ yield* git(cwd, ["init"]);+ yield* git(cwd, ["config", "user.email", "[email protected]"]);+ yield* git(cwd, ["config", "user.name", "Test"]);+ const files = Array.from(+ { length: 6_000 },+ (_, index) => `file-${String(index).padStart(5, "0")}-${"x".repeat(160)}.txt`,+ );+ yield* Effect.forEach(files, (file) => fs.writeFileString(path.join(cwd, file), "before\n"), {+ concurrency: 16,+ discard: true,+ });+ yield* git(cwd, ["add", "."]);+ const unborn = yield* driver.statusDetailsLocal(cwd);+ assert.lengthOf(unborn.workingTree.files, files.length);+ assert.equal(unborn.workingTree.insertions, files.length);+ const initial = yield* driver.commit(cwd, "initial", "");+ assert.match(initial.commitSha, /^[a-f0-9]{40}$/);+ assert.isFalse((yield* driver.statusDetailsLocal(cwd)).hasWorkingTreeChanges);+ yield* Effect.forEach(files, (file) => fs.writeFileString(path.join(cwd, file), "after\n"), {+ concurrency: 16,+ discard: true,+ });+ const status = yield* driver.statusDetailsLocal(cwd);+ assert.isTrue(status.hasWorkingTreeChanges);+ assert.lengthOf(status.workingTree.files, files.length);+ assert.equal(status.workingTree.insertions, files.length);+ assert.equal(status.workingTree.deletions, files.length);+ const context = yield* driver.prepareCommitContext(cwd, undefined, { includePatch: false });+ assert.isNotNull(context);+ assert.isAbove(context!.stagedSummary.length, 1_000_000);+ assert.lengthOf(context!.stagedSummary.split("\n"), files.length);+ }),+ );describe("structured errors", () => {it.effect("does not retain git arguments or stderr in command failures", () =>Effect.gen(function* () {diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.tsindex 49149d95f58..c486c6744cb 100644--- a/apps/server/src/vcs/GitVcsDriverCore.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.ts@@ -2097,6 +2097,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*statusArgs,{allowNonZeroExit: true,+ maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES,},).pipe(Effect.catchTags({@@ -2137,24 +2138,25 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*"GitVcsDriver.statusDetails.numstat",cwd,["diff-index", "-M", "--numstat", "-z", "HEAD", "--"],- { allowNonZeroExit: true },+ { allowNonZeroExit: true, maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },).pipe(Effect.flatMap((result) => {if (result.exitCode === 0) return Effect.succeed(parseReviewNumstat(result.stdout));if (isUnbornHeadStderr(result.stderr)) {return Effect.map(Effect.all([- runGitStdout("GitVcsDriver.statusDetails.numstat.unborn", cwd, [- "diff-files",- "--numstat",- "-z",- ]),- runGitStdout("GitVcsDriver.statusDetails.numstat.unborn.staged", cwd, [- "diff",- "--cached",- "--numstat",- "-z",- ]),+ runGitStdoutWithOptions(+ "GitVcsDriver.statusDetails.numstat.unborn",+ cwd,+ ["diff-files", "--numstat", "-z"],+ { maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },+ ),+ runGitStdoutWithOptions(+ "GitVcsDriver.statusDetails.numstat.unborn.staged",+ cwd,+ ["diff", "--cached", "--numstat", "-z"],+ { maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },+ ),]),([unstagedStdout, stagedStdout]) => [...parseReviewNumstat(stagedStdout),@@ -2444,7 +2446,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*"GitVcsDriver.prepareCommitContext.stagedSummary",cwd,["diff", "--cached", "--name-status"],- { env },+ { env, maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },).pipe(Effect.map((stdout) => stdout.trim()));if (stagedSummary.length === 0) {return null;@@ -2508,6 +2510,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*options.progress?.onOutputLine?.({ stream: "stderr", text: line }) ?? Effect.void,};yield* executeGit("GitVcsDriver.commit.commit", cwd, args, {+ maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES,...(options?.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),...(progress ? { progress } : {}),}).pipe(Effect.asVoid);