@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 115 lines 3.97 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 aiplatform from "@distilled.cloud/gcp/aiplatform_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 // Pool create + update + delete takes ~10s. The very first Vertex AI
15 // creates on a freshly provisioned project take 4–9 minutes (one-time
16 // service provisioning); that exceeds the test timeout once, and the
17 // provider's recovery settles the pending create so cleanup still deletes it.
18 const runLifecycle = !process.env.FAST;
19
20 const waitUntilGone = (name: string) =>
21 aiplatform.getProjectsLocationsDeploymentResourcePools({ 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 "getProjectsLocationsDeploymentResourcePools on a missing pool fails with a typed tag",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 const parent = `projects/${project}/locations/us-central1`;
37 yield* stack.destroy();
38
39 const error = yield* Effect.flip(
40 aiplatform.getProjectsLocationsDeploymentResourcePools({
41 name: `${parent}/deploymentResourcePools/alchemy-aiplatform-missing`,
42 }),
43 );
44 expect(error._tag).toEqual("NotFound");
45 const page = yield* aiplatform.listProjectsLocationsDeploymentResourcePools({
46 parent,
47 pageSize: 10,
48 });
49 expect((page.deploymentResourcePools ?? []).map((item) => item.name)).not.toContain(
50 `${parent}/deploymentResourcePools/alchemy-aiplatform-missing`,
51 );
52
53 yield* stack.destroy();
54 }).pipe(logLevel),
55 {
56 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
57 timeout: 90_000,
58 },
59 );
60
61 test.provider.skipIf(!runLifecycle)(
62 "create, update, and delete a deployment resource pool",
63 (stack) =>
64 Effect.gen(function* () {
65 yield* stack.destroy();
66
67 const created = yield* stack.deploy(
68 Effect.gen(function* () {
69 return yield* GCP.AIPlatform.DeploymentResourcePool("Shared", {
70 location: "us-central1",
71 dedicatedResources: {
72 minReplicaCount: 1,
73 maxReplicaCount: 1,
74 machineSpec: { machineType: "n1-standard-2" },
75 },
76 });
77 }),
78 );
79
80 expect(created.name).toContain("/deploymentResourcePools/");
81 expect(created.deploymentResourcePoolId.startsWith("alch-")).toEqual(true);
82 expect(created.dedicatedResources?.minReplicaCount).toEqual(1);
83
84 const fetched = yield* aiplatform.getProjectsLocationsDeploymentResourcePools({
85 name: created.name,
86 });
87 expect(fetched.name).toEqual(created.name);
88
89 const updated = yield* stack.deploy(
90 Effect.gen(function* () {
91 return yield* GCP.AIPlatform.DeploymentResourcePool("Shared", {
92 deploymentResourcePoolId: created.deploymentResourcePoolId,
93 location: "us-central1",
94 dedicatedResources: {
95 minReplicaCount: 1,
96 maxReplicaCount: 2,
97 machineSpec: { machineType: "n1-standard-2" },
98 },
99 });
100 }),
101 );
102
103 expect(updated.name).toEqual(created.name);
104 expect(updated.dedicatedResources?.maxReplicaCount).toEqual(2);
105
106 yield* stack.destroy();
107
108 const gone = yield* waitUntilGone(created.name);
109 expect(gone).toEqual("gone");
110 }).pipe(logLevel),
111 {
112 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
113 timeout: 120_000,
114 },
115 );