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 vmwareengine from "@distilled.cloud/gcp/vmwareengine_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 | // Private clouds need VMware Engine node quota and bill thousands of dollars |
| 15 | // a month; set GCP_TEST_VMWAREENGINE=1 on an entitled project to opt in. |
| 16 | const runLifecycle = !!process.env.GCP_TEST_VMWAREENGINE && !process.env.FAST; |
| 17 | |
| 18 | const waitUntilGone = (name: string) => |
| 19 | vmwareengine.getProjectsLocationsNetworkPoliciesExternalAccessRules({ name }).pipe( |
| 20 | Effect.as("found" as const), |
| 21 | Effect.catchTag("NotFound", () => 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 | "getProjectsLocationsNetworkPoliciesExternalAccessRules on a missing rule fails with a typed tag", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | const { project } = yield* GcpEnvironment.current; |
| 34 | |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const error = yield* Effect.flip( |
| 38 | vmwareengine.getProjectsLocationsNetworkPoliciesExternalAccessRules({ |
| 39 | name: `projects/${project}/locations/us-central1/networkPolicies/alchemy-missing/externalAccessRules/missing`, |
| 40 | }), |
| 41 | ); |
| 42 | expect(error._tag).toEqual("NotFound"); |
| 43 | |
| 44 | yield* stack.destroy(); |
| 45 | }).pipe(logLevel), |
| 46 | { |
| 47 | tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"], |
| 48 | timeout: 90_000, |
| 49 | }, |
| 50 | ); |
| 51 | |
| 52 | test.provider.skipIf(!runLifecycle)( |
| 53 | "create, update, and delete an external access rule", |
| 54 | (stack) => |
| 55 | Effect.gen(function* () { |
| 56 | yield* stack.destroy(); |
| 57 | |
| 58 | const created = yield* stack.deploy( |
| 59 | Effect.gen(function* () { |
| 60 | const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", { |
| 61 | type: "STANDARD", |
| 62 | description: "rule grandparent", |
| 63 | }); |
| 64 | const policy = yield* GCP.VMwareEngine.NetworkPolicy("Edge", { |
| 65 | vmwareEngineNetwork: ven.name, |
| 66 | edgeServicesCidr: "192.168.100.0/26", |
| 67 | internetAccess: { enabled: true }, |
| 68 | externalIp: { enabled: true }, |
| 69 | description: "rule parent", |
| 70 | }); |
| 71 | const rule = yield* GCP.VMwareEngine.NetworkPoliciesExternalAccessRule("Https", { |
| 72 | networkPolicy: policy.name, |
| 73 | action: "ALLOW", |
| 74 | ipProtocol: "tcp", |
| 75 | priority: 1000, |
| 76 | sourceIpRanges: [{ ipAddressRange: "0.0.0.0/0" }], |
| 77 | destinationIpRanges: [{ ipAddressRange: "0.0.0.0/0" }], |
| 78 | destinationPorts: ["443"], |
| 79 | description: "alchemy-test-ear", |
| 80 | }); |
| 81 | return { ven, policy, rule }; |
| 82 | }), |
| 83 | ); |
| 84 | |
| 85 | expect(created.rule.name).toContain("/externalAccessRules/"); |
| 86 | expect(created.rule.action).toEqual("ALLOW"); |
| 87 | expect(created.rule.priority).toEqual(1000); |
| 88 | expect(created.rule.description).toEqual("alchemy-test-ear"); |
| 89 | |
| 90 | const fetched = yield* vmwareengine.getProjectsLocationsNetworkPoliciesExternalAccessRules({ |
| 91 | name: created.rule.name, |
| 92 | }); |
| 93 | expect(fetched.name).toEqual(created.rule.name); |
| 94 | expect(fetched.description).toContain("alchemy-id="); |
| 95 | expect(fetched.description).toContain("alchemy-test-ear"); |
| 96 | |
| 97 | const updated = yield* stack.deploy( |
| 98 | Effect.gen(function* () { |
| 99 | const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", { |
| 100 | vmwareEngineNetworkId: created.ven.vmwareEngineNetworkId, |
| 101 | type: "STANDARD", |
| 102 | description: "rule grandparent", |
| 103 | }); |
| 104 | const policy = yield* GCP.VMwareEngine.NetworkPolicy("Edge", { |
| 105 | networkPolicyId: created.policy.networkPolicyId, |
| 106 | vmwareEngineNetwork: ven.name, |
| 107 | edgeServicesCidr: "192.168.100.0/26", |
| 108 | internetAccess: { enabled: true }, |
| 109 | externalIp: { enabled: true }, |
| 110 | description: "rule parent", |
| 111 | }); |
| 112 | const rule = yield* GCP.VMwareEngine.NetworkPoliciesExternalAccessRule("Https", { |
| 113 | networkPolicy: policy.name, |
| 114 | externalAccessRuleId: created.rule.externalAccessRuleId, |
| 115 | action: "DENY", |
| 116 | ipProtocol: "tcp", |
| 117 | priority: 2000, |
| 118 | sourceIpRanges: [{ ipAddressRange: "0.0.0.0/0" }], |
| 119 | destinationIpRanges: [{ ipAddressRange: "0.0.0.0/0" }], |
| 120 | destinationPorts: ["443"], |
| 121 | description: "alchemy-prod-ear", |
| 122 | }); |
| 123 | return { ven, policy, rule }; |
| 124 | }), |
| 125 | ); |
| 126 | |
| 127 | expect(updated.rule.name).toEqual(created.rule.name); |
| 128 | expect(updated.rule.action).toEqual("DENY"); |
| 129 | expect(updated.rule.priority).toEqual(2000); |
| 130 | expect(updated.rule.description).toEqual("alchemy-prod-ear"); |
| 131 | |
| 132 | yield* stack.destroy(); |
| 133 | |
| 134 | const gone = yield* waitUntilGone(created.rule.name); |
| 135 | expect(gone).toEqual("gone"); |
| 136 | }).pipe(logLevel), |
| 137 | { |
| 138 | tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"], |
| 139 | timeout: 120_000, |
| 140 | }, |
| 141 | ); |