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

main
ts 118 lines 3.96 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 essentialcontacts from "@distilled.cloud/gcp/essentialcontacts_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 essentialcontacts.getProjectsContacts({ 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 "getProjectsContacts on a missing contact 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 essentialcontacts.getProjectsContacts({
34 name: `projects/${project}/contacts/0`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:essentialcontacts", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "create, update, replace, and delete a project essential contact",
49 (stack) =>
50 Effect.gen(function* () {
51 const { project } = yield* GcpEnvironment.current;
52 yield* stack.destroy();
53
54 const created = yield* stack.deploy(
55 Effect.gen(function* () {
56 return yield* GCP.EssentialContacts.Contact("Ops", {
57 email: "ops@example.com",
58 languageTag: "en-US",
59 notificationCategorySubscriptions: ["ALL"],
60 });
61 }),
62 );
63
64 expect(created.contactId.length).toBeGreaterThan(0);
65 expect(created.name).toContain("/contacts/");
66 expect(created.email).toEqual("ops@example.com");
67 expect(created.languageTag).toEqual("en-US");
68 expect(created.notificationCategorySubscriptions).toEqual(["ALL"]);
69 expect(created.project).toEqual(project);
70
71 const fetched = yield* essentialcontacts.getProjectsContacts({
72 name: created.name,
73 });
74 expect(fetched.name).toEqual(created.name);
75 expect(fetched.email).toContain("+alc.");
76 expect(fetched.email).toContain("ops@");
77 expect(fetched.languageTag).toEqual("en-US");
78
79 const updated = yield* stack.deploy(
80 Effect.gen(function* () {
81 return yield* GCP.EssentialContacts.Contact("Ops", {
82 email: "ops@example.com",
83 languageTag: "en-GB",
84 notificationCategorySubscriptions: ["SECURITY", "TECHNICAL"],
85 });
86 }),
87 );
88
89 expect(updated.name).toEqual(created.name);
90 expect(updated.email).toEqual("ops@example.com");
91 expect(updated.languageTag).toEqual("en-GB");
92 expect(updated.notificationCategorySubscriptions).toEqual(["SECURITY", "TECHNICAL"]);
93
94 const replaced = yield* stack.deploy(
95 Effect.gen(function* () {
96 return yield* GCP.EssentialContacts.Contact("Ops", {
97 email: "security@example.com",
98 languageTag: "en-GB",
99 notificationCategorySubscriptions: ["SECURITY"],
100 });
101 }),
102 );
103
104 expect(replaced.email).toEqual("security@example.com");
105 expect(replaced.contactId.length).toBeGreaterThan(0);
106 expect(replaced.languageTag).toEqual("en-GB");
107 expect(replaced.notificationCategorySubscriptions).toEqual(["SECURITY"]);
108
109 yield* stack.destroy();
110
111 const gone = yield* waitUntilGone(replaced.name);
112 expect(gone).toEqual("gone");
113 }).pipe(logLevel),
114 {
115 tags: ["provider:gcp", "provider:gcp:essentialcontacts", "live"],
116 timeout: 90_000,
117 },
118 );