@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 82 lines 2.68 KB
Raw
1 import * as Fly from "@alchemy.run/fly";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as machines from "@distilled.cloud/fly-io/machines";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8 import * as pathe from "pathe";
9 import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
10 import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
11
12 const { test } = Test.make({ providers: Fly.providers() });
13
14 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
15
16 const fixtureDir = pathe.resolve(
17 import.meta.dirname,
18 "../../AWS/Website/fixtures/tanstack-start-app",
19 );
20 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
21 const fixtureEntries = [".gitignore", "package.json", "vite.config.ts", "src", "public"];
22
23 const waitUntilGone = (appName: string) =>
24 machines.getApp({ app_name: appName }).pipe(
25 Effect.as("found" as const),
26 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
27 Effect.repeat({
28 schedule: Schedule.spaced("1 second"),
29 until: (status) => status === "gone",
30 times: 10,
31 }),
32 );
33
34 test.provider(
35 "TanStackStart: deploy, GET /, destroy, gone",
36 (stack) =>
37 Effect.gen(function* () {
38 yield* stack.destroy();
39
40 const rootDir = yield* cloneFixture(fixtureDir, {
41 prefix: "alchemy-tanstack-start-fly-",
42 tempRoot,
43 entries: fixtureEntries,
44 });
45
46 const deployed = yield* stack.deploy(
47 Effect.gen(function* () {
48 const site = yield* Fly.Website.TanStackStart("Web", {
49 rootDir,
50 memo: {
51 include: ["src/**", "public/**", "package.json", "vite.config.ts"],
52 },
53 });
54 return { site };
55 }),
56 );
57
58 const url = deployed.site.url;
59 expect(url).toBeDefined();
60 expect(url).toMatch(/^https:\/\//);
61 expect(deployed.site.service).toBeDefined();
62 expect(deployed.site.app).toBeDefined();
63
64 yield* expectUrlContains(`${url!}/`, "TANSTACK_AWS_PAGE_MARKER", {
65 timeout: "90 seconds",
66 label: "home page",
67 });
68 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "TANSTACK_AWS_API_MARKER", {
69 timeout: "30 seconds",
70 label: "api route",
71 });
72
73 const appName = deployed.site.app!.appName;
74 yield* stack.destroy();
75 const gone = yield* waitUntilGone(appName);
76 expect(gone).toEqual("gone");
77 }).pipe(logLevel),
78 {
79 tags: ["provider:fly", "provider:fly:machine", "provider:fly:website", "live"],
80 timeout: 180000,
81 },
82 );