Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,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", "test@test.com"]);
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* () {
Expand Down
29 changes: 16 additions & 13 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
statusArgs,
{
allowNonZeroExit: true,
maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES,
},
).pipe(
Effect.catchTags({
Expand Down Expand Up @@ -2094,24 +2095,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),
Expand Down Expand Up @@ -2401,7 +2403,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;
Expand Down Expand Up @@ -2465,6 +2467,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);
Expand Down
Loading