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 apim from "@distilled.cloud/gcp/apim_v1alpha"; |
| 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 | // The API Management API is not enabled in the testing project: every call |
| 15 | // answers 403 SERVICE_DISABLED (typed `ServiceDisabled`). Set GCP_TEST_APIM=1 |
| 16 | // on a project with the API enabled to run the lifecycle. |
| 17 | const apimEnabled = !!process.env.GCP_TEST_APIM; |
| 18 | const runLifecycle = !process.env.FAST && apimEnabled; |
| 19 | const location = "us-central1"; |
| 20 | |
| 21 | const waitUntilGone = (name: string) => |
| 22 | apim.getProjectsLocationsObservationJobs({ name }).pipe( |
| 23 | Effect.as("found" as const), |
| 24 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 25 | Effect.repeat({ |
| 26 | schedule: Schedule.spaced("2 seconds"), |
| 27 | until: (status) => status === "gone", |
| 28 | times: 10, |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | test.provider( |
| 33 | "getProjectsLocationsObservationJobs on a missing job fails with ServiceDisabled while the API is disabled", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const { project } = yield* GcpEnvironment.current; |
| 37 | const parent = `projects/${project}/locations/${location}`; |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | |
| 41 | const error = yield* Effect.flip( |
| 42 | apim.getProjectsLocationsObservationJobs({ |
| 43 | name: `${parent}/observationJobs/alchemy-missing-job`, |
| 44 | }), |
| 45 | ); |
| 46 | expect(["ServiceDisabled", "NotFound"]).toContain(error._tag); |
| 47 | |
| 48 | yield* stack.destroy(); |
| 49 | }).pipe(logLevel), |
| 50 | { tags: ["provider:gcp", "provider:gcp:apim", "live"], timeout: 90_000 }, |
| 51 | ); |
| 52 | |
| 53 | test.provider.skipIf(!runLifecycle)( |
| 54 | "create, enable, and delete an API Observation job", |
| 55 | (stack) => |
| 56 | Effect.gen(function* () { |
| 57 | const { project } = yield* GcpEnvironment.current; |
| 58 | const parent = `projects/${project}/locations/${location}`; |
| 59 | |
| 60 | yield* stack.destroy(); |
| 61 | |
| 62 | const created = yield* stack.deploy( |
| 63 | Effect.gen(function* () { |
| 64 | return yield* GCP.Apim.ObservationJob("Shadow", { |
| 65 | location, |
| 66 | enabled: false, |
| 67 | }); |
| 68 | }), |
| 69 | ); |
| 70 | |
| 71 | expect(created.name).toContain("/observationJobs/"); |
| 72 | expect(created.observationJobId).toEqual(expect.any(String)); |
| 73 | expect(created.location).toEqual(location); |
| 74 | expect(created.enabled).toEqual(false); |
| 75 | |
| 76 | const fetched = yield* apim.getProjectsLocationsObservationJobs({ |
| 77 | name: created.name, |
| 78 | }); |
| 79 | expect(fetched.name).toEqual(created.name); |
| 80 | |
| 81 | const updated = yield* stack.deploy( |
| 82 | Effect.gen(function* () { |
| 83 | return yield* GCP.Apim.ObservationJob("Shadow", { |
| 84 | observationJobId: created.observationJobId, |
| 85 | location, |
| 86 | enabled: true, |
| 87 | }); |
| 88 | }), |
| 89 | ); |
| 90 | |
| 91 | expect(updated.name).toEqual(created.name); |
| 92 | expect(updated.enabled).toEqual(true); |
| 93 | |
| 94 | const refetched = yield* apim.getProjectsLocationsObservationJobs({ |
| 95 | name: created.name, |
| 96 | }); |
| 97 | expect((refetched.state ?? "").toUpperCase()).toEqual("ENABLED"); |
| 98 | |
| 99 | yield* stack.destroy(); |
| 100 | const gone = yield* waitUntilGone(created.name); |
| 101 | expect(gone).toEqual("gone"); |
| 102 | }).pipe(logLevel), |
| 103 | { tags: ["provider:gcp", "provider:gcp:apim", "live"], timeout: 120_000 }, |
| 104 | ); |