The best way to control Claude Code, Codex and more from any computer or phone

main
ts 125 lines 5.17 KB
Raw
1 import { providers } from "@alchemy.run/neon/Providers";
2 import { WebsiteArtifact } from "@alchemy.run/neon/Website/Artifact";
3 import { Astro } from "@alchemy.run/neon/Website/Astro";
4 import { deployWebsite } from "@alchemy.run/neon/Website/FrameworkSite";
5 import { Nextjs } from "@alchemy.run/neon/Website/Nextjs";
6 import { describe, expect } from "@alchemy.run/test";
7 import * as Test from "@alchemy.run/test/Alchemy";
8 import { getProject, getProjectBranchFunction } from "@distilled.cloud/neon";
9 import * as Effect from "effect/Effect";
10 import * as FileSystem from "effect/FileSystem";
11 import * as HttpClient from "effect/http/HttpClient";
12 import * as Path from "effect/Path";
13 import { functionRolloutTimeout } from "../FunctionRollout.ts";
14 import { exampleRoot, updatedBodyContaining } from "./Fixture.ts";
15
16 const { test } = Test.make({ providers: providers() });
17
18 describe.sequential(
19 "Neon Website feasibility",
20 { tags: ["provider:neon", "provider:neon:website", "live"] },
21 () => {
22 // Live deploy + rollout polling takes minutes; skip under --fast.
23 test.provider.skipIf(!!process.env.FAST)(
24 "static Fetch files deploy, update, no-op, HEAD, and destroy",
25 (stack) =>
26 Effect.gen(function* () {
27 yield* stack.destroy();
28 const fs = yield* FileSystem.FileSystem;
29 const path = yield* Path.Path;
30 const root = yield* fs.makeTempDirectoryScoped({ prefix: "neon-static-feasibility-" });
31 const distDir = path.join(root, "dist");
32 yield* fs.makeDirectory(distDir);
33 yield* fs.writeFileString(
34 path.join(distDir, "index.html"),
35 "<h1>Neon static feasibility</h1>",
36 );
37 yield* fs.writeFileString(path.join(distDir, "asset.json"), '{"ok":true}');
38 const deploy = stack.deploy(
39 Effect.gen(function* () {
40 const artifact = yield* WebsiteArtifact("Artifact", {
41 root,
42 distDir,
43 static: { notFoundHandling: "spa" },
44 });
45 return yield* deployWebsite({}, artifact);
46 }),
47 );
48 const site = yield* deploy;
49 expect(site.function).toBeDefined();
50 const fn = site.function!;
51 expect(
52 yield* HttpClient.get(`${site.url}/deep/link`).pipe(Effect.flatMap((res) => res.text)),
53 ).toContain("Neon static feasibility");
54 const head = yield* HttpClient.head(`${site.url}/asset.json`);
55 expect(head.status).toBe(200);
56 expect(yield* head.text).toBe("");
57 const observed = yield* getProjectBranchFunction({
58 project_id: fn.projectId,
59 branch_id: fn.branchId,
60 slug: fn.slug,
61 });
62 expect(observed).toBeDefined();
63 const unchanged = yield* deploy;
64 expect(unchanged.function!.activeDeploymentId).toBe(fn.activeDeploymentId);
65 yield* fs.writeFileString(
66 path.join(distDir, "index.html"),
67 "<h1>Neon static updated</h1>",
68 );
69 const updated = yield* deploy;
70 expect(updated.function!.functionId).toBe(fn.functionId);
71 expect(updated.function!.activeDeploymentId).not.toBe(fn.activeDeploymentId);
72 expect(updated.url).toBe(site.url);
73 yield* updatedBodyContaining(String(updated.url), "Neon static updated");
74 yield* stack.destroy();
75 expect(
76 yield* getProject({ project_id: fn.projectId }).pipe(
77 Effect.as(false),
78 Effect.catchTag("NotFound", () => Effect.succeed(true)),
79 ),
80 ).toBe(true);
81 }).pipe(Effect.scoped),
82 { timeout: functionRolloutTimeout },
83 );
84
85 for (const [slug, website] of [
86 ["astro", Astro],
87 ["nextjs", Nextjs],
88 ] as const) {
89 test.provider.skipIf(!!process.env.FAST)(
90 `${slug} real framework deploy feasibility`,
91 (stack) =>
92 Effect.gen(function* () {
93 yield* stack.destroy();
94 const rootDir = yield* exampleRoot(slug);
95 const site = yield* stack.deploy(
96 website("Web", {
97 rootDir,
98 memo: slug === "nextjs" ? false : undefined,
99 env: { GREETING: `Hello from ${slug === "astro" ? "Astro" : "Next.js"} on Neon!` },
100 }),
101 );
102 const response = yield* HttpClient.get(String(site.url));
103 expect(response.status).toBe(200);
104 expect(yield* response.text).toContain("Neon");
105 expect((yield* HttpClient.get(`${site.url}/example.json`)).status).toBe(200);
106 expect((yield* HttpClient.get(`${site.url}/api/hello?name=Alchemy`)).status).toBe(200);
107 const fn = site.function!;
108 yield* getProjectBranchFunction({
109 project_id: fn.projectId,
110 branch_id: fn.branchId,
111 slug: fn.slug,
112 });
113 yield* stack.destroy();
114 expect(
115 yield* getProject({ project_id: fn.projectId }).pipe(
116 Effect.as(false),
117 Effect.catchTag("NotFound", () => Effect.succeed(true)),
118 ),
119 ).toBe(true);
120 }),
121 { timeout: 120_000 },
122 );
123 }
124 },
125 );