@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 152 lines 5.73 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 discoveryengine from "@distilled.cloud/gcp/discoveryengine_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { quotaTolerant } from "./parent.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 // createAssistants is rejected on a plain search engine with BadRequest "Only
16 // default_assistant is allowed." even for assistantId default_assistant; it
17 // needs a Gemini Enterprise (Agentspace) engine. Set
18 // GCP_TEST_DISCOVERYENGINE_ASSISTANT=1 on a project with one.
19 const runLifecycle = !process.env.FAST && !!process.env.GCP_TEST_DISCOVERYENGINE_ASSISTANT;
20
21 const waitUntilGone = (tenant: string, name: string) =>
22 discoveryengine
23 .getProjectsLocationsCollectionsEnginesAssistantsAgentsA2aV1TasksPushNotificationConfigs({
24 tenant,
25 name,
26 })
27 .pipe(
28 Effect.as("found" as const),
29 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
30 Effect.repeat({
31 schedule: Schedule.spaced("2 seconds"),
32 until: (status) => status === "gone",
33 times: 10,
34 }),
35 );
36
37 test.provider(
38 "getProjectsLocationsCollectionsEnginesAssistantsAgentsA2aV1TasksPushNotificationConfigs on a missing config fails with a typed tag",
39 (stack) =>
40 Effect.gen(function* () {
41 const { project } = yield* GcpEnvironment.current;
42
43 yield* stack.destroy();
44
45 const error = yield* Effect.flip(
46 discoveryengine.getProjectsLocationsCollectionsEnginesAssistantsAgentsA2aV1TasksPushNotificationConfigs(
47 {
48 tenant: `projects/${project}/locations/global/collections/default_collection/engines/alchemy-missing/assistants/alchemy-missing`,
49 name: "tasks/alchemy-missing/pushNotificationConfigs/alchemy-missing",
50 },
51 ),
52 );
53 expect(error._tag).toEqual("NotFound");
54
55 yield* stack.destroy();
56 }).pipe(logLevel, quotaTolerant),
57 {
58 tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"],
59 timeout: 90_000,
60 },
61 );
62
63 test.provider.skipIf(!runLifecycle)(
64 "create, update, and delete an A2A push notification config",
65 (stack) =>
66 Effect.gen(function* () {
67 yield* stack.destroy();
68
69 const created = yield* stack.deploy(
70 Effect.gen(function* () {
71 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
72 location: "global",
73 displayName: "a2a-docs",
74 });
75 const engine = yield* GCP.DiscoveryEngine.CollectionsEngine("Search", {
76 location: "global",
77 dataStoreIds: [store.dataStoreId],
78 displayName: "a2a engine",
79 });
80 const assistant = yield* GCP.DiscoveryEngine.CollectionsEnginesAssistant("Help", {
81 engine: engine.name,
82 // Engines accept only their default assistant.
83 assistantId: "default_assistant",
84 displayName: "a2a helper",
85 });
86 const config =
87 yield* GCP.DiscoveryEngine.CollectionsEnginesAssistantsAgentsA2aV1TasksPushNotificationConfig(
88 "Notify",
89 {
90 tenant: assistant.name,
91 parent: "tasks/alchemy-test-task",
92 url: "https://example.com/hooks/a2a",
93 },
94 );
95 return { store, engine, assistant, config };
96 }),
97 );
98
99 expect(created.config.name).toContain("pushNotificationConfigs");
100 expect(created.config.tenant).toEqual(created.assistant.name);
101 expect(created.config.url).toEqual("https://example.com/hooks/a2a");
102
103 const fetched =
104 yield* discoveryengine.getProjectsLocationsCollectionsEnginesAssistantsAgentsA2aV1TasksPushNotificationConfigs(
105 { tenant: created.config.tenant, name: created.config.name },
106 );
107 expect(fetched.name).toEqual(created.config.name);
108
109 const updated = yield* stack.deploy(
110 Effect.gen(function* () {
111 const store = yield* GCP.DiscoveryEngine.CollectionsDataStore("Docs", {
112 dataStoreId: created.store.dataStoreId,
113 location: "global",
114 displayName: "a2a-docs",
115 });
116 const engine = yield* GCP.DiscoveryEngine.CollectionsEngine("Search", {
117 engineId: created.engine.engineId,
118 location: "global",
119 dataStoreIds: [store.dataStoreId],
120 displayName: "a2a engine",
121 });
122 const assistant = yield* GCP.DiscoveryEngine.CollectionsEnginesAssistant("Help", {
123 engine: engine.name,
124 assistantId: created.assistant.assistantId,
125 displayName: "a2a helper",
126 });
127 const config =
128 yield* GCP.DiscoveryEngine.CollectionsEnginesAssistantsAgentsA2aV1TasksPushNotificationConfig(
129 "Notify",
130 {
131 tenant: assistant.name,
132 parent: "tasks/alchemy-test-task",
133 configId: created.config.configId,
134 url: "https://example.com/hooks/a2a-prod",
135 },
136 );
137 return { store, engine, assistant, config };
138 }),
139 );
140
141 expect(updated.config.url).toEqual("https://example.com/hooks/a2a-prod");
142
143 yield* stack.destroy();
144
145 const gone = yield* waitUntilGone(created.config.tenant, created.config.name);
146 expect(gone).toEqual("gone");
147 }).pipe(logLevel, quotaTolerant),
148 {
149 tags: ["provider:gcp", "provider:gcp:discoveryengine", "live"],
150 timeout: 120_000,
151 },
152 );