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 { 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.getProjectsLocationsBackendsDomains({ 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 | "getProjectsLocationsBackendsDomains on a missing domain 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.getProjectsLocationsBackendsDomains({ |
| 39 | name: `${missingBackend()}/domains/alchemy-missing.example.com`, |
| 40 | }), |
| 41 | ); |
| 42 | expect(error._tag).toEqual("NotFound"); |
| 43 | |
| 44 | const page = yield* firebaseapphosting.listProjectsLocationsBackendsDomains({ |
| 45 | parent: `projects/${project}/locations/-/backends/-`, |
| 46 | pageSize: 10, |
| 47 | }); |
| 48 | expect((page.domains ?? []).map((item) => item.name)).not.toContain( |
| 49 | `${missingBackend()}/domains/alchemy-missing.example.com`, |
| 50 | ); |
| 51 | |
| 52 | yield* stack.destroy(); |
| 53 | }).pipe(logLevel), |
| 54 | { |
| 55 | tags: ["provider:gcp", "provider:gcp:firebaseapphosting", "live"], |
| 56 | timeout: 90_000, |
| 57 | }, |
| 58 | ); |
| 59 | |
| 60 | test.provider( |
| 61 | "create against a missing backend is rejected with a typed tag", |
| 62 | (stack) => |
| 63 | Effect.gen(function* () { |
| 64 | const project = yield* currentProject; |
| 65 | const missingBackend = missingBackendOf(project); |
| 66 | |
| 67 | yield* stack.destroy(); |
| 68 | |
| 69 | const error = yield* Effect.flip( |
| 70 | stack.deploy( |
| 71 | Effect.gen(function* () { |
| 72 | return yield* GCP.FirebaseAppHosting.BackendsDomain("Www", { |
| 73 | backend: missingBackend(), |
| 74 | domainId: "alchemy-missing.example.com", |
| 75 | labels: { env: "test" }, |
| 76 | }); |
| 77 | }), |
| 78 | ), |
| 79 | ); |
| 80 | expect(error._tag).toEqual("NotFound"); |
| 81 | |
| 82 | yield* stack.destroy(); |
| 83 | }).pipe(logLevel), |
| 84 | { |
| 85 | tags: ["provider:gcp", "provider:gcp:firebaseapphosting", "live"], |
| 86 | timeout: 90_000, |
| 87 | }, |
| 88 | ); |
| 89 | |
| 90 | // Custom-domain create stays pending (the LRO did not finish within 5 minutes) |
| 91 | // until the domain's DNS points at App Hosting. Set |
| 92 | // GCP_TEST_FIREBASE_APP_HOSTING_DOMAIN to a domain you control to run this. |
| 93 | const customDomain = process.env.GCP_TEST_FIREBASE_APP_HOSTING_DOMAIN; |
| 94 | |
| 95 | test.provider.skipIf(!customDomain)( |
| 96 | "create, update, and delete a backend domain", |
| 97 | (stack) => |
| 98 | Effect.gen(function* () { |
| 99 | const project = yield* currentProject; |
| 100 | const serviceAccount = serviceAccountOf(project); |
| 101 | |
| 102 | yield* stack.destroy(); |
| 103 | |
| 104 | const created = yield* stack.deploy( |
| 105 | Effect.gen(function* () { |
| 106 | const backend = yield* GCP.FirebaseAppHosting.Backend("Web", { |
| 107 | serviceAccount, |
| 108 | servingLocality: "GLOBAL_ACCESS", |
| 109 | displayName: "alchemy-test-domain-backend", |
| 110 | labels: { env: "test" }, |
| 111 | }); |
| 112 | const domain = yield* GCP.FirebaseAppHosting.BackendsDomain("Www", { |
| 113 | domainId: customDomain, |
| 114 | backend: backend.name, |
| 115 | displayName: "alchemy-test-domain", |
| 116 | disabled: true, |
| 117 | labels: { env: "test" }, |
| 118 | }); |
| 119 | return { backend, domain }; |
| 120 | }), |
| 121 | ); |
| 122 | |
| 123 | expect(created.domain.name).toContain("/domains/"); |
| 124 | expect(created.domain.backend).toEqual(created.backend.name); |
| 125 | expect(created.domain.location).toEqual(location); |
| 126 | expect(created.domain.disabled).toEqual(true); |
| 127 | expect(created.domain.displayName).toEqual("alchemy-test-domain"); |
| 128 | expect(created.domain.labels).toMatchObject({ env: "test" }); |
| 129 | |
| 130 | const fetched = yield* firebaseapphosting.getProjectsLocationsBackendsDomains({ |
| 131 | name: created.domain.name, |
| 132 | }); |
| 133 | expect(fetched.name).toEqual(created.domain.name); |
| 134 | expect(fetched.displayName).toEqual("alchemy-test-domain"); |
| 135 | expect(fetched.labels?.env).toEqual("test"); |
| 136 | |
| 137 | const updated = yield* stack.deploy( |
| 138 | Effect.gen(function* () { |
| 139 | const backend = yield* GCP.FirebaseAppHosting.Backend("Web", { |
| 140 | backendId: created.backend.backendId, |
| 141 | serviceAccount, |
| 142 | servingLocality: "GLOBAL_ACCESS", |
| 143 | displayName: "alchemy-test-domain-backend", |
| 144 | labels: { env: "test" }, |
| 145 | }); |
| 146 | const domain = yield* GCP.FirebaseAppHosting.BackendsDomain("Www", { |
| 147 | domainId: created.domain.domainId, |
| 148 | backend: backend.name, |
| 149 | displayName: "alchemy-prod-domain", |
| 150 | disabled: true, |
| 151 | labels: { env: "prod", role: "web" }, |
| 152 | }); |
| 153 | return domain; |
| 154 | }), |
| 155 | ); |
| 156 | |
| 157 | expect(updated.name).toEqual(created.domain.name); |
| 158 | expect(updated.displayName).toEqual("alchemy-prod-domain"); |
| 159 | expect(updated.labels).toMatchObject({ env: "prod", role: "web" }); |
| 160 | |
| 161 | yield* stack.destroy(); |
| 162 | |
| 163 | const gone = yield* waitUntilGone(created.domain.name); |
| 164 | expect(gone).toEqual("gone"); |
| 165 | }).pipe(logLevel), |
| 166 | { |
| 167 | tags: ["provider:gcp", "provider:gcp:firebaseapphosting", "live"], |
| 168 | timeout: 420_000, |
| 169 | }, |
| 170 | ); |