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