@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 107 lines 3.62 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 { prepareNextjsFixture } from "../../Cloudflare/Website/TypeScriptCompat.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/nextjs-app");
20 const fixtureEntries = [
21 ".gitignore",
22 "package.json",
23 "next.config.ts",
24 "tsconfig.json",
25 "app",
26 "public",
27 ];
28
29 const readService = Query.fn((id: string) => ({ deletedAt: RailwayApi.service({ id }).deletedAt }));
30
31 const waitUntilGone = (serviceId: string) =>
32 readService(serviceId).pipe(
33 Effect.map((service) => (service.deletedAt != null ? ("gone" as const) : ("found" as const))),
34 Effect.catchTag("RailwayNotFound", () => Effect.succeed("gone" as const)),
35 Effect.repeat({
36 schedule: Schedule.spaced("1 second"),
37 until: (status) => status === "gone",
38 times: 10,
39 }),
40 );
41
42 test.provider(
43 "Nextjs: deploy, GET /, destroy, gone",
44 (stack) =>
45 Effect.gen(function* () {
46 yield* stack.destroy();
47
48 // Clone OUTSIDE the repo (OS temp dir): an in-workspace clone makes
49 // Next treat the alchemy monorepo as the workspace root and look up
50 // the root's typescript (catalog:build = tsgo, which has no JS compiler).
51 const rootDir = yield* cloneFixture(fixtureDir, {
52 prefix: "alchemy-nextjs-railway-",
53 entries: fixtureEntries,
54 });
55 yield* prepareNextjsFixture(rootDir);
56
57 const deployed = yield* stack.deploy(
58 Effect.gen(function* () {
59 const { project, environment } = yield* suitePartition;
60 const site = yield* Railway.Website.Nextjs("Web", {
61 project,
62 environment,
63 rootDir,
64 memo: {
65 include: ["app/**", "public/**", "package.json", "next.config.ts", "tsconfig.json"],
66 },
67 });
68 return { site };
69 }),
70 );
71
72 const url = deployed.site.url;
73 expect(url).toBeDefined();
74 expect(url).toMatch(/^https:\/\//);
75 expect(deployed.site.service).toBeDefined();
76 expect(deployed.site.project).toBeDefined();
77
78 yield* expectUrlContains(`${url!}/`, "NEXTJS_AWS_PAGE_MARKER", {
79 timeout: "90 seconds",
80 label: "home page",
81 });
82 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "NEXTJS_AWS_API_MARKER", {
83 timeout: "30 seconds",
84 label: "api route",
85 });
86 yield* expectUrlContains(`${url!}/static`, "NEXTJS_AWS_STATIC_MARKER", {
87 timeout: "30 seconds",
88 label: "extra route",
89 });
90
91 const serviceId = deployed.site.service!.serviceId;
92 yield* stack.destroy();
93 const gone = yield* waitUntilGone(serviceId);
94 expect(gone).toEqual("gone");
95 }).pipe(logLevel),
96 {
97 tags: [
98 "provider:railway",
99 "provider:railway:project",
100 "provider:railway:projectenvironment",
101 "provider:railway:service",
102 "provider:railway:website",
103 "live",
104 ],
105 timeout: 120_000,
106 },
107 );