@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 102 lines 3.59 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, "../../Cloudflare/Website/vite-spa-fixture");
20 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
21 const fixtureEntries = ["index.html", "package.json", "src"];
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 "Vite SPA: deploy, GET /, destroy, gone",
38 (stack) =>
39 Effect.gen(function* () {
40 yield* stack.destroy();
41
42 const rootDir = yield* cloneFixture(fixtureDir, {
43 prefix: "alchemy-vite-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.Vite("Web", {
52 project,
53 environment,
54 rootDir,
55 memo: { include: ["index.html", "src/**", "package.json"] },
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 expect(deployed.site.service!.serviceId.length).toBeGreaterThan(0);
66 expect(deployed.site.project).toBeDefined();
67
68 yield* expectUrlContains(`${url!}/`, "Vite SPA fixture", {
69 timeout: "90 seconds",
70 label: "vite spa index",
71 });
72 yield* expectUrlContains(`${url!}/missing-client-route`, "Vite SPA fixture", {
73 timeout: "15 seconds",
74 label: "vite spa fallback",
75 });
76
77 const client = yield* HttpClient.HttpClient;
78 const health = yield* client.get(`${url!}/health`).pipe(
79 Effect.flatMap((res) =>
80 res.status === 200 ? res.text : Effect.fail(new Error(`health returned ${res.status}`)),
81 ),
82 Effect.retry({ schedule: Schedule.exponential("500 millis"), times: 6 }),
83 );
84 expect(health).toContain("ok");
85
86 const serviceId = deployed.site.service!.serviceId;
87 yield* stack.destroy();
88 const gone = yield* waitUntilGone(serviceId);
89 expect(gone).toEqual("gone");
90 }).pipe(logLevel),
91 {
92 tags: [
93 "provider:railway",
94 "provider:railway:project",
95 "provider:railway:projectenvironment",
96 "provider:railway:service",
97 "provider:railway:website",
98 "live",
99 ],
100 timeout: 120_000,
101 },
102 );