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
| 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 eventarc from "@distilled.cloud/gcp/eventarc_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 runLifecycle = !process.env.FAST; |
| 15 | const LOCATION = "us-east4"; |
| 16 | |
| 17 | const waitUntilGone = (name: string) => |
| 18 | eventarc.getProjectsLocationsGoogleApiSources({ name }).pipe( |
| 19 | Effect.as("found" as const), |
| 20 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 21 | Effect.repeat({ |
| 22 | schedule: Schedule.spaced("2 seconds"), |
| 23 | until: (status) => status === "gone", |
| 24 | times: 10, |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | test.provider( |
| 29 | "getProjectsLocationsGoogleApiSources on a missing source fails with a typed tag", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | const { project } = yield* GcpEnvironment.current; |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const error = yield* Effect.flip( |
| 36 | eventarc.getProjectsLocationsGoogleApiSources({ |
| 37 | name: `projects/${project}/locations/${LOCATION}/googleApiSources/alchemy-missing-source`, |
| 38 | }), |
| 39 | ); |
| 40 | expect(error._tag).toEqual("NotFound"); |
| 41 | |
| 42 | yield* stack.destroy(); |
| 43 | }).pipe(logLevel), |
| 44 | { tags: ["provider:gcp", "provider:gcp:eventarc", "live"], timeout: 90_000 }, |
| 45 | ); |
| 46 | |
| 47 | test.provider.skipIf(!runLifecycle)( |
| 48 | "create, update, and delete an Eventarc Google API source", |
| 49 | (stack) => |
| 50 | Effect.gen(function* () { |
| 51 | yield* stack.destroy(); |
| 52 | |
| 53 | const created = yield* stack.deploy( |
| 54 | Effect.gen(function* () { |
| 55 | const bus = yield* GCP.Eventarc.MessageBus("Events", { |
| 56 | location: LOCATION, |
| 57 | labels: { env: "test" }, |
| 58 | }); |
| 59 | const source = yield* GCP.Eventarc.GoogleApiSource("GoogleEvents", { |
| 60 | location: LOCATION, |
| 61 | destination: bus.name, |
| 62 | displayName: "google events", |
| 63 | labels: { env: "test" }, |
| 64 | }); |
| 65 | return { bus, source }; |
| 66 | }), |
| 67 | ); |
| 68 | |
| 69 | expect(created.source.name).toContain("/googleApiSources/"); |
| 70 | expect(created.source.googleApiSourceId).toEqual(expect.any(String)); |
| 71 | expect(created.source.location).toEqual(LOCATION); |
| 72 | expect(created.source.destination).toEqual(created.bus.name); |
| 73 | expect(created.source.labels).toMatchObject({ env: "test" }); |
| 74 | |
| 75 | const fetched = yield* eventarc.getProjectsLocationsGoogleApiSources({ |
| 76 | name: created.source.name, |
| 77 | }); |
| 78 | expect(fetched.name).toEqual(created.source.name); |
| 79 | expect(fetched.labels?.env).toEqual("test"); |
| 80 | expect(fetched.destination).toEqual(created.bus.name); |
| 81 | |
| 82 | const updated = yield* stack.deploy( |
| 83 | Effect.gen(function* () { |
| 84 | const bus = yield* GCP.Eventarc.MessageBus("Events", { |
| 85 | messageBusId: created.bus.messageBusId, |
| 86 | location: LOCATION, |
| 87 | labels: { env: "test" }, |
| 88 | }); |
| 89 | return yield* GCP.Eventarc.GoogleApiSource("GoogleEvents", { |
| 90 | googleApiSourceId: created.source.googleApiSourceId, |
| 91 | location: LOCATION, |
| 92 | destination: bus.name, |
| 93 | displayName: "google events v2", |
| 94 | loggingConfig: { logSeverity: "INFO" }, |
| 95 | labels: { env: "prod", role: "source" }, |
| 96 | }); |
| 97 | }), |
| 98 | ); |
| 99 | |
| 100 | expect(updated.name).toEqual(created.source.name); |
| 101 | expect(updated.googleApiSourceId).toEqual(created.source.googleApiSourceId); |
| 102 | expect(updated.displayName).toEqual("google events v2"); |
| 103 | expect(updated.labels).toMatchObject({ env: "prod", role: "source" }); |
| 104 | |
| 105 | const refetched = yield* eventarc.getProjectsLocationsGoogleApiSources({ |
| 106 | name: created.source.name, |
| 107 | }); |
| 108 | expect(refetched.labels?.env).toEqual("prod"); |
| 109 | expect(refetched.labels?.role).toEqual("source"); |
| 110 | expect(refetched.displayName).toEqual("google events v2"); |
| 111 | |
| 112 | yield* stack.destroy(); |
| 113 | |
| 114 | const gone = yield* waitUntilGone(created.source.name); |
| 115 | expect(gone).toEqual("gone"); |
| 116 | }).pipe(logLevel), |
| 117 | { tags: ["provider:gcp", "provider:gcp:eventarc", "live"], timeout: 180_000 }, |
| 118 | ); |