The best way to control Claude Code, Codex and more from any computer or phone

main
ts 79 lines 2.65 KB
Raw
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 { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8 import * as pathe from "pathe";
9 import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
10 import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
11
12 const { test } = Test.make({ providers: Fly.providers() });
13
14 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
15
16 const fixtureDir = pathe.resolve(import.meta.dirname, "../../AWS/Website/fixtures/astro-app");
17 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
18 const fixtureEntries = [".gitignore", "package.json", "astro.config.mjs", "src", "public"];
19
20 const waitUntilGone = (appName: string) =>
21 machines.getApp({ app_name: appName }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("1 second"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider(
32 "Astro SSR: GET / and a dynamic API route",
33 (stack) =>
34 Effect.gen(function* () {
35 yield* stack.destroy();
36
37 const rootDir = yield* cloneFixture(fixtureDir, {
38 prefix: "alchemy-astro-fly-",
39 tempRoot,
40 entries: fixtureEntries,
41 });
42
43 const deployed = yield* stack.deploy(
44 Effect.gen(function* () {
45 const site = yield* Fly.Website.Astro("Web", {
46 rootDir,
47 memo: {
48 include: ["src/**", "public/**", "package.json", "astro.config.mjs"],
49 },
50 });
51 return { site };
52 }),
53 );
54
55 const url = deployed.site.url;
56 expect(url).toBeDefined();
57 expect(url).toMatch(/^https:\/\//);
58 expect(deployed.site.service).toBeDefined();
59 expect(deployed.site.app).toBeDefined();
60
61 yield* expectUrlContains(`${url!}/`, "ASTRO_AWS_PAGE_MARKER", {
62 timeout: "90 seconds",
63 label: "astro ssr home",
64 });
65 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "ASTRO_AWS_API_MARKER", {
66 timeout: "30 seconds",
67 label: "astro api route",
68 });
69
70 const appName = deployed.site.app!.appName;
71 yield* stack.destroy();
72 const gone = yield* waitUntilGone(appName);
73 expect(gone).toEqual("gone");
74 }).pipe(logLevel),
75 {
76 tags: ["provider:fly", "provider:fly:machine", "provider:fly:website", "live"],
77 timeout: 240_000,
78 },
79 );