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.getProjectsLocationsIndexEndpoints({ 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 "getProjectsLocationsIndexEndpoints 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.getProjectsLocationsIndexEndpoints({
38 name: `${parent}/indexEndpoints/1234567890123456789`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42 const page = yield* aiplatform.listProjectsLocationsIndexEndpoints({
43 parent,
44 pageSize: 10,
45 });
46 expect(
47 (page.indexEndpoints ?? []).map((item) => item.name),
48 ).not.toContain(`${parent}/indexEndpoints/1234567890123456789`);
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 an index 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.IndexEndpoint("Search", {
67 location: "us-central1",
68 displayName: "alchemy-index-endpoint",
69 description: "public search",
70 publicEndpointEnabled: true,
71 labels: { env: "test" },
72 });
73 }),
74 );
75
76 expect(created.name).toContain("/indexEndpoints/");
77 expect(created.location).toEqual("us-central1");
78 expect(created.labels).toMatchObject({ env: "test" });
79 expect(created.description).toEqual("public search");
80
81 const fetched = yield* aiplatform.getProjectsLocationsIndexEndpoints({
82 name: created.name,
83 });
84 expect(fetched.name).toEqual(created.name);
85 expect(fetched.labels?.env).toEqual("test");
86
87 const updated = yield* stack.deploy(
88 Effect.gen(function* () {
89 return yield* GCP.AIPlatform.IndexEndpoint("Search", {
90 location: "us-central1",
91 displayName: "alchemy-index-endpoint",
92 description: "public search v2",
93 publicEndpointEnabled: true,
94 labels: { env: "prod", role: "search" },
95 });
96 }),
97 );
98
99 expect(updated.name).toEqual(created.name);
100 expect(updated.description).toEqual("public search v2");
101 expect(updated.labels).toMatchObject({ env: "prod", role: "search" });
102
103 yield* stack.destroy();
104
105 const gone = yield* waitUntilGone(created.name);
106 expect(gone).toEqual("gone");
107 }).pipe(logLevel),
108 {
109 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
110 timeout: 180_000,
111 },
112);