@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 98 lines 3.11 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/unstable/aiplatform_v1beta1";
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 // AgentService serves only v1beta1. The lifecycle test creates a real agent;
15 // set GCP_TEST_AIPLATFORM_AGENTS=1 to run it.
16 const runLifecycle = !process.env.FAST && !!process.env.GCP_TEST_AIPLATFORM_AGENTS;
17
18 const waitUntilGone = (name: string) =>
19 aiplatform.getProjectsLocationsAgents({ name }).pipe(
20 Effect.as("found" as const),
21 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
22 Effect.repeat({
23 schedule: Schedule.spaced("2 seconds"),
24 until: (status) => status === "gone",
25 times: 10,
26 }),
27 );
28
29 test.provider(
30 "getProjectsLocationsAgents on a missing agent fails with NotFound",
31 (stack) =>
32 Effect.gen(function* () {
33 const { project } = yield* GcpEnvironment.current;
34 const parent = `projects/${project}/locations/global`;
35 yield* stack.destroy();
36
37 const error = yield* Effect.flip(
38 aiplatform.getProjectsLocationsAgents({
39 name: `${parent}/agents/1234567890123456789`,
40 }),
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: 90_000,
49 },
50 );
51
52 test.provider.skipIf(!runLifecycle)(
53 "create, update, and delete a vertex agent",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 return yield* GCP.AIPlatform.Agent("Support", {
61 systemInstruction: "Answer briefly.",
62 metadata: { env: "test" },
63 });
64 }),
65 );
66
67 expect(created.name).toContain("/agents/");
68 expect(created.location).toEqual("global");
69 expect(created.metadata).toMatchObject({ env: "test" });
70
71 const fetched = yield* aiplatform.getProjectsLocationsAgents({
72 name: created.name,
73 });
74 expect(fetched.name).toEqual(created.name);
75
76 const updated = yield* stack.deploy(
77 Effect.gen(function* () {
78 return yield* GCP.AIPlatform.Agent("Support", {
79 agentId: created.agentId,
80 systemInstruction: "Answer in one sentence.",
81 metadata: { env: "prod" },
82 });
83 }),
84 );
85
86 expect(updated.name).toEqual(created.name);
87 expect(updated.systemInstruction).toEqual("Answer in one sentence.");
88
89 yield* stack.destroy();
90
91 const gone = yield* waitUntilGone(created.name);
92 expect(gone).toEqual("gone");
93 }).pipe(logLevel),
94 {
95 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
96 timeout: 120_000,
97 },
98 );