@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 150 lines 4.61 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 cnr from "@distilled.cloud/gcp/cloudnumberregistry_v1alpha";
5 import * as Effect from "effect/Effect";
6 import {
7 location,
8 logLevel,
9 currentProject,
10 entitled,
11 runLifecycle,
12 waitUntilGone,
13 } from "./common.ts";
14
15 const { test } = Test.make({ providers: GCP.providers() });
16
17 test.provider.skipIf(!entitled)(
18 "getProjectsLocationsRealms on a missing realm fails with a typed tag",
19 (stack) =>
20 Effect.gen(function* () {
21 const project = yield* currentProject;
22
23 yield* stack.destroy();
24
25 const error = yield* Effect.flip(
26 cnr.getProjectsLocationsRealms({
27 name: `projects/${project}/locations/${location}/realms/alchemy-missing-realm`,
28 }),
29 );
30 expect(error._tag).toEqual("NotFound");
31
32 yield* stack.destroy();
33 }).pipe(logLevel),
34 {
35 tags: ["provider:gcp", "provider:gcp:cloudnumberregistry", "live"],
36 timeout: 90_000,
37 },
38 );
39
40 test.provider.skipIf(entitled)(
41 "getProjectsLocationsRealms fails with ServiceDisabled while the API is disabled",
42 (stack) =>
43 Effect.gen(function* () {
44 const project = yield* currentProject;
45
46 yield* stack.destroy();
47
48 const error = yield* Effect.flip(
49 cnr.getProjectsLocationsRealms({
50 name: `projects/${project}/locations/${location}/realms/alchemy-missing-realm`,
51 }),
52 );
53 expect(["ServiceDisabled", "NotFound"]).toContain(error._tag);
54
55 yield* stack.destroy();
56 }).pipe(logLevel),
57 {
58 tags: ["provider:gcp", "provider:gcp:cloudnumberregistry", "live"],
59 timeout: 90_000,
60 },
61 );
62
63 test.provider.skipIf(!runLifecycle)(
64 "create, update, and delete a realm",
65 (stack) =>
66 Effect.gen(function* () {
67 const project = yield* currentProject;
68
69 yield* stack.destroy();
70
71 const created = yield* stack.deploy(
72 Effect.gen(function* () {
73 const book = yield* GCP.CloudNumberRegistry.RegistryBook("Inventory", {
74 location,
75 labels: { env: "test" },
76 });
77 const realm = yield* GCP.CloudNumberRegistry.Realm("Private", {
78 location,
79 registryBook: book.name,
80 trafficType: "PRIVATE",
81 managementType: "USER",
82 ipVersion: "IPV4",
83 labels: { env: "test" },
84 });
85 return { book, realm };
86 }),
87 );
88
89 expect(created.realm.realmId).toEqual(expect.any(String));
90 expect(created.realm.name).toEqual(
91 `projects/${project}/locations/${location}/realms/${created.realm.realmId}`,
92 );
93 expect(created.realm.location).toEqual(location);
94 expect(created.realm.trafficType).toEqual("PRIVATE");
95 expect(created.realm.managementType).toEqual("USER");
96 expect(created.realm.labels).toMatchObject({ env: "test" });
97
98 const fetched = yield* cnr.getProjectsLocationsRealms({
99 name: created.realm.name,
100 });
101 expect(fetched.name).toEqual(created.realm.name);
102 expect(fetched.labels?.env).toEqual("test");
103 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
104 true,
105 );
106
107 const updated = yield* stack.deploy(
108 Effect.gen(function* () {
109 const book = yield* GCP.CloudNumberRegistry.RegistryBook("Inventory", {
110 registryBookId: created.book.registryBookId,
111 location,
112 labels: { env: "test" },
113 });
114 const realm = yield* GCP.CloudNumberRegistry.Realm("Private", {
115 realmId: created.realm.realmId,
116 location,
117 registryBook: book.name,
118 trafficType: "PRIVATE",
119 managementType: "USER",
120 ipVersion: "IPV4",
121 labels: { env: "prod", role: "realm" },
122 });
123 return { book, realm };
124 }),
125 );
126
127 expect(updated.realm.name).toEqual(created.realm.name);
128 expect(updated.realm.realmId).toEqual(created.realm.realmId);
129 expect(updated.realm.labels).toMatchObject({
130 env: "prod",
131 role: "realm",
132 });
133
134 const refetched = yield* cnr.getProjectsLocationsRealms({
135 name: created.realm.name,
136 });
137 expect(refetched.labels?.env).toEqual("prod");
138 expect(refetched.labels?.role).toEqual("realm");
139
140 yield* stack.destroy();
141 const gone = yield* waitUntilGone(
142 cnr.getProjectsLocationsRealms({ name: created.realm.name }),
143 );
144 expect(gone).toEqual("gone");
145 }).pipe(logLevel),
146 {
147 tags: ["provider:gcp", "provider:gcp:cloudnumberregistry", "live"],
148 timeout: 90_000,
149 },
150 );