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 appengine from "@distilled.cloud/gcp/appengine_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 | // Needs an App Engine application in the project, which is permanent once |
| 15 | // created (it can never be deleted). The testing project has none and the |
| 16 | // App Engine Admin API is off (ServiceDisabled: "App Engine Admin API has not been |
| 17 | // used in project ... or it is disabled."). Set GCP_TEST_APPENGINE_APP=1 on a |
| 18 | // project with an app to run the lifecycle. |
| 19 | const runLifecycle = !!process.env.GCP_TEST_APPENGINE_APP; |
| 20 | |
| 21 | const domain = process.env.GCP_TEST_APPENGINE_DOMAIN ?? "alchemy-appengine.test"; |
| 22 | |
| 23 | const waitUntilGone = (appsId: string, domainId: string) => |
| 24 | appengine |
| 25 | .getAppsDomainMappings({ |
| 26 | appsId, |
| 27 | domainMappingsId: domainId, |
| 28 | }) |
| 29 | .pipe( |
| 30 | Effect.as("found" as const), |
| 31 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 32 | Effect.repeat({ |
| 33 | schedule: Schedule.spaced("1 second"), |
| 34 | until: (status) => status === "gone", |
| 35 | times: 10, |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | test.provider( |
| 40 | "getAppsDomainMappings on a missing mapping fails with a typed tag", |
| 41 | (stack) => |
| 42 | Effect.gen(function* () { |
| 43 | const { project } = yield* GcpEnvironment.current; |
| 44 | yield* stack.destroy(); |
| 45 | |
| 46 | const error = yield* Effect.flip( |
| 47 | appengine.getAppsDomainMappings({ |
| 48 | appsId: project, |
| 49 | domainMappingsId: "alchemy-missing.example.com", |
| 50 | }), |
| 51 | ); |
| 52 | expect(["ServiceDisabled", "NotFound"]).toContain(error._tag); |
| 53 | |
| 54 | yield* stack.destroy(); |
| 55 | }).pipe(logLevel), |
| 56 | { tags: ["provider:gcp", "provider:gcp:appengine", "live"], timeout: 90_000 }, |
| 57 | ); |
| 58 | |
| 59 | test.provider.skipIf(runLifecycle)( |
| 60 | "createAppsDomainMappings without an App Engine app fails with a typed tag", |
| 61 | (stack) => |
| 62 | Effect.gen(function* () { |
| 63 | const { project } = yield* GcpEnvironment.current; |
| 64 | yield* stack.destroy(); |
| 65 | |
| 66 | const error = yield* Effect.flip( |
| 67 | appengine.createAppsDomainMappings({ |
| 68 | appsId: project, |
| 69 | body: { |
| 70 | id: "alchemy-missing.example.com", |
| 71 | sslSettings: { sslManagementType: "AUTOMATIC" }, |
| 72 | }, |
| 73 | }), |
| 74 | ); |
| 75 | expect(["ServiceDisabled", "NotFound"]).toContain(error._tag); |
| 76 | |
| 77 | yield* stack.destroy(); |
| 78 | }).pipe(logLevel), |
| 79 | { tags: ["provider:gcp", "provider:gcp:appengine", "live"], timeout: 90_000 }, |
| 80 | ); |
| 81 | |
| 82 | test.provider.skipIf(!runLifecycle)( |
| 83 | "create, update, and delete a domain mapping", |
| 84 | (stack) => |
| 85 | Effect.gen(function* () { |
| 86 | const { project } = yield* GcpEnvironment.current; |
| 87 | yield* stack.destroy(); |
| 88 | |
| 89 | const created = yield* stack.deploy( |
| 90 | Effect.gen(function* () { |
| 91 | return yield* GCP.AppEngine.AppsDomainMapping("Www", { |
| 92 | domain, |
| 93 | sslSettings: { sslManagementType: "AUTOMATIC" }, |
| 94 | }); |
| 95 | }), |
| 96 | ); |
| 97 | |
| 98 | expect(created.domain).toEqual(domain); |
| 99 | expect(created.appsId).toEqual(project); |
| 100 | |
| 101 | const fetched = yield* appengine.getAppsDomainMappings({ |
| 102 | appsId: created.appsId, |
| 103 | domainMappingsId: created.domain, |
| 104 | }); |
| 105 | expect(fetched.id).toEqual(created.domain); |
| 106 | |
| 107 | const updated = yield* stack.deploy( |
| 108 | Effect.gen(function* () { |
| 109 | return yield* GCP.AppEngine.AppsDomainMapping("Www", { |
| 110 | domain: created.domain, |
| 111 | sslSettings: { sslManagementType: "MANUAL" }, |
| 112 | }); |
| 113 | }), |
| 114 | ); |
| 115 | |
| 116 | expect(updated.domain).toEqual(created.domain); |
| 117 | expect(updated.sslManagementType).toEqual("MANUAL"); |
| 118 | |
| 119 | yield* stack.destroy(); |
| 120 | |
| 121 | const gone = yield* waitUntilGone(created.appsId, created.domain); |
| 122 | expect(gone).toEqual("gone"); |
| 123 | }).pipe(logLevel), |
| 124 | { tags: ["provider:gcp", "provider:gcp:appengine", "live"], timeout: 90_000 }, |
| 125 | ); |