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

main
ts 112 lines 3.82 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 migrationcenter from "@distilled.cloud/gcp/migrationcenter_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 waitUntilGone = (name: string) =>
15 migrationcenter.getProjectsLocationsGroups({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsGroups on a missing group fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 migrationcenter.getProjectsLocationsGroups({
34 name: `projects/${project}/locations/us-central1/groups/alchemy-missing-group`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:migrationcenter", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "create, update, and delete a migration center group",
49 (stack) =>
50 Effect.gen(function* () {
51 const { project } = yield* GcpEnvironment.current;
52 yield* stack.destroy();
53
54 const created = yield* stack.deploy(
55 Effect.gen(function* () {
56 return yield* GCP.MigrationCenter.Group("Workloads", {
57 location: "us-central1",
58 displayName: "workloads",
59 description: "production vms",
60 labels: { env: "test" },
61 });
62 }),
63 );
64
65 expect(created.groupId).toEqual(expect.any(String));
66 expect(created.name).toEqual(
67 `projects/${project}/locations/us-central1/groups/${created.groupId}`,
68 );
69 expect(created.location).toEqual("us-central1");
70 expect(created.displayName).toEqual("workloads");
71 expect(created.description).toEqual("production vms");
72 expect(created.labels).toMatchObject({ env: "test" });
73
74 const fetched = yield* migrationcenter.getProjectsLocationsGroups({
75 name: created.name,
76 });
77 expect(fetched.name).toEqual(created.name);
78 expect(fetched.displayName).toEqual("workloads");
79 expect(fetched.labels?.env).toEqual("test");
80
81 const updated = yield* stack.deploy(
82 Effect.gen(function* () {
83 return yield* GCP.MigrationCenter.Group("Workloads", {
84 groupId: created.groupId,
85 location: "us-central1",
86 displayName: "workloads-v2",
87 description: "production vms v2",
88 labels: { env: "prod", team: "migration" },
89 });
90 }),
91 );
92
93 expect(updated.name).toEqual(created.name);
94 expect(updated.displayName).toEqual("workloads-v2");
95 expect(updated.description).toEqual("production vms v2");
96 expect(updated.labels).toMatchObject({ env: "prod", team: "migration" });
97
98 const fetchedUpdate = yield* migrationcenter.getProjectsLocationsGroups({
99 name: updated.name,
100 });
101 expect(fetchedUpdate.displayName).toEqual("workloads-v2");
102 expect(fetchedUpdate.labels?.team).toEqual("migration");
103
104 yield* stack.destroy();
105 const gone = yield* waitUntilGone(created.name);
106 expect(gone).toEqual("gone");
107 }).pipe(logLevel),
108 {
109 tags: ["provider:gcp", "provider:gcp:migrationcenter", "live"],
110 timeout: 90_000,
111 },
112 );