|
| 1 | +import * as Sink from "effect/Sink"; |
| 2 | +import * as Deferred from "effect/Deferred"; |
| 3 | +import * as Fiber from "effect/Fiber"; |
| 4 | +import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; |
| 5 | +import * as TestClock from "effect/testing/TestClock"; |
1 | 6 | import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; |
2 | 7 | import * as NodePath from "@effect/platform-node/NodePath"; |
3 | 8 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
@@ -671,6 +676,93 @@ it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => { |
671 | 676 | }), |
672 | 677 | ); |
673 | 678 |
|
| 679 | + const preflightHelper = (exitDelay: Effect.Effect<void>) => { |
| 680 | + const spawns = { count: 0 }; |
| 681 | + const started = Deferred.makeUnsafe<void>(); |
| 682 | + const spawner = ChildProcessSpawner.make(() => |
| 683 | + Effect.sync(() => { |
| 684 | + spawns.count += 1; |
| 685 | + return ChildProcessSpawner.makeHandle({ |
| 686 | + pid: ChildProcessSpawner.ProcessId(1), |
| 687 | + exitCode: Deferred.succeed(started, undefined).pipe( |
| 688 | + Effect.andThen(exitDelay), |
| 689 | + Effect.as(ChildProcessSpawner.ExitCode(0)), |
| 690 | + ), |
| 691 | + isRunning: Effect.succeed(false), |
| 692 | + kill: () => Effect.void, |
| 693 | + unref: Effect.succeed(Effect.void), |
| 694 | + stdin: Sink.drain, |
| 695 | + stdout: Stream.empty, |
| 696 | + stderr: Stream.encodeText( |
| 697 | + Stream.make( |
| 698 | + `${ANTIGRAVITY_AUTH_BROWSER_MARKER}"https://example.invalid/t3-antigravity-browser-preflight"\n`, |
| 699 | + ), |
| 700 | + ), |
| 701 | + all: Stream.empty, |
| 702 | + getInputFd: () => Sink.drain, |
| 703 | + getOutputFd: () => Stream.empty, |
| 704 | + }); |
| 705 | + }), |
| 706 | + ); |
| 707 | + return { spawner, spawns, started }; |
| 708 | + }; |
| 709 | + |
| 710 | + const prepareWithHelper = Effect.fn("prepareWithHelper")(function* ( |
| 711 | + runtimeExecutablePath: string, |
| 712 | + spawner: ChildProcessSpawner.ChildProcessSpawner["Service"], |
| 713 | + ) { |
| 714 | + const fs = yield* FileSystem.FileSystem; |
| 715 | + const path = yield* Path.Path; |
| 716 | + const directory = yield* fs.makeTempDirectoryScoped(); |
| 717 | + return yield* prepareAntigravityProfile({ |
| 718 | + profileDirectory: path.join(directory, "profile"), |
| 719 | + userHome: path.join(directory, "home"), |
| 720 | + runtimeExecutablePath, |
| 721 | + platform: "linux", |
| 722 | + baseEnv: {}, |
| 723 | + }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner)); |
| 724 | + }); |
| 725 | + |
| 726 | + it.effect("allows a browser preflight that takes longer than five seconds", () => |
| 727 | + Effect.gen(function* () { |
| 728 | + const helper = preflightHelper(Effect.sleep("20 seconds")); |
| 729 | + const fiber = yield* prepareWithHelper("/fake/slow-node", helper.spawner).pipe( |
| 730 | + Effect.forkChild, |
| 731 | + ); |
| 732 | + yield* Deferred.await(helper.started); |
| 733 | + yield* TestClock.adjust("20 seconds"); |
| 734 | + yield* Fiber.join(fiber); |
| 735 | + |
| 736 | + expect(helper.spawns.count).toBe(1); |
| 737 | + }), |
| 738 | + ); |
| 739 | + |
| 740 | + it.effect("fails a hung preflight after 30 seconds and verifies again on the next open", () => |
| 741 | + Effect.gen(function* () { |
| 742 | + const hung = preflightHelper(Effect.never); |
| 743 | + const fiber = yield* prepareWithHelper("/fake/hung-node", hung.spawner).pipe( |
| 744 | + Effect.result, |
| 745 | + Effect.forkChild, |
| 746 | + ); |
| 747 | + yield* Deferred.await(hung.started); |
| 748 | + yield* TestClock.adjust("29 seconds"); |
| 749 | + expect(fiber.pollUnsafe()).toBeUndefined(); |
| 750 | + yield* TestClock.adjust("1 second"); |
| 751 | + const result = yield* Fiber.join(fiber); |
| 752 | + expect(Result.isFailure(result)).toBe(true); |
| 753 | + if (Result.isFailure(result)) { |
| 754 | + expect(result.failure).toMatchObject({ |
| 755 | + _tag: "AcpTransportError", |
| 756 | + detail: "Antigravity browser suppression verification timed out.", |
| 757 | + }); |
| 758 | + } |
| 759 | + |
| 760 | + const recovered = preflightHelper(Effect.void); |
| 761 | + yield* prepareWithHelper("/fake/hung-node", recovered.spawner); |
| 762 | + expect(recovered.spawns.count).toBe(1); |
| 763 | + }), |
| 764 | + ); |
| 765 | + |
674 | 766 | it.effect("rejects Python BROWSER delimiter collisions before starting a helper", () => |
675 | 767 | Effect.gen(function* () { |
676 | 768 | const fs = yield* FileSystem.FileSystem; |
|
0 commit comments