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

main
ts 96 lines 3.19 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 dialogflow from "@distilled.cloud/gcp/dialogflow_v3";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { deleteAgent, ensureAgent, 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 const runLifecycle = !process.env.FAST;
16 const agentDisplayName = "alch-df-pv";
17
18 const waitUntilGone = (name: string) =>
19 dialogflow.getProjectsLocationsAgentsPlaybooksVersions({ 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 "getProjectsLocationsAgentsPlaybooksVersions on a missing version fails with a typed tag",
31 (stack) =>
32 Effect.gen(function* () {
33 const { project } = yield* GcpEnvironment.current;
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 dialogflow.getProjectsLocationsAgentsPlaybooksVersions({
38 name: `projects/${project}/locations/global/agents/missing/playbooks/missing/versions/999999`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 yield* stack.destroy();
44 }).pipe(logLevel, quotaTolerant),
45 {
46 tags: ["provider:gcp", "provider:gcp:dialogflow", "live"],
47 timeout: 90_000,
48 },
49 );
50
51 test.provider.skipIf(!runLifecycle)(
52 "create and delete a playbook version",
53 (stack) =>
54 Effect.gen(function* () {
55 const { project } = yield* GcpEnvironment.current;
56 yield* stack.destroy();
57
58 const agent = yield* ensureAgent(project, agentDisplayName);
59 const agentName = agent.name ?? "";
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 const playbook = yield* GCP.Dialogflow.AgentsPlaybook("Support", {
64 agent: agentName,
65 displayName: "support-pv",
66 goal: "Greet the user.",
67 });
68 const version = yield* GCP.Dialogflow.AgentsPlaybooksVersion("v1", {
69 playbook: playbook.name,
70 description: "initial",
71 });
72 return { playbook, version };
73 }),
74 );
75
76 expect(created.version.name).toContain("/versions/");
77 expect(created.version.playbook).toEqual(created.playbook.name);
78 expect(created.version.description).toEqual("initial");
79
80 const fetched = yield* dialogflow.getProjectsLocationsAgentsPlaybooksVersions({
81 name: created.version.name,
82 });
83 expect(fetched.name).toEqual(created.version.name);
84
85 yield* stack.destroy();
86
87 const gone = yield* waitUntilGone(created.version.name);
88 expect(gone).toEqual("gone");
89
90 yield* deleteAgent(agentName);
91 }).pipe(logLevel, quotaTolerant),
92 {
93 tags: ["provider:gcp", "provider:gcp:dialogflow", "live"],
94 timeout: 120_000,
95 },
96 );