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

main
ts 113 lines 4.07 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.getProjectsLocationsAutoLabelingRules({ 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 "getProjectsLocationsAutoLabelingRules 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.getProjectsLocationsAutoLabelingRules({
34 name: `projects/${project}/locations/us-central1/autoLabelingRules/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 // Needs Contact Center AI Insights features the testing project does not
48 // have enabled: create returns 404 NOT_FOUND "Requested entity was not found." and list returns 400 INVALID_ARGUMENT.
49 test.provider.skipIf(!process.env.GCP_TEST_CCAI_QUALITY || !!process.env.FAST)(
50 "create, update, and delete an auto labeling rule",
51 (stack) =>
52 Effect.gen(function* () {
53 yield* stack.destroy();
54
55 const created = yield* stack.deploy(
56 Effect.gen(function* () {
57 return yield* GCP.ContactCenterInsights.AutoLabelingRule("Topic", {
58 displayName: "billing-topic",
59 description: "billing",
60 active: false,
61 conditions: [{ value: '"billing"', condition: "true" }],
62 });
63 }),
64 );
65
66 expect(created.autoLabelingRuleId).toEqual(expect.any(String));
67 expect(created.name).toContain("/autoLabelingRules/");
68 expect(created.location).toEqual("us-central1");
69 expect(created.displayName).toEqual("billing-topic");
70 expect(created.description).toEqual("billing");
71 expect(created.active).toEqual(false);
72 expect(created.labelKeyType).toEqual("LABEL_KEY_TYPE_CUSTOM");
73
74 const fetched = yield* cci.getProjectsLocationsAutoLabelingRules({
75 name: created.name,
76 });
77 expect(fetched.name).toEqual(created.name);
78 expect(fetched.description).toContain("alchemy-id=");
79 expect(fetched.description).toContain("billing");
80
81 const updated = yield* stack.deploy(
82 Effect.gen(function* () {
83 return yield* GCP.ContactCenterInsights.AutoLabelingRule("Topic", {
84 autoLabelingRuleId: created.autoLabelingRuleId,
85 location: "us-central1",
86 displayName: "billing-topic-v2",
87 description: "billing-v2",
88 active: false,
89 conditions: [{ value: '"support"', condition: "true" }],
90 });
91 }),
92 );
93
94 expect(updated.name).toEqual(created.name);
95 expect(updated.displayName).toEqual("billing-topic-v2");
96 expect(updated.description).toEqual("billing-v2");
97 expect(updated.conditions[0]?.value).toEqual('"support"');
98
99 const fetchedUpdate = yield* cci.getProjectsLocationsAutoLabelingRules({
100 name: updated.name,
101 });
102 expect(fetchedUpdate.displayName).toEqual("billing-topic-v2");
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 );