@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 112 lines 3.6 KB
Raw
1 import * as Hetzner from "@alchemy.run/hetzner";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as servers from "@distilled.cloud/hetzner/servers";
5 import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as Path from "effect/Path";
8 import { MinimumLogLevel } from "effect/References";
9 import * as Schedule from "effect/Schedule";
10 import * as pathe from "pathe";
11 import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
12 import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
13
14 const { test } = Test.make({ providers: Hetzner.providers() });
15
16 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
17
18 const hasHetznerCreds = !!process.env.HCLOUD_TOKEN;
19
20 const fixtureDir = pathe.resolve(import.meta.dirname, "../../AWS/Website/fixtures/octane-app");
21 const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
22 const fixtureEntries = [
23 ".gitignore",
24 "package.json",
25 "octane.config.ts",
26 "vite.config.ts",
27 "index.html",
28 "src",
29 "public",
30 ];
31
32 const waitUntilGone = (id: number) =>
33 servers.getServer({ id }).pipe(
34 Effect.as("found" as const),
35 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
36 Effect.repeat({
37 schedule: Schedule.spaced("1 second"),
38 until: (status) => status === "gone",
39 times: 10,
40 }),
41 );
42
43 test.provider.skipIf(!hasHetznerCreds)(
44 "Octane: deploy, GET /, destroy, gone",
45 (stack) =>
46 Effect.gen(function* () {
47 yield* stack.destroy();
48
49 const rootDir = yield* cloneFixture(fixtureDir, {
50 prefix: "alchemy-octane-hetzner-",
51 tempRoot,
52 entries: fixtureEntries,
53 });
54
55 const fs = yield* FileSystem.FileSystem;
56 const pathMod = yield* Path.Path;
57 const configPath = pathMod.join(rootDir, "octane.config.ts");
58 const raw = yield* fs.readFileString(configPath);
59 expect(raw).not.toContain("adapter:");
60 expect(raw).not.toContain("@alchemy.run/frontend-frameworks");
61
62 const deployed = yield* stack.deploy(
63 Effect.gen(function* () {
64 const site = yield* Hetzner.Website.Octane("Web", {
65 rootDir,
66 memo: {
67 include: [
68 "src/**",
69 "public/**",
70 "package.json",
71 "octane.config.ts",
72 "vite.config.ts",
73 "index.html",
74 ],
75 },
76 });
77 return { site };
78 }),
79 );
80
81 expect(yield* fs.readFileString(configPath)).toBe(raw);
82 const url = deployed.site.url;
83 expect(url).toBeDefined();
84 expect(url).toMatch(/^http:\/\//);
85 expect(deployed.site.service).toBeDefined();
86 expect(deployed.site.server).toBeDefined();
87
88 yield* expectUrlContains(`${url!}/`, "OCTANE_AWS_PAGE_MARKER", {
89 timeout: "90 seconds",
90 label: "home page",
91 });
92 yield* expectUrlContains(`${url!}/api/hello?echo=roundtrip`, "OCTANE_AWS_API_MARKER", {
93 timeout: "30 seconds",
94 label: "api route",
95 });
96
97 const serverId = deployed.site.server!.serverId;
98 yield* stack.destroy();
99 const gone = yield* waitUntilGone(serverId);
100 expect(gone).toEqual("gone");
101 }).pipe(
102 logLevel,
103 Effect.ensuring(stack.destroy().pipe(Effect.orDie)),
104 Effect.catchTag(["PreconditionFailed", "Forbidden"], (error) =>
105 Effect.logWarning(`skipping: Hetzner quota (${error._tag})`),
106 ),
107 ),
108 {
109 tags: ["provider:hetzner", "provider:hetzner:service", "provider:hetzner:website", "live"],
110 timeout: 180000,
111 },
112 );