Skip to content

Commit c2e999d

Browse files
committed
fix(server): preserve measured checkpoint output limit errors
Use the existing process error mode for numstat requests. Keep output truncation as the default for other VCS calls. Created with GPT-6 Astra (preview) in Codex.
1 parent a489c74 commit c2e999d

4 files changed

Lines changed: 31 additions & 48 deletions

File tree

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

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as PlatformError from "effect/PlatformError";
77
import { ChildProcessSpawner } from "effect/unstable/process";
88
import { assert, it } from "@effect/vitest";
99

10-
import { CheckpointRef, GitCommandError } from "@t3tools/contracts";
10+
import { GitCommandError } from "@t3tools/contracts";
1111
import * as ServerConfig from "../config.ts";
1212
import * as GitVcsDriver from "./GitVcsDriver.ts";
1313
import * as VcsProcess from "./VcsProcess.ts";
@@ -68,6 +68,7 @@ runVcsDriverContractSuite<GitVcsDriver.GitVcsDriver, GitContractError>({
6868
it.effect("GitVcsDriver forwards execute env to the VCS process", () => {
6969
let observedEnv: NodeJS.ProcessEnv | undefined;
7070
let observedAppendTruncationMarker: boolean | undefined;
71+
let observedOutputMode: VcsProcess.VcsProcessInput["outputMode"];
7172

7273
return Effect.gen(function* () {
7374
const driver = yield* GitVcsDriver.makeVcsDriverShape();
@@ -80,12 +81,14 @@ it.effect("GitVcsDriver forwards execute env to the VCS process", () => {
8081
GIT_INDEX_FILE: "/tmp/t3-index",
8182
},
8283
appendTruncationMarker: true,
84+
outputMode: "error",
8385
});
8486

8587
assert.deepStrictEqual(observedEnv, {
8688
GIT_INDEX_FILE: "/tmp/t3-index",
8789
});
8890
assert.strictEqual(observedAppendTruncationMarker, true);
91+
assert.strictEqual(observedOutputMode, "error");
8992
}).pipe(
9093
Effect.provide(
9194
Layer.mergeAll(
@@ -95,6 +98,7 @@ it.effect("GitVcsDriver forwards execute env to the VCS process", () => {
9598
Effect.sync(() => {
9699
observedEnv = input.env;
97100
observedAppendTruncationMarker = input.appendTruncationMarker;
101+
observedOutputMode = input.outputMode;
98102
return {
99103
exitCode: ChildProcessSpawner.ExitCode(0),
100104
stdout: "",
@@ -108,37 +112,3 @@ it.effect("GitVcsDriver forwards execute env to the VCS process", () => {
108112
),
109113
);
110114
});
111-
112-
it.effect("rejects truncated checkpoint numstat instead of returning a partial file list", () =>
113-
Effect.gen(function* () {
114-
const driver = yield* GitVcsDriver.makeVcsDriverShape();
115-
116-
const error = yield* Effect.flip(
117-
driver.checkpoints.diffCheckpoints({
118-
cwd: "/repo",
119-
fromCheckpointRef: CheckpointRef.make("refs/t3/checkpoints/from"),
120-
toCheckpointRef: CheckpointRef.make("refs/t3/checkpoints/to"),
121-
ignoreWhitespace: false,
122-
format: "numstat",
123-
}),
124-
);
125-
126-
assert.strictEqual(error._tag, "VcsProcessOutputReadError");
127-
}).pipe(
128-
Effect.provide(
129-
Layer.mergeAll(
130-
NodeServices.layer,
131-
Layer.mock(VcsProcess.VcsProcess)({
132-
run: () =>
133-
Effect.succeed({
134-
exitCode: ChildProcessSpawner.ExitCode(0),
135-
stdout: ["1\t0\tfirst.txt", "2\t0\tlast"].join("\0"),
136-
stderr: "",
137-
stdoutTruncated: true,
138-
stderrTruncated: false,
139-
}),
140-
}),
141-
),
142-
),
143-
),
144-
);

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ChildProcessSpawner } from "effect/unstable/process";
1212
import {
1313
GitCommandError,
1414
VcsProcessExitError,
15-
VcsProcessOutputReadError,
1615
type VcsSwitchRefInput,
1716
type VcsSwitchRefResult,
1817
type VcsCreateRefInput,
@@ -432,6 +431,7 @@ const gitCommand = (
432431
readonly allowNonZeroExit?: boolean;
433432
readonly timeoutMs?: number;
434433
readonly maxOutputBytes?: number;
434+
readonly outputMode?: VcsProcess.VcsProcessInput["outputMode"];
435435
readonly appendTruncationMarker?: boolean;
436436
},
437437
) =>
@@ -448,6 +448,7 @@ const gitCommand = (
448448
: {}),
449449
...(options?.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
450450
...(options?.maxOutputBytes !== undefined ? { maxOutputBytes: options.maxOutputBytes } : {}),
451+
...(options?.outputMode !== undefined ? { outputMode: options.outputMode } : {}),
451452
...(options?.appendTruncationMarker !== undefined
452453
? { appendTruncationMarker: options.appendTruncationMarker }
453454
: {}),
@@ -486,6 +487,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
486487
...(input.allowNonZeroExit !== undefined ? { allowNonZeroExit: input.allowNonZeroExit } : {}),
487488
...(input.timeoutMs !== undefined ? { timeoutMs: input.timeoutMs } : {}),
488489
...(input.maxOutputBytes !== undefined ? { maxOutputBytes: input.maxOutputBytes } : {}),
490+
...(input.outputMode !== undefined ? { outputMode: input.outputMode } : {}),
489491
...(input.appendTruncationMarker !== undefined
490492
? { appendTruncationMarker: input.appendTruncationMarker }
491493
: {}),
@@ -882,6 +884,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
882884
],
883885
allowNonZeroExit: true,
884886
maxOutputBytes: CHECKPOINT_DIFF_MAX_OUTPUT_BYTES,
887+
outputMode: input.format === "numstat" ? "error" : "truncate",
885888
});
886889

887890
if (result.exitCode !== 0) {
@@ -894,16 +897,6 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
894897
});
895898
}
896899

897-
if (input.format === "numstat" && result.stdoutTruncated) {
898-
return yield* new VcsProcessOutputReadError({
899-
operation,
900-
command: "git diff",
901-
cwd: input.cwd,
902-
stream: "stdout",
903-
cause: new Error("Checkpoint numstat output was truncated."),
904-
});
905-
}
906-
907900
return result.stdout;
908901
}),
909902

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
2-
import { describe, expect, it } from "@effect/vitest";
2+
import { assert, describe, expect, it } from "@effect/vitest";
3+
import { HostProcessWorkingDirectory } from "@t3tools/shared/hostProcess";
34
import * as Duration from "effect/Duration";
45
import * as Deferred from "effect/Deferred";
56
import * as Effect from "effect/Effect";
@@ -359,6 +360,24 @@ describe("VcsProcess.run", () => {
359360
}).pipe(provideLive),
360361
);
361362

363+
it.effect("fails with measured byte counts when output must not be truncated", () =>
364+
Effect.gen(function* () {
365+
const error = yield* run({
366+
operation: "test.output-limit",
367+
command: "node",
368+
args: ["-e", "process.stdout.write('x'.repeat(2048))"],
369+
cwd: yield* HostProcessWorkingDirectory,
370+
maxOutputBytes: 128,
371+
outputMode: "error",
372+
}).pipe(Effect.flip);
373+
374+
assert(error._tag === "VcsProcessOutputLimitError");
375+
expect(error.stream).toBe("stdout");
376+
expect(error.maxBytes).toBe(128);
377+
expect(error.observedBytes).toBeGreaterThan(error.maxBytes);
378+
}).pipe(provideLive),
379+
);
380+
362381
it.effect("fails with VcsProcessTimeoutError on timeout", () =>
363382
Effect.gen(function* () {
364383
const errorFiber = yield* run({

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface VcsProcessInput {
2929
readonly allowNonZeroExit?: boolean;
3030
readonly timeoutMs?: number;
3131
readonly maxOutputBytes?: number;
32+
readonly outputMode?: ProcessRunner.ProcessRunInput["outputMode"];
3233
readonly appendTruncationMarker?: boolean;
3334
}
3435

@@ -125,7 +126,7 @@ export const make = Effect.gen(function* () {
125126
...(input.env !== undefined ? { env: input.env } : {}),
126127
timeout: input.timeoutMs ?? DEFAULT_TIMEOUT_MS,
127128
maxOutputBytes: input.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES,
128-
outputMode: "truncate",
129+
outputMode: input.outputMode ?? "truncate",
129130
truncatedMarker: input.appendTruncationMarker ? OUTPUT_TRUNCATED_MARKER : "",
130131
timeoutBehavior: "error",
131132
})

0 commit comments

Comments
 (0)