@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 135 lines 4.79 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 ccaip from "@distilled.cloud/gcp/contactcenteraiplatform_v1alpha1";
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 // The Contact Center AI Platform API is not enabled in the testing project.
15 // Set GCP_TEST_CONTACT_CENTER_AI_PLATFORM=1 on a project where it is; the
16 // lifecycle also needs GCP_TEST_SLOW (instances take 30–45 minutes).
17 const entitled = !!process.env.GCP_TEST_CONTACT_CENTER_AI_PLATFORM;
18 const runLifecycle = entitled && !!process.env.GCP_TEST_SLOW && !process.env.FAST;
19
20 const waitUntilGone = (name: string) =>
21 ccaip.getProjectsLocationsContactCenters({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("2 seconds"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider.skipIf(!entitled)(
32 "getProjectsLocationsContactCenters on a missing contact center fails with a typed tag",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 const parent = `projects/${project}/locations/us-central1`;
37 const missingName = `${parent}/contactCenters/alchemy-missing-cc`;
38
39 yield* stack.destroy();
40 const error = yield* Effect.flip(
41 ccaip.getProjectsLocationsContactCenters({ name: missingName }),
42 );
43 expect(error._tag).toEqual("NotFound");
44
45 const page = yield* ccaip.listProjectsLocationsContactCenters({
46 parent,
47 pageSize: 10,
48 });
49 expect((page.contactCenters ?? []).map((item) => item.name)).not.toContain(missingName);
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 {
54 tags: ["provider:gcp", "provider:gcp:contactcenteraiplatform", "live"],
55 timeout: 90_000,
56 },
57 );
58
59 test.provider.skipIf(entitled)(
60 "getProjectsLocationsContactCenters fails with ServiceDisabled while the API is disabled",
61 (stack) =>
62 Effect.gen(function* () {
63 const { project } = yield* GcpEnvironment.current;
64 yield* stack.destroy();
65
66 const error = yield* Effect.flip(
67 ccaip.getProjectsLocationsContactCenters({
68 name: `projects/${project}/locations/us-central1/contactCenters/alchemy-missing-cc`,
69 }),
70 );
71 expect(["ServiceDisabled", "NotFound"]).toContain(error._tag);
72
73 yield* stack.destroy();
74 }).pipe(logLevel),
75 {
76 tags: ["provider:gcp", "provider:gcp:contactcenteraiplatform", "live"],
77 timeout: 90_000,
78 },
79 );
80
81 test.provider.skipIf(!runLifecycle)(
82 "create, update, and delete a contact center",
83 (stack) =>
84 Effect.gen(function* () {
85 yield* stack.destroy();
86
87 const created = yield* stack.deploy(
88 Effect.gen(function* () {
89 return yield* GCP.ContactCenterAIPlatform.ContactCenter("Support", {
90 displayName: "support",
91 instanceSize: "DEV_SMALL",
92 labels: { env: "test" },
93 });
94 }),
95 );
96
97 expect(created.name).toContain("/contactCenters/");
98 expect(created.location).toEqual("us-central1");
99 expect(created.displayName).toEqual("support");
100 expect(created.customerDomainPrefix).toEqual(expect.any(String));
101 expect(created.labels).toMatchObject({ env: "test" });
102
103 const fetched = yield* ccaip.getProjectsLocationsContactCenters({
104 name: created.name,
105 });
106 expect(fetched.name).toEqual(created.name);
107 expect(fetched.labels?.env).toEqual("test");
108 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
109
110 const updated = yield* stack.deploy(
111 Effect.gen(function* () {
112 return yield* GCP.ContactCenterAIPlatform.ContactCenter("Support", {
113 contactCenterId: created.contactCenterId,
114 location: created.location,
115 customerDomainPrefix: created.customerDomainPrefix,
116 displayName: "support-desk",
117 instanceSize: "DEV_SMALL",
118 labels: { env: "prod", role: "ccaip" },
119 });
120 }),
121 );
122
123 expect(updated.name).toEqual(created.name);
124 expect(updated.displayName).toEqual("support-desk");
125 expect(updated.labels).toMatchObject({ env: "prod", role: "ccaip" });
126
127 yield* stack.destroy();
128 const gone = yield* waitUntilGone(created.name);
129 expect(gone).toEqual("gone");
130 }).pipe(logLevel),
131 {
132 tags: ["provider:gcp", "provider:gcp:contactcenteraiplatform", "live"],
133 timeout: 3_600_000,
134 },
135 );