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

main
ts 119 lines 4.03 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 "getProjectsLocationsUnits on a missing unit 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.getProjectsLocationsUnits({
19 name: `projects/${project}/locations/${location}/units/alchemy-missing-unit`,
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 unit",
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 tenant = yield* GCP.SaasServiceManagement.Tenant("Acme", {
45 location,
46 saas: product.name,
47 });
48 const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", {
49 location,
50 saas: product.name,
51 });
52 const unit = yield* GCP.SaasServiceManagement.Unit("Store1", {
53 location,
54 unitKind: kind.name,
55 tenant: tenant.name,
56 managementMode: "MANAGEMENT_MODE_USER",
57 labels: { env: "test" },
58 });
59 return { product, tenant, kind, unit };
60 }),
61 );
62
63 expect(created.unit.name).toContain("/units/");
64 expect(created.unit.unitKindId).toEqual(created.kind.unitKindId);
65 expect(created.unit.tenantId).toEqual(created.tenant.tenantId);
66 expect(created.unit.labels).toMatchObject({ env: "test" });
67
68 const fetched = yield* saasservicemgmt.getProjectsLocationsUnits({
69 name: created.unit.name,
70 });
71 expect(fetched.name).toEqual(created.unit.name);
72 expect(fetched.labels?.env).toEqual("test");
73 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
74 true,
75 );
76
77 const updated = yield* stack.deploy(
78 Effect.gen(function* () {
79 const product = yield* GCP.SaasServiceManagement.Saa("Inventory", {
80 saasId: created.product.saasId,
81 location,
82 locations: [{ name: location }],
83 });
84 const tenant = yield* GCP.SaasServiceManagement.Tenant("Acme", {
85 tenantId: created.tenant.tenantId,
86 location,
87 saas: product.name,
88 });
89 const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", {
90 unitKindId: created.kind.unitKindId,
91 location,
92 saas: product.name,
93 });
94 const unit = yield* GCP.SaasServiceManagement.Unit("Store1", {
95 unitId: created.unit.unitId,
96 location,
97 unitKind: kind.name,
98 tenant: tenant.name,
99 managementMode: "MANAGEMENT_MODE_USER",
100 labels: { env: "prod" },
101 });
102 return { product, tenant, kind, unit };
103 }),
104 );
105
106 expect(updated.unit.name).toEqual(created.unit.name);
107 expect(updated.unit.labels).toMatchObject({ env: "prod" });
108
109 yield* stack.destroy();
110 const gone = yield* waitUntilGone(
111 saasservicemgmt.getProjectsLocationsUnits({ name: created.unit.name }),
112 );
113 expect(gone).toEqual("gone");
114 }).pipe(logLevel),
115 {
116 tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"],
117 timeout: 90_000,
118 },
119 );