@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 129 lines 5.03 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 cloudfront from "@distilled.cloud/aws/cloudfront";
5 import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as Path from "effect/Path";
8 import * as Schedule from "effect/Schedule";
9 import * as pathe from "pathe";
10 import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
11 import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
12
13 const { test } = Test.make({ providers: AWS.providers() });
14
15 // Gated with the rest of the AWS.Website suites: the CloudFront lifecycle
16 // dominates the runtime (create ~5-15 min, destroy ~5-15 min).
17 const runLive = !process.env.FAST;
18
19 const fixtureDir = pathe.resolve(import.meta.dirname, "fixtures", "octane-app");
20
21 // Clone under the alchemy package so `octane`/`@octanejs/*`/`vite` resolve
22 // from the workspace's hoisted node_modules (the fixture has no
23 // node_modules).
24 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
25
26 const fixtureEntries = [
27 ".gitignore",
28 "package.json",
29 "octane.config.ts",
30 "vite.config.ts",
31 "index.html",
32 "src",
33 "public",
34 ];
35
36 // Skipped under the floci runner: in dev the composite deploys only the
37 // framework dev server (no Lambda/S3/CloudFront), so this test's live
38 // topology assertions are meaningless there. Dev behavior is covered by
39 // the co-located Octane.local.test.ts suite.
40 const runEmulated = process.env.ALCHEMY_TEST_DEV === "1";
41
42 describe.skipIf(!runLive || runEmulated)(
43 "AWS.Website.Octane",
44 { tags: ["provider:aws", "provider:aws:cloudfront", "provider:aws:website", "live"] },
45 () => {
46 test.provider(
47 "deploys SSR on a Lambda Web Function with S3 assets behind CloudFront",
48 (stack) =>
49 Effect.gen(function* () {
50 yield* stack.destroy();
51
52 const rootDir = yield* cloneFixture(fixtureDir, {
53 prefix: "alchemy-octane-aws-",
54 tempRoot,
55 entries: fixtureEntries,
56 });
57
58 const fs = yield* FileSystem.FileSystem;
59 const path = yield* Path.Path;
60 const configPath = path.join(rootDir, "octane.config.ts");
61 const config = yield* fs.readFileString(configPath);
62 expect(config).not.toContain("adapter:");
63 expect(config).not.toContain("@alchemy.run/frontend-frameworks");
64
65 const deployed = yield* stack.deploy(
66 Effect.gen(function* () {
67 const site = yield* AWS.Website.Octane("OctaneSite", {
68 rootDir,
69 forceDestroy: true,
70 invalidation: { paths: "all", wait: true },
71 });
72 return { site };
73 }),
74 );
75
76 expect(yield* fs.readFileString(configPath)).toBe(config);
77 const url = deployed.site.url! as string;
78 expect(url).toMatch(/^https:\/\//);
79 expect(deployed.site.serverUrl).toBeDefined();
80 // The server is a Lambda Web Function (the default).
81 expect(deployed.site.serverUrl).toContain(".lambda-web.");
82 yield* Effect.log(`site url: ${url} | server url: ${deployed.site.serverUrl}`);
83
84 // The Lambda Function URL serves the SSR page directly — isolates
85 // server-function health from the CloudFront edge routing.
86 yield* expectUrlContains(`${deployed.site.serverUrl!}`, "OCTANE_AWS_PAGE_MARKER", {
87 timeout: "120 seconds",
88 label: "SSR direct from Lambda URL",
89 });
90
91 // SSR page rendered by the Lambda through CloudFront.
92 yield* expectUrlContains(`${url}/`, "OCTANE_AWS_PAGE_MARKER", {
93 timeout: "180 seconds",
94 label: "SSR home page",
95 });
96 // Server API route through the streaming Function URL origin.
97 yield* expectUrlContains(`${url}/api/hello?echo=roundtrip`, "OCTANE_AWS_API_MARKER", {
98 label: "API route",
99 });
100 yield* expectUrlContains(`${url}/api/hello?echo=roundtrip`, "roundtrip", {
101 label: "API route query echo",
102 });
103 // Public file served from S3 via the KV file manifest.
104 yield* expectUrlContains(`${url}/robots.txt`, "octane-aws-robots-marker", {
105 label: "public asset from S3",
106 });
107
108 const distributionId = deployed.site.distribution!.distributionId;
109
110 if (!process.env.NO_DESTROY) {
111 yield* stack.destroy();
112 yield* assertDistributionDeleted(distributionId);
113 }
114 }),
115 { timeout: 2_400_000 },
116 );
117 },
118 );
119
120 const assertDistributionDeleted = (distributionId: string) =>
121 cloudfront.getDistribution({ Id: distributionId }).pipe(
122 Effect.flatMap(() => Effect.fail(new Error("DistributionStillExists"))),
123 Effect.catchTag("NoSuchDistribution", () => Effect.void),
124 Effect.retry({
125 while: (error): boolean =>
126 error instanceof Error && error.message === "DistributionStillExists",
127 schedule: Schedule.max([Schedule.fixed("10 seconds"), Schedule.recurs(60)]),
128 }),
129 );