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

main
ts 99 lines 3.39 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 vmmigration from "@distilled.cloud/gcp/vmmigration_v1";
5 import * as Effect from "effect/Effect";
6 import { logLevel, currentProject, waitUntilGone } from "./common.ts";
7
8 const { test } = Test.make({ providers: GCP.providers() });
9
10 test.provider(
11 "getProjectsLocationsTargetProjects on a missing target fails with a typed tag",
12 (stack) =>
13 Effect.gen(function* () {
14 const project = yield* currentProject;
15 yield* stack.destroy();
16
17 const error = yield* Effect.flip(
18 vmmigration.getProjectsLocationsTargetProjects({
19 name: `projects/${project}/locations/global/targetProjects/alchemy-missing-target`,
20 }),
21 );
22 expect(error._tag).toEqual("NotFound");
23
24 yield* stack.destroy();
25 }).pipe(logLevel),
26 {
27 tags: ["provider:gcp", "provider:gcp:vmmigration", "live"],
28 timeout: 90_000,
29 },
30 );
31
32 // Migrate to VMs registers the host project as a target on first use, and a
33 // project can be a target only once (BadRequest "failed precondition: an
34 // existing target project exists for project ..."). Set
35 // GCP_TEST_VMMIGRATION_TARGET_PROJECT to a second project id to run this.
36 const targetProject = process.env.GCP_TEST_VMMIGRATION_TARGET_PROJECT;
37
38 test.provider.skipIf(!targetProject)(
39 "create, update, and delete a vm migration target project",
40 (stack) =>
41 Effect.gen(function* () {
42 const hostProject = yield* currentProject;
43 const project = targetProject!;
44 yield* stack.destroy();
45
46 const created = yield* stack.deploy(
47 Effect.gen(function* () {
48 return yield* GCP.VMMigration.Target("Landing", {
49 project,
50 description: "landing zone",
51 });
52 }),
53 );
54
55 expect(created.targetProjectId).toEqual(expect.any(String));
56 expect(created.name).toEqual(
57 `projects/${hostProject}/locations/global/targetProjects/${created.targetProjectId}`,
58 );
59 expect(created.location).toEqual("global");
60 expect(created.project).toEqual(project);
61 expect(created.description).toEqual("landing zone");
62
63 const fetched = yield* vmmigration.getProjectsLocationsTargetProjects({
64 name: created.name,
65 });
66 expect(fetched.name).toEqual(created.name);
67 expect(fetched.project).toEqual(project);
68 expect(fetched.description).toContain("alchemy-id=");
69 expect(fetched.description).toContain("landing zone");
70
71 const updated = yield* stack.deploy(
72 Effect.gen(function* () {
73 return yield* GCP.VMMigration.Target("Landing", {
74 targetProjectId: created.targetProjectId,
75 project,
76 description: "landing zone v2",
77 });
78 }),
79 );
80
81 expect(updated.name).toEqual(created.name);
82 expect(updated.description).toEqual("landing zone v2");
83
84 const fetchedUpdate = yield* vmmigration.getProjectsLocationsTargetProjects({
85 name: updated.name,
86 });
87 expect(fetchedUpdate.description).toContain("landing zone v2");
88
89 yield* stack.destroy();
90 const gone = yield* waitUntilGone(
91 vmmigration.getProjectsLocationsTargetProjects({ name: created.name }),
92 );
93 expect(gone).toEqual("gone");
94 }).pipe(logLevel),
95 {
96 tags: ["provider:gcp", "provider:gcp:vmmigration", "live"],
97 timeout: 90_000,
98 },
99 );