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.getProjectsLocationsReasoningEngines({ 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 "getProjectsLocationsReasoningEngines on a missing engine fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 aiplatform.getProjectsLocationsReasoningEngines({
37 name: `projects/${project}/locations/us-central1/reasoningEngines/1234567890123456789`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41 const page = yield* aiplatform.listProjectsLocationsReasoningEngines({
42 parent: `projects/${project}/locations/us-central1`,
43 pageSize: 10,
44 });
45 expect(
46 (page.reasoningEngines ?? []).map((item) => item.name),
47 ).not.toContain(
48 `projects/${project}/locations/us-central1/reasoningEngines/1234567890123456789`,
49 );
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 {
54 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
55 timeout: 90_000,
56 },
57);
58
59test.provider(
60 "create, update, and delete a reasoning engine",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const created = yield* stack.deploy(
66 Effect.gen(function* () {
67 return yield* GCP.AIPlatform.ReasoningEngine("Agent", {
68 location: "us-central1",
69 displayName: "alchemy-test-engine",
70 description: "test",
71 labels: { env: "test" },
72 spec: { agentFramework: "custom" },
73 });
74 }),
75 );
76
77 expect(created.name).toContain("/reasoningEngines/");
78 expect(created.reasoningEngineId).toEqual(expect.any(String));
79 expect(created.location).toEqual("us-central1");
80 expect(created.displayName).toEqual("alchemy-test-engine");
81 expect(created.labels).toMatchObject({ env: "test" });
82
83 const fetched = yield* aiplatform.getProjectsLocationsReasoningEngines({
84 name: created.name,
85 });
86 expect(fetched.name).toEqual(created.name);
87 expect(fetched.labels?.env).toEqual("test");
88 expect(fetched.displayName).toEqual("alchemy-test-engine");
89
90 const updated = yield* stack.deploy(
91 Effect.gen(function* () {
92 return yield* GCP.AIPlatform.ReasoningEngine("Agent", {
93 reasoningEngineId: created.reasoningEngineId,
94 location: "us-central1",
95 displayName: "alchemy-prod-engine",
96 description: "prod",
97 labels: { env: "prod", role: "agent" },
98 spec: { agentFramework: "custom" },
99 });
100 }),
101 );
102
103 expect(updated.name).toEqual(created.name);
104 expect(updated.displayName).toEqual("alchemy-prod-engine");
105 expect(updated.labels).toMatchObject({ env: "prod", role: "agent" });
106
107 const refetched = yield* aiplatform.getProjectsLocationsReasoningEngines({
108 name: created.name,
109 });
110 expect(refetched.displayName).toEqual("alchemy-prod-engine");
111 expect(refetched.labels?.env).toEqual("prod");
112 expect(refetched.labels?.role).toEqual("agent");
113
114 yield* stack.destroy();
115
116 const gone = yield* waitUntilGone(created.name);
117 expect(gone).toEqual("gone");
118 }).pipe(logLevel),
119 {
120 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
121 timeout: 120_000,
122 },
123);