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

main
ts 164 lines 5.92 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as gkeonprem from "@distilled.cloud/gcp/gkeonprem_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8 import {
9 bareMetalControlPlane,
10 bareMetalLoadBalancer,
11 bareMetalNetwork,
12 bareMetalStorage,
13 missingBareMetalCluster,
14 missingMembership,
15 currentProject,
16 bareMetalAdminMembership,
17 runBareMetalLifecycle,
18 } from "./common.ts";
19
20 const { test } = Test.make({ providers: GCP.providers() });
21
22 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
23
24 const waitUntilGone = (name: string) =>
25 gkeonprem.getProjectsLocationsBareMetalClustersBareMetalNodePools({ name }).pipe(
26 Effect.as("found" as const),
27 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
28 Effect.repeat({
29 schedule: Schedule.spaced("2 seconds"),
30 until: (status) => status === "gone",
31 times: 10,
32 }),
33 );
34
35 test.provider(
36 "getProjectsLocationsBareMetalClustersBareMetalNodePools on a missing pool fails with a typed tag",
37 (stack) =>
38 Effect.gen(function* () {
39 const project = yield* currentProject;
40
41 yield* stack.destroy();
42
43 const error = yield* Effect.flip(
44 gkeonprem.getProjectsLocationsBareMetalClustersBareMetalNodePools({
45 name: `${missingBareMetalCluster(project)}/bareMetalNodePools/alchemy-missing-pool`,
46 }),
47 );
48 expect(error._tag).toEqual("NotFound");
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 { tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], timeout: 90_000 },
53 );
54
55 test.provider.skipIf(runBareMetalLifecycle)(
56 "create under a missing cluster is rejected with a typed tag",
57 (stack) =>
58 Effect.gen(function* () {
59 const project = yield* currentProject;
60
61 yield* stack.destroy();
62
63 const error = yield* Effect.flip(
64 stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.GKEOnPrem.BareMetalClustersBareMetalNodePool("Workers", {
67 bareMetalCluster: missingBareMetalCluster(project),
68 nodePoolConfig: {
69 nodeConfigs: [{ nodeIp: "10.200.0.11" }],
70 },
71 displayName: "alchemy-test-bmnp",
72 labels: { env: "test" },
73 });
74 }),
75 ),
76 );
77 expect(error._tag).toEqual("NotFound");
78
79 yield* stack.destroy();
80 }).pipe(logLevel),
81 { tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], timeout: 90_000 },
82 );
83
84 test.provider.skipIf(!runBareMetalLifecycle)(
85 "create, update, and delete a bare metal node pool",
86 (stack) =>
87 Effect.gen(function* () {
88 const project = yield* currentProject;
89
90 yield* stack.destroy();
91
92 const created = yield* stack.deploy(
93 Effect.gen(function* () {
94 const cluster = yield* GCP.GKEOnPrem.BareMetalCluster("Workload", {
95 adminClusterMembership: bareMetalAdminMembership ?? missingMembership(project),
96 bareMetalVersion: "1.28.0-gke.1",
97 controlPlane: bareMetalControlPlane,
98 storage: bareMetalStorage,
99 networkConfig: bareMetalNetwork,
100 loadBalancer: bareMetalLoadBalancer,
101 description: "node pool parent",
102 });
103 const pool = yield* GCP.GKEOnPrem.BareMetalClustersBareMetalNodePool("Workers", {
104 bareMetalCluster: cluster.name,
105 nodePoolConfig: {
106 nodeConfigs: [{ nodeIp: "10.200.0.11" }],
107 },
108 displayName: "alchemy-test-bmnp",
109 labels: { env: "test" },
110 });
111 return { cluster, pool };
112 }),
113 );
114
115 expect(created.pool.name).toContain("/bareMetalNodePools/");
116 expect(created.pool.bareMetalCluster).toEqual(created.cluster.name);
117 expect(created.pool.displayName).toEqual("alchemy-test-bmnp");
118
119 const fetched = yield* gkeonprem.getProjectsLocationsBareMetalClustersBareMetalNodePools({
120 name: created.pool.name,
121 });
122 expect(fetched.name).toEqual(created.pool.name);
123 expect(fetched.displayName).toContain("alchemy-id=");
124 expect(fetched.annotations?.["alchemy-id"]).toBeDefined();
125
126 const updated = yield* stack.deploy(
127 Effect.gen(function* () {
128 const cluster = yield* GCP.GKEOnPrem.BareMetalCluster("Workload", {
129 bareMetalClusterId: created.cluster.bareMetalClusterId,
130 location: created.cluster.location,
131 adminClusterMembership:
132 created.cluster.adminClusterMembership ??
133 bareMetalAdminMembership ??
134 missingMembership(project),
135 bareMetalVersion: created.cluster.bareMetalVersion ?? "1.28.0-gke.1",
136 controlPlane: created.cluster.controlPlane ?? bareMetalControlPlane,
137 storage: created.cluster.storage ?? bareMetalStorage,
138 networkConfig: created.cluster.networkConfig ?? bareMetalNetwork,
139 loadBalancer: created.cluster.loadBalancer ?? bareMetalLoadBalancer,
140 description: "node pool parent",
141 });
142 const pool = yield* GCP.GKEOnPrem.BareMetalClustersBareMetalNodePool("Workers", {
143 bareMetalNodePoolId: created.pool.bareMetalNodePoolId,
144 bareMetalCluster: cluster.name,
145 nodePoolConfig: {
146 nodeConfigs: [{ nodeIp: "10.200.0.11" }, { nodeIp: "10.200.0.12" }],
147 },
148 displayName: "alchemy-test-bmnp-v2",
149 });
150 return { cluster, pool };
151 }),
152 );
153
154 expect(updated.pool.displayName).toEqual("alchemy-test-bmnp-v2");
155 expect(updated.pool.bareMetalNodePoolId).toEqual(created.pool.bareMetalNodePoolId);
156
157 yield* stack.destroy();
158 yield* waitUntilGone(created.pool.name);
159 }).pipe(logLevel),
160 {
161 tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"],
162 timeout: 120_000,
163 },
164 );