@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 104 lines 4.5 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", "nuxt-app");
16
17 // Clone under the alchemy package so `nuxt`/`nitropack` 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", "nuxt.config.ts", "app", "server", "public"];
22
23 describe(
24 "AWS.Website.Nuxt local",
25 { tags: ["provider:aws", "provider:aws:website", "local"] },
26 () => {
27 test.provider(
28 "dev runs Nuxt'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-nuxt-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.Nuxt("NuxtSite", {
45 rootDir,
46 env: { NUXT_PUBLIC_ENV_MARKER: "nuxt-aws-dev-env-marker" },
47 });
48 return { site };
49 }),
50 );
51
52 // The site is the framework's own dev server: a localhost URL and
53 // no cloud rows at all (proof no AWS call ran).
54 const url = deployed.site.url! as string;
55 expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1|\[[0-9a-fA-F:]+\])/);
56 expect(deployed.site.distribution).toBeUndefined();
57 expect(deployed.site.server).toBeUndefined();
58 expect(deployed.site.bucket).toBeUndefined();
59
60 // SSR page served by the nuxt dev server (native HMR toolchain).
61 yield* expectUrlContains(`${url}/`, "NUXT_AWS_PAGE_MARKER", {
62 timeout: "120 seconds",
63 label: "dev SSR home page",
64 });
65 // The fixture's own nuxt.config.ts applied in dev too.
66 yield* expectUrlContains(`${url}/`, "config:nuxt-aws-user-config-loaded", {
67 label: "user nuxt.config.ts applied (dev)",
68 });
69 // server.environment reaches the dev server's process env — the
70 // same values the Lambda gets on deploy (dev/live parity).
71 yield* expectUrlContains(`${url}/`, "env:nuxt-aws-dev-env-marker", {
72 label: "server.environment injected into dev server",
73 });
74 // Server API route through the dev server.
75 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "NUXT_AWS_API_MARKER", {
76 label: "API route (dev)",
77 });
78
79 // ── HMR: edit the API route in place. The stack is NOT re-applied —
80 // nitro's dev rebuild must pick the change up and serve it through
81 // the same URL ───────────────────────────────────────────────────
82 const helloPath = path.join(rootDir, "server/api/hello.ts");
83 const hello = yield* fs.readFileString(helloPath);
84 yield* fs.writeFileString(
85 helloPath,
86 hello.replace("NUXT_AWS_API_MARKER", "NUXT_AWS_API_MARKER_V2"),
87 );
88 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "NUXT_AWS_API_MARKER_V2", {
89 timeout: "90 seconds",
90 label: "API route after HMR edit",
91 });
92 // server.environment survived the dev rebuild — the injected env
93 // still reaches SSR after the reload (dev/live parity holds across
94 // hot updates, not just at boot).
95 yield* expectUrlContains(`${url}/`, "env:nuxt-aws-dev-env-marker", {
96 label: "server.environment after HMR edit",
97 });
98
99 yield* stack.destroy();
100 }),
101 { timeout: 600_000 },
102 );
103 },
104 );