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.getReasoningEnginesSandboxEnvironments({ 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 "getReasoningEnginesSandboxEnvironments on a missing sandbox 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.getReasoningEnginesSandboxEnvironments({
37 name: `projects/${project}/locations/us-central1/reasoningEngines/1234567890123456789/sandboxEnvironments/1234567890123456789`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 yield* stack.destroy();
43 }).pipe(logLevel),
44 {
45 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
46 timeout: 90_000,
47 },
48);
49
50test.provider.skipIf(!!process.env.FAST)(
51 "create and delete a sandbox environment",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 const engine = yield* GCP.AIPlatform.ReasoningEngine("Agent", {
59 location: "us-central1",
60 displayName: "alchemy-sandbox-engine",
61 labels: { env: "test" },
62 spec: { agentFramework: "custom" },
63 });
64 const sandbox =
65 yield* GCP.AIPlatform.ReasoningEnginesSandboxEnvironment("Code", {
66 reasoningEngine: engine.name,
67 displayName: "code",
68 ttl: "600s",
69 spec: {
70 codeExecutionEnvironment: {
71 codeLanguage: "LANGUAGE_PYTHON",
72 machineConfig: "MACHINE_CONFIG_VCPU4_RAM4GIB",
73 },
74 },
75 });
76 return { engine, sandbox };
77 }),
78 );
79
80 expect(created.sandbox.name).toContain("/sandboxEnvironments/");
81 expect(created.sandbox.displayName).toEqual("code");
82 expect(created.sandbox.reasoningEngine).toEqual(created.engine.name);
83
84 const fetched = yield* aiplatform.getReasoningEnginesSandboxEnvironments({
85 name: created.sandbox.name,
86 });
87 expect(fetched.name).toEqual(created.sandbox.name);
88 expect(fetched.displayName ?? "").toMatch(/\[alc(hemy)? /);
89
90 yield* stack.destroy();
91
92 const gone = yield* waitUntilGone(created.sandbox.name);
93 expect(gone).toEqual("gone");
94 }).pipe(logLevel),
95 {
96 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
97 timeout: 180_000,
98 },
99);