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

main
ts 113 lines 3.9 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 cci from "@distilled.cloud/gcp/contactcenterinsights_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 cci.getProjectsLocationsAnalysisRules({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsAnalysisRules on a missing rule 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 cci.getProjectsLocationsAnalysisRules({
34 name: `projects/${project}/locations/us-central1/analysisRules/alchemy-missing-rule`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "create, update, and delete an analysis rule",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 return yield* GCP.ContactCenterInsights.AnalysisRule("Draft", {
56 displayName: "draft",
57 active: false,
58 analysisPercentage: 0,
59 annotatorSelector: { runSentimentAnnotator: true },
60 });
61 }),
62 );
63
64 expect(created.analysisRuleId).toEqual(expect.any(String));
65 expect(created.name).toContain("/analysisRules/");
66 expect(created.location).toEqual("us-central1");
67 expect(created.displayName).toEqual("draft");
68 expect(created.active).toEqual(false);
69 expect(created.annotatorSelector?.runSentimentAnnotator).toEqual(true);
70
71 const fetched = yield* cci.getProjectsLocationsAnalysisRules({
72 name: created.name,
73 });
74 expect(fetched.name).toEqual(created.name);
75 expect(fetched.displayName).toContain("alchemy-id=");
76 expect(fetched.displayName).toContain("draft");
77 expect(fetched.active ?? false).toEqual(false);
78
79 const updated = yield* stack.deploy(
80 Effect.gen(function* () {
81 return yield* GCP.ContactCenterInsights.AnalysisRule("Draft", {
82 analysisRuleId: created.analysisRuleId,
83 location: "us-central1",
84 displayName: "draft-2",
85 conversationFilter: 'agent_id="alchemy-agent"',
86 active: false,
87 analysisPercentage: 0,
88 annotatorSelector: { runSilenceAnnotator: true },
89 });
90 }),
91 );
92
93 expect(updated.name).toEqual(created.name);
94 expect(updated.displayName).toEqual("draft-2");
95 expect(updated.conversationFilter).toEqual('agent_id="alchemy-agent"');
96 expect(updated.annotatorSelector?.runSilenceAnnotator).toEqual(true);
97
98 const fetchedUpdate = yield* cci.getProjectsLocationsAnalysisRules({
99 name: updated.name,
100 });
101 expect(fetchedUpdate.conversationFilter).toEqual('agent_id="alchemy-agent"');
102 expect(fetchedUpdate.annotatorSelector?.runSilenceAnnotator).toEqual(true);
103
104 yield* stack.destroy();
105
106 const gone = yield* waitUntilGone(created.name);
107 expect(gone).toEqual("gone");
108 }).pipe(logLevel),
109 {
110 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
111 timeout: 90_000,
112 },
113 );