Skip to content

Commit 51e5e1f

Browse files
test(server): trim Git output collection tests to two cases
The six-case matrix restated one invariant per callback/cap combination. Keep one parity test (same split UTF-8 and NUL output with and without line callbacks, lines still emitted) and one no-callback cap test, which is the path the onLine guard changes. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 4418aa4 commit 51e5e1f

1 file changed

Lines changed: 62 additions & 86 deletions

File tree

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

Lines changed: 62 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -88,99 +88,75 @@ const makeFailedHandle = (stderr: string) =>
8888
});
8989

9090
describe("Git output collection", () => {
91-
it.effect.each([false, true])(
92-
"preserves chunked UTF-8 and NUL output with callbacks=%s",
93-
(callbacks) =>
94-
Effect.gen(function* () {
95-
const stdout = "a\\b\0雪\nlast ";
96-
const stderr = "Receiving é\r\nUpdating 雪\rdone";
97-
const chunks = (text: string) =>
98-
Stream.fromIterable(
99-
Array.from(new TextEncoder().encode(text), (byte) => Uint8Array.of(byte)),
100-
);
101-
const spawner = ChildProcessSpawner.make(() =>
91+
// Git writes in arbitrary chunk sizes; one byte per chunk splits every
92+
// multibyte character across reads.
93+
const byteChunks = (text: string) =>
94+
Stream.fromIterable(Array.from(new TextEncoder().encode(text), (byte) => Uint8Array.of(byte)));
95+
const makeDriver = (output: { stdout?: string; stderr?: string }) =>
96+
makeGitVcsDriverCore().pipe(
97+
Effect.provideService(
98+
ChildProcessSpawner.ChildProcessSpawner,
99+
ChildProcessSpawner.make(() =>
102100
Effect.succeed(
103101
ChildProcessSpawner.makeHandle({
104102
...makeSuccessfulHandle(""),
105-
stdout: chunks(stdout),
106-
stderr: chunks(stderr),
103+
stdout: byteChunks(output.stdout ?? ""),
104+
stderr: byteChunks(output.stderr ?? ""),
107105
}),
108106
),
109-
);
110-
const driver = yield* makeGitVcsDriverCore().pipe(
111-
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
112-
);
113-
const stdoutLines: string[] = [];
114-
const stderrLines: string[] = [];
115-
const result = yield* driver.execute({
116-
operation: "test.chunkedGitOutput",
117-
cwd: "/repo",
118-
args: ["status"],
119-
...(callbacks
120-
? {
121-
progress: {
122-
onStdoutLine: (line: string) => Effect.sync(() => void stdoutLines.push(line)),
123-
onStderrLine: (line: string) => Effect.sync(() => void stderrLines.push(line)),
124-
},
125-
}
126-
: {}),
127-
});
128-
assert.deepEqual(result, {
129-
exitCode: 0,
130-
stdout,
131-
stderr,
132-
stdoutTruncated: false,
133-
stderrTruncated: false,
134-
});
135-
assert.deepEqual(stdoutLines, callbacks ? ["a\\b\0雪", "last "] : []);
136-
assert.deepEqual(stderrLines, callbacks ? ["Receiving é", "Updating 雪", "done"] : []);
137-
}).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
107+
),
108+
),
109+
);
110+
111+
it.effect("returns the same split UTF-8 and NUL output with and without line callbacks", () =>
112+
Effect.gen(function* () {
113+
const stdout = "a\\b\0雪\nlast ";
114+
const stderr = "Receiving é\r\nUpdating 雪\rdone";
115+
const driver = yield* makeDriver({ stdout, stderr });
116+
const input = { operation: "test.chunkedGitOutput", cwd: "/repo", args: ["status"] };
117+
const expected = {
118+
exitCode: 0,
119+
stdout,
120+
stderr,
121+
stdoutTruncated: false,
122+
stderrTruncated: false,
123+
};
124+
125+
assert.deepEqual(yield* driver.execute(input), expected);
126+
127+
const stdoutLines: string[] = [];
128+
const stderrLines: string[] = [];
129+
const withCallbacks = yield* driver.execute({
130+
...input,
131+
progress: {
132+
onStdoutLine: (line) => Effect.sync(() => void stdoutLines.push(line)),
133+
onStderrLine: (line) => Effect.sync(() => void stderrLines.push(line)),
134+
},
135+
});
136+
assert.deepEqual(withCallbacks, expected);
137+
assert.deepEqual(stdoutLines, ["a\\b\0雪", "last "]);
138+
assert.deepEqual(stderrLines, ["Receiving é", "Updating 雪", "done"]);
139+
}).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
138140
);
139141

140-
it.effect.each([
141-
{ callbacks: false, keep: false },
142-
{ callbacks: false, keep: true },
143-
{ callbacks: true, keep: false },
144-
{ callbacks: true, keep: true },
145-
])(
146-
"preserves byte caps with callbacks=$callbacks and continued callbacks=$keep",
147-
({ callbacks, keep }) =>
148-
Effect.gen(function* () {
149-
const bytes = new TextEncoder().encode("é雪\rdone");
150-
const spawner = ChildProcessSpawner.make(() =>
151-
Effect.succeed(
152-
ChildProcessSpawner.makeHandle({
153-
...makeSuccessfulHandle(""),
154-
stderr: Stream.fromIterable(Array.from(bytes, (byte) => Uint8Array.of(byte))),
155-
}),
156-
),
157-
);
158-
const driver = yield* makeGitVcsDriverCore().pipe(
159-
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
160-
);
161-
const lines: string[] = [];
162-
const input = {
163-
operation: "test.cappedGitOutput",
164-
cwd: "/repo",
165-
args: ["status"],
166-
maxOutputBytes: 3,
167-
keepLineCallbacksAfterTruncation: keep,
168-
...(callbacks
169-
? {
170-
progress: {
171-
onStderrLine: (line: string) => Effect.sync(() => void lines.push(line)),
172-
},
173-
}
174-
: {}),
175-
};
176-
const result = yield* driver.execute({ ...input, appendTruncationMarker: true });
177-
assert.equal(result.stderr, "é\uFFFD");
178-
assert.isTrue(result.stderrTruncated);
179-
assert.deepEqual(lines, callbacks ? (keep ? ["é雪", "done"] : ["é\uFFFD"]) : []);
180-
const error = yield* driver.execute(input).pipe(Effect.flip);
181-
assert.equal(error.outputLength, 4);
182-
assert.include(error.detail, "exceeded 3 bytes");
183-
}).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
142+
it.effect("caps output without line callbacks", () =>
143+
Effect.gen(function* () {
144+
const driver = yield* makeDriver({ stderr: "é雪\rdone" });
145+
const input = {
146+
operation: "test.cappedGitOutput",
147+
cwd: "/repo",
148+
args: ["status"],
149+
maxOutputBytes: 3,
150+
};
151+
152+
const truncated = yield* driver.execute({ ...input, appendTruncationMarker: true });
153+
assert.equal(truncated.stderr, "é\uFFFD");
154+
assert.isTrue(truncated.stderrTruncated);
155+
156+
const error = yield* driver.execute(input).pipe(Effect.flip);
157+
assert.equal(error.outputLength, 4);
158+
assert.include(error.detail, "exceeded 3 bytes");
159+
}).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
184160
);
185161
});
186162

0 commit comments

Comments
 (0)