The best way to control Claude Code, Codex and more from any computer or phone
| 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", "sveltekit-app"); |
| 16 | |
| 17 | // Clone under the alchemy package so `@sveltejs/kit`/`svelte`/`vite` |
| 18 | // resolve from the workspace's hoisted node_modules (the fixture has no |
| 19 | // node_modules). |
| 20 | const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp"); |
| 21 | |
| 22 | const fixtureEntries = [".gitignore", "package.json", "src", "static"]; |
| 23 | |
| 24 | describe( |
| 25 | "AWS.Website.SvelteKit local", |
| 26 | { tags: ["provider:aws", "provider:aws:website", "local"] }, |
| 27 | () => { |
| 28 | test.provider( |
| 29 | "dev runs SvelteKit's own dev server with no cloud resources", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | const fs = yield* FileSystem.FileSystem; |
| 33 | const path = yield* Path.Path; |
| 34 | |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 38 | prefix: "alchemy-sveltekit-aws-local-", |
| 39 | tempRoot, |
| 40 | entries: fixtureEntries, |
| 41 | }); |
| 42 | |
| 43 | const deployed = yield* stack.deploy( |
| 44 | Effect.gen(function* () { |
| 45 | const site = yield* AWS.Website.SvelteKit("SvelteKitSite", { rootDir }); |
| 46 | return { site }; |
| 47 | }), |
| 48 | ); |
| 49 | |
| 50 | // The site is the framework's own dev server: a localhost URL and |
| 51 | // no 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 | expect(deployed.site.distribution).toBeUndefined(); |
| 55 | expect(deployed.site.server).toBeUndefined(); |
| 56 | expect(deployed.site.bucket).toBeUndefined(); |
| 57 | |
| 58 | // SSR page served by the kit dev server (native HMR toolchain). |
| 59 | yield* expectUrlContains(`${url}/`, "SVELTEKIT_AWS_PAGE_MARKER", { |
| 60 | timeout: "120 seconds", |
| 61 | label: "dev SSR home page", |
| 62 | }); |
| 63 | // Server API route through the dev server. |
| 64 | yield* expectUrlContains(`${url}/api/hello?echo=dev`, "SVELTEKIT_AWS_API_MARKER", { |
| 65 | label: "API route (dev)", |
| 66 | }); |
| 67 | yield* expectUrlContains(`${url}/api/hello?echo=dev`, "dev", { |
| 68 | label: "API route query echo (dev)", |
| 69 | }); |
| 70 | |
| 71 | // ── HMR: edit the API route in place. The stack is NOT re-applied — |
| 72 | // the kit/vite dev rebuild must pick the change up and serve it |
| 73 | // through the same URL ─────────────────────────────────────────── |
| 74 | const helloPath = path.join(rootDir, "src/routes/api/hello/+server.ts"); |
| 75 | const hello = yield* fs.readFileString(helloPath); |
| 76 | yield* fs.writeFileString( |
| 77 | helloPath, |
| 78 | hello.replace("SVELTEKIT_AWS_API_MARKER", "SVELTEKIT_AWS_API_MARKER_V2"), |
| 79 | ); |
| 80 | yield* expectUrlContains(`${url}/api/hello?echo=dev`, "SVELTEKIT_AWS_API_MARKER_V2", { |
| 81 | timeout: "90 seconds", |
| 82 | label: "API route after HMR edit", |
| 83 | }); |
| 84 | // The route still round-trips its query after the reload. |
| 85 | yield* expectUrlContains(`${url}/api/hello?echo=post-hmr`, "post-hmr", { |
| 86 | label: "API route query echo after HMR edit", |
| 87 | }); |
| 88 | |
| 89 | yield* stack.destroy(); |
| 90 | }), |
| 91 | { timeout: 600_000 }, |
| 92 | ); |
| 93 | }, |
| 94 | ); |