@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 113 lines 3.9 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as compute from "@distilled.cloud/gcp/compute_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const region = "us-central1";
15
16 const waitUntilGone = (projectId: string, regionName: string, templateName: string) =>
17 compute
18 .getRegionInstanceTemplates({
19 project: projectId,
20 region: regionName,
21 instanceTemplate: templateName,
22 })
23 .pipe(
24 Effect.as("found" as const),
25 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
26 Effect.repeat({
27 schedule: Schedule.spaced("1 second"),
28 until: (status) => status === "gone",
29 times: 10,
30 }),
31 );
32
33 test.provider(
34 "create, replace, and delete a regional instance template",
35 (stack) =>
36 Effect.gen(function* () {
37 const { project } = yield* GcpEnvironment.current;
38 yield* stack.destroy();
39
40 const created = yield* stack.deploy(
41 Effect.gen(function* () {
42 return yield* GCP.Compute.RegionInstanceTemplate("Web", {
43 region,
44 machineType: "e2-micro",
45 labels: { env: "test" },
46 disks: [
47 {
48 boot: true,
49 autoDelete: true,
50 sourceImage: "projects/debian-cloud/global/images/family/debian-12",
51 diskSizeGb: 10,
52 },
53 ],
54 networkInterfaces: [{ network: "global/networks/default" }],
55 });
56 }),
57 );
58
59 expect(created.templateName).toEqual(expect.any(String));
60 expect(created.region).toEqual(region);
61 expect(created.machineType).toEqual("e2-micro");
62 expect(created.labels).toMatchObject({ env: "test" });
63 expect(created.project).toEqual(project);
64
65 const fetched = yield* compute.getRegionInstanceTemplates({
66 project,
67 region,
68 instanceTemplate: created.templateName,
69 });
70 expect(fetched.name).toEqual(created.templateName);
71 expect(fetched.properties?.machineType).toEqual("e2-micro");
72 expect(fetched.properties?.labels?.env).toEqual("test");
73 expect(fetched.properties?.labels?.["alchemy-id"]).toEqual(expect.any(String));
74
75 const updated = yield* stack.deploy(
76 Effect.gen(function* () {
77 return yield* GCP.Compute.RegionInstanceTemplate("Web", {
78 templateName: created.templateName,
79 region,
80 machineType: "e2-small",
81 labels: { env: "prod", role: "web" },
82 disks: [
83 {
84 boot: true,
85 autoDelete: true,
86 sourceImage: "projects/debian-cloud/global/images/family/debian-12",
87 diskSizeGb: 10,
88 },
89 ],
90 networkInterfaces: [{ network: "global/networks/default" }],
91 });
92 }),
93 );
94
95 expect(updated.templateName).toEqual(created.templateName);
96 expect(updated.machineType).toEqual("e2-small");
97 expect(updated.labels).toMatchObject({ env: "prod", role: "web" });
98
99 const refetched = yield* compute.getRegionInstanceTemplates({
100 project,
101 region,
102 instanceTemplate: updated.templateName,
103 });
104 expect(refetched.properties?.machineType).toEqual("e2-small");
105 expect(refetched.properties?.labels?.env).toEqual("prod");
106
107 yield* stack.destroy();
108
109 const gone = yield* waitUntilGone(project, region, created.templateName);
110 expect(gone).toEqual("gone");
111 }).pipe(logLevel),
112 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
113 );