1import * as GCP from "@/GCP";
2import { GcpEnvironment } from "@/GCP/Environment";
3import * as Test from "@/Test/Alchemy";
4import * as aiplatform from "@distilled.cloud/gcp/aiplatform_v1";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7import { MinimumLogLevel } from "effect/References";
8import * as Schedule from "effect/Schedule";
9
10const { test } = Test.make({ providers: GCP.providers() });
11
12const logLevel = Effect.provideService(
13 MinimumLogLevel,
14 process.env.DEBUG ? "Debug" : "Info",
15);
16
17const waitUntilGone = (name: string) =>
18 aiplatform.getProjectsLocationsEndpoints({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("2 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28test.provider(
29 "getProjectsLocationsEndpoints on a missing endpoint fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33 const parent = `projects/${project}/locations/us-central1`;
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 aiplatform.getProjectsLocationsEndpoints({
38 name: `${parent}/endpoints/alchemy-missing`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42 const page = yield* aiplatform.listProjectsLocationsEndpoints({
43 parent,
44 pageSize: 10,
45 });
46 expect((page.endpoints ?? []).map((item) => item.name)).not.toContain(
47 `${parent}/endpoints/alchemy-missing`,
48 );
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 {
53 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
54 timeout: 90_000,
55 },
56);
57
58test.provider(
59 "create, update, and delete a vertex endpoint",
60 (stack) =>
61 Effect.gen(function* () {
62 yield* stack.destroy();
63
64 const created = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.AIPlatform.Endpoint("Predictor", {
67 location: "us-central1",
68 displayName: "alchemy-endpoint",
69 description: "online predict",
70 labels: { env: "test" },
71 });
72 }),
73 );
74
75 expect(created.name).toContain("/endpoints/");
76 expect(created.location).toEqual("us-central1");
77 expect(created.displayName).toEqual("alchemy-endpoint");
78 expect(created.labels).toMatchObject({ env: "test" });
79
80 const fetched = yield* aiplatform.getProjectsLocationsEndpoints({
81 name: created.name,
82 });
83 expect(fetched.name).toEqual(created.name);
84 expect(fetched.labels?.env).toEqual("test");
85
86 const updated = yield* stack.deploy(
87 Effect.gen(function* () {
88 return yield* GCP.AIPlatform.Endpoint("Predictor", {
89 endpointId: created.endpointId,
90 location: "us-central1",
91 displayName: "alchemy-endpoint-prod",
92 description: "updated",
93 labels: { env: "prod", role: "predict" },
94 });
95 }),
96 );
97
98 expect(updated.name).toEqual(created.name);
99 expect(updated.displayName).toEqual("alchemy-endpoint-prod");
100 expect(updated.labels).toMatchObject({ env: "prod", role: "predict" });
101
102 yield* stack.destroy();
103
104 const gone = yield* waitUntilGone(created.name);
105 expect(gone).toEqual("gone");
106 }).pipe(logLevel),
107 {
108 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
109 timeout: 180_000,
110 },
111);