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