@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 120 lines 4.13 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 // Project setup (one-time): Application Integration must be provisioned in
13 // us-central1, else calls fail with `Found zero or more than one active
14 // project` / `Failed to client for project`:
15 // POST https://integrations.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/clients:provision
16 // {"createSampleWorkflows": false}
17
18 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
19
20 const waitUntilGone = (name: string) =>
21 integrations.getProjectsLocationsAuthConfigs({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("1 second"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 const credential = {
32 credentialType: "USERNAME_AND_PASSWORD" as const,
33 usernameAndPassword: { username: "alchemy", password: "test-secret" },
34 };
35
36 test.provider(
37 "getProjectsLocationsAuthConfigs on a missing config fails with a typed tag",
38 (stack) =>
39 Effect.gen(function* () {
40 const { project } = yield* GcpEnvironment.current;
41 yield* stack.destroy();
42
43 const error = yield* Effect.flip(
44 integrations.getProjectsLocationsAuthConfigs({
45 name: `projects/${project}/locations/us-central1/authConfigs/alchemy-missing-auth`,
46 }),
47 );
48 expect(error._tag).toEqual("NotFound");
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 {
53 tags: ["provider:gcp", "provider:gcp:integrations", "live"],
54 timeout: 90_000,
55 },
56 );
57
58 test.provider(
59 "create, update, and delete an auth config",
60 (stack) =>
61 Effect.gen(function* () {
62 yield* stack.destroy();
63
64 const created = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.Integrations.AuthConfig("Salesforce", {
67 location: "us-central1",
68 displayName: "alchemy-salesforce",
69 description: "basic auth",
70 credentialType: "USERNAME_AND_PASSWORD",
71 decryptedCredential: credential,
72 visibility: "PRIVATE",
73 });
74 }),
75 );
76
77 expect(created.name).toContain("/authConfigs/");
78 expect(created.location).toEqual("us-central1");
79 expect(created.displayName).toEqual("alchemy-salesforce");
80 expect(created.description).toEqual("basic auth");
81 expect(created.credentialType).toEqual("USERNAME_AND_PASSWORD");
82
83 const fetched = yield* integrations.getProjectsLocationsAuthConfigs({
84 name: created.name,
85 });
86 expect(fetched.name).toEqual(created.name);
87 expect(fetched.description).toContain("alchemy-id=");
88 expect(fetched.description).toContain("basic auth");
89
90 const updated = yield* stack.deploy(
91 Effect.gen(function* () {
92 return yield* GCP.Integrations.AuthConfig("Salesforce", {
93 authConfigId: created.authConfigId,
94 location: "us-central1",
95 displayName: "alchemy-salesforce",
96 description: "updated auth",
97 credentialType: "USERNAME_AND_PASSWORD",
98 decryptedCredential: credential,
99 visibility: "PRIVATE",
100 });
101 }),
102 );
103
104 expect(updated.name).toEqual(created.name);
105 expect(updated.description).toEqual("updated auth");
106
107 const fetchedUpdate = yield* integrations.getProjectsLocationsAuthConfigs({
108 name: updated.name,
109 });
110 expect(fetchedUpdate.description).toContain("updated auth");
111
112 yield* stack.destroy();
113 const gone = yield* waitUntilGone(created.name);
114 expect(gone).toEqual("gone");
115 }).pipe(logLevel),
116 {
117 tags: ["provider:gcp", "provider:gcp:integrations", "live"],
118 timeout: 90_000,
119 },
120 );