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

main
ts 72 lines 2.85 KB
Raw
1 import { expect } from "bun:test";
2 import * as Cloud from "@alchemy.run/fly";
3 import * as Test from "@alchemy.run/test/Bun";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6 import * as Path from "effect/Path";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: Cloud.providers(), dev: true });
10
11 test.provider(
12 "native vinext development serves routes, environment, and hot reload",
13 (stack) =>
14 Effect.gen(function* () {
15 yield* stack.destroy();
16 const fs = yield* FileSystem.FileSystem;
17 const path = yield* Path.Path;
18 const rootDir = yield* path.fromFileUrl(new URL("../", import.meta.url));
19 const { site } = yield* stack.deploy(
20 Effect.gen(function* () {
21 return {
22 site: yield* Cloud.Website.Vinext("Web", {
23 rootDir,
24 env: { GREETING: "Hello from vinext on Fly!" },
25 }),
26 };
27 }),
28 );
29 expect(site.url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1):\d+/);
30 const url = String(site.url).replace(/\/+$/, "");
31 const home = yield* Test.getWhenReady(url).pipe(Effect.flatMap((response) => response.text));
32 expect(home).toContain("Hello from vinext on Fly!");
33 const api = yield* Test.getWhenReady(`${url}/api/hello?name=Alchemy`);
34 expect(yield* api.json).toEqual({
35 name: "Alchemy",
36 greeting: "Hello from vinext on Fly!",
37 });
38 const robots = yield* Test.getWhenReady(`${url}/robots.txt`);
39 expect(yield* robots.text).toContain("User-agent:");
40 const isr = yield* Test.getWhenReady(`${url}/isr`);
41 expect(yield* isr.text).toContain("ISR");
42 const page = path.join(rootDir, "app/page.tsx");
43 const source = yield* fs.readFileString(page);
44 const marker = "Updated by the vinext development test";
45 yield* Effect.acquireUseRelease(
46 fs.writeFileString(page, source.replace("Hello from vinext on Fly!", marker)),
47 () =>
48 Test.getWhenReady(url).pipe(
49 Effect.flatMap((response) => response.text),
50 Effect.repeat({
51 schedule: Schedule.spaced("500 millis"),
52 times: 20,
53 until: (body) => body.includes(marker),
54 }),
55 Effect.tap((body) => Effect.sync(() => expect(body).toContain(marker))),
56 ),
57 () => fs.writeFileString(page, source).pipe(Effect.orDie),
58 );
59 const restored = yield* Test.getWhenReady(url).pipe(
60 Effect.flatMap((response) => response.text),
61 Effect.repeat({
62 schedule: Schedule.spaced("500 millis"),
63 times: 20,
64 until: (body) => !body.includes(marker),
65 }),
66 );
67 expect(restored).toContain("Hello from vinext on Fly!");
68 expect(restored).not.toContain(marker);
69 yield* stack.destroy();
70 }),
71 { timeout: 120_000 },
72 );