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 networksecurity from "@distilled.cloud/gcp/networksecurity_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 | // An attachment needs a SAC realm already paired with its SSE partner |
| 15 | // (Palo Alto Prisma Access / Symantec), which happens outside GCP. Set |
| 16 | // GCP_TEST_SAC_PARTNER_REALM to the full resource name of such a realm to |
| 17 | // run the lifecycle. The NCC gateway spoke it needs takes well over 5 |
| 18 | // minutes to provision. |
| 19 | const partnerRealm = process.env.GCP_TEST_SAC_PARTNER_REALM; |
| 20 | const runLifecycle = !!partnerRealm && !!process.env.GCP_TEST_SLOW && !process.env.FAST; |
| 21 | |
| 22 | const waitUntilGone = (name: string) => |
| 23 | networksecurity.getProjectsLocationsSacAttachments({ name }).pipe( |
| 24 | Effect.as("found" as const), |
| 25 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 26 | Effect.repeat({ |
| 27 | schedule: Schedule.spaced("2 seconds"), |
| 28 | until: (status) => status === "gone", |
| 29 | times: 10, |
| 30 | }), |
| 31 | ); |
| 32 | |
| 33 | test.provider( |
| 34 | "getProjectsLocationsSacAttachments on a missing attachment fails with a typed tag", |
| 35 | (stack) => |
| 36 | Effect.gen(function* () { |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const { project } = yield* GcpEnvironment.current; |
| 40 | const error = yield* Effect.flip( |
| 41 | networksecurity.getProjectsLocationsSacAttachments({ |
| 42 | name: `projects/${project}/locations/us-central1/sacAttachments/alchemy-missing`, |
| 43 | }), |
| 44 | ); |
| 45 | expect(error._tag).toEqual("NotFound"); |
| 46 | |
| 47 | yield* stack.destroy(); |
| 48 | }).pipe(logLevel), |
| 49 | { |
| 50 | tags: ["provider:gcp", "provider:gcp:networksecurity", "live"], |
| 51 | timeout: 90_000, |
| 52 | }, |
| 53 | ); |
| 54 | |
| 55 | // GCP validates the gateway before the realm, so proving the typed |
| 56 | // unpaired-realm rejection needs a real NCC gateway spoke (slow). |
| 57 | test.provider.skipIf(!process.env.GCP_TEST_SLOW || !!process.env.FAST)( |
| 58 | "createProjectsLocationsSacAttachments on an unpaired realm fails with SacRealmNotPaired", |
| 59 | (stack) => |
| 60 | Effect.gen(function* () { |
| 61 | yield* stack.destroy(); |
| 62 | |
| 63 | const { project } = yield* GcpEnvironment.current; |
| 64 | const { realm, gateway } = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | const hub = yield* GCP.NetworkConnectivity.Hub("ProbeMesh", { |
| 67 | description: "sac unpaired probe hub", |
| 68 | }); |
| 69 | const gateway = yield* GCP.NetworkConnectivity.Spoke("ProbeGateway", { |
| 70 | location: "us-central1", |
| 71 | hub: hub.name, |
| 72 | gateway: { |
| 73 | capacity: "CAPACITY_1_GBPS", |
| 74 | ipRangeReservations: [{ ipRange: "10.22.0.0/23" }], |
| 75 | }, |
| 76 | }); |
| 77 | const realm = yield* GCP.NetworkSecurity.SacRealm("Unpaired", { |
| 78 | securityService: "PALO_ALTO_PRISMA_ACCESS", |
| 79 | }); |
| 80 | return { realm, gateway }; |
| 81 | }), |
| 82 | ); |
| 83 | |
| 84 | const error = yield* Effect.flip( |
| 85 | networksecurity.createProjectsLocationsSacAttachments({ |
| 86 | parent: `projects/${project}/locations/us-central1`, |
| 87 | sacAttachmentId: "alchemy-unpaired-probe", |
| 88 | body: { sacRealm: realm.name, nccGateway: gateway.name }, |
| 89 | }), |
| 90 | ); |
| 91 | expect(error._tag).toEqual("SacRealmNotPaired"); |
| 92 | |
| 93 | yield* stack.destroy(); |
| 94 | }).pipe(logLevel), |
| 95 | { |
| 96 | tags: ["provider:gcp", "provider:gcp:networksecurity", "live"], |
| 97 | timeout: 2_400_000, |
| 98 | retry: 0, |
| 99 | }, |
| 100 | ); |
| 101 | |
| 102 | test.provider.skipIf(!runLifecycle)( |
| 103 | "create and delete a sac attachment", |
| 104 | (stack) => |
| 105 | Effect.gen(function* () { |
| 106 | yield* stack.destroy(); |
| 107 | |
| 108 | const created = yield* stack.deploy( |
| 109 | Effect.gen(function* () { |
| 110 | const hub = yield* GCP.NetworkConnectivity.Hub("Mesh", { |
| 111 | description: "sac hub", |
| 112 | }); |
| 113 | const gateway = yield* GCP.NetworkConnectivity.Spoke("Gateway", { |
| 114 | location: "us-central1", |
| 115 | hub: hub.name, |
| 116 | gateway: { |
| 117 | capacity: "CAPACITY_1_GBPS", |
| 118 | ipRangeReservations: [{ ipRange: "10.20.0.0/23" }], |
| 119 | }, |
| 120 | }); |
| 121 | const attachment = yield* GCP.NetworkSecurity.SacAttachment("PrismaLink", { |
| 122 | location: "us-central1", |
| 123 | sacRealm: partnerRealm!, |
| 124 | nccGateway: gateway.name, |
| 125 | labels: { env: "test" }, |
| 126 | }); |
| 127 | return { hub, gateway, attachment }; |
| 128 | }), |
| 129 | ); |
| 130 | |
| 131 | expect(created.attachment.name).toContain("/sacAttachments/"); |
| 132 | expect(created.attachment.location).toEqual("us-central1"); |
| 133 | expect(created.attachment.labels).toMatchObject({ env: "test" }); |
| 134 | expect(created.attachment.sacRealm).toContain(partnerRealm!.split("/").pop()!); |
| 135 | |
| 136 | const fetched = yield* networksecurity.getProjectsLocationsSacAttachments({ |
| 137 | name: created.attachment.name, |
| 138 | }); |
| 139 | expect(fetched.name).toEqual(created.attachment.name); |
| 140 | expect(fetched.labels?.env).toEqual("test"); |
| 141 | expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual( |
| 142 | true, |
| 143 | ); |
| 144 | |
| 145 | yield* stack.destroy(); |
| 146 | |
| 147 | const gone = yield* waitUntilGone(created.attachment.name); |
| 148 | expect(gone).toEqual("gone"); |
| 149 | }).pipe(logLevel), |
| 150 | { |
| 151 | tags: ["provider:gcp", "provider:gcp:networksecurity", "live"], |
| 152 | timeout: 1_200_000, |
| 153 | retry: 0, |
| 154 | }, |
| 155 | ); |