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

main
ts 155 lines 5.87 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 Output from "alchemy/Output";
7 import * as Effect from "effect/Effect";
8 import { MinimumLogLevel } from "effect/References";
9 import * as Schedule from "effect/Schedule";
10 import { ChatTranscript } from "./transcript.ts";
11
12 const { test } = Test.make({ providers: GCP.providers() });
13
14 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
15
16 const waitUntilGone = (name: string) =>
17 cci
18 .getProjectsLocationsAuthorizedViewSetsAuthorizedViewsConversationsFeedbackLabels({ name })
19 .pipe(
20 Effect.as("found" as const),
21 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
22 Effect.repeat({
23 schedule: Schedule.spaced("1 second"),
24 until: (status) => status === "gone",
25 times: 10,
26 }),
27 );
28
29 test.provider(
30 "get feedback label on a missing resource fails with a typed tag",
31 (stack) =>
32 Effect.gen(function* () {
33 const { project } = yield* GcpEnvironment.current;
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 cci.getProjectsLocationsAuthorizedViewSetsAuthorizedViewsConversationsFeedbackLabels({
38 name: `projects/${project}/locations/us-central1/authorizedViewSets/missing-set/authorizedViews/missing-view/conversations/missing-conv/feedbackLabels/missing-label`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 yield* stack.destroy();
44 }).pipe(logLevel),
45 {
46 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
47 timeout: 90_000,
48 },
49 );
50
51 // Creating through an authorized view fails with BadRequest "subject length
52 // must be at most 127" on the testing project (cause not yet isolated).
53 // Set GCP_TEST_CCI_AUTHORIZED_VIEW_WRITES=1 to run it.
54 test.provider.skipIf(!!process.env.FAST || !process.env.GCP_TEST_CCI_AUTHORIZED_VIEW_WRITES)(
55 "create, update, and delete a feedback label through an authorized view",
56 (stack) =>
57 Effect.gen(function* () {
58 yield* stack.destroy();
59
60 const created = yield* stack.deploy(
61 Effect.gen(function* () {
62 const set = yield* GCP.ContactCenterInsights.AuthorizedViewSet("QaViews", {
63 displayName: "qa",
64 });
65 const view = yield* GCP.ContactCenterInsights.AuthorizedViewSetsAuthorizedView(
66 "Reviewers",
67 { parent: set.name, displayName: "reviewers" },
68 );
69 const conversation = yield* GCP.ContactCenterInsights.Conversation("Chat", {
70 dataSource: yield* ChatTranscript,
71 medium: "CHAT",
72 languageCode: "en-US",
73 agentId: "agent-1",
74 labels: { env: "test" },
75 });
76 const feedback =
77 yield* GCP.ContactCenterInsights.AuthorizedViewSetsAuthorizedViewsConversationsFeedbackLabel(
78 "Topic",
79 {
80 parent: Output.interpolate`${view.name}/conversations/${conversation.conversationId}`,
81 label: "billing",
82 },
83 );
84 return { set, view, conversation, feedback };
85 }),
86 );
87
88 expect(created.feedback.feedbackLabelId).toEqual(expect.any(String));
89 expect(created.feedback.name).toContain("/feedbackLabels/");
90 expect(created.feedback.label).toEqual("billing");
91
92 const fetched =
93 yield* cci.getProjectsLocationsAuthorizedViewSetsAuthorizedViewsConversationsFeedbackLabels(
94 { name: created.feedback.name },
95 );
96 expect(fetched.name).toEqual(created.feedback.name);
97 expect(fetched.label).toContain("alchemy-id=");
98 expect(fetched.label).toContain("billing");
99
100 const updated = yield* stack.deploy(
101 Effect.gen(function* () {
102 const set = yield* GCP.ContactCenterInsights.AuthorizedViewSet("QaViews", {
103 authorizedViewSetId: created.set.authorizedViewSetId,
104 location: "us-central1",
105 displayName: "qa",
106 });
107 const view = yield* GCP.ContactCenterInsights.AuthorizedViewSetsAuthorizedView(
108 "Reviewers",
109 {
110 parent: set.name,
111 authorizedViewId: created.view.authorizedViewId,
112 displayName: "reviewers",
113 },
114 );
115 const conversation = yield* GCP.ContactCenterInsights.Conversation("Chat", {
116 dataSource: yield* ChatTranscript,
117 conversationId: created.conversation.conversationId,
118 location: "us-central1",
119 medium: "CHAT",
120 languageCode: "en-US",
121 agentId: "agent-1",
122 labels: { env: "test" },
123 });
124 const feedback =
125 yield* GCP.ContactCenterInsights.AuthorizedViewSetsAuthorizedViewsConversationsFeedbackLabel(
126 "Topic",
127 {
128 parent: Output.interpolate`${view.name}/conversations/${conversation.conversationId}`,
129 feedbackLabelId: created.feedback.feedbackLabelId,
130 label: "support",
131 },
132 );
133 return { set, view, conversation, feedback };
134 }),
135 );
136
137 expect(updated.feedback.name).toEqual(created.feedback.name);
138 expect(updated.feedback.label).toEqual("support");
139
140 const fetchedUpdate =
141 yield* cci.getProjectsLocationsAuthorizedViewSetsAuthorizedViewsConversationsFeedbackLabels(
142 { name: updated.feedback.name },
143 );
144 expect(fetchedUpdate.label).toContain("support");
145
146 yield* stack.destroy();
147
148 const gone = yield* waitUntilGone(created.feedback.name);
149 expect(gone).toEqual("gone");
150 }).pipe(logLevel),
151 {
152 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
153 timeout: 90_000,
154 },
155 );