@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 109 lines 3.86 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.getProjectsLocationsIssueModelsIssues({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsIssueModelsIssues on a missing issue 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.getProjectsLocationsIssueModelsIssues({
34 name: `projects/${project}/locations/us-central1/issueModels/missing/issues/missing`,
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 a project with at least 100 analyzed conversations; otherwise create fails with
48 // BadRequest "Project: `...` has too few conversations with the given filters.
49 // Current number: 0. Minimum requirement is: 100."
50 test.provider.skipIf(!!process.env.FAST || !process.env.GCP_TEST_CCI_ISSUE_MODELS)(
51 "create, update, and delete an issue model issue",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 const model = yield* GCP.ContactCenterInsights.IssueModel("Topics", {
59 location: "us-central1",
60 displayName: "issue-parent",
61 languageCode: "en-US",
62 modelType: "TYPE_V2",
63 });
64 return yield* GCP.ContactCenterInsights.IssueModelsIssue("Billing", {
65 parent: model.name,
66 displayName: "billing",
67 displayDescription: "questions about invoices",
68 });
69 }),
70 );
71
72 expect(created.name).toContain("/issues/");
73 expect(created.displayName).toEqual("billing");
74 expect(created.displayDescription).toEqual("questions about invoices");
75
76 const fetched = yield* cci.getProjectsLocationsIssueModelsIssues({
77 name: created.name,
78 });
79 expect(fetched.name).toEqual(created.name);
80 expect(fetched.displayDescription).toContain("alchemy-id=");
81
82 const updated = yield* stack.deploy(
83 Effect.gen(function* () {
84 const model = yield* GCP.ContactCenterInsights.IssueModel("Topics", {
85 location: "us-central1",
86 displayName: "issue-parent",
87 languageCode: "en-US",
88 modelType: "TYPE_V2",
89 });
90 return yield* GCP.ContactCenterInsights.IssueModelsIssue("Billing", {
91 parent: model.name,
92 displayName: "billing-v2",
93 displayDescription: "updated invoices",
94 });
95 }),
96 );
97 expect(updated.name).toEqual(created.name);
98 expect(updated.displayName).toEqual("billing-v2");
99 expect(updated.displayDescription).toEqual("updated invoices");
100
101 yield* stack.destroy();
102 const gone = yield* waitUntilGone(created.name);
103 expect(gone).toEqual("gone");
104 }).pipe(logLevel),
105 {
106 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
107 timeout: 120_000,
108 },
109 );