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 compute from "@distilled.cloud/gcp/compute_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 waitUntilGone = (targetGrpcProxyName: string) => |
| 15 | GcpEnvironment.current.pipe( |
| 16 | Effect.flatMap(({ project }) => |
| 17 | compute.getTargetGrpcProxies({ project, targetGrpcProxy: targetGrpcProxyName }).pipe( |
| 18 | Effect.as("found" as const), |
| 19 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 20 | Effect.repeat({ |
| 21 | schedule: Schedule.spaced("1 second"), |
| 22 | until: (status) => status === "gone", |
| 23 | times: 10, |
| 24 | }), |
| 25 | ), |
| 26 | ), |
| 27 | ); |
| 28 | |
| 29 | const resourceTail = (value: string | undefined): string => { |
| 30 | if (value === undefined || value.length === 0) return ""; |
| 31 | const parts = value.split("/").filter((part) => part.length > 0); |
| 32 | return parts[parts.length - 1] ?? ""; |
| 33 | }; |
| 34 | |
| 35 | test.provider( |
| 36 | "create, update, and delete a target grpc proxy", |
| 37 | (stack) => |
| 38 | Effect.gen(function* () { |
| 39 | const { project } = yield* GcpEnvironment.current; |
| 40 | yield* stack.destroy(); |
| 41 | |
| 42 | const created = yield* stack.deploy( |
| 43 | Effect.gen(function* () { |
| 44 | const backend = yield* GCP.Compute.BackendService("Grpc", { |
| 45 | protocol: "GRPC", |
| 46 | loadBalancingScheme: "INTERNAL_SELF_MANAGED", |
| 47 | description: "grpc backend", |
| 48 | }); |
| 49 | const map = yield* GCP.Compute.UrlMap("Map", { |
| 50 | description: "grpc routes", |
| 51 | defaultService: backend.selfLink, |
| 52 | }); |
| 53 | return yield* GCP.Compute.TargetGrpcProxy("Proxy", { |
| 54 | description: "grpc frontend", |
| 55 | urlMap: map.urlMapName, |
| 56 | }); |
| 57 | }), |
| 58 | ); |
| 59 | |
| 60 | expect(created.targetGrpcProxyName).toEqual(expect.any(String)); |
| 61 | expect(created.description).toEqual("grpc frontend"); |
| 62 | expect(created.validateForProxyless).toEqual(false); |
| 63 | expect(resourceTail(created.urlMap).length).toBeGreaterThan(0); |
| 64 | |
| 65 | const fetched = yield* compute.getTargetGrpcProxies({ |
| 66 | project, |
| 67 | targetGrpcProxy: created.targetGrpcProxyName, |
| 68 | }); |
| 69 | expect(fetched.name).toEqual(created.targetGrpcProxyName); |
| 70 | expect(resourceTail(fetched.urlMap)).toEqual(resourceTail(created.urlMap)); |
| 71 | expect(fetched.validateForProxyless).toEqual(false); |
| 72 | expect(fetched.description).toContain("[alchemy "); |
| 73 | expect(fetched.description).toContain("grpc frontend"); |
| 74 | |
| 75 | const updated = yield* stack.deploy( |
| 76 | Effect.gen(function* () { |
| 77 | const backend = yield* GCP.Compute.BackendService("Grpc", { |
| 78 | protocol: "GRPC", |
| 79 | loadBalancingScheme: "INTERNAL_SELF_MANAGED", |
| 80 | description: "grpc backend", |
| 81 | }); |
| 82 | const map = yield* GCP.Compute.UrlMap("Map", { |
| 83 | description: "grpc routes", |
| 84 | defaultService: backend.selfLink, |
| 85 | }); |
| 86 | return yield* GCP.Compute.TargetGrpcProxy("Proxy", { |
| 87 | targetGrpcProxyName: created.targetGrpcProxyName, |
| 88 | description: "updated frontend", |
| 89 | urlMap: map.urlMapName, |
| 90 | }); |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | expect(updated.targetGrpcProxyName).toEqual(created.targetGrpcProxyName); |
| 95 | expect(updated.description).toEqual("updated frontend"); |
| 96 | expect(resourceTail(updated.urlMap)).toEqual(resourceTail(created.urlMap)); |
| 97 | |
| 98 | const refetched = yield* compute.getTargetGrpcProxies({ |
| 99 | project, |
| 100 | targetGrpcProxy: updated.targetGrpcProxyName, |
| 101 | }); |
| 102 | expect(refetched.description).toContain("updated frontend"); |
| 103 | expect(resourceTail(refetched.urlMap)).toEqual(resourceTail(updated.urlMap)); |
| 104 | |
| 105 | yield* stack.destroy(); |
| 106 | |
| 107 | const gone = yield* waitUntilGone(created.targetGrpcProxyName); |
| 108 | expect(gone).toEqual("gone"); |
| 109 | }).pipe(logLevel), |
| 110 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 180_000 }, |
| 111 | ); |