@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 154 lines 5.29 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as managedidentities from "@distilled.cloud/gcp/managedidentities_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // Backups require a provisioned Managed AD domain (20-60 minutes).
15 // Create against a missing parent returns `NotFound` (`parent resource
16 // not found for .../domains/missing.alch.test/backups/...`). Set
17 // GCP_TEST_MANAGEDIDENTITIES=1 to run the full lifecycle.
18 const runLifecycle = !process.env.FAST && process.env.GCP_TEST_MANAGEDIDENTITIES === "1";
19
20 const waitUntilGone = (name: string) =>
21 managedidentities.getProjectsLocationsGlobalDomainsBackups({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("2 seconds"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider(
32 "getProjectsLocationsGlobalDomainsBackups on a missing backup fails with a typed tag",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 const missingDomain = `projects/${project}/locations/global/domains/missing.alch.test`;
37 yield* stack.destroy();
38
39 const error = yield* Effect.flip(
40 managedidentities.getProjectsLocationsGlobalDomainsBackups({
41 name: `${missingDomain}/backups/alchemy-backup-missing`,
42 }),
43 );
44 expect(error._tag).toEqual("NotFound");
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 {
49 tags: ["provider:gcp", "provider:gcp:managedidentities", "live"],
50 timeout: 90_000,
51 },
52 );
53
54 test.provider.skipIf(runLifecycle)(
55 "create is rejected with a typed tag when the parent domain is missing",
56 (stack) =>
57 Effect.gen(function* () {
58 const { project } = yield* GcpEnvironment.current;
59 const missingDomain = `projects/${project}/locations/global/domains/missing.alch.test`;
60 yield* stack.destroy();
61
62 const error = yield* Effect.flip(
63 stack.deploy(
64 Effect.gen(function* () {
65 return yield* GCP.ManagedIdentities.DomainsBackup("Nightly", {
66 domain: missingDomain,
67 labels: { env: "test" },
68 });
69 }),
70 ),
71 );
72 expect(error._tag).toEqual("NotFound");
73
74 yield* stack.destroy();
75 }).pipe(logLevel),
76 {
77 tags: ["provider:gcp", "provider:gcp:managedidentities", "live"],
78 timeout: 90_000,
79 },
80 );
81
82 test.provider.skipIf(!runLifecycle)(
83 "create, update, and delete a domain backup",
84 (stack) =>
85 Effect.gen(function* () {
86 yield* stack.destroy();
87
88 const created = yield* stack.deploy(
89 Effect.gen(function* () {
90 const domain = yield* GCP.ManagedIdentities.Domain("Ad", {
91 reservedIpRange: "172.16.1.0/24",
92 locations: ["us-central1"],
93 authorizedNetworks: ["default"],
94 labels: { env: "test" },
95 });
96 const backup = yield* GCP.ManagedIdentities.DomainsBackup("Nightly", {
97 domain: domain.name,
98 labels: { env: "test" },
99 });
100 return { domain, backup };
101 }),
102 );
103
104 expect(created.backup.name).toContain("/backups/");
105 expect(created.backup.backupId).toEqual(expect.any(String));
106 expect(created.backup.domain).toEqual(created.domain.name);
107 expect(created.backup.labels).toMatchObject({ env: "test" });
108
109 const fetched = yield* managedidentities.getProjectsLocationsGlobalDomainsBackups({
110 name: created.backup.name,
111 });
112 expect(fetched.name).toEqual(created.backup.name);
113 expect(fetched.labels?.env).toEqual("test");
114
115 const updated = yield* stack.deploy(
116 Effect.gen(function* () {
117 const domain = yield* GCP.ManagedIdentities.Domain("Ad", {
118 domainName: created.domain.domainName,
119 reservedIpRange: "172.16.1.0/24",
120 locations: ["us-central1"],
121 authorizedNetworks: ["default"],
122 labels: { env: "test" },
123 });
124 const backup = yield* GCP.ManagedIdentities.DomainsBackup("Nightly", {
125 domain: domain.name,
126 backupId: created.backup.backupId,
127 labels: { env: "prod", role: "backup" },
128 });
129 return { domain, backup };
130 }),
131 );
132
133 expect(updated.backup.name).toEqual(created.backup.name);
134 expect(updated.backup.labels).toMatchObject({
135 env: "prod",
136 role: "backup",
137 });
138
139 const refetched = yield* managedidentities.getProjectsLocationsGlobalDomainsBackups({
140 name: created.backup.name,
141 });
142 expect(refetched.labels?.env).toEqual("prod");
143 expect(refetched.labels?.role).toEqual("backup");
144
145 yield* stack.destroy();
146
147 const gone = yield* waitUntilGone(created.backup.name);
148 expect(gone).toEqual("gone");
149 }).pipe(logLevel),
150 {
151 tags: ["provider:gcp", "provider:gcp:managedidentities", "live"],
152 timeout: 240_000,
153 },
154 );