@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 123 lines 4.26 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 runLifecycle = !!process.env.GCP_TEST_COMPUTE_INTERCONNECT && !process.env.FAST;
15
16 const waitUntilGone = (interconnect: string) =>
17 GcpEnvironment.current.pipe(
18 Effect.flatMap(({ project }) =>
19 compute.getInterconnects({ project, interconnect }).pipe(
20 Effect.as("found" as const),
21 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
22 Effect.repeat({
23 schedule: Schedule.spaced("1 second"),
24 until: (status) => status === "gone",
25 times: 10,
26 }),
27 ),
28 ),
29 );
30
31 test.provider(
32 "getInterconnects on a missing interconnect fails with NotFound",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 yield* stack.destroy();
37
38 const error = yield* Effect.flip(
39 compute.getInterconnects({
40 project,
41 interconnect: "alchemy-missing-interconnect",
42 }),
43 );
44 expect(error._tag).toBe("NotFound");
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
49 );
50
51 test.provider(
52 "insertInterconnects without customerName fails with BadRequest",
53 () =>
54 Effect.gen(function* () {
55 const { project } = yield* GcpEnvironment.current;
56 const error = yield* Effect.flip(
57 compute.insertInterconnects({
58 project,
59 body: {
60 name: "alchemy-ix-probe",
61 description: "alchemy entitlement probe",
62 location: `projects/${project}/global/interconnectLocations/iad-zone1-1`,
63 interconnectType: "DEDICATED",
64 linkType: "LINK_TYPE_ETHERNET_10G_LR",
65 requestedLinkCount: 1,
66 },
67 }),
68 );
69 expect(error._tag).toEqual("BadRequest");
70 }).pipe(logLevel),
71 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 60_000 },
72 );
73
74 test.provider.skipIf(!runLifecycle)(
75 "create, update, and delete an interconnect",
76 (stack) =>
77 Effect.gen(function* () {
78 const { project } = yield* GcpEnvironment.current;
79 yield* stack.destroy();
80
81 const created = yield* stack.deploy(
82 Effect.gen(function* () {
83 return yield* GCP.Compute.Interconnect("Pairing", {
84 location: `projects/${project}/global/interconnectLocations/iad-zone1-1`,
85 interconnectType: "DEDICATED",
86 linkType: "LINK_TYPE_ETHERNET_10G_LR",
87 requestedLinkCount: 1,
88 description: "dedicated pair",
89 });
90 }),
91 );
92
93 expect(created.interconnectName).toEqual(expect.any(String));
94 expect(created.description).toEqual("dedicated pair");
95 expect(created.interconnectType).toEqual("DEDICATED");
96
97 const fetched = yield* compute.getInterconnects({
98 project: created.project,
99 interconnect: created.interconnectName,
100 });
101 expect(fetched.name).toEqual(created.interconnectName);
102 expect(fetched.description).toContain("[alchemy ");
103
104 const updated = yield* stack.deploy(
105 Effect.gen(function* () {
106 return yield* GCP.Compute.Interconnect("Pairing", {
107 interconnectName: created.interconnectName,
108 location: `projects/${project}/global/interconnectLocations/iad-zone1-1`,
109 interconnectType: "DEDICATED",
110 linkType: "LINK_TYPE_ETHERNET_10G_LR",
111 requestedLinkCount: 1,
112 description: "updated pair",
113 });
114 }),
115 );
116 expect(updated.description).toEqual("updated pair");
117
118 yield* stack.destroy();
119 const gone = yield* waitUntilGone(created.interconnectName);
120 expect(gone).toEqual("gone");
121 }).pipe(logLevel),
122 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
123 );