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

main
ts 98 lines 3.76 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", "foldkit-app");
16
17 // Clone under the alchemy package so `vite`, `foldkit`, and
18 // `@foldkit/vite-plugin` resolve from the workspace's hoisted node_modules
19 // (the fixture has none of its own).
20 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
21
22 const fixtureEntries = [
23 ".gitignore",
24 "package.json",
25 "vite.config.ts",
26 "index.html",
27 "src",
28 "public",
29 ];
30
31 describe(
32 "AWS.Website.Foldkit local",
33 { tags: ["provider:aws", "provider:aws:website", "local"] },
34 () => {
35 test.provider(
36 "dev runs the app's own Vite dev server with no cloud resources",
37 (stack) =>
38 Effect.gen(function* () {
39 const fs = yield* FileSystem.FileSystem;
40 const path = yield* Path.Path;
41
42 yield* stack.destroy();
43
44 const rootDir = yield* cloneFixture(fixtureDir, {
45 prefix: "alchemy-foldkit-aws-local-",
46 tempRoot,
47 entries: fixtureEntries,
48 });
49
50 const deployed = yield* stack.deploy(
51 Effect.gen(function* () {
52 const site = yield* AWS.Website.Foldkit("FoldkitSite", { rootDir });
53 return { site };
54 }),
55 );
56
57 // The site is Vite's own dev server (the Foldkit plugin runs inside
58 // it): a localhost URL and no cloud rows at all — proof no AWS call
59 // ran, and specifically NOT a *.cloudfront.net URL.
60 const url = deployed.site.url! as string;
61 expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1|\[[0-9a-fA-F:]+\])/);
62 expect(deployed.site.distribution).toBeUndefined();
63 expect(deployed.site.server).toBeUndefined();
64 expect(deployed.site.bucket).toBeUndefined();
65 expect(deployed.site.files).toBeUndefined();
66
67 // The shell serves through Vite's dev server (index.html transformed
68 // on the fly, module scripts served from source).
69 yield* expectUrlContains(`${url}/`, "FOLDKIT_AWS_PAGE_MARKER", {
70 timeout: "120 seconds",
71 label: "dev index page",
72 });
73 // The Foldkit app's source modules serve straight from src/ — no
74 // build ran.
75 yield* expectUrlContains(`${url}/src/main.ts`, "FOLDKIT_AWS_MODULE_MARKER", {
76 label: "dev module source",
77 });
78
79 // ── HMR surface: edit index.html in place. The stack is NOT
80 // re-applied — Vite's dev server serves the transformed html per
81 // request, so the same URL must show the new marker ───────────────
82 const indexPath = path.join(rootDir, "index.html");
83 const index = yield* fs.readFileString(indexPath);
84 yield* fs.writeFileString(
85 indexPath,
86 index.replaceAll("FOLDKIT_AWS_PAGE_MARKER", "FOLDKIT_AWS_PAGE_MARKER_V2"),
87 );
88 yield* expectUrlContains(`${url}/`, "FOLDKIT_AWS_PAGE_MARKER_V2", {
89 timeout: "90 seconds",
90 label: "index page after edit",
91 });
92
93 yield* stack.destroy();
94 }),
95 { timeout: 600_000 },
96 );
97 },
98 );