@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 06:00 UTC

main
ts 100 lines 3.53 KB
Raw
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 * as HttpClient from "effect/http/HttpClient";
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 import { suitePartition } from "../suiteProject.ts";
14
15 const { test } = Test.make({ providers: Railway.providers() });
16
17 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
18
19 const fixtureDir = pathe.resolve(import.meta.dirname, "../../AWS/Website/fixtures/astro-app");
20 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
21 const fixtureEntries = [".gitignore", "package.json", "astro.config.mjs", "src", "public"];
22
23 const readService = Query.fn((id: string) => ({ deletedAt: RailwayApi.service({ id }).deletedAt }));
24
25 const waitUntilGone = (serviceId: string) =>
26 readService(serviceId).pipe(
27 Effect.map((service) => (service.deletedAt != null ? ("gone" as const) : ("found" as const))),
28 Effect.catchTag("RailwayNotFound", () => Effect.succeed("gone" as const)),
29 Effect.repeat({
30 schedule: Schedule.spaced("1 second"),
31 until: (status) => status === "gone",
32 times: 10,
33 }),
34 );
35
36 test.provider(
37 "Astro SSR: GET / and a dynamic API route",
38 (stack) =>
39 Effect.gen(function* () {
40 yield* stack.destroy();
41
42 const rootDir = yield* cloneFixture(fixtureDir, {
43 prefix: "alchemy-astro-railway-",
44 tempRoot,
45 entries: fixtureEntries,
46 });
47
48 const deployed = yield* stack.deploy(
49 Effect.gen(function* () {
50 const { project, environment } = yield* suitePartition;
51 const site = yield* Railway.Website.Astro("Web", {
52 project,
53 environment,
54 rootDir,
55 memo: { include: ["src/**", "public/**", "package.json", "astro.config.mjs"] },
56 });
57 return { site };
58 }),
59 );
60
61 const url = deployed.site.url;
62 expect(url).toBeDefined();
63 expect(url).toMatch(/^https:\/\//);
64 expect(deployed.site.service).toBeDefined();
65
66 yield* expectUrlContains(`${url!}/`, "ASTRO_AWS_PAGE_MARKER", {
67 timeout: "90 seconds",
68 label: "astro ssr home",
69 });
70 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "ASTRO_AWS_API_MARKER", {
71 timeout: "30 seconds",
72 label: "astro api route",
73 });
74
75 const client = yield* HttpClient.HttpClient;
76 const health = yield* client.get(`${url!}/health`).pipe(
77 Effect.flatMap((res) =>
78 res.status === 200 ? res.text : Effect.fail(new Error(`health returned ${res.status}`)),
79 ),
80 Effect.retry({ schedule: Schedule.exponential("500 millis"), times: 6 }),
81 );
82 expect(health).toContain("ok");
83
84 const serviceId = deployed.site.service!.serviceId;
85 yield* stack.destroy();
86 const gone = yield* waitUntilGone(serviceId);
87 expect(gone).toEqual("gone");
88 }).pipe(logLevel),
89 {
90 tags: [
91 "provider:railway",
92 "provider:railway:project",
93 "provider:railway:projectenvironment",
94 "provider:railway:service",
95 "provider:railway:website",
96 "live",
97 ],
98 timeout: 120_000,
99 },
100 );