@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 149 lines 5.05 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 {
7 location,
8 logLevel,
9 currentProject,
10 blueprintPackage,
11 runBlueprintLifecycle,
12 waitUntilGone,
13 } from "./common.ts";
14
15 const { test } = Test.make({ providers: GCP.providers() });
16
17 test.provider(
18 "getProjectsLocationsUnitOperations on a missing unit operation fails with a typed tag",
19 (stack) =>
20 Effect.gen(function* () {
21 const project = yield* currentProject;
22 yield* stack.destroy();
23
24 const error = yield* Effect.flip(
25 saasservicemgmt.getProjectsLocationsUnitOperations({
26 name: `projects/${project}/locations/${location}/unitOperations/alchemy-missing-uop`,
27 }),
28 );
29 expect(error._tag).toEqual("NotFound");
30
31 yield* stack.destroy();
32 }).pipe(logLevel),
33 {
34 tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"],
35 timeout: 90_000,
36 },
37 );
38
39 test.provider.skipIf(!runBlueprintLifecycle)(
40 "create, update, and delete a unit operation",
41 (stack) =>
42 Effect.gen(function* () {
43 const blueprint = blueprintPackage ?? "";
44 yield* stack.destroy();
45
46 const created = yield* stack.deploy(
47 Effect.gen(function* () {
48 const product = yield* GCP.SaasServiceManagement.Saa("Inventory", {
49 location,
50 locations: [{ name: location }],
51 });
52 const tenant = yield* GCP.SaasServiceManagement.Tenant("Acme", {
53 location,
54 saas: product.name,
55 });
56 const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", {
57 location,
58 saas: product.name,
59 });
60 const release = yield* GCP.SaasServiceManagement.Release("V1", {
61 location,
62 unitKind: kind.name,
63 blueprint: { package: blueprint },
64 });
65 const unit = yield* GCP.SaasServiceManagement.Unit("Store1", {
66 location,
67 unitKind: kind.name,
68 tenant: tenant.name,
69 managementMode: "MANAGEMENT_MODE_USER",
70 });
71 const operation = yield* GCP.SaasServiceManagement.UnitOperation("Provision", {
72 location,
73 unit: unit.name,
74 provision: { release: release.name },
75 labels: { env: "test" },
76 });
77 return { product, tenant, kind, release, unit, operation };
78 }),
79 );
80
81 expect(created.operation.name).toContain("/unitOperations/");
82 expect(created.operation.unitId).toEqual(created.unit.unitId);
83 expect(created.operation.labels).toMatchObject({ env: "test" });
84
85 const fetched = yield* saasservicemgmt.getProjectsLocationsUnitOperations({
86 name: created.operation.name,
87 });
88 expect(fetched.name).toEqual(created.operation.name);
89 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
90 true,
91 );
92
93 const updated = yield* stack.deploy(
94 Effect.gen(function* () {
95 const product = yield* GCP.SaasServiceManagement.Saa("Inventory", {
96 saasId: created.product.saasId,
97 location,
98 locations: [{ name: location }],
99 });
100 const tenant = yield* GCP.SaasServiceManagement.Tenant("Acme", {
101 tenantId: created.tenant.tenantId,
102 location,
103 saas: product.name,
104 });
105 const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", {
106 unitKindId: created.kind.unitKindId,
107 location,
108 saas: product.name,
109 });
110 const release = yield* GCP.SaasServiceManagement.Release("V1", {
111 releaseId: created.release.releaseId,
112 location,
113 unitKind: kind.name,
114 blueprint: { package: blueprint },
115 });
116 const unit = yield* GCP.SaasServiceManagement.Unit("Store1", {
117 unitId: created.unit.unitId,
118 location,
119 unitKind: kind.name,
120 tenant: tenant.name,
121 managementMode: "MANAGEMENT_MODE_USER",
122 });
123 const operation = yield* GCP.SaasServiceManagement.UnitOperation("Provision", {
124 unitOperationId: created.operation.unitOperationId,
125 location,
126 unit: unit.name,
127 provision: { release: release.name },
128 labels: { env: "prod" },
129 });
130 return { product, tenant, kind, release, unit, operation };
131 }),
132 );
133
134 expect(updated.operation.name).toEqual(created.operation.name);
135 expect(updated.operation.labels).toMatchObject({ env: "prod" });
136
137 yield* stack.destroy();
138 const gone = yield* waitUntilGone(
139 saasservicemgmt.getProjectsLocationsUnitOperations({
140 name: created.operation.name,
141 }),
142 );
143 expect(gone).toEqual("gone");
144 }).pipe(logLevel),
145 {
146 tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"],
147 timeout: 90_000,
148 },
149 );