The best way to control Claude Code, Codex and more from any computer or phone
| 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 machines from "@distilled.cloud/fly-io/machines"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as FileSystem from "effect/FileSystem"; |
| 7 | import * as Path from "effect/Path"; |
| 8 | import { MinimumLogLevel } from "effect/References"; |
| 9 | import * as Schedule from "effect/Schedule"; |
| 10 | import * as pathe from "pathe"; |
| 11 | import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts"; |
| 12 | import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts"; |
| 13 | |
| 14 | const { test } = Test.make({ providers: Fly.providers() }); |
| 15 | |
| 16 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 17 | |
| 18 | const fixtureDir = pathe.resolve(import.meta.dirname, "../../AWS/Website/fixtures/octane-app"); |
| 19 | const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp"); |
| 20 | const fixtureEntries = [ |
| 21 | ".gitignore", |
| 22 | "package.json", |
| 23 | "octane.config.ts", |
| 24 | "vite.config.ts", |
| 25 | "index.html", |
| 26 | "src", |
| 27 | "public", |
| 28 | ]; |
| 29 | |
| 30 | const waitUntilGone = (appName: string) => |
| 31 | machines.getApp({ app_name: appName }).pipe( |
| 32 | Effect.as("found" as const), |
| 33 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 34 | Effect.repeat({ |
| 35 | schedule: Schedule.spaced("1 second"), |
| 36 | until: (status) => status === "gone", |
| 37 | times: 10, |
| 38 | }), |
| 39 | ); |
| 40 | |
| 41 | test.provider( |
| 42 | "Octane: deploy, GET /, destroy, gone", |
| 43 | (stack) => |
| 44 | Effect.gen(function* () { |
| 45 | yield* stack.destroy(); |
| 46 | |
| 47 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 48 | prefix: "alchemy-octane-fly-", |
| 49 | tempRoot, |
| 50 | entries: fixtureEntries, |
| 51 | }); |
| 52 | |
| 53 | const fs = yield* FileSystem.FileSystem; |
| 54 | const pathMod = yield* Path.Path; |
| 55 | const configPath = pathMod.join(rootDir, "octane.config.ts"); |
| 56 | const raw = yield* fs.readFileString(configPath); |
| 57 | expect(raw).not.toContain("adapter:"); |
| 58 | expect(raw).not.toContain("@alchemy.run/frontend-frameworks"); |
| 59 | |
| 60 | const deployed = yield* stack.deploy( |
| 61 | Effect.gen(function* () { |
| 62 | const site = yield* Fly.Website.Octane("Web", { |
| 63 | rootDir, |
| 64 | memo: { |
| 65 | include: [ |
| 66 | "src/**", |
| 67 | "public/**", |
| 68 | "package.json", |
| 69 | "octane.config.ts", |
| 70 | "vite.config.ts", |
| 71 | "index.html", |
| 72 | ], |
| 73 | }, |
| 74 | }); |
| 75 | return { site }; |
| 76 | }), |
| 77 | ); |
| 78 | |
| 79 | expect(yield* fs.readFileString(configPath)).toBe(raw); |
| 80 | const url = deployed.site.url; |
| 81 | expect(url).toBeDefined(); |
| 82 | expect(url).toMatch(/^https:\/\//); |
| 83 | expect(deployed.site.service).toBeDefined(); |
| 84 | expect(deployed.site.app).toBeDefined(); |
| 85 | |
| 86 | yield* expectUrlContains(`${url!}/`, "OCTANE_AWS_PAGE_MARKER", { |
| 87 | timeout: "90 seconds", |
| 88 | label: "home page", |
| 89 | }); |
| 90 | yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "OCTANE_AWS_API_MARKER", { |
| 91 | timeout: "30 seconds", |
| 92 | label: "api route", |
| 93 | }); |
| 94 | |
| 95 | const appName = deployed.site.app!.appName; |
| 96 | yield* stack.destroy(); |
| 97 | const gone = yield* waitUntilGone(appName); |
| 98 | expect(gone).toEqual("gone"); |
| 99 | }).pipe(logLevel), |
| 100 | { |
| 101 | tags: ["provider:fly", "provider:fly:machine", "provider:fly:website", "live"], |
| 102 | timeout: 240000, |
| 103 | }, |
| 104 | ); |