@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 134 lines 5.43 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, expectUrlOk } 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", "tanstack-start-app");
16
17 // Clone under the alchemy package so `@tanstack/react-start`,
18 // `@tanstack/react-router`, `vite`, `react`, and `@vitejs/plugin-react`
19 // resolve from the workspace's node_modules (the fixture has none).
20 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
21
22 const fixtureEntries = [".gitignore", "package.json", "vite.config.ts", "src", "public"];
23
24 describe(
25 "AWS.Website.TanStackStart local",
26 { tags: ["provider:aws", "provider:aws:website", "local"] },
27 () => {
28 test.provider(
29 "dev runs TanStack Start's own Vite dev server with no cloud resources",
30 (stack) =>
31 Effect.gen(function* () {
32 yield* stack.destroy();
33
34 const rootDir = yield* cloneFixture(fixtureDir, {
35 prefix: "alchemy-tanstack-start-aws-local-",
36 tempRoot,
37 entries: fixtureEntries,
38 });
39
40 const deployed = yield* stack.deploy(
41 Effect.gen(function* () {
42 const site = yield* AWS.Website.TanStackStart("TanStackStartSite", {
43 rootDir,
44 env: { TANSTACK_ENV_MARKER: "tanstack-start-aws-dev-env-marker" },
45 });
46 return { site };
47 }),
48 );
49
50 // The site is the framework's own dev server: a localhost URL and no
51 // cloud rows at all (proof no AWS call ran).
52 const url = deployed.site.url! as string;
53 expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1|\[[0-9a-fA-F:]+\])/);
54 // The URL is an origin, not a directory — appending a path must not
55 // produce a double slash.
56 expect(url.endsWith("/")).toBe(false);
57 expect(deployed.site.distribution).toBeUndefined();
58 expect(deployed.site.server).toBeUndefined();
59 expect(deployed.site.bucket).toBeUndefined();
60
61 // The dev server is reachable from another process.
62 expect(yield* expectUrlOk(`${url}/`)).toBe(200);
63
64 yield* stack.destroy();
65 }),
66 { timeout: 600_000 },
67 );
68
69 test.provider(
70 "dev serves SSR, the project's vite.config.ts, injected env, and HMR",
71 (stack) =>
72 Effect.gen(function* () {
73 const fs = yield* FileSystem.FileSystem;
74 const path = yield* Path.Path;
75
76 yield* stack.destroy();
77
78 const rootDir = yield* cloneFixture(fixtureDir, {
79 prefix: "alchemy-tanstack-start-aws-local-ssr-",
80 tempRoot,
81 entries: fixtureEntries,
82 });
83
84 const deployed = yield* stack.deploy(
85 Effect.gen(function* () {
86 const site = yield* AWS.Website.TanStackStart("TanStackStartSite", {
87 rootDir,
88 env: { TANSTACK_ENV_MARKER: "tanstack-start-aws-dev-env-marker" },
89 });
90 return { site };
91 }),
92 );
93
94 const url = deployed.site.url! as string;
95
96 // SSR page served by the TanStack Start dev server (native HMR).
97 yield* expectUrlContains(`${url}/`, "TANSTACK_AWS_PAGE_MARKER", {
98 timeout: "120 seconds",
99 label: "dev SSR home page",
100 });
101 // The fixture's own vite.config.ts applied in dev too.
102 yield* expectUrlContains(`${url}/`, "config:tanstack-start-aws-user-config-loaded", {
103 label: "user vite.config.ts applied (dev)",
104 });
105 // server.environment reaches the dev server's process env — the same
106 // values the Lambda gets on deploy (dev/live parity).
107 yield* expectUrlContains(`${url}/`, "env:tanstack-start-aws-dev-env-marker", {
108 label: "server.environment injected into dev server",
109 });
110 // Server route through the dev server.
111 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "TANSTACK_AWS_API_MARKER", {
112 label: "server route (dev)",
113 });
114
115 // ── HMR: edit the server route in place. The stack is NOT
116 // re-applied — vite's dev rebuild must pick the change up and serve
117 // it through the same URL ─────────────────────────────────────────
118 const helloPath = path.join(rootDir, "src/routes/api.hello.ts");
119 const hello = yield* fs.readFileString(helloPath);
120 yield* fs.writeFileString(
121 helloPath,
122 hello.replace("TANSTACK_AWS_API_MARKER", "TANSTACK_AWS_API_MARKER_V2"),
123 );
124 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "TANSTACK_AWS_API_MARKER_V2", {
125 timeout: "90 seconds",
126 label: "server route after HMR edit",
127 });
128
129 yield* stack.destroy();
130 }),
131 { timeout: 600_000 },
132 );
133 },
134 );