|
1 | 1 | import { |
| 2 | + SERVER_EXIT_CODE_MANAGED_POLICY, |
2 | 3 | SERVER_EXIT_CODE_STATE_DIR_OWNED, |
3 | 4 | DesktopBackendBootstrap, |
4 | 5 | type DesktopBackendBootstrap as DesktopBackendBootstrapValue, |
@@ -623,56 +624,63 @@ describe("DesktopBackendManager", () => { |
623 | 624 | ), |
624 | 625 | ); |
625 | 626 |
|
626 | | - it.effect("reports a crash loop with the server output on the third restart", () => |
627 | | - Effect.scoped( |
628 | | - Effect.gen(function* () { |
629 | | - const message = "Error: Cannot find module 'zod/v4' in /Users/René"; |
630 | | - let exitCount = 0; |
631 | | - const firstExit = yield* Deferred.make<void>(); |
632 | | - const reports = yield* Queue.unbounded<{ |
633 | | - readonly exitCount: number; |
634 | | - readonly failure: DesktopBackendManager.BackendStartupFailure; |
635 | | - }>(); |
636 | | - const instance = yield* makeTestInstance({ |
637 | | - spawnerLayer: Layer.succeed( |
638 | | - ChildProcessSpawner.ChildProcessSpawner, |
639 | | - ChildProcessSpawner.make(() => |
640 | | - Effect.succeed( |
641 | | - makeProcess({ |
642 | | - // "é" split across chunks must not decode as U+FFFD, and the 4,000-char cut |
643 | | - // lands inside the emoji's surrogate pair. |
644 | | - stderr: Stream.make( |
645 | | - new TextEncoder().encode( |
646 | | - `😀${"x".repeat(3_999 - message.length)}${message.slice(0, -1)}`, |
| 627 | + // A policy refusal is reported on the first exit, since retrying cannot fix it. |
| 628 | + it.effect.each([ |
| 629 | + { code: 1, exits: 3, managedPolicy: false }, |
| 630 | + { code: SERVER_EXIT_CODE_MANAGED_POLICY, exits: 1, managedPolicy: true }, |
| 631 | + ])( |
| 632 | + "reports exit $code with the server output after $exits exits", |
| 633 | + ({ code, exits, managedPolicy }) => |
| 634 | + Effect.scoped( |
| 635 | + Effect.gen(function* () { |
| 636 | + const message = "Error: Cannot find module 'zod/v4' in /Users/René"; |
| 637 | + let exitCount = 0; |
| 638 | + const firstExit = yield* Deferred.make<void>(); |
| 639 | + const reports = yield* Queue.unbounded<{ |
| 640 | + readonly exitCount: number; |
| 641 | + readonly failure: DesktopBackendManager.BackendStartupFailure; |
| 642 | + }>(); |
| 643 | + const instance = yield* makeTestInstance({ |
| 644 | + spawnerLayer: Layer.succeed( |
| 645 | + ChildProcessSpawner.ChildProcessSpawner, |
| 646 | + ChildProcessSpawner.make(() => |
| 647 | + Effect.succeed( |
| 648 | + makeProcess({ |
| 649 | + // "é" split across chunks must not decode as U+FFFD, and the 4,000-char cut |
| 650 | + // lands inside the emoji's surrogate pair. |
| 651 | + stderr: Stream.make( |
| 652 | + new TextEncoder().encode( |
| 653 | + `😀${"x".repeat(3_999 - message.length)}${message.slice(0, -1)}`, |
| 654 | + ), |
| 655 | + new Uint8Array([0xc3]), |
| 656 | + new Uint8Array([0xa9]), |
647 | 657 | ), |
648 | | - new Uint8Array([0xc3]), |
649 | | - new Uint8Array([0xa9]), |
650 | | - ), |
651 | | - exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(1)), |
652 | | - }), |
| 658 | + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(code)), |
| 659 | + }), |
| 660 | + ), |
653 | 661 | ), |
654 | 662 | ), |
655 | | - ), |
656 | | - httpClientLayer: layerHttpClient(() => Effect.never), |
657 | | - backendOutputLog: { |
658 | | - persistFailure: () => { |
659 | | - exitCount += 1; |
660 | | - return Deferred.succeed(firstExit, undefined).pipe(Effect.asVoid); |
| 663 | + httpClientLayer: layerHttpClient(() => Effect.never), |
| 664 | + backendOutputLog: { |
| 665 | + persistFailure: () => { |
| 666 | + exitCount += 1; |
| 667 | + return Deferred.succeed(firstExit, undefined).pipe(Effect.asVoid); |
| 668 | + }, |
661 | 669 | }, |
662 | | - }, |
663 | | - onStartupFailure: (failure) => |
664 | | - Queue.offer(reports, { exitCount, failure }).pipe(Effect.asVoid), |
665 | | - }); |
666 | | - yield* instance.start; |
667 | | - yield* Deferred.await(firstExit); |
668 | | - yield* TestClock.adjust(Duration.minutes(1)); |
669 | | - const { exitCount: exitsWhenReported, failure } = yield* Queue.take(reports); |
670 | | - assert.equal(exitsWhenReported, 3); |
671 | | - assert.equal(failure.reason, "The server could not start (code=1)."); |
672 | | - assert.isTrue(failure.output.endsWith(message)); |
673 | | - assert.isTrue(failure.output.isWellFormed()); |
674 | | - }).pipe(Effect.provide(TestClock.layer())), |
675 | | - ), |
| 670 | + onStartupFailure: (failure) => |
| 671 | + Queue.offer(reports, { exitCount, failure }).pipe(Effect.asVoid), |
| 672 | + }); |
| 673 | + yield* instance.start; |
| 674 | + yield* Deferred.await(firstExit); |
| 675 | + yield* TestClock.adjust(Duration.minutes(1)); |
| 676 | + const { exitCount: exitsWhenReported, failure } = yield* Queue.take(reports); |
| 677 | + assert.equal(exitsWhenReported, exits); |
| 678 | + assert.equal(failure.reason, `The server could not start (code=${code}).`); |
| 679 | + assert.equal(failure.managedPolicy, managedPolicy); |
| 680 | + assert.isTrue(failure.output.endsWith(message)); |
| 681 | + assert.isTrue(failure.output.isWellFormed()); |
| 682 | + }).pipe(Effect.provide(TestClock.layer())), |
| 683 | + ), |
676 | 684 | ); |
677 | 685 |
|
678 | 686 | it.effect("waits out a slow startup and reports one that never becomes ready", () => |
|
0 commit comments