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

main
ts 103 lines 4.24 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6 import * as Path from "effect/Path";
7 import * as pathe from "pathe";
8 import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
9 import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
10 import { prepareNextjsFixture } from "../../Cloudflare/Website/TypeScriptCompat.ts";
11
12 // `dev: true` runs local providers behind the RPC sidecar proxy by default,
13 // matching the process topology of the real `alchemy dev` command.
14 const { test } = Test.make({ providers: AWS.providers(), dev: true });
15
16 const fixtureDir = pathe.resolve(import.meta.dirname, "fixtures", "nextjs-app");
17
18 const fixtureEntries = [
19 ".gitignore",
20 "package.json",
21 "next.config.ts",
22 "tsconfig.json",
23 "app",
24 "public",
25 ];
26
27 describe(
28 "AWS.Website.Nextjs local",
29 { tags: ["provider:aws", "provider:aws:website", "local"] },
30 () => {
31 test.provider(
32 "dev runs Next's own dev server with no cloud resources",
33 (stack) =>
34 Effect.gen(function* () {
35 const fs = yield* FileSystem.FileSystem;
36 const path = yield* Path.Path;
37
38 yield* stack.destroy();
39
40 // Clone OUTSIDE the repo (OS temp dir): an in-workspace clone makes
41 // OpenNext detect the workspace as a monorepo and trace the server
42 // bundle against bun's isolated-install symlink store, which drops
43 // transitive deps (e.g. @swc/helpers) from the shipped node_modules.
44 const rootDir = yield* cloneFixture(fixtureDir, {
45 prefix: "alchemy-nextjs-aws-local-",
46 entries: fixtureEntries,
47 });
48 yield* prepareNextjsFixture(rootDir);
49
50 const deployed = yield* stack.deploy(
51 Effect.gen(function* () {
52 const site = yield* AWS.Website.Nextjs("NextjsSite", { rootDir });
53 return { site };
54 }),
55 );
56
57 // The site is the framework's own dev server: a localhost URL and
58 // no cloud rows at all (proof no AWS call ran).
59 const url = deployed.site.url! as string;
60 expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1|\[[0-9a-fA-F:]+\])/);
61 expect(deployed.site.distribution).toBeUndefined();
62 expect(deployed.site.server).toBeUndefined();
63 expect(deployed.site.bucket).toBeUndefined();
64 expect(deployed.site.revalidationQueue).toBeUndefined();
65 expect(deployed.site.tagCacheTable).toBeUndefined();
66
67 // SSR page served by the next dev server (native HMR toolchain).
68 yield* expectUrlContains(`${url}/`, "NEXTJS_AWS_PAGE_MARKER", {
69 timeout: "180 seconds",
70 label: "dev SSR home page",
71 });
72 // App Router API route through the dev server.
73 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "NEXTJS_AWS_API_MARKER", {
74 label: "API route (dev)",
75 });
76 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "dev", {
77 label: "API route query echo (dev)",
78 });
79
80 // ── HMR: edit the App Router route in place. The stack is NOT
81 // re-applied — next dev must recompile the route and serve it
82 // through the same URL ───────────────────────────────────────────
83 const routePath = path.join(rootDir, "app/api/hello/route.ts");
84 const route = yield* fs.readFileString(routePath);
85 yield* fs.writeFileString(
86 routePath,
87 route.replace("NEXTJS_AWS_API_MARKER", "NEXTJS_AWS_API_MARKER_V2"),
88 );
89 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "NEXTJS_AWS_API_MARKER_V2", {
90 timeout: "120 seconds",
91 label: "API route after HMR edit",
92 });
93 // The route still round-trips its query after the recompile.
94 yield* expectUrlContains(`${url}/api/hello?echo=post-hmr`, "post-hmr", {
95 label: "API route query echo after HMR edit",
96 });
97
98 yield* stack.destroy();
99 }),
100 { timeout: 600_000 },
101 );
102 },
103 );