The best way to control Claude Code, Codex and more from any computer or phone
| 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 developerconnect from "@distilled.cloud/gcp/developerconnect_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 | developerconnect.getProjectsLocationsAccountConnectors({ 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 | "getProjectsLocationsAccountConnectors on a missing connector 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 | developerconnect.getProjectsLocationsAccountConnectors({ |
| 34 | name: `projects/${project}/locations/us-central1/accountConnectors/alchemy-missing-connector`, |
| 35 | }), |
| 36 | ); |
| 37 | expect(error._tag).toEqual("NotFound"); |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | }).pipe(logLevel), |
| 41 | { |
| 42 | tags: ["provider:gcp", "provider:gcp:developerconnect", "live"], |
| 43 | timeout: 90_000, |
| 44 | }, |
| 45 | ); |
| 46 | |
| 47 | test.provider( |
| 48 | "create, update, replace, and delete an account connector", |
| 49 | (stack) => |
| 50 | Effect.gen(function* () { |
| 51 | yield* stack.destroy(); |
| 52 | |
| 53 | const created = yield* stack.deploy( |
| 54 | Effect.gen(function* () { |
| 55 | return yield* GCP.DeveloperConnect.AccountConnector("Github", { |
| 56 | location: "us-central1", |
| 57 | providerOauthConfig: { |
| 58 | systemProviderId: "GITHUB", |
| 59 | scopes: ["repo"], |
| 60 | }, |
| 61 | labels: { env: "test" }, |
| 62 | }); |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(created.accountConnectorId).toEqual(expect.any(String)); |
| 67 | expect(created.name).toContain("/accountConnectors/"); |
| 68 | expect(created.location).toEqual("us-central1"); |
| 69 | expect(created.labels).toMatchObject({ env: "test" }); |
| 70 | expect(created.providerOauthConfig?.systemProviderId).toEqual("GITHUB"); |
| 71 | |
| 72 | const fetched = yield* developerconnect.getProjectsLocationsAccountConnectors({ |
| 73 | name: created.name, |
| 74 | }); |
| 75 | expect(fetched.name).toEqual(created.name); |
| 76 | expect(fetched.labels?.env).toEqual("test"); |
| 77 | expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String)); |
| 78 | expect(fetched.providerOauthConfig?.systemProviderId).toEqual("GITHUB"); |
| 79 | |
| 80 | const updated = yield* stack.deploy( |
| 81 | Effect.gen(function* () { |
| 82 | return yield* GCP.DeveloperConnect.AccountConnector("Github", { |
| 83 | accountConnectorId: created.accountConnectorId, |
| 84 | location: "us-central1", |
| 85 | providerOauthConfig: { |
| 86 | systemProviderId: "GITHUB", |
| 87 | scopes: ["repo"], |
| 88 | }, |
| 89 | labels: { env: "prod", role: "scm" }, |
| 90 | proxyConfig: { enabled: true }, |
| 91 | }); |
| 92 | }), |
| 93 | ); |
| 94 | |
| 95 | expect(updated.name).toEqual(created.name); |
| 96 | expect(updated.labels).toMatchObject({ env: "prod", role: "scm" }); |
| 97 | expect(updated.proxyConfig?.enabled).toEqual(true); |
| 98 | |
| 99 | const fetchedUpdate = yield* developerconnect.getProjectsLocationsAccountConnectors({ |
| 100 | name: updated.name, |
| 101 | }); |
| 102 | expect(fetchedUpdate.labels?.env).toEqual("prod"); |
| 103 | expect(fetchedUpdate.labels?.role).toEqual("scm"); |
| 104 | expect(fetchedUpdate.proxyConfig?.enabled).toEqual(true); |
| 105 | |
| 106 | const replaced = yield* stack.deploy( |
| 107 | Effect.gen(function* () { |
| 108 | return yield* GCP.DeveloperConnect.AccountConnector("Github", { |
| 109 | accountConnectorId: created.accountConnectorId, |
| 110 | location: "us-east1", |
| 111 | providerOauthConfig: { |
| 112 | systemProviderId: "GITHUB", |
| 113 | scopes: ["repo"], |
| 114 | }, |
| 115 | labels: { env: "test" }, |
| 116 | }); |
| 117 | }), |
| 118 | ); |
| 119 | |
| 120 | expect(replaced.accountConnectorId).toEqual(created.accountConnectorId); |
| 121 | expect(replaced.location).toEqual("us-east1"); |
| 122 | expect(replaced.name).toContain("/locations/us-east1/"); |
| 123 | expect(replaced.name).not.toEqual(created.name); |
| 124 | |
| 125 | const oldGone = yield* waitUntilGone(created.name); |
| 126 | expect(oldGone).toEqual("gone"); |
| 127 | |
| 128 | yield* stack.destroy(); |
| 129 | |
| 130 | const gone = yield* waitUntilGone(replaced.name); |
| 131 | expect(gone).toEqual("gone"); |
| 132 | }).pipe(logLevel), |
| 133 | { |
| 134 | tags: ["provider:gcp", "provider:gcp:developerconnect", "live"], |
| 135 | timeout: 90_000, |
| 136 | }, |
| 137 | ); |