@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 97 lines 5.35 KB
Raw
1 import { stageWebsiteArtifact } from "@alchemy.run/neon/Website/Artifact";
2 import { expect, it } from "@alchemy.run/test";
3 import * as NodeServices from "@effect/platform-node/NodeServices";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6 import * as Path from "effect/Path";
7 import * as ChildProcess from "effect/process/ChildProcess";
8 import * as Stream from "effect/Stream";
9 import { buildPortableExample } from "./Fixture.ts";
10
11 for (const slug of ["nextjs", "vocs"] as const) {
12 it.live.skipIf(!process.env.NEON_WEBSITE_LINUX)(
13 `${slug} production artifact runs on Linux ARM64 glibc without host dependencies`,
14 () =>
15 Effect.gen(function* () {
16 const fs = yield* FileSystem.FileSystem;
17 const path = yield* Path.Path;
18 const next = slug === "nextjs";
19 const artifact = yield* stageWebsiteArtifact(yield* buildPortableExample(slug));
20 const probe = [
21 'import assert from "node:assert/strict";',
22 'import fs from "node:fs";',
23 'import path from "node:path";',
24 'import { createRequire } from "node:module";',
25 "try {",
26 'assert.equal(process.platform, "linux"); assert.equal(process.arch, "arm64");',
27 "assert.ok(process.report.getReport().header.glibcVersionRuntime);",
28 ...(next
29 ? [
30 'const entry = [...fs.globSync("files/**/serve-neon.mjs")][0]; fs.writeFileSync(path.join(path.dirname(entry), "public/pixel.png"), Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=", "base64"));',
31 ]
32 : []),
33 'const { default: handler } = await import("./index.mjs");',
34 ...(next
35 ? [
36 'const require = createRequire(path.join(process.cwd(), "package.json")); const sharp = createRequire(require.resolve("next/package.json"))("sharp"); assert.ok(sharp.versions.vips);',
37 ]
38 : []),
39 'const request = (url, method = "GET", headers) => handler.fetch(new Request("http://localhost" + url, { method, headers }));',
40 'const home = await request("/"); assert.equal(home.status, 200); const html = await home.text(); assert.match(html, /Neon/);',
41 'for (const method of ["GET", "HEAD"]) { const res = await request("/example.json", method); assert.equal(res.status, 200); const text = await res.text(); if (method === "HEAD") assert.equal(text, ""); else assert.match(text, /framework/); }',
42 'const assets = [...html.matchAll(/(?:src|href)="([^" ]+\\.(?:js|css)(?:\\?[^" ]*)?)"/g)].map(m => m[1]).filter(url => url.startsWith("/")); assert.ok(assets.length > 0);',
43 "for (const url of assets.slice(0, 3)) { const res = await request(url); assert.equal(res.status, 200, url); assert.ok((await res.arrayBuffer()).byteLength > 0); }",
44 ...(next
45 ? [
46 'const image = await request("/_next/image?url=%2Fpixel.png&w=64&q=75", "GET", { accept: "image/webp" }); assert.equal(image.status, 200, await (image.status === 200 ? Promise.resolve("") : image.text())); assert.match(image.headers.get("content-type"), /^image\\/webp/); assert.ok((await image.arrayBuffer()).byteLength > 0);',
47 'const stream = await request("/api/stream"); assert.equal(stream.status, 200); assert.match(stream.headers.get("content-type"), /text\\/event-stream/); const reader = stream.body.getReader(); const first = await reader.read(); assert.match(new TextDecoder().decode(first.value), /data: first/); let rest = ""; for (;;) { const part = await reader.read(); if (part.done) break; rest += new TextDecoder().decode(part.value); } assert.match(rest, /data: second/);',
48 ]
49 : [
50 'const page = await request("/guide"); assert.equal(page.status, 200); assert.match(await page.text(), /Guide/);',
51 ]),
52 'console.log("NEON_LINUX_ARTIFACT_OK"); process.exit(0);',
53 "} catch (error) { console.error(error); process.exit(1); }",
54 ].join("\n");
55 yield* fs.writeFileString(path.join(artifact.directory, "probe.mjs"), probe);
56 const proc = yield* ChildProcess.make("docker", [
57 "run",
58 "--rm",
59 "--network=none",
60 "--memory=1g",
61 "--memory-swap=1g",
62 "--cpus=2",
63 "--platform=linux/arm64",
64 "--mount",
65 `type=bind,source=${artifact.directory},target=/app`,
66 "--workdir",
67 "/app",
68 "--env",
69 "NODE_ENV=production",
70 "node:24-bookworm-slim",
71 "node",
72 "probe.mjs",
73 ]);
74 const [code, stdout, stderr] = yield* Effect.all(
75 [
76 proc.exitCode,
77 proc.stdout.pipe(Stream.decodeText, Stream.mkString),
78 proc.stderr.pipe(Stream.decodeText, Stream.mkString),
79 ],
80 { concurrency: "unbounded" },
81 ).pipe(Effect.timeout("45 seconds"));
82 expect({ code, stderr: code === 0 ? "" : stderr }).toEqual({
83 code: 0,
84 stderr: "",
85 });
86 expect({
87 completed: stdout.includes("NEON_LINUX_ARTIFACT_OK"),
88 stdout,
89 stderr,
90 }).toMatchObject({ completed: true });
91 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
92 {
93 tags: ["provider:neon", "provider:neon:website", "local"],
94 timeout: 120_000,
95 },
96 );
97 }