Skip to content

Commit b5ea611

Browse files
committed
fix(server): allow large Git status metadata within review budget
1 parent 826ef55 commit b5ea611

2 files changed

Lines changed: 52 additions & 13 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,43 @@ it.effect("retries a fetch that lost a ref update to another Git process", () =>
16081608
);
16091609

16101610
it.layer(layerTest)("GitVcsDriver core integration", (it) => {
1611+
it.effect("keeps large change sets available for status and commit preparation", () =>
1612+
Effect.gen(function* () {
1613+
const cwd = yield* makeTmpDir();
1614+
const fs = yield* FileSystem.FileSystem;
1615+
const path = yield* Path.Path;
1616+
const driver = yield* GitVcsDriver.GitVcsDriver;
1617+
yield* git(cwd, ["init"]);
1618+
yield* git(cwd, ["config", "user.email", "[email protected]"]);
1619+
yield* git(cwd, ["config", "user.name", "Test"]);
1620+
const files = Array.from(
1621+
{ length: 6_000 },
1622+
(_, index) => `file-${String(index).padStart(5, "0")}-${"x".repeat(160)}.txt`,
1623+
);
1624+
yield* Effect.forEach(files, (file) => fs.writeFileString(path.join(cwd, file), "before\n"), {
1625+
concurrency: 16,
1626+
discard: true,
1627+
});
1628+
yield* git(cwd, ["add", "."]);
1629+
const unborn = yield* driver.statusDetailsLocal(cwd);
1630+
assert.lengthOf(unborn.workingTree.files, files.length);
1631+
assert.equal(unborn.workingTree.insertions, files.length);
1632+
yield* git(cwd, ["commit", "-qm", "initial"]);
1633+
yield* Effect.forEach(files, (file) => fs.writeFileString(path.join(cwd, file), "after\n"), {
1634+
concurrency: 16,
1635+
discard: true,
1636+
});
1637+
const status = yield* driver.statusDetailsLocal(cwd);
1638+
assert.isTrue(status.hasWorkingTreeChanges);
1639+
assert.lengthOf(status.workingTree.files, files.length);
1640+
assert.equal(status.workingTree.insertions, files.length);
1641+
assert.equal(status.workingTree.deletions, files.length);
1642+
const context = yield* driver.prepareCommitContext(cwd, undefined, { includePatch: false });
1643+
assert.isNotNull(context);
1644+
assert.isAbove(context!.stagedSummary.length, 1_000_000);
1645+
assert.lengthOf(context!.stagedSummary.split("\n"), files.length);
1646+
}),
1647+
);
16111648
describe("process environment", () => {
16121649
it.effect("preserves the caller locale for general Git subprocesses", () =>
16131650
Effect.gen(function* () {

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
20472047
statusArgs,
20482048
{
20492049
allowNonZeroExit: true,
2050+
maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES,
20502051
},
20512052
).pipe(
20522053
Effect.catchTags({
@@ -2088,24 +2089,25 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
20882089
"GitVcsDriver.statusDetails.numstat",
20892090
cwd,
20902091
["diff-index", "-M", "--numstat", "-z", "HEAD", "--"],
2091-
{ allowNonZeroExit: true },
2092+
{ allowNonZeroExit: true, maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
20922093
).pipe(
20932094
Effect.flatMap((result) => {
20942095
if (result.exitCode === 0) return Effect.succeed(parseReviewNumstat(result.stdout));
20952096
if (isUnbornHeadStderr(result.stderr)) {
20962097
return Effect.map(
20972098
Effect.all([
2098-
runGitStdout("GitVcsDriver.statusDetails.numstat.unborn", cwd, [
2099-
"diff-files",
2100-
"--numstat",
2101-
"-z",
2102-
]),
2103-
runGitStdout("GitVcsDriver.statusDetails.numstat.unborn.staged", cwd, [
2104-
"diff",
2105-
"--cached",
2106-
"--numstat",
2107-
"-z",
2108-
]),
2099+
runGitStdoutWithOptions(
2100+
"GitVcsDriver.statusDetails.numstat.unborn",
2101+
cwd,
2102+
["diff-files", "--numstat", "-z"],
2103+
{ maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
2104+
),
2105+
runGitStdoutWithOptions(
2106+
"GitVcsDriver.statusDetails.numstat.unborn.staged",
2107+
cwd,
2108+
["diff", "--cached", "--numstat", "-z"],
2109+
{ maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
2110+
),
21092111
]),
21102112
([unstagedStdout, stagedStdout]) => [
21112113
...parseReviewNumstat(stagedStdout),
@@ -2395,7 +2397,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
23952397
"GitVcsDriver.prepareCommitContext.stagedSummary",
23962398
cwd,
23972399
["diff", "--cached", "--name-status"],
2398-
{ env },
2400+
{ env, maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES },
23992401
).pipe(Effect.map((stdout) => stdout.trim()));
24002402
if (stagedSummary.length === 0) {
24012403
return null;

0 commit comments

Comments
 (0)