@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 130 lines 4.79 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import { CloudflareEnvironment } from "@alchemy.run/cloudflare/CloudflareEnvironment";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as Path from "effect/Path";
8 import { MinimumLogLevel } from "effect/References";
9 import * as pathe from "pathe";
10 import { cloneFixture } from "../Utils/Fixture.ts";
11 import { expectUrlContains } from "../Utils/Http.ts";
12 import { expectWorkerExists, waitForWorkerToBeDeleted } from "../Utils/Worker.ts";
13
14 const { test } = Test.make({ providers: Cloudflare.providers() });
15
16 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
17
18 const fixtureDir = pathe.resolve(
19 import.meta.dirname,
20 "../../../../../examples/cloudflare-website-vocs",
21 );
22 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
23 const fixtureEntries = ["package.json", "public", "src", "tsconfig.json", "vocs.config.ts"];
24
25 const vocsProps = (rootDir: string) => ({
26 rootDir,
27 workersDev: { enabled: true, previewsEnabled: true },
28 compatibility: { date: "2026-03-10" },
29 memo: { include: ["src/**", "public/**", "package.json", "tsconfig.json", "vocs.config.ts"] },
30 });
31
32 describe.concurrent(
33 "Vocs",
34 {
35 tags: [
36 "provider:cloudflare",
37 "provider:cloudflare:website",
38 "provider:cloudflare:worker",
39 "live",
40 ],
41 },
42 () => {
43 test.provider(
44 "Vocs: deploys SSR, MDX, generated and public assets, and memoizes rebuilds",
45 (stack) =>
46 Effect.gen(function* () {
47 const { accountId } = yield* yield* CloudflareEnvironment;
48 const fs = yield* FileSystem.FileSystem;
49 const path = yield* Path.Path;
50
51 yield* stack.destroy();
52
53 const rootDir = yield* cloneFixture(fixtureDir, {
54 prefix: "alchemy-vocs-",
55 tempRoot,
56 entries: fixtureEntries,
57 });
58
59 const deploy = () =>
60 stack.deploy(Cloudflare.Website.Vocs("VocsSite", vocsProps(rootDir)));
61
62 const site1 = yield* deploy();
63
64 expect(site1.url).toBeDefined();
65 expect(site1.hash?.input).toBeDefined();
66 yield* expectWorkerExists(site1.workerName, accountId);
67
68 yield* expectUrlContains(`${site1.url!}/`, "Alchemy with Vocs", {
69 timeout: "120 seconds",
70 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
71 label: "Vocs SSR shell and home page",
72 });
73 yield* expectUrlContains(`${site1.url!}/guide`, "Deployment guide", {
74 timeout: "60 seconds",
75 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
76 label: "Vocs prerendered MDX guide",
77 });
78 yield* expectUrlContains(`${site1.url!}/counter`, "Interactive component", {
79 timeout: "60 seconds",
80 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
81 label: "Vocs MDX client-component page",
82 });
83 yield* expectUrlContains(
84 `${site1.url!}/hello.txt`,
85 "hello from the Vocs public directory",
86 {
87 timeout: "60 seconds",
88 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
89 label: "Vocs public asset",
90 },
91 );
92 yield* expectUrlContains(`${site1.url!}/llms.txt`, "Alchemy with Vocs", {
93 timeout: "60 seconds",
94 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
95 label: "Vocs generated llms asset",
96 });
97
98 const site2 = yield* deploy();
99 expect(site2.hash?.input).toEqual(site1.hash?.input);
100 expect(site2.url).toBe(site1.url);
101
102 const pagePath = path.join(rootDir, "src/pages/index.mdx");
103 const page = yield* fs.readFileString(pagePath);
104 yield* fs.writeFileString(
105 pagePath,
106 page.replace(
107 "No Wrangler configuration or Vocs adapter setup is required.",
108 "This Vocs page was updated by a deployment.",
109 ),
110 );
111
112 const site3 = yield* deploy();
113 expect(site3.hash?.input).not.toEqual(site1.hash?.input);
114 yield* expectUrlContains(
115 `${site3.url!}/?__alchemy_cb=${Date.now()}`,
116 "This Vocs page was updated by a deployment.",
117 {
118 timeout: "180 seconds",
119 headers: { accept: "text/html", "user-agent": "Mozilla/5.0" },
120 label: "Vocs page after source update",
121 },
122 );
123
124 yield* stack.destroy();
125 yield* waitForWorkerToBeDeleted(site1.workerName, accountId);
126 }).pipe(logLevel),
127 { timeout: 360_000 },
128 );
129 },
130 );