@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 133 lines 4.33 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_WIRE_GROUP && !process.env.FAST;
15
16 const waitUntilGone = (projectId: string, crossSiteNetwork: string, wireGroup: string) =>
17 compute
18 .getWireGroups({
19 project: projectId,
20 crossSiteNetwork,
21 wireGroup,
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 "getWireGroups on a missing group fails with NotFound",
35 (stack) =>
36 Effect.gen(function* () {
37 const { project } = yield* GcpEnvironment.current;
38 yield* stack.destroy();
39
40 const error = yield* Effect.flip(
41 compute.getWireGroups({
42 project,
43 crossSiteNetwork: "alchemy-missing-csn",
44 wireGroup: "alchemy-missing-wire-group",
45 }),
46 );
47 expect(error._tag).toBe("NotFound");
48
49 yield* stack.destroy();
50 }).pipe(logLevel),
51 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
52 );
53
54 test.provider.skipIf(!runLifecycle)(
55 "create, update, and delete a wire group",
56 (stack) =>
57 Effect.gen(function* () {
58 yield* stack.destroy();
59
60 const created = yield* stack.deploy(
61 Effect.gen(function* () {
62 return yield* GCP.Compute.WireGroup("Metro", {
63 crossSiteNetwork: process.env.GCP_TEST_CROSS_SITE_NETWORK ?? "",
64 description: "nyc-to-sfo",
65 adminEnabled: true,
66 wireProperties: {
67 bandwidthUnmetered: "10",
68 bandwidthAllocation: "SHARED_WITH_WIRE_GROUP",
69 },
70 endpoints: {
71 nyc: {
72 interconnects: {
73 a: {
74 interconnect:
75 process.env.GCP_TEST_INTERCONNECT_A ?? "global/interconnects/nyc-a",
76 vlanTags: [100],
77 },
78 },
79 },
80 sfo: {
81 interconnects: {
82 a: {
83 interconnect:
84 process.env.GCP_TEST_INTERCONNECT_B ?? "global/interconnects/sfo-a",
85 vlanTags: [100],
86 },
87 },
88 },
89 },
90 });
91 }),
92 );
93
94 expect(created.wireGroupName).toEqual(expect.any(String));
95 expect(created.adminEnabled).toEqual(true);
96 expect(created.description).toEqual("nyc-to-sfo");
97
98 const fetched = yield* compute.getWireGroups({
99 project: created.project,
100 crossSiteNetwork: created.crossSiteNetwork,
101 wireGroup: created.wireGroupName,
102 });
103 expect(fetched.name).toEqual(created.wireGroupName);
104 expect(fetched.description).toContain("[alchemy ");
105 expect(fetched.description).toContain("nyc-to-sfo");
106
107 const updated = yield* stack.deploy(
108 Effect.gen(function* () {
109 return yield* GCP.Compute.WireGroup("Metro", {
110 wireGroupName: created.wireGroupName,
111 crossSiteNetwork: created.crossSiteNetwork,
112 description: "nyc-to-sfo updated",
113 adminEnabled: false,
114 wireProperties: created.wireProperties,
115 endpoints: created.endpoints,
116 });
117 }),
118 );
119
120 expect(updated.wireGroupName).toEqual(created.wireGroupName);
121 expect(updated.description).toEqual("nyc-to-sfo updated");
122 expect(updated.adminEnabled).toEqual(false);
123
124 yield* stack.destroy();
125 const gone = yield* waitUntilGone(
126 created.project,
127 created.crossSiteNetwork,
128 created.wireGroupName,
129 );
130 expect(gone).toEqual("gone");
131 }).pipe(logLevel),
132 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
133 );