@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 93 lines 3.59 KB
Raw
1 import { providers } from "@alchemy.run/neon/Providers";
2 import { Vite } from "@alchemy.run/neon/Website/Vite";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import { getProject, getProjectBranchFunction } from "@distilled.cloud/neon";
6 import * as Alchemy from "alchemy";
7 import * as Effect from "effect/Effect";
8 import * as FileSystem from "effect/FileSystem";
9 import * as HttpClient from "effect/http/HttpClient";
10 import * as Path from "effect/Path";
11 import * as Redacted from "effect/Redacted";
12 import { bodyContaining, exampleRoot } from "./Fixture.ts";
13
14 const { test } = Test.make({ providers: providers(), dev: true });
15
16 test.provider(
17 "Vite hot reloads files and restarts for environment changes",
18 (stack) =>
19 Effect.gen(function* () {
20 yield* stack.destroy();
21 const fs = yield* FileSystem.FileSystem;
22 const path = yield* Path.Path;
23 const rootDir = yield* exampleRoot("vite");
24 const asset = path.join(rootDir, "public", "example.json");
25 const original = yield* fs.readFileString(asset);
26 yield* Effect.addFinalizer(() => fs.writeFileString(asset, original).pipe(Effect.orDie));
27 const deploy = (value: string) =>
28 stack.deploy(Vite("Web", { rootDir, env: { VITE_REVISION: value } }));
29 const site = yield* deploy("first");
30 yield* bodyContaining(`${site.url}/src/App.tsx`, "Vite");
31 yield* fs.writeFileString(asset, '{"framework":"hot-reloaded"}');
32 yield* bodyContaining(`${site.url}/example.json`, "hot-reloaded");
33 const restarted = yield* deploy("second");
34 expect(restarted.function).toBeUndefined();
35 yield* bodyContaining(`${restarted.url}/src/App.tsx`, "second");
36 yield* stack.destroy();
37 }).pipe(Effect.scoped),
38 {
39 tags: ["provider:neon", "provider:neon:website", "local"],
40 timeout: 120_000,
41 },
42 );
43
44 test.provider(
45 "remote opts into a real Function and destroys its stamped live resources",
46 (stack) =>
47 Effect.gen(function* () {
48 yield* stack.destroy();
49 const rootDir = yield* exampleRoot("vite");
50 const site = yield* stack.deploy(
51 Vite("Web", {
52 rootDir,
53 env: {
54 VITE_REVISION: "public-build-marker",
55 SERVER_ONLY_MARKER: Redacted.make("private-runtime-marker"),
56 },
57 }).pipe(Alchemy.remote()),
58 );
59 expect(site.url).toMatch(/^https:\/\//);
60 const fn = site.function!;
61 expect(fn.functionId.startsWith("dev:")).toBe(false);
62 const observed = yield* getProjectBranchFunction({
63 project_id: fn.projectId,
64 branch_id: fn.branchId,
65 slug: fn.slug,
66 });
67 expect(observed.function.id).toBe(fn.functionId);
68 const html = yield* bodyContaining(`${site.url}/deep/link`, "Vite on Neon");
69 const scripts = [...html.matchAll(/<script\b[^>]*\bsrc="([^"]+)"/g)].map(
70 (match) => match[1]!,
71 );
72 expect(scripts.length).toBeGreaterThan(0);
73 let javascript = "";
74 for (const script of scripts) {
75 javascript += yield* HttpClient.get(new URL(script, String(site.url)).href).pipe(
76 Effect.flatMap((response) => response.text),
77 );
78 }
79 expect(javascript).toContain("public-build-marker");
80 expect(html + javascript).not.toContain("private-runtime-marker");
81 yield* stack.destroy();
82 expect(
83 yield* getProject({ project_id: fn.projectId }).pipe(
84 Effect.as(false),
85 Effect.catchTag("NotFound", () => Effect.succeed(true)),
86 ),
87 ).toBe(true);
88 }),
89 {
90 tags: ["provider:neon", "provider:neon:website", "live"],
91 timeout: 120_000,
92 },
93 );