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

main
ts 100 lines 4.19 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", "astro-app");
16
17 // Clone under the alchemy package so `astro` resolves from the workspace's
18 // 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", "astro.config.mjs", "src", "public"];
22
23 describe(
24 "AWS.Website.Astro local",
25 { tags: ["provider:aws", "provider:aws:website", "local"] },
26 () => {
27 test.provider(
28 "dev runs Astro'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-astro-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.Astro("AstroSite", {
45 rootDir,
46 // Pin the dev server to a deterministic port — `dev.port`
47 // flows through Server's port probe into the framework kit.
48 dev: { port: 43117 },
49 });
50 return { site };
51 }),
52 );
53
54 // The site is the framework's own dev server: a localhost URL and
55 // no cloud rows at all (proof no AWS call ran).
56 const url = deployed.site.url! as string;
57 expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1|\[[0-9a-fA-F:]+\])/);
58 // The preferred `dev.port` was honored.
59 expect(url).toContain(":43117");
60 expect(deployed.site.distribution).toBeUndefined();
61 expect(deployed.site.server).toBeUndefined();
62 expect(deployed.site.bucket).toBeUndefined();
63
64 // SSR page served by the astro dev server (native HMR toolchain).
65 yield* expectUrlContains(`${url}/`, "ASTRO_AWS_PAGE_MARKER", {
66 timeout: "120 seconds",
67 label: "dev SSR home page",
68 });
69 // API route through the dev server.
70 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "ASTRO_AWS_API_MARKER", {
71 label: "API route (dev)",
72 });
73 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "dev", {
74 label: "API route query echo (dev)",
75 });
76
77 // ── HMR: edit the API route in place. The stack is NOT re-applied —
78 // astro's dev rebuild must pick the change up and serve it through
79 // the same URL ───────────────────────────────────────────────────
80 const helloPath = path.join(rootDir, "src/pages/api/hello.ts");
81 const hello = yield* fs.readFileString(helloPath);
82 yield* fs.writeFileString(
83 helloPath,
84 hello.replace("ASTRO_AWS_API_MARKER", "ASTRO_AWS_API_MARKER_V2"),
85 );
86 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "ASTRO_AWS_API_MARKER_V2", {
87 timeout: "90 seconds",
88 label: "API route after HMR edit",
89 });
90 // The route still round-trips its query after the reload.
91 yield* expectUrlContains(`${url}/api/hello?echo=post-hmr`, "post-hmr", {
92 label: "API route query echo after HMR edit",
93 });
94
95 yield* stack.destroy();
96 }),
97 { timeout: 600_000 },
98 );
99 },
100 );