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

main
ts 112 lines 3.98 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.getProjectsLocationsAssessmentRules({ 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 "getProjectsLocationsAssessmentRules 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.getProjectsLocationsAssessmentRules({
34 name: `projects/${project}/locations/us-central1/assessmentRules/alchemymissingrule`,
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 assessment 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.AssessmentRule("Qa", {
58 displayName: "qa",
59 active: false,
60 sampleRule: { samplePercentage: 0.1 },
61 scheduleInfo: { schedule: "every 1 hours", timeZone: "UTC" },
62 });
63 }),
64 );
65
66 expect(created.assessmentRuleId).toEqual(expect.any(String));
67 expect(created.name).toContain("/assessmentRules/");
68 expect(created.location).toEqual("us-central1");
69 expect(created.displayName).toEqual("qa");
70 expect(created.active).toEqual(false);
71 expect(created.sampleRule?.samplePercentage).toEqual(0.1);
72
73 const fetched = yield* cci.getProjectsLocationsAssessmentRules({
74 name: created.name,
75 });
76 expect(fetched.name).toEqual(created.name);
77 expect(fetched.displayName).toContain("alchemy-id=");
78 expect(fetched.active ?? false).toEqual(false);
79
80 const updated = yield* stack.deploy(
81 Effect.gen(function* () {
82 return yield* GCP.ContactCenterInsights.AssessmentRule("Qa", {
83 assessmentRuleId: created.assessmentRuleId,
84 location: "us-central1",
85 displayName: "qa-2",
86 active: false,
87 sampleRule: { samplePercentage: 0.2 },
88 scheduleInfo: { schedule: "every 2 hours", timeZone: "UTC" },
89 });
90 }),
91 );
92
93 expect(updated.name).toEqual(created.name);
94 expect(updated.displayName).toEqual("qa-2");
95 expect(updated.sampleRule?.samplePercentage).toEqual(0.2);
96 expect(updated.scheduleInfo?.schedule).toEqual("every 2 hours");
97
98 const fetchedUpdate = yield* cci.getProjectsLocationsAssessmentRules({
99 name: updated.name,
100 });
101 expect(fetchedUpdate.sampleRule?.samplePercentage).toEqual(0.2);
102
103 yield* stack.destroy();
104
105 const gone = yield* waitUntilGone(created.name);
106 expect(gone).toEqual("gone");
107 }).pipe(logLevel),
108 {
109 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
110 timeout: 90_000,
111 },
112 );