Skip to content

Commit 51fd066

Browse files
ScottN-PVclaude
andcommitted
fix(server): a pull that fast-forwards no longer fails on large Git output
pullCurrentBranch ran git pull with the default 1 MB output cap and no truncation, so a large fast-forward's diffstat failed the command after the pull had already applied. The pull's output is never read; success comes from HEAD before and after. It now drains and bounds the output instead of failing on it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 29980a3 commit 51fd066

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,91 @@ it.effect("coalesces concurrent ref pages into one repository snapshot", () =>
496496
).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
497497
);
498498

499+
describe("pull output beyond the output cap", () => {
500+
// A fast-forward that prints over 1 MB takes thousands of files, so the real pull's output is
501+
// padded past the cap instead.
502+
const withPaddedPull = (stream: "stdout" | "stderr") =>
503+
Effect.gen(function* () {
504+
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
505+
const padding = new Uint8Array(1_000_001).fill(0x20);
506+
const paddingSpawner = ChildProcessSpawner.make((command) =>
507+
Effect.gen(function* () {
508+
const handle = yield* delegate.spawn(command);
509+
const isPull =
510+
ChildProcess.isStandardCommand(command) &&
511+
command.args.includes("pull") &&
512+
command.args.includes("--ff-only");
513+
return isPull
514+
? ChildProcessSpawner.makeHandle({
515+
...handle,
516+
[stream]: Stream.concat(handle[stream], Stream.make(padding)),
517+
})
518+
: handle;
519+
}),
520+
);
521+
return yield* makeGitVcsDriverCore().pipe(
522+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, paddingSpawner),
523+
);
524+
});
525+
526+
const cloneBehindRemote = Effect.gen(function* () {
527+
const cwd = yield* makeTmpDir();
528+
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
529+
const updater = yield* makeTmpDir("git-vcs-driver-updater-");
530+
const { initialBranch } = yield* initRepoWithCommit(cwd);
531+
yield* git(remote, ["init", "--bare"]);
532+
yield* git(cwd, ["remote", "add", "origin", remote]);
533+
yield* git(cwd, ["push", "-u", "origin", initialBranch]);
534+
yield* git(updater, ["clone", remote, "."]);
535+
yield* git(updater, ["config", "user.email", "[email protected]"]);
536+
yield* git(updater, ["config", "user.name", "Test"]);
537+
yield* writeTextFile(updater, "remote.txt", "remote\n");
538+
yield* git(updater, ["add", "remote.txt"]);
539+
yield* git(updater, ["commit", "-m", "remote commit"]);
540+
yield* git(updater, ["push", "origin", initialBranch]);
541+
return { cwd, remoteHead: yield* git(updater, ["rev-parse", "HEAD"]) };
542+
});
543+
544+
it.effect.each(["stdout", "stderr"] as const)(
545+
"reports a fast-forward whose %s passes the cap as pulled",
546+
(stream) =>
547+
Effect.scoped(
548+
Effect.gen(function* () {
549+
const driver = yield* withPaddedPull(stream);
550+
yield* Effect.gen(function* () {
551+
const { cwd, remoteHead } = yield* cloneBehindRemote;
552+
553+
const result = yield* driver.pullCurrentBranch(cwd);
554+
555+
assert.equal(result.status, "pulled");
556+
assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), remoteHead);
557+
}).pipe(Effect.provideService(GitVcsDriver.GitVcsDriver, driver));
558+
}),
559+
).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
560+
);
561+
562+
it.effect("still fails a pull that Git rejects, whatever its output size", () =>
563+
Effect.scoped(
564+
Effect.gen(function* () {
565+
const driver = yield* withPaddedPull("stderr");
566+
yield* Effect.gen(function* () {
567+
const { cwd } = yield* cloneBehindRemote;
568+
// A local commit the remote lacks: `pull --ff-only` cannot fast-forward and exits 128.
569+
yield* writeTextFile(cwd, "local.txt", "local\n");
570+
yield* git(cwd, ["add", "local.txt"]);
571+
yield* git(cwd, ["commit", "-m", "local commit"]);
572+
573+
const error = yield* Effect.flip(driver.pullCurrentBranch(cwd));
574+
575+
assert.equal(error.operation, "GitVcsDriver.pullCurrentBranch.pull");
576+
assert.equal(error.exitCode, 128);
577+
assert.notInclude(error.detail, "exceeded");
578+
}).pipe(Effect.provideService(GitVcsDriver.GitVcsDriver, driver));
579+
}),
580+
).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
581+
);
582+
});
583+
499584
it.effect("retries an in-flight ref snapshot invalidated by a mutation", () =>
500585
Effect.scoped(
501586
Effect.gen(function* () {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,9 +2512,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
25122512
["rev-parse", "HEAD"],
25132513
true,
25142514
).pipe(Effect.map((stdout) => stdout.trim()));
2515+
// After a successful pull, HEAD before and after decides the result, so its output is not
2516+
// needed. A large fast-forward's diffstat can exceed the output cap, which must not fail a
2517+
// pull Git applied.
25152518
yield* executeGit("GitVcsDriver.pullCurrentBranch.pull", cwd, ["pull", "--ff-only"], {
25162519
timeoutMs: 30_000,
25172520
fallbackErrorDetail: "git pull failed",
2521+
appendTruncationMarker: true,
25182522
});
25192523
const afterSha = yield* runGitStdout(
25202524
"GitVcsDriver.pullCurrentBranch.afterSha",

0 commit comments

Comments
 (0)