@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 101 lines 4.76 KB
Raw
1 import { providers } from "@alchemy.run/neon/Providers";
2 import { stageWebsiteArtifact } from "@alchemy.run/neon/Website/Artifact";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as Command from "alchemy/Command";
6 import { Server } from "alchemy/Website/Server";
7 import * as Effect from "effect/Effect";
8 import * as Path from "effect/Path";
9 import * as ChildProcess from "effect/process/ChildProcess";
10 import * as Stream from "effect/Stream";
11 import { exampleRoot } from "./Fixture.ts";
12 import { frameworks } from "./Frameworks.ts";
13
14 const { test } = Test.make({ providers: providers() });
15
16 describe.sequential(
17 "Neon Website production Fetch artifacts",
18 { tags: ["provider:neon", "provider:neon:website", "live"] },
19 () => {
20 for (const { slug, name } of frameworks) {
21 // Production builds spawn multi-GiB build children (nuxt/vocs ~3 GiB)
22 // that cannot share a 4 GiB budget with a long-lived suite process.
23 test.provider.skipIf(!!process.env.FAST)(
24 slug,
25 (stack) =>
26 Effect.gen(function* () {
27 yield* stack.destroy();
28 const path = yield* Path.Path;
29 const root = yield* exampleRoot(slug);
30 const framework = slug;
31 const target = `@alchemy.run/frontend-frameworks/${framework}/neon`;
32 const build = yield* stack.deploy(
33 Effect.gen(function* () {
34 return yield* slug === "static"
35 ? Command.Build("Build", {
36 cwd: root,
37 command: "bun run build",
38 outdir: "dist",
39 memo: false,
40 }).pipe(
41 Effect.map((build) => ({ distDir: build.outdir, serverEntry: undefined })),
42 )
43 : Server("Build", {
44 root,
45 framework:
46 slug === "nextjs" || slug === "vocs"
47 ? target
48 : `@alchemy.run/frontend-frameworks/${framework}`,
49 target,
50 memo: false,
51 env: { GREETING: `Hello from ${name} on Neon!` },
52 options: slug === "astro" ? { astro: { output: "server" } } : {},
53 });
54 }),
55 );
56 expect(build.distDir).toBeDefined();
57 const artifact = yield* stageWebsiteArtifact({
58 root,
59 distDir: build.distDir!,
60 serverEntry: build.serverEntry,
61 static: slug === "static" ? {} : undefined,
62 layout: slug === "nextjs" ? "next" : "output",
63 });
64 const proc = yield* ChildProcess.make("node", [
65 "--input-type=module",
66 "-e",
67 [
68 `const {default: handler} = await import(${JSON.stringify(path.join(artifact.directory, "index.mjs"))});`,
69 'for (const [method, pathname] of [["GET", "/"], ["GET", "/example.json"], ["HEAD", "/example.json"]]) {',
70 'const response = await handler.fetch(new Request("http://localhost" + pathname, { method }));',
71 "const body = await response.text();",
72 'if (response.status !== 200 || (method === "HEAD" && body !== "") || (pathname === "/" && !body.includes("Neon"))) { throw new Error(method + " " + pathname + " returned " + response.status + ": " + body.slice(0, 300)); }',
73 "}",
74 ...(slug === "sveltekit"
75 ? [
76 'for (const method of ["GET", "HEAD"]) {',
77 'const response = await handler.fetch(new Request("http://localhost/about", { method }));',
78 'const body = await response.text(); if (response.status !== 200 || (method === "HEAD" ? body !== "" : !body.includes("prerendered"))) throw new Error(method + " /about returned " + response.status + ": " + body);',
79 "}",
80 ]
81 : []),
82 'console.log("NEON_FETCH_ARTIFACT_OK"); process.exit(0);',
83 ].join("\n"),
84 ]);
85 const [code, stdout, stderr] = yield* Effect.all(
86 [
87 proc.exitCode,
88 proc.stdout.pipe(Stream.decodeText, Stream.mkString),
89 proc.stderr.pipe(Stream.decodeText, Stream.mkString),
90 ],
91 { concurrency: "unbounded" },
92 ).pipe(Effect.timeout("30 seconds"));
93 expect({ code, stderr: code === 0 ? "" : stderr }).toEqual({ code: 0, stderr: "" });
94 expect(stdout).toContain("NEON_FETCH_ARTIFACT_OK");
95 yield* stack.destroy();
96 }).pipe(Effect.scoped),
97 { timeout: 120_000 },
98 );
99 }
100 },
101 );