Skip to content

Commit b0d2a8f

Browse files
fix(server): untracked byte budget counts only files the review index adds
A staged deletion whose file is still on disk is left out of the temporary index, so its size no longer suppresses otherwise valid Changes totals. AI-assisted; verified with the tests and tools listed above.
1 parent 8162895 commit b0d2a8f

2 files changed

Lines changed: 40 additions & 14 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,6 +4029,30 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
40294029
}).pipe(Effect.provide(layerServerConfig)),
40304030
);
40314031

4032+
it.effect("counts totals when a large unstaged copy of a removed file stays on disk", () =>
4033+
Effect.gen(function* () {
4034+
const cwd = yield* makeTmpDir();
4035+
yield* initRepoWithCommit(cwd);
4036+
const driver = yield* GitVcsDriver.GitVcsDriver;
4037+
const fileSystem = yield* FileSystem.FileSystem;
4038+
const pathService = yield* Path.Path;
4039+
yield* writeTextFile(cwd, "asset.data", "old\n");
4040+
yield* git(cwd, ["add", "asset.data"]);
4041+
yield* git(cwd, ["commit", "-m", "add asset"]);
4042+
yield* git(cwd, ["rm", "--cached", "asset.data"]);
4043+
yield* fileSystem.truncate(pathService.join(cwd, "asset.data"), 257 * 1024 * 1024);
4044+
yield* writeTextFile(cwd, "ordinary.txt", "new\n");
4045+
4046+
const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
4047+
4048+
assert.deepStrictEqual(status.branchChanges, {
4049+
baseRef: null,
4050+
insertions: 1,
4051+
deletions: 1,
4052+
});
4053+
}),
4054+
);
4055+
40324056
it.effect("reports changes to a file named HEAD", () =>
40334057
Effect.gen(function* () {
40344058
const cwd = yield* makeTmpDir();

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,6 +3131,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31313131
const prepareReviewIndex = Effect.fn("prepareReviewIndex")(function* (
31323132
cwd: string,
31333133
untrackedPaths: ReadonlyArray<string>,
3134+
maxBytes?: number,
31343135
) {
31353136
const [stagedDeletionsStdout, indexValue] = yield* Effect.all(
31363137
[
@@ -3160,6 +3161,19 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31603161
const stagedDeletions = new Set(stagedDeletionsStdout.split("\0").filter(Boolean));
31613162
const pathsToAdd = untrackedPaths.filter((relativePath) => !stagedDeletions.has(relativePath));
31623163
if (pathsToAdd.length === 0) return undefined;
3164+
if (maxBytes !== undefined) {
3165+
const sizes = yield* Effect.forEach(
3166+
pathsToAdd,
3167+
(relativePath) =>
3168+
fileSystem.lstat(path.resolve(cwd, relativePath)).pipe(
3169+
Effect.map((info) => (info.type === "File" ? Number(info.size) : 0)),
3170+
Effect.orElseSucceed(() => 0),
3171+
),
3172+
{ concurrency: 16 },
3173+
);
3174+
// null: over the byte budget, so the caller reports totals as unavailable.
3175+
if (sizes.reduce((total, size) => total + size, 0) > maxBytes) return null;
3176+
}
31633177

31643178
const indexPath = path.isAbsolute(indexValue.trim())
31653179
? indexValue.trim()
@@ -3251,20 +3265,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
32513265
if (paths.length === 0) return { env: undefined };
32523266
if (paths.length > REVIEW_UNTRACKED_MAX_FILES)
32533267
return { unavailable: "Too many untracked files to count." };
3254-
if (maxBytes !== undefined) {
3255-
const sizes = yield* Effect.forEach(
3256-
paths,
3257-
(relativePath) =>
3258-
fileSystem.lstat(path.resolve(cwd, relativePath)).pipe(
3259-
Effect.map((info) => (info.type === "File" ? Number(info.size) : 0)),
3260-
Effect.orElseSucceed(() => 0),
3261-
),
3262-
{ concurrency: 16 },
3263-
);
3264-
if (sizes.reduce((total, size) => total + size, 0) > maxBytes)
3265-
return { unavailable: "Untracked files are too large to count." };
3266-
}
3267-
const env = yield* prepareReviewIndex(cwd, paths).pipe(
3268+
const env = yield* prepareReviewIndex(cwd, paths, maxBytes).pipe(
32683269
Effect.catchTags({
32693270
PlatformError: (cause) =>
32703271
Effect.fail(
@@ -3278,6 +3279,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
32783279
),
32793280
}),
32803281
);
3282+
if (env === null) return { unavailable: "Untracked files are too large to count." };
32813283
return { env };
32823284
});
32833285
const prepareUntrackedReviewIndex = (

0 commit comments

Comments
 (0)