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

main
ts 126 lines 4.41 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 oracle from "@distilled.cloud/gcp/oracledatabase_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 // Oracle Database@Google Cloud is not enabled in the test project
15 // (ServiceDisabled) and needs an Oracle Cloud subscription. Set
16 // GCP_TEST_ORACLE=1 in a project that has one.
17 const runLifecycle = !!process.env.GCP_TEST_ORACLE && !process.env.FAST;
18 const location = "us-central1";
19
20 const waitUntilGone = (name: string) =>
21 oracle.getProjectsLocationsOdbNetworksOdbSubnets({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("2 seconds"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider.skipIf(runLifecycle)(
32 "getProjectsLocationsOdbNetworksOdbSubnets without Oracle Database enabled fails with ServiceDisabled",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36
37 yield* stack.destroy();
38
39 const error = yield* Effect.flip(
40 oracle.getProjectsLocationsOdbNetworksOdbSubnets({
41 name: `projects/${project}/locations/${location}/odbNetworks/alchemy-odb-missing/odbSubnets/alchemy-subnet-missing`,
42 }),
43 );
44 expect(error._tag).toEqual("ServiceDisabled");
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 {
49 tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"],
50 timeout: 90_000,
51 },
52 );
53
54 test.provider.skipIf(!runLifecycle)(
55 "create, update, and delete an odb subnet",
56 (stack) =>
57 Effect.gen(function* () {
58 const { project } = yield* GcpEnvironment.current;
59
60 yield* stack.destroy();
61
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 const net = yield* GCP.OracleDatabase.OdbNetwork("OracleNet", {
65 location,
66 network: "default",
67 labels: { env: "test" },
68 });
69 const subnet = yield* GCP.OracleDatabase.OdbNetworksOdbSubnet("Client", {
70 odbNetwork: net.name,
71 location,
72 cidrRange: "10.250.0.0/27",
73 purpose: "CLIENT_SUBNET",
74 labels: { env: "test" },
75 });
76 return { net, subnet };
77 }),
78 );
79
80 expect(created.subnet.name).toContain("/odbSubnets/");
81 expect(created.subnet.odbSubnetId).toEqual(expect.any(String));
82 expect(created.subnet.odbNetwork).toEqual(created.net.name);
83 expect(created.subnet.cidrRange).toEqual("10.250.0.0/27");
84 expect(created.subnet.purpose).toEqual("CLIENT_SUBNET");
85 expect(created.subnet.labels).toMatchObject({ env: "test" });
86
87 const fetched = yield* oracle.getProjectsLocationsOdbNetworksOdbSubnets({
88 name: created.subnet.name,
89 });
90 expect(fetched.name).toEqual(created.subnet.name);
91 expect(fetched.cidrRange).toEqual("10.250.0.0/27");
92 expect(fetched.labels?.env).toEqual("test");
93
94 const updated = yield* stack.deploy(
95 Effect.gen(function* () {
96 const net = yield* GCP.OracleDatabase.OdbNetwork("OracleNet", {
97 odbNetworkId: created.net.odbNetworkId,
98 location,
99 network: "default",
100 labels: { env: "prod" },
101 });
102 const subnet = yield* GCP.OracleDatabase.OdbNetworksOdbSubnet("Client", {
103 odbNetwork: net.name,
104 odbSubnetId: created.subnet.odbSubnetId,
105 location,
106 cidrRange: "10.250.0.0/27",
107 purpose: "CLIENT_SUBNET",
108 labels: { env: "prod", role: "client" },
109 });
110 return { net, subnet };
111 }),
112 );
113
114 expect(updated.subnet.name).toEqual(created.subnet.name);
115 expect(updated.subnet.odbSubnetId).toEqual(created.subnet.odbSubnetId);
116
117 yield* stack.destroy();
118
119 const gone = yield* waitUntilGone(created.subnet.name);
120 expect(gone).toEqual("gone");
121 }).pipe(logLevel),
122 {
123 tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"],
124 timeout: 120_000,
125 },
126 );