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

main
ts 93 lines 3.85 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
11 // `dev: true` runs local providers behind the RPC sidecar proxy by default,
12 // matching the process topology of the real `alchemy dev` command.
13 const { test } = Test.make({ providers: AWS.providers(), dev: true });
14
15 const fixtureDir = pathe.resolve(import.meta.dirname, "fixtures", "waku-app");
16
17 // Clone under the alchemy package so `waku`/`react` resolve from the
18 // workspace's hoisted node_modules (the fixture has no node_modules).
19 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
20
21 const fixtureEntries = [".gitignore", "package.json", "tsconfig.json", "src", "public"];
22
23 describe(
24 "AWS.Website.Waku local",
25 { tags: ["provider:aws", "provider:aws:website", "local"] },
26 () => {
27 test.provider(
28 "dev runs Waku's own dev server with no cloud resources",
29 (stack) =>
30 Effect.gen(function* () {
31 const fs = yield* FileSystem.FileSystem;
32 const path = yield* Path.Path;
33
34 yield* stack.destroy();
35
36 const rootDir = yield* cloneFixture(fixtureDir, {
37 prefix: "alchemy-waku-aws-local-",
38 tempRoot,
39 entries: fixtureEntries,
40 });
41
42 const deployed = yield* stack.deploy(
43 Effect.gen(function* () {
44 const site = yield* AWS.Website.Waku("WakuSite", { rootDir });
45 return { site };
46 }),
47 );
48
49 // The site is the framework's own dev server: a localhost URL and
50 // no cloud rows at all (proof no AWS call ran).
51 const url = deployed.site.url! as string;
52 expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1|\[[0-9a-fA-F:]+\])/);
53 expect(deployed.site.distribution).toBeUndefined();
54 expect(deployed.site.server).toBeUndefined();
55 expect(deployed.site.bucket).toBeUndefined();
56
57 // SSR page served by the waku dev server (native HMR toolchain).
58 yield* expectUrlContains(`${url}/`, "WAKU_AWS_PAGE_MARKER", {
59 timeout: "120 seconds",
60 label: "dev SSR home page",
61 });
62 // API route (waku's `_api` pattern) through the dev server.
63 yield* expectUrlContains(`${url}/echo?echo=dev`, "WAKU_AWS_API_MARKER", {
64 label: "API route (dev)",
65 });
66 yield* expectUrlContains(`${url}/echo?echo=dev`, "dev", {
67 label: "API route query echo (dev)",
68 });
69
70 // ── HMR: edit the API route in place. The stack is NOT re-applied —
71 // waku's vite dev rebuild must pick the change up and serve it
72 // through the same URL ───────────────────────────────────────────
73 const echoPath = path.join(rootDir, "src/pages/_api/echo.ts");
74 const echo = yield* fs.readFileString(echoPath);
75 yield* fs.writeFileString(
76 echoPath,
77 echo.replaceAll("WAKU_AWS_API_MARKER", "WAKU_AWS_API_MARKER_V2"),
78 );
79 yield* expectUrlContains(`${url}/echo?echo=dev`, "WAKU_AWS_API_MARKER_V2", {
80 timeout: "90 seconds",
81 label: "API route after HMR edit",
82 });
83 // The route still round-trips its query after the reload.
84 yield* expectUrlContains(`${url}/echo?echo=post-hmr`, "post-hmr", {
85 label: "API route query echo after HMR edit",
86 });
87
88 yield* stack.destroy();
89 }),
90 { timeout: 600_000 },
91 );
92 },
93 );