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 { 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 | // Needs Cloud Armor Managed Protection Plus (GCP_TEST_CLOUD_ARMOR=1); without |
| 15 | // it insert fails with `BadRequest: Network Security Policies require Cloud |
| 16 | // Armor Managed Protection Plus tier and above to use.` |
| 17 | const runLifecycle = !!process.env.GCP_TEST_CLOUD_ARMOR && !process.env.FAST; |
| 18 | |
| 19 | const region = "us-central1"; |
| 20 | |
| 21 | const waitUntilGone = (networkEdgeSecurityService: string) => |
| 22 | GcpEnvironment.current.pipe( |
| 23 | Effect.flatMap(({ project }) => |
| 24 | compute |
| 25 | .getNetworkEdgeSecurityServices({ |
| 26 | project, |
| 27 | region, |
| 28 | networkEdgeSecurityService, |
| 29 | }) |
| 30 | .pipe( |
| 31 | Effect.as("found" as const), |
| 32 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 33 | Effect.repeat({ |
| 34 | schedule: Schedule.spaced("1 second"), |
| 35 | until: (status) => status === "gone", |
| 36 | times: 10, |
| 37 | }), |
| 38 | ), |
| 39 | ), |
| 40 | ); |
| 41 | |
| 42 | test.provider( |
| 43 | "getNetworkEdgeSecurityServices on a missing service fails with NotFound", |
| 44 | (stack) => |
| 45 | Effect.gen(function* () { |
| 46 | const { project } = yield* GcpEnvironment.current; |
| 47 | yield* stack.destroy(); |
| 48 | |
| 49 | const error = yield* Effect.flip( |
| 50 | compute.getNetworkEdgeSecurityServices({ |
| 51 | project, |
| 52 | region, |
| 53 | networkEdgeSecurityService: "alchemy-missing-ness", |
| 54 | }), |
| 55 | ); |
| 56 | expect(error._tag).toBe("NotFound"); |
| 57 | |
| 58 | yield* stack.destroy(); |
| 59 | }).pipe(logLevel), |
| 60 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 61 | ); |
| 62 | |
| 63 | test.provider( |
| 64 | "insertNetworkEdgeSecurityServices without Cloud Armor Enterprise fails with CloudArmorEnterpriseRequired", |
| 65 | () => |
| 66 | Effect.gen(function* () { |
| 67 | const { project } = yield* GcpEnvironment.current; |
| 68 | const error = yield* Effect.flip( |
| 69 | compute.insertNetworkEdgeSecurityServices({ |
| 70 | project, |
| 71 | region, |
| 72 | body: { |
| 73 | name: "alchemy-ness-probe", |
| 74 | description: "alchemy entitlement probe", |
| 75 | }, |
| 76 | }), |
| 77 | ); |
| 78 | expect(error._tag).toEqual("CloudArmorEnterpriseRequired"); |
| 79 | }).pipe(logLevel), |
| 80 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 60_000 }, |
| 81 | ); |
| 82 | |
| 83 | test.provider.skipIf(!runLifecycle)( |
| 84 | "create, update, and delete a network edge security service", |
| 85 | (stack) => |
| 86 | Effect.gen(function* () { |
| 87 | yield* stack.destroy(); |
| 88 | |
| 89 | const created = yield* stack.deploy( |
| 90 | Effect.gen(function* () { |
| 91 | return yield* GCP.Compute.NetworkEdgeSecurityService("EdgeArmor", { |
| 92 | region, |
| 93 | description: "regional network armor", |
| 94 | }); |
| 95 | }), |
| 96 | ); |
| 97 | |
| 98 | expect(created.networkEdgeSecurityServiceName).toEqual(expect.any(String)); |
| 99 | expect(created.region).toEqual(region); |
| 100 | expect(created.description).toEqual("regional network armor"); |
| 101 | |
| 102 | const fetched = yield* compute.getNetworkEdgeSecurityServices({ |
| 103 | project: created.project, |
| 104 | region, |
| 105 | networkEdgeSecurityService: created.networkEdgeSecurityServiceName, |
| 106 | }); |
| 107 | expect(fetched.name).toEqual(created.networkEdgeSecurityServiceName); |
| 108 | expect(fetched.description).toContain("[alchemy "); |
| 109 | |
| 110 | const updated = yield* stack.deploy( |
| 111 | Effect.gen(function* () { |
| 112 | return yield* GCP.Compute.NetworkEdgeSecurityService("EdgeArmor", { |
| 113 | networkEdgeSecurityServiceName: created.networkEdgeSecurityServiceName, |
| 114 | region, |
| 115 | description: "updated network armor", |
| 116 | }); |
| 117 | }), |
| 118 | ); |
| 119 | expect(updated.description).toEqual("updated network armor"); |
| 120 | |
| 121 | yield* stack.destroy(); |
| 122 | const gone = yield* waitUntilGone(created.networkEdgeSecurityServiceName); |
| 123 | expect(gone).toEqual("gone"); |
| 124 | }).pipe(logLevel), |
| 125 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 126 | ); |