The best way to control Claude Code, Codex and more from any computer or phone

main
ts 141 lines 4.8 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 vpcaccess from "@distilled.cloud/gcp/vpcaccess_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 // Create + patch + delete each take ~2–4 minutes (~7 minutes end to end).
15 const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST;
16
17 const waitUntilGone = (name: string) =>
18 vpcaccess.getProjectsLocationsConnectors({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("2 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsLocationsConnectors on a missing connector fails with NotFound",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 vpcaccess.getProjectsLocationsConnectors({
38 name: `projects/${project}/locations/us-central1/connectors/alchemy-vpc-con-missing`,
39 }),
40 );
41 expect(error._tag).toBe("NotFound");
42
43 const page = yield* vpcaccess.listProjectsLocationsConnectors({
44 parent: `projects/${project}/locations/us-central1`,
45 pageSize: 100,
46 });
47 expect((page.connectors ?? []).map((connector) => connector.name)).not.toContain(
48 `projects/${project}/locations/us-central1/connectors/alchemy-vpc-con-missing`,
49 );
50
51 const locations = yield* vpcaccess.listProjectsLocations({
52 name: `projects/${project}`,
53 pageSize: 100,
54 });
55 expect((locations.locations ?? []).map((location) => location.locationId)).toContain(
56 "us-central1",
57 );
58
59 yield* stack.destroy();
60 }).pipe(logLevel),
61 { tags: ["provider:gcp", "provider:gcp:vpcaccess", "live"], timeout: 90_000 },
62 );
63
64 test.provider.skipIf(!runLifecycle)(
65 "create, update, and delete a vpc access connector",
66 (stack) =>
67 Effect.gen(function* () {
68 const { project } = yield* GcpEnvironment.current;
69
70 yield* stack.destroy();
71
72 const created = yield* stack.deploy(
73 Effect.gen(function* () {
74 return yield* GCP.VpcAccess.Connector("Egress", {
75 location: "us-central1",
76 network: "default",
77 ipCidrRange: "10.88.0.0/28",
78 machineType: "e2-micro",
79 minInstances: 2,
80 maxInstances: 3,
81 });
82 }),
83 );
84
85 expect(created.connectorId).toEqual(expect.any(String));
86 expect(created.location).toEqual("us-central1");
87 expect(created.project).toEqual(project);
88 expect(created.name).toEqual(
89 `projects/${project}/locations/us-central1/connectors/${created.connectorId}`,
90 );
91 expect(created.state).toEqual("READY");
92 expect(created.network).toEqual("default");
93 expect(created.ipCidrRange).toEqual("10.88.0.0/28");
94 expect(created.minInstances).toEqual(2);
95 expect(created.maxInstances).toEqual(3);
96
97 const fetched = yield* vpcaccess.getProjectsLocationsConnectors({
98 name: created.name,
99 });
100 expect(fetched.name).toEqual(created.name);
101 expect(fetched.state).toEqual("READY");
102 expect(fetched.network).toEqual("default");
103 expect(fetched.ipCidrRange).toEqual("10.88.0.0/28");
104 expect(fetched.minInstances).toEqual(2);
105 expect(fetched.maxInstances).toEqual(3);
106
107 const updated = yield* stack.deploy(
108 Effect.gen(function* () {
109 return yield* GCP.VpcAccess.Connector("Egress", {
110 connectorId: created.connectorId,
111 location: "us-central1",
112 network: "default",
113 ipCidrRange: "10.88.0.0/28",
114 machineType: "e2-micro",
115 minInstances: 2,
116 maxInstances: 4,
117 });
118 }),
119 );
120
121 expect(updated.name).toEqual(created.name);
122 expect(updated.maxInstances).toEqual(4);
123 expect(updated.minInstances).toEqual(2);
124 expect(updated.state).toEqual("READY");
125
126 const fetchedUpdate = yield* vpcaccess.getProjectsLocationsConnectors({
127 name: created.name,
128 });
129 expect(fetchedUpdate.maxInstances).toEqual(4);
130 expect(fetchedUpdate.minInstances).toEqual(2);
131
132 yield* stack.destroy();
133
134 const gone = yield* waitUntilGone(created.name);
135 expect(gone).toEqual("gone");
136 }).pipe(logLevel),
137 {
138 tags: ["provider:gcp", "provider:gcp:vpcaccess", "live"],
139 timeout: 540_000,
140 },
141 );