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

main
ts 112 lines 4.01 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.getProjectsLocationsPreferenceSets({ 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 "getProjectsLocationsPreferenceSets on a missing set 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.getProjectsLocationsPreferenceSets({
34 name: `projects/${project}/locations/us-central1/preferenceSets/alchemy-missing-prefset`,
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 preference set",
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.PreferenceSet("Prod", {
57 location: "us-central1",
58 displayName: "prod-gce",
59 description: "gce defaults",
60 });
61 }),
62 );
63
64 expect(created.preferenceSetId).toEqual(expect.any(String));
65 expect(created.name).toEqual(
66 `projects/${project}/locations/us-central1/preferenceSets/${created.preferenceSetId}`,
67 );
68 expect(created.displayName).toEqual("prod-gce");
69 expect(created.description).toEqual("gce defaults");
70 expect(created.virtualMachinePreferences?.targetProduct).toEqual(
71 "COMPUTE_MIGRATION_TARGET_PRODUCT_COMPUTE_ENGINE",
72 );
73
74 const fetched = yield* migrationcenter.getProjectsLocationsPreferenceSets({
75 name: created.name,
76 });
77 expect(fetched.name).toEqual(created.name);
78 expect(fetched.displayName).toEqual("prod-gce");
79 expect(fetched.description).toContain("alchemy-id=");
80 expect(fetched.description).toContain("gce defaults");
81
82 const updated = yield* stack.deploy(
83 Effect.gen(function* () {
84 return yield* GCP.MigrationCenter.PreferenceSet("Prod", {
85 preferenceSetId: created.preferenceSetId,
86 location: "us-central1",
87 displayName: "prod-gce-v2",
88 description: "gce moderate",
89 virtualMachinePreferences: {
90 targetProduct: "COMPUTE_MIGRATION_TARGET_PRODUCT_COMPUTE_ENGINE",
91 regionPreferences: { preferredRegions: ["us-central1"] },
92 sizingOptimizationStrategy: "SIZING_OPTIMIZATION_STRATEGY_MODERATE",
93 commitmentPlan: "COMMITMENT_PLAN_ONE_YEAR",
94 },
95 });
96 }),
97 );
98
99 expect(updated.name).toEqual(created.name);
100 expect(updated.displayName).toEqual("prod-gce-v2");
101 expect(updated.description).toEqual("gce moderate");
102 expect(updated.virtualMachinePreferences?.commitmentPlan).toEqual("COMMITMENT_PLAN_ONE_YEAR");
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 );