| 1 | import * as AWS from "@/AWS"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import { describe, expect } from "alchemy-test"; |
| 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", "octane-app"); |
| 16 | |
| 17 | // Clone under the alchemy package so `octane`/`@octanejs/*`/`vite` resolve |
| 18 | // 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 = [ |
| 23 | ".gitignore", |
| 24 | "package.json", |
| 25 | "octane.config.ts", |
| 26 | "vite.config.ts", |
| 27 | "index.html", |
| 28 | "src", |
| 29 | "public", |
| 30 | ]; |
| 31 | |
| 32 | describe( |
| 33 | "AWS.Website.Octane local", |
| 34 | { tags: ["provider:aws", "provider:aws:website", "local"] }, |
| 35 | () => { |
| 36 | test.provider( |
| 37 | "dev runs Octane's own dev server with no cloud resources", |
| 38 | (stack) => |
| 39 | Effect.gen(function* () { |
| 40 | const fs = yield* FileSystem.FileSystem; |
| 41 | const path = yield* Path.Path; |
| 42 | |
| 43 | yield* stack.destroy(); |
| 44 | |
| 45 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 46 | prefix: "alchemy-octane-aws-local-", |
| 47 | tempRoot, |
| 48 | entries: fixtureEntries, |
| 49 | }); |
| 50 | |
| 51 | const deployed = yield* stack.deploy( |
| 52 | Effect.gen(function* () { |
| 53 | const site = yield* AWS.Website.Octane("OctaneSite", { |
| 54 | rootDir, |
| 55 | }); |
| 56 | return { site }; |
| 57 | }), |
| 58 | ); |
| 59 | |
| 60 | // The site is the framework's own dev server: a localhost URL and |
| 61 | // no cloud rows at all (proof no AWS call ran). |
| 62 | const url = deployed.site.url! as string; |
| 63 | expect(url).toMatch( |
| 64 | /^http:\/\/(localhost|127\.0\.0\.1|\[[0-9a-fA-F:]+\])/, |
| 65 | ); |
| 66 | expect(deployed.site.distribution).toBeUndefined(); |
| 67 | expect(deployed.site.server).toBeUndefined(); |
| 68 | expect(deployed.site.bucket).toBeUndefined(); |
| 69 | |
| 70 | // SSR page served by Octane's Vite dev server (native HMR |
| 71 | // toolchain). NOTE: Octane's dev middleware supplies no platform |
| 72 | // bindings — the plain dev server is the whole story here. |
| 73 | yield* expectUrlContains(`${url}/`, "OCTANE_AWS_PAGE_MARKER", { |
| 74 | timeout: "120 seconds", |
| 75 | label: "dev SSR home page", |
| 76 | }); |
| 77 | // Server API route through the dev server. |
| 78 | yield* expectUrlContains( |
| 79 | `${url}/api/hello?echo=dev`, |
| 80 | "OCTANE_AWS_API_MARKER", |
| 81 | { label: "API route (dev)" }, |
| 82 | ); |
| 83 | yield* expectUrlContains(`${url}/api/hello?echo=dev`, "dev", { |
| 84 | label: "API route query echo (dev)", |
| 85 | }); |
| 86 | |
| 87 | // ── HMR: edit the page component in place. The stack is NOT |
| 88 | // re-applied — Octane's Vite dev server must hot-update the module |
| 89 | // and serve the new marker through the same URL ────────────────── |
| 90 | const appPath = path.join(rootDir, "src/App.tsx"); |
| 91 | const app = yield* fs.readFileString(appPath); |
| 92 | yield* fs.writeFileString( |
| 93 | appPath, |
| 94 | app.replace("OCTANE_AWS_PAGE_MARKER", "OCTANE_AWS_PAGE_MARKER_V2"), |
| 95 | ); |
| 96 | yield* expectUrlContains(`${url}/`, "OCTANE_AWS_PAGE_MARKER_V2", { |
| 97 | timeout: "90 seconds", |
| 98 | label: "SSR page after HMR edit", |
| 99 | }); |
| 100 | // The API route (octane.config.ts server route) survived the |
| 101 | // client-module hot update. |
| 102 | yield* expectUrlContains( |
| 103 | `${url}/api/hello?echo=post-hmr`, |
| 104 | "OCTANE_AWS_API_MARKER", |
| 105 | { label: "API route after HMR edit" }, |
| 106 | ); |
| 107 | |
| 108 | yield* stack.destroy(); |
| 109 | }), |
| 110 | { timeout: 600_000 }, |
| 111 | ); |
| 112 | }, |
| 113 | ); |