@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 109 lines 3.36 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 { 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 "../../AWS/Website/fixtures/react-router-app",
21 );
22 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
23 const fixtureEntries = [
24 ".gitignore",
25 "package.json",
26 "react-router.config.ts",
27 "vite.config.ts",
28 "app",
29 "public",
30 ];
31
32 const readService = Query.fn((id: string) => ({ deletedAt: RailwayApi.service({ id }).deletedAt }));
33
34 const waitUntilGone = (serviceId: string) =>
35 readService(serviceId).pipe(
36 Effect.map((service) => (service.deletedAt != null ? ("gone" as const) : ("found" as const))),
37 Effect.catchTag("RailwayNotFound", () => Effect.succeed("gone" as const)),
38 Effect.repeat({
39 schedule: Schedule.spaced("1 second"),
40 until: (status) => status === "gone",
41 times: 10,
42 }),
43 );
44
45 test.provider(
46 "ReactRouter: deploy, GET /, destroy, gone",
47 (stack) =>
48 Effect.gen(function* () {
49 yield* stack.destroy();
50
51 const rootDir = yield* cloneFixture(fixtureDir, {
52 prefix: "alchemy-react-router-railway-",
53 tempRoot,
54 entries: fixtureEntries,
55 });
56
57 const deployed = yield* stack.deploy(
58 Effect.gen(function* () {
59 const { project, environment } = yield* suitePartition;
60 const site = yield* Railway.Website.ReactRouter("Web", {
61 project,
62 environment,
63 rootDir,
64 memo: {
65 include: [
66 "app/**",
67 "public/**",
68 "package.json",
69 "react-router.config.ts",
70 "vite.config.ts",
71 ],
72 },
73 });
74 return { site };
75 }),
76 );
77
78 const url = deployed.site.url;
79 expect(url).toBeDefined();
80 expect(url).toMatch(/^https:\/\//);
81 expect(deployed.site.service).toBeDefined();
82 expect(deployed.site.project).toBeDefined();
83
84 yield* expectUrlContains(`${url!}/`, "REACT_ROUTER_AWS_PAGE_MARKER", {
85 timeout: "60 seconds",
86 label: "home page",
87 });
88 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "REACT_ROUTER_AWS_API_MARKER", {
89 timeout: "30 seconds",
90 label: "api route",
91 });
92
93 const serviceId = deployed.site.service!.serviceId;
94 yield* stack.destroy();
95 const gone = yield* waitUntilGone(serviceId);
96 expect(gone).toEqual("gone");
97 }).pipe(logLevel),
98 {
99 tags: [
100 "provider:railway",
101 "provider:railway:project",
102 "provider:railway:projectenvironment",
103 "provider:railway:service",
104 "provider:railway:website",
105 "live",
106 ],
107 timeout: 120_000,
108 },
109 );