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 apphub from "@distilled.cloud/gcp/apphub_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 | // App Hub is not enabled in the test project; live calls fail with |
| 15 | // ServiceDisabled: |
| 16 | // "App Hub API has not been used in project <project> |
| 17 | // before or it is disabled." |
| 18 | const runLifecycle = !process.env.FAST && process.env.GCP_TEST_APPHUB === "1"; |
| 19 | const location = "global"; |
| 20 | |
| 21 | const waitUntilGone = (name: string) => |
| 22 | apphub.getProjectsLocationsServiceProjectAttachments({ name }).pipe( |
| 23 | Effect.as("found" as const), |
| 24 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 25 | Effect.repeat({ |
| 26 | schedule: Schedule.spaced("1 second"), |
| 27 | until: (status) => status === "gone", |
| 28 | times: 10, |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | test.provider.skipIf(runLifecycle)( |
| 33 | "getProjectsLocationsServiceProjectAttachments on a missing attachment fails with a typed tag", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const { project } = yield* GcpEnvironment.current; |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const error = yield* Effect.flip( |
| 40 | apphub.getProjectsLocationsServiceProjectAttachments({ |
| 41 | name: `projects/${project}/locations/${location}/serviceProjectAttachments/alchemy-missing-spa`, |
| 42 | }), |
| 43 | ); |
| 44 | expect(["ServiceDisabled", "NotFound"]).toContain(error._tag); |
| 45 | |
| 46 | yield* stack.destroy(); |
| 47 | }).pipe(logLevel), |
| 48 | { tags: ["provider:gcp", "provider:gcp:apphub", "live"], timeout: 90_000 }, |
| 49 | ); |
| 50 | |
| 51 | test.provider.skipIf(!runLifecycle)( |
| 52 | "create and delete an App Hub service project attachment", |
| 53 | (stack) => |
| 54 | Effect.gen(function* () { |
| 55 | const { project } = yield* GcpEnvironment.current; |
| 56 | yield* stack.destroy(); |
| 57 | |
| 58 | const created = yield* stack.deploy( |
| 59 | Effect.gen(function* () { |
| 60 | return yield* GCP.AppHub.ServiceProjectAttachment("Host", { |
| 61 | serviceProject: `projects/${project}`, |
| 62 | }); |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(created.name).toContain("/serviceProjectAttachments/"); |
| 67 | expect(created.serviceProjectAttachmentId).toEqual(project); |
| 68 | expect(created.location).toEqual(location); |
| 69 | expect(created.serviceProject).toBeDefined(); |
| 70 | |
| 71 | const fetched = yield* apphub.getProjectsLocationsServiceProjectAttachments({ |
| 72 | name: created.name, |
| 73 | }); |
| 74 | expect(fetched.name).toEqual(created.name); |
| 75 | |
| 76 | yield* stack.destroy(); |
| 77 | const gone = yield* waitUntilGone(created.name); |
| 78 | expect(gone).toEqual("gone"); |
| 79 | }).pipe(logLevel), |
| 80 | { tags: ["provider:gcp", "provider:gcp:apphub", "live"], timeout: 90_000 }, |
| 81 | ); |