@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 106 lines 3.48 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 const waitUntilGone = (name: string) =>
15 aiplatform.getProjectsLocationsReasoningEnginesSessions({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsReasoningEnginesSessions on a missing session fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 aiplatform.getProjectsLocationsReasoningEnginesSessions({
34 name: `projects/${project}/locations/us-central1/reasoningEngines/1234567890123456789/sessions/1234567890123456789`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "create, update, and delete a reasoning engine session",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const engine = Effect.gen(function* () {
54 return yield* GCP.AIPlatform.ReasoningEngine("Agent", {
55 location: "us-central1",
56 displayName: "alchemy-session-engine",
57 spec: { agentFramework: "custom" },
58 });
59 });
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 const { name: parent } = yield* engine;
64 return yield* GCP.AIPlatform.ReasoningEnginesSession("Chat", {
65 parent,
66 userId: "alchemy-user",
67 displayName: "support-chat",
68 labels: { env: "test" },
69 });
70 }),
71 );
72
73 expect(created.name).toContain("/sessions/");
74 expect(created.userId).toEqual("alchemy-user");
75 expect(created.labels).toMatchObject({ env: "test" });
76
77 const fetched = yield* aiplatform.getProjectsLocationsReasoningEnginesSessions({
78 name: created.name,
79 });
80 expect(fetched.name).toEqual(created.name);
81
82 const updated = yield* stack.deploy(
83 Effect.gen(function* () {
84 const { name: parent } = yield* engine;
85 return yield* GCP.AIPlatform.ReasoningEnginesSession("Chat", {
86 parent,
87 sessionId: created.sessionId,
88 userId: "alchemy-user",
89 displayName: "support-chat-v2",
90 labels: { env: "prod" },
91 });
92 }),
93 );
94 expect(updated.name).toEqual(created.name);
95 expect(updated.displayName).toEqual("support-chat-v2");
96 expect(updated.labels).toMatchObject({ env: "prod" });
97
98 yield* stack.destroy();
99 const gone = yield* waitUntilGone(created.name);
100 expect(gone).toEqual("gone");
101 }).pipe(logLevel),
102 {
103 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
104 timeout: 300_000,
105 },
106 );