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

main
ts 124 lines 4.57 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.getProjectsLocationsReportConfigs({ 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 "getProjectsLocationsReportConfigs on a missing config 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.getProjectsLocationsReportConfigs({
34 name: `projects/${project}/locations/us-central1/reportConfigs/alchemy-missing-config`,
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 and delete a migration center report config",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 const group = yield* GCP.MigrationCenter.Group("Workloads", {
56 location: "us-central1",
57 displayName: "tco-group",
58 });
59 const prefs = yield* GCP.MigrationCenter.PreferenceSet("Prod", {
60 location: "us-central1",
61 displayName: "tco-prefs",
62 });
63 const config = yield* GCP.MigrationCenter.ReportConfig("Tco", {
64 location: "us-central1",
65 displayName: "tco",
66 description: "quarterly tco",
67 groupPreferencesetAssignments: [{ group: group.name, preferenceSet: prefs.name }],
68 });
69 return { group, prefs, config };
70 }),
71 );
72
73 expect(created.config.reportConfigId).toEqual(expect.any(String));
74 expect(created.config.displayName).toEqual("tco");
75 expect(created.config.description).toEqual("quarterly tco");
76 expect(created.config.groupPreferencesetAssignments).toHaveLength(1);
77 expect(created.config.groupPreferencesetAssignments[0]?.group).toEqual(created.group.name);
78 expect(created.config.groupPreferencesetAssignments[0]?.preferenceSet).toEqual(
79 created.prefs.name,
80 );
81
82 const fetched = yield* migrationcenter.getProjectsLocationsReportConfigs({
83 name: created.config.name,
84 });
85 expect(fetched.name).toEqual(created.config.name);
86 expect(fetched.description).toContain("alchemy-id=");
87 expect(fetched.description).toContain("quarterly tco");
88
89 const updated = yield* stack.deploy(
90 Effect.gen(function* () {
91 const group = yield* GCP.MigrationCenter.Group("Workloads", {
92 groupId: created.group.groupId,
93 location: "us-central1",
94 displayName: "tco-group",
95 });
96 const prefs = yield* GCP.MigrationCenter.PreferenceSet("Prod", {
97 preferenceSetId: created.prefs.preferenceSetId,
98 location: "us-central1",
99 displayName: "tco-prefs",
100 });
101 const config = yield* GCP.MigrationCenter.ReportConfig("Tco", {
102 reportConfigId: created.config.reportConfigId,
103 location: "us-central1",
104 displayName: "tco-v2",
105 description: "quarterly tco v2",
106 groupPreferencesetAssignments: [{ group: group.name, preferenceSet: prefs.name }],
107 });
108 return { group, prefs, config };
109 }),
110 );
111
112 expect(updated.config.reportConfigId).toEqual(created.config.reportConfigId);
113 expect(updated.config.displayName).toEqual("tco-v2");
114 expect(updated.config.description).toEqual("quarterly tco v2");
115
116 yield* stack.destroy();
117 const gone = yield* waitUntilGone(updated.config.name);
118 expect(gone).toEqual("gone");
119 }).pipe(logLevel),
120 {
121 tags: ["provider:gcp", "provider:gcp:migrationcenter", "live"],
122 timeout: 120_000,
123 },
124 );