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

main
ts 118 lines 3.82 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 FileSystem from "effect/FileSystem";
8 import * as Path from "effect/Path";
9 import { MinimumLogLevel } from "effect/References";
10 import * as Schedule from "effect/Schedule";
11 import * as pathe from "pathe";
12 import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
13 import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
14 import { suitePartition } from "../suiteProject.ts";
15
16 const { test } = Test.make({ providers: Railway.providers() });
17
18 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
19
20 const fixtureDir = pathe.resolve(import.meta.dirname, "../../AWS/Website/fixtures/octane-app");
21 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
22 const fixtureEntries = [
23 ".gitignore",
24 "package.json",
25 "octane.config.ts",
26 "vite.config.ts",
27 "index.html",
28 "src",
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 "Octane: deploy, GET /, destroy, gone",
47 (stack) =>
48 Effect.gen(function* () {
49 yield* stack.destroy();
50
51 const rootDir = yield* cloneFixture(fixtureDir, {
52 prefix: "alchemy-octane-railway-",
53 tempRoot,
54 entries: fixtureEntries,
55 });
56
57 const fs = yield* FileSystem.FileSystem;
58 const pathMod = yield* Path.Path;
59 const configPath = pathMod.join(rootDir, "octane.config.ts");
60 const raw = yield* fs.readFileString(configPath);
61 expect(raw).not.toContain("adapter:");
62 expect(raw).not.toContain("@alchemy.run/frontend-frameworks");
63
64 const deployed = yield* stack.deploy(
65 Effect.gen(function* () {
66 const { project, environment } = yield* suitePartition;
67 const site = yield* Railway.Website.Octane("Web", {
68 project,
69 environment,
70 rootDir,
71 memo: {
72 include: [
73 "src/**",
74 "public/**",
75 "package.json",
76 "octane.config.ts",
77 "vite.config.ts",
78 "index.html",
79 ],
80 },
81 });
82 return { site };
83 }),
84 );
85
86 expect(yield* fs.readFileString(configPath)).toBe(raw);
87 const url = deployed.site.url;
88 expect(url).toBeDefined();
89 expect(url).toMatch(/^https:\/\//);
90 expect(deployed.site.service).toBeDefined();
91 expect(deployed.site.project).toBeDefined();
92
93 yield* expectUrlContains(`${url!}/`, "OCTANE_AWS_PAGE_MARKER", {
94 timeout: "90 seconds",
95 label: "home page",
96 });
97 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "OCTANE_AWS_API_MARKER", {
98 timeout: "30 seconds",
99 label: "api route",
100 });
101
102 const serviceId = deployed.site.service!.serviceId;
103 yield* stack.destroy();
104 const gone = yield* waitUntilGone(serviceId);
105 expect(gone).toEqual("gone");
106 }).pipe(logLevel),
107 {
108 tags: [
109 "provider:railway",
110 "provider:railway:project",
111 "provider:railway:projectenvironment",
112 "provider:railway:service",
113 "provider:railway:website",
114 "live",
115 ],
116 timeout: 120_000,
117 },
118 );