The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Railway from "@alchemy.run/railway"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import { Query } from "@distilled.cloud/core/query"; |
| 5 | import { Railway as RailwayApi } from "@distilled.cloud/railway"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import * as pathe from "pathe"; |
| 10 | import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts"; |
| 11 | import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts"; |
| 12 | import { suitePartition } from "../suiteProject.ts"; |
| 13 | |
| 14 | const { test } = Test.make({ providers: Railway.providers() }); |
| 15 | |
| 16 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 17 | |
| 18 | const fixtureDir = pathe.resolve( |
| 19 | import.meta.dirname, |
| 20 | "../../../../../examples/cloudflare-website-vocs", |
| 21 | ); |
| 22 | const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp"); |
| 23 | const fixtureEntries = ["package.json", "public", "src", "tsconfig.json", "vocs.config.ts"]; |
| 24 | |
| 25 | const readService = Query.fn((id: string) => ({ deletedAt: RailwayApi.service({ id }).deletedAt })); |
| 26 | |
| 27 | const waitUntilGone = (serviceId: string) => |
| 28 | readService(serviceId).pipe( |
| 29 | Effect.map((service) => (service.deletedAt != null ? ("gone" as const) : ("found" as const))), |
| 30 | Effect.catchTag("RailwayNotFound", () => Effect.succeed("gone" as const)), |
| 31 | Effect.repeat({ |
| 32 | schedule: Schedule.spaced("1 second"), |
| 33 | until: (status) => status === "gone", |
| 34 | times: 10, |
| 35 | }), |
| 36 | ); |
| 37 | |
| 38 | test.provider( |
| 39 | "Vocs: deploy, GET /, destroy, gone", |
| 40 | (stack) => |
| 41 | Effect.gen(function* () { |
| 42 | yield* stack.destroy(); |
| 43 | |
| 44 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 45 | prefix: "alchemy-vocs-railway-", |
| 46 | tempRoot, |
| 47 | entries: fixtureEntries, |
| 48 | }); |
| 49 | |
| 50 | const deployed = yield* stack.deploy( |
| 51 | Effect.gen(function* () { |
| 52 | const { project, environment } = yield* suitePartition; |
| 53 | const site = yield* Railway.Website.Vocs("Web", { |
| 54 | project, |
| 55 | environment, |
| 56 | rootDir, |
| 57 | memo: { |
| 58 | include: ["src/**", "public/**", "package.json", "tsconfig.json", "vocs.config.ts"], |
| 59 | }, |
| 60 | }); |
| 61 | return { site }; |
| 62 | }), |
| 63 | ); |
| 64 | |
| 65 | const url = deployed.site.url; |
| 66 | expect(url).toBeDefined(); |
| 67 | expect(url).toMatch(/^https:\/\//); |
| 68 | expect(deployed.site.service).toBeDefined(); |
| 69 | expect(deployed.site.project).toBeDefined(); |
| 70 | |
| 71 | yield* expectUrlContains(`${url!}/`, "Alchemy with Vocs", { |
| 72 | timeout: "90 seconds", |
| 73 | label: "home page", |
| 74 | }); |
| 75 | |
| 76 | const serviceId = deployed.site.service!.serviceId; |
| 77 | yield* stack.destroy(); |
| 78 | const gone = yield* waitUntilGone(serviceId); |
| 79 | expect(gone).toEqual("gone"); |
| 80 | }).pipe(logLevel), |
| 81 | { |
| 82 | tags: [ |
| 83 | "provider:railway", |
| 84 | "provider:railway:project", |
| 85 | "provider:railway:projectenvironment", |
| 86 | "provider:railway:service", |
| 87 | "provider:railway:website", |
| 88 | "live", |
| 89 | ], |
| 90 | timeout: 120_000, |
| 91 | }, |
| 92 | ); |