Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

VcsProcess.test.ts

704 lines24.1 KB

1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, describe, expect, it } from "@effect/vitest";
3import * as HostProcess from "@t3tools/shared/HostProcess";
4import * as Duration from "effect/Duration";
5import * as Deferred from "effect/Deferred";
6import * as Effect from "effect/Effect";
7import * as Exit from "effect/Exit";
8import * as Cause from "effect/Cause";
9import * as Fiber from "effect/Fiber";
10import * as FileSystem from "effect/FileSystem";
11import * as Layer from "effect/Layer";
12import * as Path from "effect/Path";
13import * as Queue from "effect/Queue";
14import * as Ref from "effect/Ref";
15import * as Schema from "effect/Schema";
16import { TestClock } from "effect/testing";
17import { ChildProcessSpawner } from "effect/process";
18​
19import {
20 VcsProcessExitError,
21 VcsProcessSpawnError,
22 VcsProcessTimeoutError,
23} from "@t3tools/contracts";
24import * as ProcessRunner from "../processRunner.ts";
25import * as VcsProcess from "./VcsProcess.ts";
26​
27const encodeExitError = Schema.encodeEffect(Schema.fromJsonString(VcsProcessExitError));
28​
29const run = (input: VcsProcess.VcsProcessInput) =>
30 Effect.gen(function* () {
31 const process = yield* VcsProcess.VcsProcess;
32 return yield* process.run(input);
33 });
34​
35const layerLive = VcsProcess.layer.pipe(Layer.provide(NodeServices.layer));
36​
37const provideLive = <A, E, R>(effect: Effect.Effect<A, E, R | VcsProcess.VcsProcess>) =>
38 effect.pipe(Effect.provide(layerLive));
39​
40const baseInput = {
41 operation: "test.process-boundary",
42 command: "git",
43 args: ["status", "--short"],
44 cwd: "/workspace",
45} satisfies VcsProcess.VcsProcessInput;
46​
47const captureProcessResult = (
48 result: Effect.Effect<ProcessRunner.ProcessRunOutput, ProcessRunner.ProcessRunError>,
49) =>
50 VcsProcess.make.pipe(
51 Effect.provideService(
52 ProcessRunner.ProcessRunner,
53 ProcessRunner.ProcessRunner.of({ run: () => result }),
54 ),
55 Effect.flatMap((service) => service.run(baseInput)),
56 Effect.flip,
57 );
58​
59describe("VcsProcess.run", () => {
60 it.effect.each([
61 { stderr: "fatal: Unable to create '/private/repo/index.lock': File exists", retryable: true },
62 {
63 stderr: "fatal: Unable to create '/private/repo/index.lock': Permission denied",
64 retryable: false,
65 },
66 { stderr: 'error: open("/private/repo/file"): No such file or directory', retryable: true },
67 {
68 stderr: "fatal: unable to stat '/private/repo/file': No such file or directory",
69 retryable: true,
70 },
71 { stderr: 'error: open("/private/repo/file"): Permission denied', retryable: false },
72 {
73 stderr: "error: '/private/repo/child/' does not have a commit checked out",
74 retryable: false,
75 },
76 { stderr: "fatal: index file corrupt", retryable: false },
77 ])(
78 "classifies Git exit retryability without retaining stderr: $stderr",
79 ({ stderr, retryable }) =>
80 Effect.gen(function* () {
81 const error = yield* captureProcessResult(
82 Effect.succeed({
83 stdout: "",
84 stderr,
85 code: ChildProcessSpawner.ExitCode(128),
86 timedOut: false,
87 stdoutTruncated: false,
88 stderrTruncated: false,
89 stdoutInvalidUtf8: false,
90 stderrInvalidUtf8: false,
91 }),
92 );
93 assert.instanceOf(error, VcsProcessExitError);
94 expect(error.retryable === true).toBe(retryable);
95 const encoded = yield* encodeExitError(error);
96 expect(encoded).not.toContain("/private/repo");
97 }),
98 );
99​
100 it.effect.each([
101 {
102 stderr: "fatal: fsync error on '.git/objects/a5/tmp_obj_Pseg66': Operation not supported",
103 fsyncMethods: ["fsync", "writeout-only"],
104 },
105 {
106 stderr:
107 "fatal: update_ref failed for ref 'refs/t3/checkpoints/x': cannot update ref 'refs/t3/checkpoints/x': couldn't write '/Volumes/share/.git/refs/t3/checkpoints/x.lock'",
108 fsyncMethods: ["fsync", "writeout-only"],
109 },
110 { stderr: "fatal: Operation not supported", fsyncMethods: ["fsync"] },
111 {
112 stderr:
113 "fatal: update_ref failed for ref 'refs/t3/checkpoints/x': cannot update ref 'refs/t3/checkpoints/x': couldn't write '/Volumes/share/.git/refs/t3/checkpoints/x.lock': Input/output error",
114 fsyncMethods: ["fsync"],
115 },
116 {
117 stderr: "fatal: fsync error on '.git/objects/a5/tmp_obj_Pseg66': Operation not supported",
118 fsyncMethods: ["fsync", "writeout-only"],
119 fallbackFails: true,
120 },
121 {
122 platform: "linux",
123 stderr: "fatal: fsync error on '.git/objects/a5/tmp_obj_Pseg66': Operation not supported",
124 fsyncMethods: ["fsync"],
125 },
126 {
127 operation: baseInput.operation,
128 stderr: "fatal: fsync error on '.git/objects/a5/tmp_obj_Pseg66': Operation not supported",
129 fsyncMethods: ["fsync"],
130 },
131 ] as const)(
132 "falls back to writeout-only only for unsupported fsync on macOS: $stderr",
133 ({ stderr, fsyncMethods, ...scenario }) =>
134 Effect.gen(function* () {
135 const seen: Array<ReadonlyArray<string>> = [];
136 const service = yield* VcsProcess.make.pipe(
137 Effect.provideService(
138 HostProcess.Platform,
139 "platform" in scenario ? scenario.platform : "darwin",
140 ),
141 Effect.provideService(ProcessRunner.ProcessRunner, {
142 run: (input) =>
143 Effect.sync(() => {
144 seen.push(input.args);
145 const failed =
146 input.args.includes("core.fsyncMethod=fsync") ||
147 ("fallbackFails" in scenario && scenario.fallbackFails);
148 return {
149 stdout: "",
150 stderr: failed ? stderr : "",
151 code: ChildProcessSpawner.ExitCode(failed ? 128 : 0),
152 timedOut: false,
153 stdoutTruncated: false,
154 stderrTruncated: false,
155 stdoutInvalidUtf8: false,
156 stderrInvalidUtf8: false,
157 };
158 }),
159 }),
160 );
161 const exit = yield* service
162 .run({
163 ...baseInput,
164 operation:
165 "operation" in scenario
166 ? scenario.operation
167 : VcsProcess.CHECKPOINT_CAPTURE_OPERATION,
168 args: ["-c", "core.fsync=objects,reference", "-c", "core.fsyncMethod=fsync", "add"],
169 })
170 .pipe(Effect.exit);
171 expect(seen).toEqual(
172 fsyncMethods.map((method) => [
173 "-c",
174 "core.fsync=objects,reference",
175 "-c",
176 `core.fsyncMethod=${method}`,
177 "add",
178 ]),
179 );
180 expect(Exit.isSuccess(exit)).toBe(
181 fsyncMethods.length === 2 && !("fallbackFails" in scenario && scenario.fallbackFails),
182 );
183 if (Exit.isFailure(exit)) {
184 expect(Cause.findErrorOption(exit.cause)).toMatchObject({
185 _tag: "Some",
186 value: { _tag: "VcsProcessExitError", exitCode: 128 },
187 });
188 }
189 }),
190 );
191​
192 it.effect.each(["timeout", "spawn"] as const)(
193 "checkpoint commands do not retry %s failures",
194 (kind) =>
195 Effect.gen(function* () {
196 let attempts = 0;
197 const fields = { command: "git", argumentCount: 2, cwd: "/workspace" };
198 const failure =
199 kind === "timeout"
200 ? new ProcessRunner.ProcessTimeoutError({ ...fields, timeoutMs: 30_000 })
201 : new ProcessRunner.ProcessSpawnError({ ...fields, cause: new Error("spawn failed") });
202 const service = yield* VcsProcess.make.pipe(
203 Effect.provideService(ProcessRunner.ProcessRunner, {
204 run: () =>
205 Effect.sync(() => {
206 attempts += 1;
207 }).pipe(Effect.andThen(Effect.fail(failure))),
208 }),
209 );
210 const error = yield* service
211 .run({
212 ...baseInput,
213 operation: VcsProcess.CHECKPOINT_CAPTURE_OPERATION,
214 })
215 .pipe(Effect.flip);
216 expect(attempts).toBe(1);
217 expect(error._tag).toBe(
218 kind === "timeout" ? "VcsProcessTimeoutError" : "VcsProcessSpawnError",
219 );
220 }),
221 );
222​
223 it.effect.each([
224 {
225 name: "recovers after two lock failures",
226 failures: 2,
227 attempts: 3,
228 transient: true,
229 capture: true,
230 streaming: false,
231 },
232 {
233 name: "bounds persistent lock failures",
234 failures: Infinity,
235 attempts: 3,
236 transient: true,
237 capture: true,
238 streaming: false,
239 },
240 {
241 name: "does not retry unknown exits",
242 failures: Infinity,
243 attempts: 1,
244 transient: false,
245 capture: true,
246 streaming: false,
247 },
248 {
249 name: "leaves other operations unchanged",
250 failures: Infinity,
251 attempts: 1,
252 transient: true,
253 capture: false,
254 streaming: false,
255 },
256 {
257 name: "does not replay stdout callbacks",
258 failures: Infinity,
259 attempts: 1,
260 transient: true,
261 capture: true,
262 streaming: true,
263 },
264 ])(
265 "checkpoint command retry $name",
266 ({ failures, attempts: expectedAttempts, transient, capture, streaming }) =>
267 Effect.gen(function* () {
268 let attempts = 0;
269 const service = yield* VcsProcess.make.pipe(
270 Effect.provideService(ProcessRunner.ProcessRunner, {
271 run: () =>
272 Effect.sync(() => {
273 attempts += 1;
274 return {
275 stdout: "",
276 stderr:
277 attempts > failures
278 ? ""
279 : transient
280 ? "fatal: Unable to create '/repo/index.lock': File exists"
281 : "fatal: index file corrupt",
282 code: ChildProcessSpawner.ExitCode(attempts > failures ? 0 : attempts),
283 timedOut: false,
284 stdoutTruncated: false,
285 stderrTruncated: false,
286 stdoutInvalidUtf8: false,
287 stderrInvalidUtf8: false,
288 };
289 }),
290 }),
291 );
292 const fiber = yield* service
293 .run({
294 ...baseInput,
295 operation: capture ? VcsProcess.CHECKPOINT_CAPTURE_OPERATION : baseInput.operation,
296 ...(streaming ? { onStdoutChunk: () => {} } : {}),
297 })
298 .pipe(Effect.exit, Effect.forkScoped);
299 yield* TestClock.adjust("150 millis");
300 const result = yield* Fiber.join(fiber);
301 expect(attempts).toBe(expectedAttempts);
302 if (failures === Infinity) {
303 if (Exit.isSuccess(result))
304 return yield* Effect.die("Expected a capture command failure");
305 const error = Cause.findErrorOption(result.cause);
306 if (error._tag === "None" || error.value._tag !== "VcsProcessExitError") {
307 return yield* Effect.die("Expected a Git exit error");
308 }
309 expect(error.value.exitCode).toBe(expectedAttempts);
310 } else {
311 expect(Exit.isSuccess(result)).toBe(true);
312 }
313 }),
314 );
315​
316 it.effect("bounds a synthetic burst of GitHub API processes", () =>
317 Effect.gen(function* () {
318 const gate = yield* Deferred.make<void>();
319 const starts = yield* Queue.unbounded<number>();
320 const active = yield* Ref.make(0);
321 const peak = yield* Ref.make(0);
322 const total = yield* Ref.make(0);
323 const service = yield* VcsProcess.make.pipe(
324 Effect.provideService(
325 ProcessRunner.ProcessRunner,
326 ProcessRunner.ProcessRunner.of({
327 run: () =>
328 Effect.gen(function* () {
329 const count = yield* Ref.updateAndGet(active, (held) => held + 1);
330 yield* Ref.update(peak, (held) => Math.max(held, count));
331 yield* Ref.update(total, (held) => held + 1);
332 yield* Queue.offer(starts, count);
333 yield* Deferred.await(gate);
334 return {
335 stdout: "",
336 stderr: "",
337 code: ChildProcessSpawner.ExitCode(0),
338 timedOut: false,
339 stdoutTruncated: false,
340 stderrTruncated: false,
341 stdoutInvalidUtf8: false,
342 stderrInvalidUtf8: false,
343 };
344 }).pipe(Effect.ensuring(Ref.update(active, (count) => count - 1))),
345 }),
346 ),
347 );
348​
349 const burst = yield* Effect.all(
350 Array.from({ length: 32 }, (_, index) =>
351 service.run({
352 operation: `synthetic.github.${index}`,
353 command: "gh",
354 args: ["api", "user"],
355 cwd: "/workspace",
356 }),
357 ),
358 { concurrency: "unbounded" },
359 ).pipe(Effect.forkChild);
360​
361 yield* Effect.all(Array.from({ length: 4 }, () => Queue.take(starts)));
362 yield* Effect.yieldNow;
363 expect(yield* Queue.size(starts)).toBe(0);
364 expect(yield* Ref.get(peak)).toBe(4);
365​
366 yield* Deferred.succeed(gate, undefined);
367 yield* Fiber.join(burst);
368 expect(yield* Ref.get(total)).toBe(32);
369 expect(yield* Ref.get(peak)).toBe(4);
370 }),
371 );
372​
373 it.effect("collects stdout", () =>
374 Effect.gen(function* () {
375 const result = yield* run({
376 operation: "test.stdout",
377 command: "node",
378 args: ["-e", "process.stdout.write('hello')"],
379 cwd: process.cwd(),
380 });
381​
382 expect(result.stdout).toBe("hello");
383 expect(result.stderr).toBe("");
384 expect(result.stdoutTruncated).toBe(false);
385 expect(result.stderrTruncated).toBe(false);
386 }).pipe(provideLive),
387 );
388​
389 it.effect("keeps git from opening a folder laid out as a bare repository", () =>
390 Effect.gen(function* () {
391 const fileSystem = yield* FileSystem.FileSystem;
392 const path = yield* Path.Path;
393 const cwd = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-vcs-bare-" });
394 yield* fileSystem.makeDirectory(path.join(cwd, "objects", "info"), { recursive: true });
395 yield* fileSystem.makeDirectory(path.join(cwd, "refs", "heads"), { recursive: true });
396 yield* fileSystem.writeFileString(path.join(cwd, "HEAD"), "ref: refs/heads/main\n");
397 yield* fileSystem.writeFileString(
398 path.join(cwd, "config"),
399 '[core]\n\trepositoryformatversion = 0\n\tbare = false\n\tworktree = .\n\tfsmonitor = "echo ran >> fsmonitor-runs; false"\n',
400 );
401​
402 const result = yield* run({
403 operation: "test.bare-repository",
404 command: "git",
405 args: ["status"],
406 cwd,
407 allowNonZeroExit: true,
408 });
409​
410 expect(result.exitCode).not.toBe(0);
411 expect(yield* fileSystem.exists(path.join(cwd, "fsmonitor-runs"))).toBe(false);
412 }).pipe(Effect.scoped, provideLive, Effect.provide(NodeServices.layer)),
413 );
414​
415 it.effect("writes stdin before waiting for exit", () =>
416 Effect.gen(function* () {
417 const result = yield* run({
418 operation: "test.stdin",
419 command: "node",
420 args: [
421 "-e",
422 [
423 "process.stdin.setEncoding('utf8');",
424 "let data='';",
425 "process.stdin.on('data', chunk => { data += chunk; });",
426 "process.stdin.on('end', () => { process.stdout.write(data); });",
427 ].join(""),
428 ],
429 cwd: process.cwd(),
430 stdin: "stdin payload",
431 });
432​
433 expect(result.stdout).toBe("stdin payload");
434 }).pipe(provideLive),
435 );
436​
437 it.effect("fails with VcsProcessExitError for non-zero exits by default", () =>
438 Effect.gen(function* () {
439 const secretArgument = "--token=super-secret-token";
440 const secretStderr = "remote rejected super-secret-token";
441 const error = yield* run({
442 operation: "test.exit",
443 command: "node",
444 args: [
445 "-e",
446 "process.stderr.write(process.argv[1]); process.exit(2)",
447 secretStderr,
448 secretArgument,
449 ],
450 cwd: process.cwd(),
451 }).pipe(Effect.flip);
452​
453 expect(error).toBeInstanceOf(VcsProcessExitError);
454 expect(error).toMatchObject({
455 operation: "test.exit",
456 command: "node",
457 argumentCount: 4,
458 exitCode: 2,
459 detail: "Process exited with a non-zero status.",
460 failureKind: "command-failed",
461 stderrLength: secretStderr.length,
462 stderrTruncated: false,
463 });
464 expect(error.message).not.toContain(secretArgument);
465 expect(error.message).not.toContain(secretStderr);
466 }).pipe(provideLive),
467 );
468​
469 it.effect("classifies authentication failures without retaining stderr", () =>
470 Effect.gen(function* () {
471 const secretStderr = "authentication failed for token super-secret-token";
472 const error = yield* run({
473 operation: "test.authentication",
474 command: "node",
475 args: ["-e", "process.stderr.write(process.argv[1]); process.exit(1)", secretStderr],
476 cwd: process.cwd(),
477 }).pipe(Effect.flip);
478​
479 expect(error).toBeInstanceOf(VcsProcessExitError);
480 expect(error).toMatchObject({
481 operation: "test.authentication",
482 command: "node",
483 exitCode: 1,
484 detail: "Authentication failed.",
485 failureKind: "authentication",
486 stderrLength: secretStderr.length,
487 stderrTruncated: false,
488 });
489 expect(error.message).not.toContain(secretStderr);
490 expect(error.message).not.toContain("super-secret-token");
491 }).pipe(provideLive),
492 );
493​
494 it.effect("classifies API rate limits without retaining provider stderr", () =>
495 Effect.gen(function* () {
496 const providerStderr =
497 "GraphQL: API rate limit already exceeded for user ID 51714798 and token secret-value.";
498 const error = yield* run({
499 operation: "test.rate-limit",
500 command: "node",
501 args: ["-e", "process.stderr.write(process.argv[1]); process.exit(1)", providerStderr],
502 cwd: process.cwd(),
503 }).pipe(Effect.flip);
504​
505 expect(error).toBeInstanceOf(VcsProcessExitError);
506 expect(error).toMatchObject({
507 command: "node",
508 exitCode: 1,
509 detail: "API rate limit exceeded.",
510 failureKind: "rate-limited",
511 stderrLength: providerStderr.length,
512 stderrTruncated: false,
513 });
514 expect(error.message).not.toContain(providerStderr);
515 expect(error.message).not.toContain("secret-value");
516 }).pipe(provideLive),
517 );
518​
519 it.effect("classifies HTTP 429 responses as rate limits", () =>
520 Effect.gen(function* () {
521 const providerStderr = "HTTP 429: Too Many Requests. request-id=secret-value";
522 const error = yield* run({
523 operation: "test.rate-limit",
524 command: "node",
525 args: ["-e", "process.stderr.write(process.argv[1]); process.exit(1)", providerStderr],
526 cwd: process.cwd(),
527 }).pipe(Effect.flip);
528​
529 expect(error).toMatchObject({
530 detail: "API rate limit exceeded.",
531 failureKind: "rate-limited",
532 });
533 expect(error.message).not.toContain(providerStderr);
534 }).pipe(provideLive),
535 );
536​
537 it.effect("retains spawn causes without exposing process arguments in the error message", () =>
538 Effect.gen(function* () {
539 const secretArgument = "--token=super-secret-token";
540 const error = yield* run({
541 operation: "test.spawn",
542 command: "definitely-not-a-t3code-executable",
543 args: [secretArgument],
544 cwd: process.cwd(),
545 }).pipe(Effect.flip);
546​
547 expect(error).toBeInstanceOf(VcsProcessSpawnError);
548 expect(error).toMatchObject({
549 operation: "test.spawn",
550 command: "definitely-not-a-t3code-executable",
551 argumentCount: 1,
552 });
553 expect(error).toHaveProperty("cause");
554 expect(error.message).not.toContain(secretArgument);
555 }).pipe(provideLive),
556 );
557​
558 it.effect("preserves real boundary causes without manufacturing structural ones", () =>
559 Effect.gen(function* () {
560 const cause = new Error("secret stdin failure");
561 const error = yield* captureProcessResult(
562 Effect.fail(
563 new ProcessRunner.ProcessStdinError({
564 command: baseInput.command,
565 argumentCount: baseInput.args.length,
566 cwd: baseInput.cwd,
567 stdinBytes: 47,
568 cause,
569 }),
570 ),
571 );
572​
573 expect(error).toMatchObject({
574 _tag: "VcsProcessStdinWriteError",
575 operation: baseInput.operation,
576 stdinBytes: 47,
577 cause,
578 });
579 expect(error.message).not.toContain(cause.message);
580​
581 const missingExitCodeError = yield* captureProcessResult(
582 Effect.succeed({
583 stdout: "",
584 stderr: "",
585 code: null,
586 timedOut: false,
587 stdoutTruncated: false,
588 stderrTruncated: false,
589 stdoutInvalidUtf8: false,
590 stderrInvalidUtf8: false,
591 }),
592 );
593​
594 expect(missingExitCodeError).toMatchObject({
595 _tag: "VcsProcessMissingExitCodeError",
596 operation: baseInput.operation,
597 command: baseInput.command,
598 cwd: baseInput.cwd,
599 argumentCount: baseInput.args.length,
600 });
601 expect(missingExitCodeError).not.toHaveProperty("cause");
602 }),
603 );
604​
605 it.effect("returns output when non-zero exits are allowed", () =>
606 Effect.gen(function* () {
607 const result = yield* run({
608 operation: "test.allowed-exit",
609 command: "node",
610 args: ["-e", "process.stderr.write('boom'); process.exit(2)"],
611 cwd: process.cwd(),
612 allowNonZeroExit: true,
613 });
614​
615 expect(result.exitCode).toBe(2);
616 expect(result.stderr).toBe("boom");
617 }).pipe(provideLive),
618 );
619​
620 it.effect("truncates output and appends the marker when requested", () =>
621 Effect.gen(function* () {
622 const result = yield* run({
623 operation: "test.truncate-marker",
624 command: "node",
625 args: ["-e", "process.stdout.write('x'.repeat(2048))"],
626 cwd: process.cwd(),
627 maxOutputBytes: 128,
628 appendTruncationMarker: true,
629 });
630​
631 expect(result.stdoutTruncated).toBe(true);
632 expect(result.stdout).toContain("[truncated]");
633 expect(result.stderrTruncated).toBe(false);
634 }).pipe(provideLive),
635 );
636​
637 it.effect("truncates without the marker when truncation markers are disabled", () =>
638 Effect.gen(function* () {
639 const result = yield* run({
640 operation: "test.truncate-silent",
641 command: "node",
642 args: ["-e", "process.stdout.write('x'.repeat(2048))"],
643 cwd: process.cwd(),
644 maxOutputBytes: 128,
645 });
646​
647 expect(result.stdoutTruncated).toBe(true);
648 expect(result.stdout).not.toContain("[truncated]");
649 }).pipe(provideLive),
650 );
651​
652 it.effect("fails with measured byte counts when output must not be truncated", () =>
653 Effect.gen(function* () {
654 const error = yield* run({
655 operation: "test.output-limit",
656 command: "node",
657 args: ["-e", "process.stdout.write('x'.repeat(2048))"],
658 cwd: yield* HostProcess.WorkingDirectory,
659 maxOutputBytes: 128,
660 outputMode: "error",
661 }).pipe(Effect.flip);
662​
663 assert(error._tag === "VcsProcessOutputLimitError");
664 expect(error.stream).toBe("stdout");
665 expect(error.maxBytes).toBe(128);
666 expect(error.observedBytes).toBeGreaterThan(error.maxBytes);
667 }).pipe(provideLive),
668 );
669​
670 it.effect("streams all stdout bytes beyond the buffered output cap", () =>
671 Effect.gen(function* () {
672 const chunks: Uint8Array[] = [];
673 const result = yield* run({
674 operation: "test.stream-output",
675 command: "node",
676 args: ["-e", "process.stdout.write('x'.repeat(131072) + '\\0S final\\0')"],
677 cwd: process.cwd(),
678 maxOutputBytes: 8,
679 onStdoutChunk: (chunk) => chunks.push(chunk),
680 });
681​
682 expect(result.stdout).toBe("xxxxxxxx");
683 expect(result.stdoutTruncated).toBe(true);
684 expect(Buffer.concat(chunks).toString()).toBe("x".repeat(131072) + "\0S final\0");
685 }).pipe(provideLive),
686 );
687​
688 it.effect("fails with VcsProcessTimeoutError on timeout", () =>
689 Effect.gen(function* () {
690 const errorFiber = yield* run({
691 operation: "test.timeout",
692 command: "node",
693 args: ["-e", "setTimeout(() => {}, 5000)"],
694 cwd: process.cwd(),
695 timeoutMs: 50,
696 }).pipe(Effect.flip, Effect.forkScoped);
697 yield* Effect.yieldNow;
698 yield* TestClock.adjust(Duration.millis(50));
699 const error = yield* Fiber.join(errorFiber);
700​
701 expect(error).toBeInstanceOf(VcsProcessTimeoutError);
702 }).pipe(provideLive),
703 );
704});