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 servicemanagement from "@distilled.cloud/gcp/servicemanagement_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 | const missingNameOf = (project: string) => `alch-missing.endpoints.${project}.cloud.goog`; |
| 15 | |
| 16 | const waitUntilGone = (serviceName: string) => |
| 17 | servicemanagement.getServices({ serviceName }).pipe( |
| 18 | Effect.as("found" as const), |
| 19 | // Service Management answers a missing service with 403 "not found or |
| 20 | // permission denied", typed ServiceNotFound. |
| 21 | Effect.catchTag(["NotFound", "ServiceNotFound"], () => Effect.succeed("gone" as const)), |
| 22 | Effect.repeat({ |
| 23 | schedule: Schedule.spaced("2 seconds"), |
| 24 | until: (status) => status === "gone", |
| 25 | times: 10, |
| 26 | }), |
| 27 | ); |
| 28 | |
| 29 | test.provider( |
| 30 | "getServices on a missing service fails with a typed tag", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | const { project } = yield* GcpEnvironment.current; |
| 34 | const missingName = missingNameOf(project); |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const error = yield* Effect.flip(servicemanagement.getServices({ serviceName: missingName })); |
| 38 | expect(error._tag).toEqual("ServiceNotFound"); |
| 39 | |
| 40 | const page = yield* servicemanagement.listServices({ |
| 41 | producerProjectId: project, |
| 42 | pageSize: 10, |
| 43 | }); |
| 44 | expect((page.services ?? []).map((service) => service.serviceName)).not.toContain( |
| 45 | missingName, |
| 46 | ); |
| 47 | |
| 48 | yield* stack.destroy(); |
| 49 | }).pipe(logLevel), |
| 50 | { |
| 51 | tags: ["provider:gcp", "provider:gcp:servicemanagement", "live"], |
| 52 | timeout: 90_000, |
| 53 | }, |
| 54 | ); |
| 55 | |
| 56 | test.provider.skipIf(!!process.env.FAST)( |
| 57 | "create, update, and delete a managed service", |
| 58 | (stack) => |
| 59 | Effect.gen(function* () { |
| 60 | const { project } = yield* GcpEnvironment.current; |
| 61 | yield* stack.destroy(); |
| 62 | |
| 63 | const created = yield* stack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | return yield* GCP.ServiceManagement.Service("Hello", { |
| 66 | title: "Alchemy SM", |
| 67 | }); |
| 68 | }), |
| 69 | ); |
| 70 | |
| 71 | // A generated name: deleted names stay reserved for 30 days. |
| 72 | expect(created.serviceName).toMatch( |
| 73 | new RegExp(`^alch-.*\\.endpoints\\.${project}\\.cloud\\.goog$`), |
| 74 | ); |
| 75 | expect(created.producerProjectId).toEqual(project); |
| 76 | expect(created.title).toEqual("Alchemy SM"); |
| 77 | |
| 78 | const fetched = yield* servicemanagement.getServices({ |
| 79 | serviceName: created.serviceName, |
| 80 | }); |
| 81 | expect(fetched.serviceName).toEqual(created.serviceName); |
| 82 | expect(fetched.producerProjectId).toEqual(project); |
| 83 | |
| 84 | const config = yield* servicemanagement.listServicesConfigs({ |
| 85 | serviceName: created.serviceName, |
| 86 | pageSize: 1, |
| 87 | }); |
| 88 | // The title is shown in the API docs: no ownership marker. |
| 89 | expect(config.serviceConfigs?.[0]?.title).toEqual("Alchemy SM"); |
| 90 | |
| 91 | const updated = yield* stack.deploy( |
| 92 | Effect.gen(function* () { |
| 93 | return yield* GCP.ServiceManagement.Service("Hello", { |
| 94 | title: "Alchemy SM v2", |
| 95 | }); |
| 96 | }), |
| 97 | ); |
| 98 | |
| 99 | expect(updated.serviceName).toEqual(created.serviceName); |
| 100 | expect(updated.title).toEqual("Alchemy SM v2"); |
| 101 | |
| 102 | yield* stack.destroy(); |
| 103 | |
| 104 | const gone = yield* waitUntilGone(created.serviceName); |
| 105 | expect(gone).toEqual("gone"); |
| 106 | }).pipe(logLevel), |
| 107 | { |
| 108 | tags: ["provider:gcp", "provider:gcp:servicemanagement", "live"], |
| 109 | timeout: 600_000, |
| 110 | }, |
| 111 | ); |