@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.3 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(
20 import.meta.dirname,
21 "../../Cloudflare/Website/staticsite-fixture",
22 );
23 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
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 "StaticSite: build command + outdir, GET index",
40 (stack) =>
41 Effect.gen(function* () {
42 yield* stack.destroy();
43
44 const cwd = yield* cloneFixture(fixtureDir, {
45 prefix: "alchemy-staticsite-railway-",
46 tempRoot,
47 entries: ["src", "build.sh"],
48 });
49
50 const deployed = yield* stack.deploy(
51 Effect.gen(function* () {
52 const { project, environment } = yield* suitePartition;
53 const site = yield* Railway.Website.StaticSite("Blog", {
54 project,
55 environment,
56 cwd,
57 command: "bash build.sh",
58 shell: true,
59 outdir: "dist",
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
70 yield* expectUrlContains(`${url!}/`, "StaticSite fixture v1", {
71 timeout: "90 seconds",
72 label: "staticsite index",
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 );