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

main
ts 162 lines 5.16 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 chromemanagement from "@distilled.cloud/gcp/chromemanagement_v1";
6 import * as Effect from "effect/Effect";
7 import {
8 customerName,
9 logLevel,
10 probeName,
11 probeParent,
12 runLifecycle,
13 waitUntilGone,
14 } from "./common.ts";
15
16 const { test } = Test.make({ providers: GCP.providers() });
17
18 const probeBody = (
19 project: string,
20 ): chromemanagement.GoogleChromeManagementVersionsV1ConnectorConfig => ({
21 displayName: "Alchemy Probe",
22 type: "REPORTING",
23 details: {
24 pubSubConfig: {
25 topicFullPath: `projects/${project}/topics/alchemy-probe`,
26 reportingSettings: {
27 enabledDefaultEvents: ["ALL_DEFAULT_EVENTS"],
28 },
29 },
30 },
31 });
32
33 test.provider.skipIf(!runLifecycle)(
34 "getCustomersConnectorConfigs on a missing connector config fails with a typed tag",
35 (stack) =>
36 Effect.gen(function* () {
37 yield* stack.destroy();
38
39 const error = yield* Effect.flip(
40 chromemanagement.getCustomersConnectorConfigs({
41 name: probeName,
42 }),
43 );
44 expect(error._tag).toEqual("NotFound");
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 {
49 tags: ["provider:gcp", "provider:gcp:chromemanagement", "live"],
50 timeout: 90_000,
51 },
52 );
53
54 test.provider.skipIf(runLifecycle)(
55 "createCustomersConnectorConfigs without Chrome Management access fails with InsufficientScopes",
56 (stack) =>
57 Effect.gen(function* () {
58 const { project } = yield* GcpEnvironment.current;
59 yield* stack.destroy();
60
61 const error = yield* Effect.flip(
62 chromemanagement.createCustomersConnectorConfigs({
63 parent: probeParent,
64 connectorConfigId: "alchemy-probe",
65 body: probeBody(project),
66 }),
67 );
68 expect(error._tag).toEqual("InsufficientScopes");
69
70 yield* stack.destroy();
71 }).pipe(logLevel),
72 {
73 tags: ["provider:gcp", "provider:gcp:chromemanagement", "live"],
74 timeout: 90_000,
75 },
76 );
77
78 test.provider.skipIf(!runLifecycle)(
79 "create, update, and delete a connector config",
80 (stack) =>
81 Effect.gen(function* () {
82 yield* stack.destroy();
83
84 const parent = customerName;
85
86 const created = yield* stack.deploy(
87 Effect.gen(function* () {
88 const topic = yield* GCP.PubSub.Topic("ChromeEvents", {});
89 const config = yield* GCP.ChromeManagement.CustomersConnectorConfig("Reporting", {
90 parent,
91 type: "REPORTING",
92 displayName: "Alchemy reporting",
93 details: {
94 pubSubConfig: {
95 topicFullPath: topic.name,
96 reportingSettings: {
97 enabledDefaultEvents: ["ALL_DEFAULT_EVENTS"],
98 },
99 },
100 },
101 });
102 return { config, topicName: topic.name };
103 }),
104 );
105
106 expect(created.config.name).toContain("/connectorConfigs/");
107 expect(created.config.parent).toEqual(parent);
108 expect(created.config.connectorConfigId.length).toBeGreaterThan(0);
109 expect(created.config.displayName).toEqual("Alchemy reporting");
110 expect(created.config.type).toEqual("REPORTING");
111 expect(created.config.details?.pubSubConfig?.topicFullPath).toEqual(created.topicName);
112
113 const fetched = yield* chromemanagement.getCustomersConnectorConfigs({
114 name: created.config.name,
115 });
116 expect(fetched.name).toEqual(created.config.name);
117 expect(fetched.displayName).toContain("[alchemy ");
118 expect(fetched.type).toEqual("REPORTING");
119
120 const updated = yield* stack.deploy(
121 Effect.gen(function* () {
122 const topic = yield* GCP.PubSub.Topic("ChromeEvents", {});
123 const config = yield* GCP.ChromeManagement.CustomersConnectorConfig("Reporting", {
124 parent: created.config.parent,
125 connectorConfigId: created.config.connectorConfigId,
126 type: "REPORTING",
127 displayName: "Alchemy reporting (prod)",
128 details: {
129 pubSubConfig: {
130 topicFullPath: topic.name,
131 reportingSettings: {
132 enabledDefaultEvents: ["BROWSER_CRASH_EVENT"],
133 enabledOptInEvents: ["ALL_OPT_IN_EVENTS"],
134 },
135 },
136 },
137 });
138 return { config, topicName: topic.name };
139 }),
140 );
141
142 expect(updated.config.name).toEqual(created.config.name);
143 expect(updated.config.displayName).toEqual("Alchemy reporting (prod)");
144 expect(
145 updated.config.details?.pubSubConfig?.reportingSettings?.enabledDefaultEvents,
146 ).toContain("BROWSER_CRASH_EVENT");
147
148 const fetchedUpdate = yield* chromemanagement.getCustomersConnectorConfigs({
149 name: updated.config.name,
150 });
151 expect(fetchedUpdate.displayName).toContain("Alchemy reporting (prod)");
152
153 yield* stack.destroy();
154
155 const gone = yield* waitUntilGone(created.config.name);
156 expect(gone).toEqual("gone");
157 }).pipe(logLevel),
158 {
159 tags: ["provider:gcp", "provider:gcp:chromemanagement", "live"],
160 timeout: 90_000,
161 },
162 );