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

main
ts 103 lines 3.46 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
17 const waitUntilGone = (name: string) =>
18 dialogflow.getProjectsLocationsAgentsFlows({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("1 second"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsLocationsAgentsFlows on a missing flow 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 dialogflow.getProjectsLocationsAgentsFlows({
37 name: `projects/${project}/locations/global/agents/alchemy-missing/flows/alchemy-missing`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 yield* stack.destroy();
43 }).pipe(logLevel, quotaTolerant),
44 {
45 tags: ["provider:gcp", "provider:gcp:dialogflow", "live"],
46 timeout: 90_000,
47 },
48 );
49
50 test.provider.skipIf(!runLifecycle)(
51 "create, update, and delete a flow",
52 (stack) =>
53 Effect.gen(function* () {
54 const { project } = yield* GcpEnvironment.current;
55 yield* stack.destroy();
56 const agent = yield* ensureAgent(project, "alchemy-df-flow");
57
58 yield* Effect.gen(function* () {
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 return yield* GCP.Dialogflow.AgentsFlow("Ordering", {
62 agent: agent.name ?? "",
63 displayName: "ordering",
64 description: "order intake",
65 });
66 }),
67 );
68
69 expect(created.name).toContain("/flows/");
70 expect(created.displayName).toEqual("ordering");
71 expect(created.description).toEqual("order intake");
72
73 const fetched = yield* dialogflow.getProjectsLocationsAgentsFlows({
74 name: created.name,
75 });
76 expect(fetched.name).toEqual(created.name);
77 expect(fetched.description).toContain("[alchemy ");
78
79 const updated = yield* stack.deploy(
80 Effect.gen(function* () {
81 return yield* GCP.Dialogflow.AgentsFlow("Ordering", {
82 agent: agent.name ?? "",
83 flowId: created.flowId,
84 displayName: "checkout",
85 description: "checkout flow",
86 });
87 }),
88 );
89
90 expect(updated.name).toEqual(created.name);
91 expect(updated.displayName).toEqual("checkout");
92 expect(updated.description).toEqual("checkout flow");
93
94 yield* stack.destroy();
95 const gone = yield* waitUntilGone(created.name);
96 expect(gone).toEqual("gone");
97 }).pipe(Effect.ensuring(deleteAgent(agent.name ?? "")));
98 }).pipe(logLevel, quotaTolerant),
99 {
100 tags: ["provider:gcp", "provider:gcp:dialogflow", "live"],
101 timeout: 120_000,
102 },
103 );