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 pathe from "pathe"; |
| 6 | import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts"; |
| 7 | import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts"; |
| 8 | import { |
| 9 | foldkitFixture, |
| 10 | foldkitMemo, |
| 11 | verifyFoldkitBrowser, |
| 12 | verifyFoldkitRendering, |
| 13 | } from "../../Website/Foldkit.ts"; |
| 14 | |
| 15 | const { test } = Test.make({ providers: AWS.providers() }); |
| 16 | |
| 17 | // Gated: CloudFront Distribution create blocks on Status === "Deployed" |
| 18 | // (~5-15 min) and destroy requires disable -> wait -> delete (another |
| 19 | // ~5-15 min). Skipped under --fast (FAST=1) (same gate |
| 20 | // as the AWS.CloudFront and AWS.Website.Vite suites). |
| 21 | const runLive = !process.env.FAST; |
| 22 | |
| 23 | const fixtureDir = pathe.resolve(import.meta.dirname, "fixtures", "foldkit-app"); |
| 24 | |
| 25 | // Clone under the alchemy package so `vite`, `foldkit`, and |
| 26 | // `@foldkit/vite-plugin` resolve from the workspace's hoisted node_modules |
| 27 | // (the fixture has none of its own). Vite's `vite:build-html` plugin also |
| 28 | // expresses emitted asset paths relative to the cwd, so the clone has to |
| 29 | // live under the same workspace root. |
| 30 | const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp"); |
| 31 | |
| 32 | const fixtureEntries = [ |
| 33 | ".gitignore", |
| 34 | "package.json", |
| 35 | "vite.config.ts", |
| 36 | "index.html", |
| 37 | "src", |
| 38 | "public", |
| 39 | ]; |
| 40 | |
| 41 | // Skipped under the floci runner: in dev the composite deploys only the |
| 42 | // framework dev server (no Lambda/S3/CloudFront), so this test's live |
| 43 | // topology assertions are meaningless there. Dev behavior is covered by |
| 44 | // the co-located Foldkit.local.test.ts suite. |
| 45 | const runEmulated = process.env.ALCHEMY_TEST_DEV === "1"; |
| 46 | |
| 47 | describe.skipIf(!runLive || runEmulated)( |
| 48 | "AWS.Website.Foldkit", |
| 49 | { tags: ["provider:aws", "provider:aws:website", "live"] }, |
| 50 | () => { |
| 51 | // The resource's reason to exist: a Foldkit app routes on the client, so |
| 52 | // the deployment is assets-only and deep links fall back to the shell |
| 53 | // without the caller configuring anything. |
| 54 | test.provider( |
| 55 | "deploys the foldkit client build to S3 behind CloudFront with SPA fallback", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | yield* stack.destroy(); |
| 59 | |
| 60 | const rootDir = yield* cloneFixture(fixtureDir, { |
| 61 | prefix: "alchemy-foldkit-aws-live-", |
| 62 | tempRoot, |
| 63 | entries: fixtureEntries, |
| 64 | }); |
| 65 | |
| 66 | const deployed = yield* stack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | // Deliberately no `spa` — the default is what's under test. |
| 69 | const site = yield* AWS.Website.Foldkit("FoldkitSite", { |
| 70 | rootDir, |
| 71 | forceDestroy: true, |
| 72 | invalidation: { paths: "all", wait: true }, |
| 73 | }); |
| 74 | return { site }; |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | const url = deployed.site.url! as string; |
| 79 | expect(url).toMatch(/^https:\/\//); |
| 80 | // Assets-only: a Foldkit app is client-only, so the composite never |
| 81 | // creates a server function. |
| 82 | expect(deployed.site.server).toBeUndefined(); |
| 83 | expect(deployed.site.serverUrl).toBeUndefined(); |
| 84 | |
| 85 | // The built index page serves from the edge. |
| 86 | yield* expectUrlContains(`${url}/`, "FOLDKIT_AWS_PAGE_MARKER", { |
| 87 | timeout: "180 seconds", |
| 88 | label: "index", |
| 89 | }); |
| 90 | // publicDir passthrough landed in the bucket. |
| 91 | yield* expectUrlContains(`${url}/robots.txt`, "User-agent", { label: "public asset" }); |
| 92 | // SPA fallback (the composite's default): a deep link boots the app |
| 93 | // instead of 404ing, and the Foldkit router resolves the route. |
| 94 | yield* expectUrlContains(`${url}/counter/42`, "FOLDKIT_AWS_PAGE_MARKER", { |
| 95 | label: "spa fallback", |
| 96 | }); |
| 97 | |
| 98 | yield* stack.destroy(); |
| 99 | }), |
| 100 | { timeout: 2_400_000 }, |
| 101 | ); |
| 102 | |
| 103 | // One distribution walked through every rendering mode. Prerendered |
| 104 | // pages are S3 objects; other routes, and every non-GET/HEAD request |
| 105 | // (a POST to a prerendered page included), reach the Web Function. |
| 106 | // `output: "static"` then drops the server and serves only the pages. |
| 107 | test.provider( |
| 108 | "renders SSR, SSG and hybrid output through the Web Function, then static output without one", |
| 109 | (stack) => |
| 110 | Effect.gen(function* () { |
| 111 | yield* stack.destroy(); |
| 112 | |
| 113 | for (const mode of ["hybrid", "ssr", "ssg"] as const) { |
| 114 | const rootDir = yield* foldkitFixture(mode); |
| 115 | const site = yield* stack.deploy( |
| 116 | AWS.Website.Foldkit("FoldkitSite", { |
| 117 | rootDir, |
| 118 | output: "server", |
| 119 | memo: foldkitMemo, |
| 120 | forceDestroy: true, |
| 121 | invalidation: { paths: "all", wait: true }, |
| 122 | }), |
| 123 | ); |
| 124 | expect(site.server).toBeDefined(); |
| 125 | yield* verifyFoldkitRendering(site.url! as string, mode); |
| 126 | yield* verifyFoldkitBrowser(site.url! as string, mode); |
| 127 | } |
| 128 | |
| 129 | const rootDir = yield* foldkitFixture("static"); |
| 130 | const site = yield* stack.deploy( |
| 131 | AWS.Website.Foldkit("FoldkitSite", { |
| 132 | rootDir, |
| 133 | output: "static", |
| 134 | errorPage: "404.html", |
| 135 | memo: foldkitMemo, |
| 136 | forceDestroy: true, |
| 137 | invalidation: { paths: "all", wait: true }, |
| 138 | }), |
| 139 | ); |
| 140 | expect(site.server).toBeUndefined(); |
| 141 | yield* verifyFoldkitRendering(site.url! as string, "static"); |
| 142 | |
| 143 | yield* stack.destroy(); |
| 144 | }), |
| 145 | { timeout: 3_600_000 }, |
| 146 | ); |
| 147 | }, |
| 148 | ); |