@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 152 lines 5.78 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 integrations from "@distilled.cloud/gcp/integrations_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 location = "us-central1";
15
16 // Updating a Salesforce instance that points at a placeholder org fails with
17 // InternalServerError ("Unknown Error."); set
18 // GCP_TEST_INTEGRATIONS_SFDC=1 when the test org ids resolve to a real
19 // Salesforce org.
20 const runSfdcLifecycle = !!process.env.GCP_TEST_INTEGRATIONS_SFDC;
21
22 // Salesforce instances must reference at least one auth config ("Auth config
23 // is not present in the request" otherwise).
24 const sfdcCredential = {
25 credentialType: "USERNAME_AND_PASSWORD" as const,
26 usernameAndPassword: { username: "alchemy", password: "test-secret" },
27 };
28
29 const waitUntilGone = (name: string) =>
30 integrations.getProjectsLocationsSfdcInstancesSfdcChannels({ name }).pipe(
31 Effect.map((row) =>
32 (row.deleteTime ?? "").length > 0 ? ("gone" as const) : ("found" as const),
33 ),
34 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
35 Effect.repeat({
36 schedule: Schedule.spaced("1 second"),
37 until: (status) => status === "gone",
38 times: 10,
39 }),
40 );
41
42 test.provider(
43 "getProjectsLocationsSfdcInstancesSfdcChannels on a missing channel fails with a typed tag",
44 (stack) =>
45 Effect.gen(function* () {
46 const { project } = yield* GcpEnvironment.current;
47 yield* stack.destroy();
48
49 const error = yield* Effect.flip(
50 integrations.getProjectsLocationsSfdcInstancesSfdcChannels({
51 name: `projects/${project}/locations/${location}/sfdcInstances/missing/sfdcChannels/alchemy-missing-channel`,
52 }),
53 );
54 expect(error._tag).toEqual("NotFound");
55
56 yield* stack.destroy();
57 }).pipe(logLevel),
58 {
59 tags: ["provider:gcp", "provider:gcp:integrations", "live"],
60 timeout: 90_000,
61 },
62 );
63
64 test.provider.skipIf(!runSfdcLifecycle)(
65 "create, update, and delete an SFDC channel",
66 (stack) =>
67 Effect.gen(function* () {
68 yield* stack.destroy();
69
70 const created = yield* stack.deploy(
71 Effect.gen(function* () {
72 const auth = yield* GCP.Integrations.AuthConfig("SalesforceAuth", {
73 location,
74 decryptedCredential: sfdcCredential,
75 });
76 const instance = yield* GCP.Integrations.SfdcInstance("Salesforce", {
77 authConfigId: [auth.authConfigId],
78 location,
79 displayName: "alchemy-sfdc-channel-parent",
80 description: "channel parent",
81 sfdcOrgId: "00Dxx0000000001",
82 });
83 const channel = yield* GCP.Integrations.SfdcInstancesSfdcChannel("Events", {
84 sfdcInstance: instance.name,
85 location,
86 displayName: "alchemy-channel",
87 description: "account events",
88 channelTopic: "/event/AlchemyTest__e",
89 });
90 return { instance, channel };
91 }),
92 );
93
94 expect(created.channel.sfdcChannelId).toEqual(expect.any(String));
95 expect(created.channel.location).toEqual(location);
96 expect(created.channel.sfdcInstance).toEqual(created.instance.name);
97 expect(created.channel.name).toEqual(
98 `${created.instance.name}/sfdcChannels/${created.channel.sfdcChannelId}`,
99 );
100 expect(created.channel.displayName).toEqual("alchemy-channel");
101 expect(created.channel.description).toEqual("account events");
102 expect(created.channel.channelTopic).toEqual("/event/AlchemyTest__e");
103
104 const fetched = yield* integrations.getProjectsLocationsSfdcInstancesSfdcChannels({
105 name: created.channel.name,
106 });
107 // The API echoes names keyed by project number.
108 expect(fetched.name?.split("/").slice(2)).toEqual(created.channel.name.split("/").slice(2));
109 expect(fetched.description).toContain("alchemy-id=");
110 expect(fetched.channelTopic).toEqual("/event/AlchemyTest__e");
111
112 const updated = yield* stack.deploy(
113 Effect.gen(function* () {
114 const auth = yield* GCP.Integrations.AuthConfig("SalesforceAuth", {
115 location,
116 decryptedCredential: sfdcCredential,
117 });
118 const instance = yield* GCP.Integrations.SfdcInstance("Salesforce", {
119 authConfigId: [auth.authConfigId],
120 sfdcInstanceId: created.instance.sfdcInstanceId,
121 location,
122 displayName: "alchemy-sfdc-channel-parent",
123 description: "channel parent",
124 sfdcOrgId: "00Dxx0000000001",
125 });
126 const channel = yield* GCP.Integrations.SfdcInstancesSfdcChannel("Events", {
127 sfdcInstance: instance.name,
128 sfdcChannelId: created.channel.sfdcChannelId,
129 location,
130 displayName: "alchemy-channel-v2",
131 description: "account events v2",
132 channelTopic: "/event/AlchemyTestV2__e",
133 });
134 return { instance, channel };
135 }),
136 );
137
138 expect(updated.channel.name).toEqual(created.channel.name);
139 expect(updated.channel.displayName).toEqual("alchemy-channel-v2");
140 expect(updated.channel.description).toEqual("account events v2");
141 expect(updated.channel.channelTopic).toEqual("/event/AlchemyTestV2__e");
142
143 yield* stack.destroy();
144
145 const gone = yield* waitUntilGone(created.channel.name);
146 expect(gone).toEqual("gone");
147 }).pipe(logLevel),
148 {
149 tags: ["provider:gcp", "provider:gcp:integrations", "live"],
150 timeout: 90_000,
151 },
152 );