The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as Fly from "@alchemy.run/fly"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as HttpClient from "effect/http/HttpClient"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { materializeIsolatedProject, removeIsolatedProject } from "../IsolatedProject.ts"; |
| 9 | import IsolatedProjectApi, { |
| 10 | IsolatedSite, |
| 11 | project as serviceProject, |
| 12 | } from "./fixtures/isolated-project-service.ts"; |
| 13 | import IsolatedProjectBox, { |
| 14 | project as spriteProject, |
| 15 | } from "./fixtures/isolated-project-sprite.ts"; |
| 16 | |
| 17 | const { test } = Test.make({ providers: Fly.providers() }); |
| 18 | |
| 19 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 20 | |
| 21 | const healthOk = (url: string) => |
| 22 | HttpClient.get(new URL("/health", url)).pipe( |
| 23 | Effect.flatMap((res) => |
| 24 | res.status === 200 ? res.json : Effect.fail(new Error(`/health returned ${res.status}`)), |
| 25 | ), |
| 26 | Effect.retry({ schedule: Schedule.spaced("4 seconds"), times: 15 }), |
| 27 | ); |
| 28 | |
| 29 | // Live proof that the Fly bun bootstrap (shared by Service and Sprite) boots |
| 30 | // when `main` lives in an isolated project (see test/IsolatedProject.ts) — |
| 31 | // the bundle `cwd` resolves none of alchemy's dependencies, so the |
| 32 | // bootstrap's `@effect/platform-bun` / `alchemy/*` imports must be bundled |
| 33 | // by the virtual-entry plugin rather than found from the project root. With |
| 34 | // them left external bun dies at module load and the app never answers. |
| 35 | test.provider( |
| 36 | "service bundled from an isolated project serves HTTP", |
| 37 | (stack) => |
| 38 | Effect.gen(function* () { |
| 39 | yield* materializeIsolatedProject(serviceProject); |
| 40 | yield* stack.destroy(); |
| 41 | |
| 42 | try { |
| 43 | const deployed = yield* stack.deploy( |
| 44 | Effect.gen(function* () { |
| 45 | const app = yield* IsolatedSite; |
| 46 | yield* Fly.IpAssignment("IsolatedProjectShared", { |
| 47 | app, |
| 48 | type: "shared_v4", |
| 49 | }); |
| 50 | return yield* IsolatedProjectApi; |
| 51 | }), |
| 52 | ); |
| 53 | expect(deployed.state).toEqual("started"); |
| 54 | expect(deployed.url).toBeTruthy(); |
| 55 | |
| 56 | expect(yield* healthOk(deployed.url!)).toEqual({ ok: true }); |
| 57 | |
| 58 | yield* stack.destroy(); |
| 59 | } finally { |
| 60 | yield* removeIsolatedProject(serviceProject); |
| 61 | } |
| 62 | }).pipe(logLevel), |
| 63 | { |
| 64 | tags: [ |
| 65 | "provider:fly", |
| 66 | "provider:fly:app", |
| 67 | "provider:fly:ipassignment", |
| 68 | "provider:fly:service", |
| 69 | "live", |
| 70 | ], |
| 71 | timeout: 180_000, |
| 72 | }, |
| 73 | ); |
| 74 | |
| 75 | test.provider( |
| 76 | "sprite bundled from an isolated project serves HTTP", |
| 77 | (stack) => |
| 78 | Effect.gen(function* () { |
| 79 | yield* materializeIsolatedProject(spriteProject); |
| 80 | yield* stack.destroy(); |
| 81 | |
| 82 | try { |
| 83 | const deployed = yield* stack.deploy( |
| 84 | Effect.gen(function* () { |
| 85 | return yield* IsolatedProjectBox; |
| 86 | }), |
| 87 | ); |
| 88 | expect(deployed.url).toContain("sprites.app"); |
| 89 | |
| 90 | expect(yield* healthOk(deployed.url)).toEqual({ ok: true }); |
| 91 | |
| 92 | yield* stack.destroy(); |
| 93 | } finally { |
| 94 | yield* removeIsolatedProject(spriteProject); |
| 95 | } |
| 96 | }).pipe(logLevel), |
| 97 | { |
| 98 | tags: ["provider:fly", "provider:fly:service", "provider:fly:sprite", "live"], |
| 99 | timeout: 180_000, |
| 100 | }, |
| 101 | ); |