@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 160 lines 6.68 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 /**
16 * SolidStart 2's dev SSR does not run under Bun.
17 *
18 * `solid-start-dev-server` answers every request through
19 * `sendNodeResponse(res, webRes)` from `srvx/node`; under Bun that writes the
20 * literal string `[object Object]` (HTTP 200, 15 bytes) instead of the
21 * rendered document. Under Node the same code path returns the SSR HTML.
22 * Verified directly against the framework integration:
23 *
24 * node -> STATUS 200 LEN 1070 "<!DOCTYPE html><html lang=\"en\">..."
25 * bun -> STATUS 200 LEN 15 "[object Object]"
26 *
27 * `alchemy dev` hosts local providers in a Bun sidecar
28 * (`bun run src/AWS/Website/ServerLocal.ts`), so the body assertions below
29 * cannot pass until the upstream `srvx`/Bun gap is closed. Everything the
30 * dev provider itself owns — the server starting, its address, and the
31 * absence of cloud resources — is asserted unconditionally in the first test.
32 *
33 * Set `ALCHEMY_TEST_SOLIDSTART_DEV_SSR=1` to run the body assertions on a
34 * Node-hosted sidecar.
35 */
36 const runDevSsr = process.env.ALCHEMY_TEST_SOLIDSTART_DEV_SSR === "1";
37
38 const fixtureDir = pathe.resolve(import.meta.dirname, "fixtures", "solidstart-app");
39
40 // Clone under the alchemy package so `@solidjs/start`, `vite`, and
41 // `@solidjs/vite-plugin-nitro-2` resolve from the workspace's hoisted
42 // node_modules (the fixture has no node_modules).
43 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
44
45 const fixtureEntries = [".gitignore", "package.json", "vite.config.ts", "src", "public"];
46
47 describe(
48 "AWS.Website.SolidStart local",
49 { tags: ["provider:aws", "provider:aws:website", "local"] },
50 () => {
51 test.provider(
52 "dev runs SolidStart's own Vite dev server with no cloud resources",
53 (stack) =>
54 Effect.gen(function* () {
55 yield* stack.destroy();
56
57 const rootDir = yield* cloneFixture(fixtureDir, {
58 prefix: "alchemy-solidstart-aws-local-",
59 tempRoot,
60 entries: fixtureEntries,
61 });
62
63 const deployed = yield* stack.deploy(
64 Effect.gen(function* () {
65 const site = yield* AWS.Website.SolidStart("SolidStartSite", {
66 rootDir,
67 env: { SOLIDSTART_ENV_MARKER: "solidstart-aws-dev-env-marker" },
68 });
69 return { site };
70 }),
71 );
72
73 // The site is the framework's own dev server: a localhost URL and
74 // no cloud rows at all (proof no AWS call ran).
75 const url = deployed.site.url! as string;
76 expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1|\[[0-9a-fA-F:]+\])/);
77 // The URL is an origin, not a directory — appending a path must not
78 // produce a double slash (SolidStart runs `appType: "custom"`, so its
79 // router sees the raw pathname and `//about` is a 404).
80 expect(url.endsWith("/")).toBe(false);
81 expect(deployed.site.distribution).toBeUndefined();
82 expect(deployed.site.server).toBeUndefined();
83 expect(deployed.site.bucket).toBeUndefined();
84
85 // The dev server is reachable from another process.
86 expect(yield* expectUrlOk(`${url}/`)).toBe(200);
87
88 yield* stack.destroy();
89 }),
90 { timeout: 600_000 },
91 );
92
93 // Body-level assertions: gated on a Node-hosted dev sidecar (see the note
94 // on `runDevSsr` above).
95 test.provider.skipIf(!runDevSsr)(
96 "dev serves SSR, the project's vite.config.ts, injected env, and HMR",
97 (stack) =>
98 Effect.gen(function* () {
99 const fs = yield* FileSystem.FileSystem;
100 const path = yield* Path.Path;
101
102 yield* stack.destroy();
103
104 const rootDir = yield* cloneFixture(fixtureDir, {
105 prefix: "alchemy-solidstart-aws-local-ssr-",
106 tempRoot,
107 entries: fixtureEntries,
108 });
109
110 const deployed = yield* stack.deploy(
111 Effect.gen(function* () {
112 const site = yield* AWS.Website.SolidStart("SolidStartSite", {
113 rootDir,
114 env: { SOLIDSTART_ENV_MARKER: "solidstart-aws-dev-env-marker" },
115 });
116 return { site };
117 }),
118 );
119
120 const url = deployed.site.url! as string;
121
122 // SSR page served by the SolidStart dev server (native HMR).
123 yield* expectUrlContains(`${url}/`, "SOLIDSTART_AWS_PAGE_MARKER", {
124 timeout: "120 seconds",
125 label: "dev SSR home page",
126 });
127 // The fixture's own vite.config.ts applied in dev too.
128 yield* expectUrlContains(`${url}/`, "config:solidstart-aws-user-config-loaded", {
129 label: "user vite.config.ts applied (dev)",
130 });
131 // server.environment reaches the dev server's process env — the
132 // same values the Lambda gets on deploy (dev/live parity).
133 yield* expectUrlContains(`${url}/`, "env:solidstart-aws-dev-env-marker", {
134 label: "server.environment injected into dev server",
135 });
136 // API route through the dev server.
137 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "SOLIDSTART_AWS_API_MARKER", {
138 label: "API route (dev)",
139 });
140
141 // ── HMR: edit the API route in place. The stack is NOT re-applied —
142 // vite's dev rebuild must pick the change up and serve it through
143 // the same URL ───────────────────────────────────────────────────
144 const helloPath = path.join(rootDir, "src/routes/api/hello.ts");
145 const hello = yield* fs.readFileString(helloPath);
146 yield* fs.writeFileString(
147 helloPath,
148 hello.replace("SOLIDSTART_AWS_API_MARKER", "SOLIDSTART_AWS_API_MARKER_V2"),
149 );
150 yield* expectUrlContains(`${url}/api/hello?echo=dev`, "SOLIDSTART_AWS_API_MARKER_V2", {
151 timeout: "90 seconds",
152 label: "API route after HMR edit",
153 });
154
155 yield* stack.destroy();
156 }),
157 { timeout: 600_000 },
158 );
159 },
160 );