@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

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