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

main
ts 127 lines 4.52 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.getProjectsLocationsAgentsFlowsTransitionRouteGroups({ 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 "getProjectsLocationsAgentsFlowsTransitionRouteGroups on a missing route group 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.getProjectsLocationsAgentsFlowsTransitionRouteGroups({
37 name: `projects/${project}/locations/global/agents/alchemy-missing/flows/alchemy-missing/transitionRouteGroups/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 transition route group",
52 (stack) =>
53 Effect.gen(function* () {
54 const { project } = yield* GcpEnvironment.current;
55 yield* stack.destroy();
56 const agent = yield* ensureAgent(project, "alchemy-df-trg");
57
58 yield* Effect.gen(function* () {
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 const flow = yield* GCP.Dialogflow.AgentsFlow("Main", {
62 agent: agent.name ?? "",
63 displayName: "main",
64 });
65 const group = yield* GCP.Dialogflow.AgentsFlowsTransitionRouteGroup("Fallback", {
66 flow: flow.name,
67 displayName: "fallback",
68 transitionRoutes: [
69 {
70 condition: "true",
71 triggerFulfillment: {
72 messages: [{ text: { text: ["ok"] } }],
73 },
74 },
75 ],
76 });
77 return { flow, group };
78 }),
79 );
80
81 expect(created.group.name).toContain("/transitionRouteGroups/");
82 expect(created.group.displayName).toEqual("fallback");
83 expect(created.group.transitionRoutes.length).toBeGreaterThan(0);
84
85 const fetched = yield* dialogflow.getProjectsLocationsAgentsFlowsTransitionRouteGroups({
86 name: created.group.name,
87 });
88 expect(fetched.name).toEqual(created.group.name);
89 expect(fetched.displayName).toMatch(/^\[(alchemy|alc) /);
90
91 const updated = yield* stack.deploy(
92 Effect.gen(function* () {
93 const flow = yield* GCP.Dialogflow.AgentsFlow("Main", {
94 agent: agent.name ?? "",
95 flowId: created.flow.flowId,
96 displayName: "main",
97 });
98 const group = yield* GCP.Dialogflow.AgentsFlowsTransitionRouteGroup("Fallback", {
99 flow: flow.name,
100 transitionRouteGroupId: created.group.transitionRouteGroupId,
101 displayName: "defaults",
102 transitionRoutes: [
103 {
104 condition: "true",
105 triggerFulfillment: {
106 messages: [{ text: { text: ["all good"] } }],
107 },
108 },
109 ],
110 });
111 return { flow, group };
112 }),
113 );
114
115 expect(updated.group.name).toEqual(created.group.name);
116 expect(updated.group.displayName).toEqual("defaults");
117
118 yield* stack.destroy();
119 const gone = yield* waitUntilGone(created.group.name);
120 expect(gone).toEqual("gone");
121 }).pipe(Effect.ensuring(deleteAgent(agent.name ?? "")));
122 }).pipe(logLevel, quotaTolerant),
123 {
124 tags: ["provider:gcp", "provider:gcp:dialogflow", "live"],
125 timeout: 120_000,
126 },
127 );