@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 93 lines 3.1 KB
Raw
1 import * as Fly from "@alchemy.run/fly";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as machines from "@distilled.cloud/fly-io/machines";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8 import * as pathe from "pathe";
9 import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
10 import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
11 import { prepareNextjsFixture } from "../../Cloudflare/Website/TypeScriptCompat.ts";
12
13 const { test } = Test.make({ providers: Fly.providers() });
14
15 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
16
17 const fixtureDir = pathe.resolve(import.meta.dirname, "../../AWS/Website/fixtures/nextjs-app");
18 const fixtureEntries = [
19 ".gitignore",
20 "package.json",
21 "next.config.ts",
22 "tsconfig.json",
23 "app",
24 "public",
25 ];
26
27 const waitUntilGone = (appName: string) =>
28 machines.getApp({ app_name: appName }).pipe(
29 Effect.as("found" as const),
30 Effect.catchTag("NotFound", () => 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 "Nextjs: deploy, GET /, destroy, gone",
40 (stack) =>
41 Effect.gen(function* () {
42 yield* stack.destroy();
43
44 // Clone OUTSIDE the repo (OS temp dir): an in-workspace clone makes
45 // Next treat the alchemy monorepo as the workspace root and look up
46 // the root's typescript (catalog:build = tsgo, which has no JS compiler).
47 const rootDir = yield* cloneFixture(fixtureDir, {
48 prefix: "alchemy-nextjs-fly-",
49 entries: fixtureEntries,
50 });
51 yield* prepareNextjsFixture(rootDir);
52
53 const deployed = yield* stack.deploy(
54 Effect.gen(function* () {
55 const site = yield* Fly.Website.Nextjs("Web", {
56 rootDir,
57 memo: {
58 include: ["app/**", "public/**", "package.json", "next.config.ts", "tsconfig.json"],
59 },
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 expect(deployed.site.app).toBeDefined();
70
71 yield* expectUrlContains(`${url!}/`, "NEXTJS_AWS_PAGE_MARKER", {
72 timeout: "90 seconds",
73 label: "home page",
74 });
75 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "NEXTJS_AWS_API_MARKER", {
76 timeout: "30 seconds",
77 label: "api route",
78 });
79 yield* expectUrlContains(`${url!}/static`, "NEXTJS_AWS_STATIC_MARKER", {
80 timeout: "30 seconds",
81 label: "extra route",
82 });
83
84 const appName = deployed.site.app!.appName;
85 yield* stack.destroy();
86 const gone = yield* waitUntilGone(appName);
87 expect(gone).toEqual("gone");
88 }).pipe(logLevel),
89 {
90 tags: ["provider:fly", "provider:fly:machine", "provider:fly:website", "live"],
91 timeout: 480000,
92 },
93 );