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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as firebaseapphosting from "@distilled.cloud/gcp/firebaseapphosting_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import { |
| 8 | location, |
| 9 | logLevel, |
| 10 | missingBackendOf, |
| 11 | currentProject, |
| 12 | serviceAccountOf, |
| 13 | } from "./common.ts"; |
| 14 | |
| 15 | const { test } = Test.make({ providers: GCP.providers() }); |
| 16 | |
| 17 | const waitUntilGone = (name: string) => |
| 18 | firebaseapphosting.getProjectsLocationsBackends({ name }).pipe( |
| 19 | Effect.as("found" as const), |
| 20 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 21 | Effect.repeat({ |
| 22 | schedule: Schedule.spaced("3 seconds"), |
| 23 | until: (status) => status === "gone", |
| 24 | times: 10, |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | test.provider( |
| 29 | "getProjectsLocationsBackends on a missing backend fails with a typed tag", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | const project = yield* currentProject; |
| 33 | const missingBackend = missingBackendOf(project); |
| 34 | |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const error = yield* Effect.flip( |
| 38 | firebaseapphosting.getProjectsLocationsBackends({ |
| 39 | name: missingBackend(), |
| 40 | }), |
| 41 | ); |
| 42 | expect(error._tag).toEqual("NotFound"); |
| 43 | |
| 44 | const page = yield* firebaseapphosting.listProjectsLocationsBackends({ |
| 45 | parent: `projects/${project}/locations/-`, |
| 46 | pageSize: 10, |
| 47 | }); |
| 48 | expect((page.backends ?? []).map((item) => item.name)).not.toContain(missingBackend()); |
| 49 | |
| 50 | yield* stack.destroy(); |
| 51 | }).pipe(logLevel), |
| 52 | { |
| 53 | tags: ["provider:gcp", "provider:gcp:firebaseapphosting", "live"], |
| 54 | timeout: 90_000, |
| 55 | }, |
| 56 | ); |
| 57 | |
| 58 | test.provider( |
| 59 | "create, update, and delete a backend", |
| 60 | (stack) => |
| 61 | Effect.gen(function* () { |
| 62 | const project = yield* currentProject; |
| 63 | const serviceAccount = serviceAccountOf(project); |
| 64 | |
| 65 | yield* stack.destroy(); |
| 66 | |
| 67 | const created = yield* stack.deploy( |
| 68 | Effect.gen(function* () { |
| 69 | return yield* GCP.FirebaseAppHosting.Backend("Web", { |
| 70 | serviceAccount, |
| 71 | servingLocality: "GLOBAL_ACCESS", |
| 72 | displayName: "alchemy-test-backend", |
| 73 | labels: { env: "test" }, |
| 74 | }); |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | expect(created.name).toContain("/backends/"); |
| 79 | expect(created.backendId).toEqual(expect.any(String)); |
| 80 | expect(created.location).toEqual(location); |
| 81 | expect(created.displayName).toEqual("alchemy-test-backend"); |
| 82 | expect(created.labels).toMatchObject({ env: "test" }); |
| 83 | expect(created.servingLocality).toEqual("GLOBAL_ACCESS"); |
| 84 | |
| 85 | const fetched = yield* firebaseapphosting.getProjectsLocationsBackends({ |
| 86 | name: created.name, |
| 87 | }); |
| 88 | expect(fetched.name).toEqual(created.name); |
| 89 | expect(fetched.displayName).toEqual("alchemy-test-backend"); |
| 90 | expect(fetched.labels?.env).toEqual("test"); |
| 91 | |
| 92 | const updated = yield* stack.deploy( |
| 93 | Effect.gen(function* () { |
| 94 | return yield* GCP.FirebaseAppHosting.Backend("Web", { |
| 95 | backendId: created.backendId, |
| 96 | serviceAccount, |
| 97 | servingLocality: "GLOBAL_ACCESS", |
| 98 | displayName: "alchemy-prod-backend", |
| 99 | labels: { env: "prod", role: "web" }, |
| 100 | }); |
| 101 | }), |
| 102 | ); |
| 103 | |
| 104 | expect(updated.name).toEqual(created.name); |
| 105 | expect(updated.displayName).toEqual("alchemy-prod-backend"); |
| 106 | expect(updated.labels).toMatchObject({ env: "prod", role: "web" }); |
| 107 | |
| 108 | yield* stack.destroy(); |
| 109 | |
| 110 | const gone = yield* waitUntilGone(created.name); |
| 111 | expect(gone).toEqual("gone"); |
| 112 | }).pipe(logLevel), |
| 113 | { |
| 114 | tags: ["provider:gcp", "provider:gcp:firebaseapphosting", "live"], |
| 115 | timeout: 300_000, |
| 116 | }, |
| 117 | ); |