@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 127 lines 4.85 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 networkservices from "@distilled.cloud/gcp/networkservices_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { withNetworkSlot } from "../networkQuota.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 // Multicast needs a multicast domain activation in the project; without one
16 // create fails with BadRequest "The request was invalid: missing
17 // multicast_domain_activation". Set GCP_TEST_MULTICAST=1 on a project with
18 // multicast activated.
19 const runLifecycle = !process.env.FAST && !!process.env.GCP_TEST_MULTICAST;
20
21 const waitUntilGone = (name: string) =>
22 networkservices.getProjectsLocationsMulticastConsumerAssociations({ name }).pipe(
23 Effect.as("found" as const),
24 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
25 Effect.repeat({
26 schedule: Schedule.spaced("2 seconds"),
27 until: (status) => status === "gone",
28 times: 10,
29 }),
30 );
31
32 test.provider(
33 "getProjectsLocationsMulticastConsumerAssociations on a missing association fails with a typed tag",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const { project } = yield* GcpEnvironment.current;
39 const error = yield* Effect.flip(
40 networkservices.getProjectsLocationsMulticastConsumerAssociations({
41 name: `projects/${project}/locations/us-central1-a/multicastConsumerAssociations/alchemy-missing`,
42 }),
43 );
44 expect(error._tag).toEqual("NotFound");
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 {
49 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
50 timeout: 90_000,
51 },
52 );
53
54 test.provider.skipIf(!runLifecycle)(
55 "create, update, and delete a multicast consumer association",
56 (stack) =>
57 Effect.gen(function* () {
58 yield* stack.destroy();
59
60 const created = yield* stack.deploy(
61 Effect.gen(function* () {
62 const vpc = yield* GCP.Compute.Network("Vpc", {
63 autoCreateSubnetworks: false,
64 description: "multicast consumer vpc",
65 });
66 const association = yield* GCP.NetworkServices.MulticastConsumerAssociation("Consumers", {
67 location: "us-central1-a",
68 network: vpc.selfLink.as<string>(),
69 description: "mcast assoc a",
70 labels: { env: "test" },
71 });
72 return { vpc, association };
73 }),
74 );
75
76 expect(created.association.name).toContain("/multicastConsumerAssociations/");
77 expect(created.association.multicastConsumerAssociationId).toEqual(expect.any(String));
78 expect(created.association.location).toEqual("us-central1-a");
79 expect(created.association.description).toEqual("mcast assoc a");
80 expect(created.association.labels).toMatchObject({ env: "test" });
81 expect(created.association.createTime).toEqual(expect.any(String));
82
83 const fetched = yield* networkservices.getProjectsLocationsMulticastConsumerAssociations({
84 name: created.association.name,
85 });
86 expect(fetched.name).toEqual(created.association.name);
87 expect(fetched.description).toEqual("mcast assoc a");
88 expect(fetched.labels?.env).toEqual("test");
89 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
90 true,
91 );
92
93 const updated = yield* stack.deploy(
94 Effect.gen(function* () {
95 const vpc = yield* GCP.Compute.Network("Vpc", {
96 networkName: created.vpc.networkName,
97 autoCreateSubnetworks: false,
98 description: "multicast consumer vpc",
99 });
100 const association = yield* GCP.NetworkServices.MulticastConsumerAssociation("Consumers", {
101 multicastConsumerAssociationId: created.association.multicastConsumerAssociationId,
102 location: "us-central1-a",
103 network: vpc.selfLink.as<string>(),
104 description: "mcast assoc b",
105 labels: { env: "prod", role: "mcast" },
106 });
107 return { vpc, association };
108 }),
109 );
110
111 expect(updated.association.name).toEqual(created.association.name);
112 expect(updated.association.description).toEqual("mcast assoc b");
113 expect(updated.association.labels).toMatchObject({
114 env: "prod",
115 role: "mcast",
116 });
117
118 yield* stack.destroy();
119
120 const gone = yield* waitUntilGone(created.association.name);
121 expect(gone).toEqual("gone");
122 }).pipe(logLevel, withNetworkSlot),
123 {
124 tags: ["provider:gcp", "provider:gcp:networkservices", "live"],
125 timeout: 900_000,
126 },
127 );