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

main
ts 111 lines 3.93 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 saasservicemgmt from "@distilled.cloud/gcp/saasservicemgmt_v1";
5 import * as Effect from "effect/Effect";
6 import { location, logLevel, currentProject, runLifecycle, waitUntilGone } from "./common.ts";
7
8 const { test } = Test.make({ providers: GCP.providers() });
9
10 test.provider(
11 "getProjectsLocationsRolloutKinds on a missing rollout kind 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 saasservicemgmt.getProjectsLocationsRolloutKinds({
19 name: `projects/${project}/locations/${location}/rolloutKinds/alchemy-missing-rk`,
20 }),
21 );
22 expect(error._tag).toEqual("NotFound");
23
24 yield* stack.destroy();
25 }).pipe(logLevel),
26 {
27 tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"],
28 timeout: 90_000,
29 },
30 );
31
32 test.provider.skipIf(!runLifecycle)(
33 "create, update, and delete a rollout kind",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const created = yield* stack.deploy(
39 Effect.gen(function* () {
40 const product = yield* GCP.SaasServiceManagement.Saa("Inventory", {
41 location,
42 locations: [{ name: location }],
43 });
44 const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", {
45 location,
46 saas: product.name,
47 });
48 const rolloutKind = yield* GCP.SaasServiceManagement.RolloutKind("Wave", {
49 location,
50 unitKind: kind.name,
51 rolloutOrchestrationStrategy: "Google.Cloud.Simple.AllAtOnce",
52 labels: { env: "test" },
53 });
54 return { product, kind, rolloutKind };
55 }),
56 );
57
58 expect(created.rolloutKind.name).toContain("/rolloutKinds/");
59 expect(created.rolloutKind.unitKindId).toEqual(created.kind.unitKindId);
60 expect(created.rolloutKind.labels).toMatchObject({ env: "test" });
61
62 const fetched = yield* saasservicemgmt.getProjectsLocationsRolloutKinds({
63 name: created.rolloutKind.name,
64 });
65 expect(fetched.name).toEqual(created.rolloutKind.name);
66 expect(fetched.labels?.env).toEqual("test");
67 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
68 true,
69 );
70
71 const updated = yield* stack.deploy(
72 Effect.gen(function* () {
73 const product = yield* GCP.SaasServiceManagement.Saa("Inventory", {
74 saasId: created.product.saasId,
75 location,
76 locations: [{ name: location }],
77 });
78 const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", {
79 unitKindId: created.kind.unitKindId,
80 location,
81 saas: product.name,
82 });
83 const rolloutKind = yield* GCP.SaasServiceManagement.RolloutKind("Wave", {
84 rolloutKindId: created.rolloutKind.rolloutKindId,
85 location,
86 unitKind: kind.name,
87 rolloutOrchestrationStrategy: "Google.Cloud.Simple.AllAtOnce",
88 errorBudget: { allowedCount: 1, allowedPercentage: 10 },
89 labels: { env: "prod" },
90 });
91 return { product, kind, rolloutKind };
92 }),
93 );
94
95 expect(updated.rolloutKind.name).toEqual(created.rolloutKind.name);
96 expect(updated.rolloutKind.labels).toMatchObject({ env: "prod" });
97 expect(updated.rolloutKind.errorBudget?.allowedCount).toEqual(1);
98
99 yield* stack.destroy();
100 const gone = yield* waitUntilGone(
101 saasservicemgmt.getProjectsLocationsRolloutKinds({
102 name: created.rolloutKind.name,
103 }),
104 );
105 expect(gone).toEqual("gone");
106 }).pipe(logLevel),
107 {
108 tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"],
109 timeout: 90_000,
110 },
111 );