The best way to control Claude Code, Codex and more from any computer or phone

main
ts 100 lines 3.47 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 // Sandbox template provisioning takes 1-2 minutes.
15 const runLifecycle = !process.env.FAST;
16
17 const waitUntilGone = (name: string) =>
18 aiplatform.getProjectsLocationsReasoningEnginesSandboxEnvironmentTemplates({ 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
28 test.provider(
29 "getProjectsLocationsReasoningEnginesSandboxEnvironmentTemplates on a missing template 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
37 .getProjectsLocationsReasoningEnginesSandboxEnvironmentTemplates({
38 name: `projects/${project}/locations/us-central1/reasoningEngines/1234567890123456789/sandboxEnvironmentTemplates/1234567890123456789`,
39 })
40 .pipe(Effect.timeout("15 seconds")),
41 );
42 expect(error._tag).toEqual("NotFound");
43
44 yield* stack.destroy();
45 }).pipe(logLevel),
46 {
47 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
48 timeout: 30_000,
49 },
50 );
51
52 test.provider.skipIf(!runLifecycle)(
53 "create and delete a sandbox environment template",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 const engine = yield* GCP.AIPlatform.ReasoningEngine("Agent", {
61 location: "us-central1",
62 displayName: "alchemy-template-engine",
63 labels: { env: "test" },
64 spec: { agentFramework: "custom" },
65 });
66 const template = yield* GCP.AIPlatform.ReasoningEnginesSandboxEnvironmentTemplate(
67 "Browser",
68 {
69 reasoningEngine: engine.name,
70 displayName: "browser",
71 defaultContainerEnvironment: {
72 defaultContainerCategory: "DEFAULT_CONTAINER_CATEGORY_COMPUTER_USE",
73 },
74 },
75 );
76 return { engine, template };
77 }),
78 );
79
80 expect(created.template.name).toContain("/sandboxEnvironmentTemplates/");
81 expect(created.template.displayName).toEqual("browser");
82 expect(created.template.reasoningEngine).toEqual(created.engine.name);
83
84 const fetched =
85 yield* aiplatform.getProjectsLocationsReasoningEnginesSandboxEnvironmentTemplates({
86 name: created.template.name,
87 });
88 expect(fetched.name).toEqual(created.template.name);
89 expect(fetched.displayName).toContain("[alchemy ");
90
91 yield* stack.destroy();
92
93 const gone = yield* waitUntilGone(created.template.name);
94 expect(gone).toEqual("gone");
95 }).pipe(logLevel),
96 {
97 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
98 timeout: 600_000,
99 },
100 );