@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 318 lines 11.9 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import { describe, expect, it } from "@alchemy.run/test";
3
4 /**
5 * Compile-time pins for the framework Website resources' prop surfaces.
6 *
7 * The resources deliberately reject the Worker props their source dispatch
8 * owns (`script`, `bundle`, `source`, `vite`, `assets` where the framework
9 * owns assets) — passing one used to type-check and only fail at runtime
10 * inside `resolveSource`. These `@ts-expect-error` pins fail the build if
11 * an `Omit` is ever loosened again. The `() => {}` bodies never run; only
12 * the types matter.
13 */
14 describe(
15 "Website prop surfaces",
16 {
17 tags: ["unit", "provider:cloudflare", "provider:cloudflare:website", "local"],
18 },
19 () => {
20 const _pins = [
21 () =>
22 Cloudflare.Website.Waku("W", {
23 // @ts-expect-error `script` is owned by the source dispatch
24 script: "export default {}",
25 }),
26 () =>
27 Cloudflare.Website.Waku("W", {
28 // @ts-expect-error `bundle` is owned by the source dispatch
29 bundle: false,
30 }),
31 () =>
32 Cloudflare.Website.SvelteKit("S", {
33 // @ts-expect-error `script` is owned by the source dispatch
34 script: "export default {}",
35 }),
36 () =>
37 Cloudflare.Website.SvelteKit("S", {
38 // @ts-expect-error `main` is not supported (no custom-entry seam)
39 main: "worker.ts",
40 }),
41 () =>
42 Cloudflare.Website.Nuxt("N", {
43 // @ts-expect-error `bundle` is owned by the source dispatch
44 bundle: false,
45 }),
46 () =>
47 Cloudflare.Website.Astro("A", {
48 // `main` is the custom Worker entry seam
49 main: "worker.ts",
50 }),
51 () =>
52 Cloudflare.Website.Octane("O", {
53 // @ts-expect-error `main` is not supported (no custom-entry seam)
54 main: "worker.ts",
55 }),
56 () =>
57 Cloudflare.Website.Octane("O", {
58 // @ts-expect-error `script` is owned by the source dispatch
59 script: "export default {}",
60 }),
61 () =>
62 Cloudflare.Website.Astro("A", {
63 // @ts-expect-error `source` is owned by the resource itself
64 source: { provider: "x", options: {} },
65 }),
66 () =>
67 Cloudflare.Website.Astro("A", {
68 prerenderEnvironment: "node",
69 }),
70 () =>
71 Cloudflare.Website.Astro("A", {
72 prerenderEnvironment: "workerd",
73 }),
74 () =>
75 Cloudflare.Website.Astro("A", {
76 // @ts-expect-error only workerd and node are supported
77 prerenderEnvironment: "bun",
78 }),
79 () =>
80 Cloudflare.Website.Nextjs("X", {
81 // @ts-expect-error `script` is owned by the source dispatch
82 script: "export default {}",
83 }),
84 () =>
85 Cloudflare.Website.Nextjs("X", {
86 // @ts-expect-error `main` is not supported (OpenNext owns the entry)
87 main: "worker.ts",
88 }),
89 () =>
90 Cloudflare.Website.Nextjs("X", {
91 // @ts-expect-error `source` is owned by the resource itself
92 source: { provider: "x", options: {} },
93 }),
94 () =>
95 Cloudflare.Website.Foldkit("F", {
96 // @ts-expect-error `script` is owned by the source dispatch
97 script: "export default {}",
98 }),
99 () =>
100 Cloudflare.Website.Foldkit("F", {
101 // @ts-expect-error `bundle` is owned by the source dispatch
102 bundle: false,
103 }),
104 () =>
105 Cloudflare.Website.Foldkit("F", {
106 // @ts-expect-error `source` is owned by the resource itself
107 source: { provider: "x", options: {} },
108 }),
109 () =>
110 Cloudflare.Website.Foldkit("F", {
111 // @ts-expect-error `viteEnvironments` is not supported (Foldkit has no RSC split)
112 viteEnvironments: { entry: "rsc", children: ["ssr"] },
113 }),
114 // `main` IS supported — a Foldkit deployment may carry a custom Worker
115 // entry (API routes, error reporting, Durable Objects) alongside the
116 // client build. Pinned positively so an `Omit` can't quietly drop it.
117 () => Cloudflare.Website.Foldkit("F", { main: "src/worker.ts" }),
118 () =>
119 Cloudflare.Website.Vocs("Docs", {
120 // @ts-expect-error `source` is owned by the Vocs integration
121 source: { provider: "x", options: {} },
122 }),
123 () =>
124 Cloudflare.Website.Vocs("Docs", {
125 // @ts-expect-error Vocs owns its Waku/RSC worker entry
126 main: "worker.ts",
127 }),
128 // ── Flat-props doctrine pins ─────────────────────────────────────
129 // Framework-named config bags are dissolved into flat, explicitly
130 // typed props; the shared vocabulary (`outDir`, `spa`, `errorPage`)
131 // is identical across composites. These pins fail the build if a bag
132 // sneaks back in or a flat prop is dropped.
133 // Astro: framework config lives in `astro.config.*`; the `astro`
134 // prop is the deploy-time override bag merged OVER the file — an
135 // explicit serializable subset, no flat mirror props, no
136 // plugins/functions.
137 () =>
138 Cloudflare.Website.Astro("A", {
139 astro: {
140 site: "https://example.com",
141 base: "/docs",
142 output: "static",
143 srcDir: "./app",
144 publicDir: "./static",
145 outDir: "./dist",
146 trailingSlash: "always",
147 },
148 }),
149 () =>
150 Cloudflare.Website.Astro("A", {
151 config: "astro.prod.config.mjs",
152 }),
153 () =>
154 Cloudflare.Website.Astro("A", {
155 // @ts-expect-error `output` lives in the `astro` override bag
156 output: "static",
157 }),
158 () =>
159 Cloudflare.Website.Astro("A", {
160 // @ts-expect-error `site` belongs in astro.config.* or the `astro` bag
161 site: "https://example.com",
162 }),
163 () =>
164 Cloudflare.Website.Astro("A", {
165 astro: {
166 // @ts-expect-error no plugins in the serializable override bag
167 integrations: [],
168 },
169 }),
170 () =>
171 Cloudflare.Website.Astro("A", {
172 astro: {
173 // @ts-expect-error only "always" | "never" | "ignore"
174 trailingSlash: "sometimes",
175 },
176 }),
177 () =>
178 Cloudflare.Website.Nextjs("X", {
179 // @ts-expect-error the `nextjs` config bag is dissolved into flat props
180 nextjs: { devMode: "hmr" },
181 }),
182 () =>
183 Cloudflare.Website.Nextjs("X", {
184 // @ts-expect-error the OpenNext pipeline knobs are gone — configure
185 // them in open-next.config.ts; dev behavior moved to `dev.mode`
186 devMode: "hmr",
187 buildCommand: "npx next build",
188 minify: true,
189 skipNextBuild: false,
190 configPath: "open-next.config.ts",
191 debug: false,
192 }),
193 // The `nuxt` bag is the ONE sanctioned override surface: serializable
194 // deploy-time config merged over nuxt.config.ts (highest-priority c12
195 // layer). Pinned positively so an `Omit` can't quietly drop it.
196 () =>
197 Cloudflare.Website.Nuxt("N", {
198 nuxt: {
199 app: { baseURL: "/docs/" },
200 runtimeConfig: { public: { apiBase: "https://example.com" } },
201 },
202 }),
203 () =>
204 Cloudflare.Website.SvelteKit("S", {
205 // @ts-expect-error `adapter` removed — fallback generation is derived
206 // from the platform-native `assets.notFoundHandling` knob
207 adapter: { notFoundHandling: "404-page", fallback: "spa" },
208 }),
209 // The `kit` bag is the deploy-time override seam: JSON-serializable
210 // config merged over the user's own `sveltekit(...)` call (the prop
211 // wins). Pinned positively so an `Omit` can't quietly drop it.
212 () =>
213 Cloudflare.Website.SvelteKit("S", {
214 kit: { paths: { base: "/docs" } },
215 }),
216 () =>
217 Cloudflare.Website.SvelteKit("S", {
218 assets: { notFoundHandling: "404-page" },
219 }),
220 () =>
221 Cloudflare.Website.Waku("W", {
222 // @ts-expect-error framework config lives in the `waku` override bag
223 srcDir: "app",
224 }),
225 () =>
226 Cloudflare.Website.Waku("W", {
227 // @ts-expect-error framework config lives in the `waku` override bag
228 outDir: "build",
229 }),
230 // The `waku` bag is the deploy-time override seam, merged over the
231 // project's own `waku.config.*` (per-key; deploy-time values win).
232 () =>
233 Cloudflare.Website.Waku("W", {
234 waku: { srcDir: "app", distDir: "build", basePath: "/docs/" },
235 }),
236 () =>
237 Cloudflare.Website.Vite("V", {
238 // No spa/errorPage sugar on CF Vite: Workers Assets' own
239 // notFoundHandling is the platform-native surface.
240 assets: { notFoundHandling: "single-page-application" },
241 }),
242 () =>
243 Cloudflare.Website.Vite("V", {
244 // @ts-expect-error spa sugar deliberately not offered on CF Vite
245 spa: true,
246 }),
247 // ── CF Vite/Foldkit: config belongs in vite.config.* ─────────────
248 // The CF composites build through the Cloudflare Vite plugin, whose
249 // pipeline has no inline-override or configFile seam — so unlike the
250 // AWS composites there is no `vite` override bag and no `config`
251 // prop; `base`/`outDir` live only in the project's own config file.
252 () =>
253 Cloudflare.Website.Vite("V", {
254 // @ts-expect-error no top-level `base` — set it in vite.config.*
255 base: "/docs/",
256 }),
257 () =>
258 Cloudflare.Website.Vite("V", {
259 // @ts-expect-error no top-level `outDir` — the plugin owns the output layout
260 outDir: "dist",
261 }),
262 () =>
263 Cloudflare.Website.Vite("V", {
264 // @ts-expect-error no `vite` override bag on CF (no seam through the plugin pipeline)
265 vite: { base: "/docs/" },
266 }),
267 () =>
268 Cloudflare.Website.Foldkit("F", {
269 // @ts-expect-error no top-level `base` — set it in vite.config.*
270 base: "/app/",
271 }),
272 () =>
273 Cloudflare.Website.Foldkit("F", {
274 // @ts-expect-error no `vite` override bag on CF (no seam through the plugin pipeline)
275 vite: { base: "/app/" },
276 }),
277 // spa/errorPage sugar was dropped from CF Foldkit with CF Vite's:
278 // Workers Assets' notFoundHandling (defaulted to SPA for Foldkit) is
279 // the platform-native surface.
280 () =>
281 Cloudflare.Website.Foldkit("F", {
282 // @ts-expect-error spa sugar removed — use assets.notFoundHandling
283 spa: false,
284 }),
285 () =>
286 Cloudflare.Website.Foldkit("F", {
287 // @ts-expect-error errorPage sugar removed — use assets.notFoundHandling: "404-page"
288 errorPage: "404.html",
289 }),
290 // StaticSite's `dev` is either an external dev server (`command`) or the
291 // local Worker's `port`/`strictPort`/`host`, never a mix of the two.
292 () =>
293 Cloudflare.Website.StaticSite("S", {
294 command: "npm run build",
295 outdir: "dist",
296 dev: { command: "npm run dev", url: "http://localhost:5173" },
297 }),
298 () =>
299 Cloudflare.Website.StaticSite("S", {
300 command: "npm run build",
301 outdir: "dist",
302 dev: { port: 4321, strictPort: true, host: "127.0.0.1" },
303 }),
304 () =>
305 Cloudflare.Website.StaticSite("S", {
306 command: "npm run build",
307 outdir: "dist",
308 // @ts-expect-error `port` configures the local Worker, which `command` replaces
309 dev: { command: "npm run dev", port: 4321 },
310 }),
311 ];
312
313 it("rejects source-dispatch props at the type level", () => {
314 // The pins above are compile-time only.
315 expect(_pins.length).toBeGreaterThan(0);
316 });
317 },
318 );