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

main
ts 108 lines 4.8 KB
Raw
1 import { providers } from "@alchemy.run/neon/Providers";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import { getProject, getProjectBranchFunction } from "@distilled.cloud/neon";
5 import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as HttpClient from "effect/http/HttpClient";
8 import * as Path from "effect/Path";
9 import { functionRolloutTimeout } from "../FunctionRollout.ts";
10 import { browserRoundtrip } from "./Browser.ts";
11 import { bodyContaining, exampleRoot, updatedBodyContaining } from "./Fixture.ts";
12 import { frameworks } from "./Frameworks.ts";
13
14 const { test } = Test.make({ providers: providers() });
15
16 describe.concurrent(
17 "Neon Website complete lifecycle",
18 { tags: ["provider:neon", "provider:neon:website", "live"] },
19 () => {
20 for (const { slug, name, website } of frameworks) {
21 // Each live lifecycle deploys, polls rollout, and browser-verifies
22 // (~3 minutes); skip the whole matrix under --fast.
23 test.provider.skipIf(!!process.env.FAST)(
24 slug,
25 (stack) =>
26 Effect.gen(function* () {
27 yield* stack.destroy();
28 const fs = yield* FileSystem.FileSystem;
29 const path = yield* Path.Path;
30 const rootDir = yield* exampleRoot(slug);
31 const asset = path.join(
32 rootDir,
33 slug === "sveltekit" ? "static" : "public",
34 "example.json",
35 );
36 const original = yield* fs.readFileString(asset);
37 yield* Effect.addFinalizer(() =>
38 fs.writeFileString(asset, original).pipe(Effect.orDie),
39 );
40 const deploy = stack.deploy(
41 Effect.gen(function* () {
42 return yield* website("Web", {
43 rootDir,
44 env: { GREETING: `Hello from ${name} on Neon!` },
45 });
46 }),
47 );
48 const site = yield* deploy;
49 expect(site.url).toMatch(/^https:\/\//);
50 const url = String(site.url).replace(/\/+$/, "");
51 const fn = site.function!;
52 yield* Effect.logInfo(
53 `Website ${slug}: deployed project=${fn.projectId} function=${fn.functionId} deployment=${fn.activeDeploymentId} url=${site.url}`,
54 );
55 yield* Effect.addFinalizer(() =>
56 Effect.gen(function* () {
57 yield* stack.destroy();
58 expect(
59 yield* getProject({ project_id: fn.projectId }).pipe(
60 Effect.as(false),
61 Effect.catchTag("NotFound", () => Effect.succeed(true)),
62 ),
63 ).toBe(true);
64 yield* Effect.logInfo(`Website ${slug}: cleanup verified`);
65 }).pipe(Effect.orDie),
66 );
67 yield* bodyContaining(`${url}/`, name);
68 yield* browserRoundtrip(url, slug).pipe(Effect.scoped);
69 const head = yield* HttpClient.head(`${url}/example.json`);
70 expect(head.status).toBe(200);
71 expect(yield* head.text).toBe("");
72 const found = yield* getProjectBranchFunction({
73 project_id: fn.projectId,
74 branch_id: fn.branchId,
75 slug: fn.slug,
76 });
77 expect(found.function.active_deployment?.id).toBe(fn.activeDeploymentId);
78 const unchanged = yield* deploy;
79 expect(unchanged.function!.activeDeploymentId).toBe(fn.activeDeploymentId);
80 yield* Effect.logInfo(`Website ${slug}: initial no-op verified`);
81 yield* fs.writeFileString(asset, '{"framework":"Neon Website lifecycle updated"}');
82 const updated = yield* deploy;
83 expect(updated.function!.functionId).toBe(fn.functionId);
84 expect(updated.url).toBe(site.url);
85 expect(updated.function!.activeDeploymentId).not.toBe(fn.activeDeploymentId);
86 yield* Effect.logInfo(
87 `Website ${slug}: update accepted deployment=${updated.function!.activeDeploymentId}`,
88 );
89 yield* updatedBodyContaining(
90 `${String(updated.url).replace(/\/+$/, "")}/example.json`,
91 "Neon Website lifecycle updated",
92 );
93 yield* Effect.logInfo(`Website ${slug}: updated content verified`);
94 const settled = yield* deploy;
95 expect(settled.function!.activeDeploymentId).toBe(updated.function!.activeDeploymentId);
96 yield* stack.destroy();
97 expect(
98 yield* getProject({ project_id: fn.projectId }).pipe(
99 Effect.as(false),
100 Effect.catchTag("NotFound", () => Effect.succeed(true)),
101 ),
102 ).toBe(true);
103 }).pipe(Effect.scoped),
104 { timeout: functionRolloutTimeout },
105 );
106 }
107 },
108 );