@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 149 lines 5.19 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 = (healthSource: string) =>
17 GcpEnvironment.current.pipe(
18 Effect.flatMap(({ project }) =>
19 compute
20 .getRegionHealthSources({
21 project,
22 region,
23 healthSource,
24 })
25 .pipe(
26 Effect.as("found" as const),
27 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
28 Effect.repeat({
29 schedule: Schedule.spaced("1 second"),
30 until: (status) => status === "gone",
31 times: 10,
32 }),
33 ),
34 ),
35 );
36
37 const resourceTail = (value: string | undefined): string => {
38 if (value === undefined || value.length === 0) return "";
39 const parts = value.split("/").filter((part) => part.length > 0);
40 return parts[parts.length - 1] ?? "";
41 };
42
43 test.provider(
44 "getRegionHealthSources on a missing source fails with NotFound",
45 (stack) =>
46 Effect.gen(function* () {
47 const { project } = yield* GcpEnvironment.current;
48 yield* stack.destroy();
49
50 const error = yield* Effect.flip(
51 compute.getRegionHealthSources({
52 project,
53 region,
54 healthSource: "alchemy-missing-hs",
55 }),
56 );
57 expect(error._tag).toBe("NotFound");
58
59 yield* stack.destroy();
60 }).pipe(logLevel),
61 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
62 );
63
64 test.provider.skipIf(!!process.env.FAST)(
65 "create, update, and delete a regional health source",
66 (stack) =>
67 Effect.gen(function* () {
68 yield* stack.destroy();
69
70 const created = yield* stack.deploy(
71 Effect.gen(function* () {
72 const policy = yield* GCP.Compute.RegionHealthAggregationPolicy("Agg", {
73 region,
74 description: "backend rollup",
75 });
76 const backend = yield* GCP.Compute.RegionBackendService("Web", {
77 region,
78 protocol: "TCP",
79 loadBalancingScheme: "INTERNAL_MANAGED",
80 description: "health source backend",
81 });
82 const source = yield* GCP.Compute.RegionHealthSource("Src", {
83 region,
84 sources: [backend.selfLink.as<string>()],
85 healthAggregationPolicy: policy.selfLink.as<string>(),
86 description: "internal backends",
87 });
88 return { policy, backend, source };
89 }),
90 );
91
92 expect(created.source.sourceName).toEqual(expect.any(String));
93 expect(created.source.region).toEqual(region);
94 expect(created.source.sourceType).toEqual("BACKEND_SERVICE");
95 expect(created.source.description).toEqual("internal backends");
96 expect(created.source.sources.length).toBeGreaterThan(0);
97
98 const fetched = yield* compute.getRegionHealthSources({
99 project: created.source.project,
100 region,
101 healthSource: created.source.sourceName,
102 });
103 expect(fetched.name).toEqual(created.source.sourceName);
104 expect(fetched.sourceType).toEqual("BACKEND_SERVICE");
105 expect(fetched.description).toContain("[alchemy ");
106 expect(fetched.description).toContain("internal backends");
107 expect(resourceTail(fetched.healthAggregationPolicy)).toEqual(created.policy.policyName);
108
109 const updated = yield* stack.deploy(
110 Effect.gen(function* () {
111 const policy = yield* GCP.Compute.RegionHealthAggregationPolicy("Agg", {
112 policyName: created.policy.policyName,
113 region,
114 description: "backend rollup",
115 });
116 const backend = yield* GCP.Compute.RegionBackendService("Web", {
117 name: created.backend.name,
118 region,
119 protocol: "TCP",
120 loadBalancingScheme: "INTERNAL_MANAGED",
121 description: "health source backend",
122 });
123 return yield* GCP.Compute.RegionHealthSource("Src", {
124 sourceName: created.source.sourceName,
125 region,
126 sources: [backend.selfLink.as<string>()],
127 healthAggregationPolicy: policy.selfLink.as<string>(),
128 description: "updated backends",
129 });
130 }),
131 );
132
133 expect(updated.sourceName).toEqual(created.source.sourceName);
134 expect(updated.description).toEqual("updated backends");
135
136 const refetched = yield* compute.getRegionHealthSources({
137 project: updated.project,
138 region,
139 healthSource: updated.sourceName,
140 });
141 expect(refetched.description).toContain("updated backends");
142
143 yield* stack.destroy();
144
145 const gone = yield* waitUntilGone(created.source.sourceName);
146 expect(gone).toEqual("gone");
147 }).pipe(logLevel),
148 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 },
149 );