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

main
ts 132 lines 3.99 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.getProjectsLocationsPhraseMatchers({ 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 const refundGroups = [
26 {
27 type: "ANY_OF" as const,
28 phraseMatchRules: [
29 {
30 query: "refund",
31 config: { exactMatchConfig: { caseSensitive: false } },
32 },
33 ],
34 },
35 ];
36
37 const cancelGroups = [
38 {
39 type: "ANY_OF" as const,
40 phraseMatchRules: [
41 {
42 query: "cancel",
43 config: { exactMatchConfig: { caseSensitive: false } },
44 },
45 ],
46 },
47 ];
48
49 test.provider(
50 "getProjectsLocationsPhraseMatchers on a missing matcher fails with a typed tag",
51 (stack) =>
52 Effect.gen(function* () {
53 const { project } = yield* GcpEnvironment.current;
54 yield* stack.destroy();
55
56 const error = yield* Effect.flip(
57 cci.getProjectsLocationsPhraseMatchers({
58 name: `projects/${project}/locations/us-central1/phraseMatchers/9876543210`,
59 }),
60 );
61 expect(error._tag).toEqual("NotFound");
62
63 yield* stack.destroy();
64 }).pipe(logLevel),
65 {
66 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
67 timeout: 90_000,
68 },
69 );
70
71 test.provider.skipIf(!!process.env.FAST)(
72 "create, update, and delete a phrase matcher",
73 (stack) =>
74 Effect.gen(function* () {
75 yield* stack.destroy();
76
77 const created = yield* stack.deploy(
78 Effect.gen(function* () {
79 return yield* GCP.ContactCenterInsights.PhraseMatcher("Refunds", {
80 location: "us-central1",
81 displayName: "refunds",
82 type: "ALL_OF",
83 active: false,
84 phraseMatchRuleGroups: refundGroups,
85 });
86 }),
87 );
88
89 expect(created.name).toContain("/phraseMatchers/");
90 expect(created.location).toEqual("us-central1");
91 expect(created.displayName).toEqual("refunds");
92 expect(created.type).toEqual("ALL_OF");
93 expect(created.active).toEqual(false);
94
95 const fetched = yield* cci.getProjectsLocationsPhraseMatchers({
96 name: created.name,
97 });
98 expect(fetched.name).toEqual(created.name);
99 expect(fetched.displayName).toContain("alchemy-id=");
100 expect(fetched.displayName).toContain("refunds");
101
102 const updated = yield* stack.deploy(
103 Effect.gen(function* () {
104 return yield* GCP.ContactCenterInsights.PhraseMatcher("Refunds", {
105 phraseMatcherId: created.phraseMatcherId,
106 location: "us-central1",
107 displayName: "cancellations",
108 type: "ALL_OF",
109 active: false,
110 phraseMatchRuleGroups: cancelGroups,
111 });
112 }),
113 );
114
115 expect(updated.name).toEqual(created.name);
116 expect(updated.displayName).toEqual("cancellations");
117 expect(updated.phraseMatchRuleGroups?.[0]?.phraseMatchRules?.[0]?.query).toEqual("cancel");
118
119 const fetchedUpdate = yield* cci.getProjectsLocationsPhraseMatchers({
120 name: updated.name,
121 });
122 expect(fetchedUpdate.displayName).toContain("cancellations");
123
124 yield* stack.destroy();
125 const gone = yield* waitUntilGone(created.name);
126 expect(gone).toEqual("gone");
127 }).pipe(logLevel),
128 {
129 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
130 timeout: 90_000,
131 },
132 );