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 networkmanagement from "@distilled.cloud/gcp/networkmanagement_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { withNetworkSlot } from "../networkQuota.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | const runLifecycle = !process.env.FAST; |
| 16 | |
| 17 | const waitUntilGone = (name: string) => |
| 18 | networkmanagement.getProjectsLocationsVpcFlowLogsConfigs({ name }).pipe( |
| 19 | Effect.as("found" as const), |
| 20 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 21 | Effect.repeat({ |
| 22 | schedule: Schedule.spaced("1 second"), |
| 23 | until: (status) => status === "gone", |
| 24 | times: 10, |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | test.provider( |
| 29 | "getProjectsLocationsVpcFlowLogsConfigs on a missing config fails with a typed tag", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | const { project } = yield* GcpEnvironment.current; |
| 33 | |
| 34 | yield* stack.destroy(); |
| 35 | |
| 36 | const error = yield* Effect.flip( |
| 37 | networkmanagement.getProjectsLocationsVpcFlowLogsConfigs({ |
| 38 | name: `projects/${project}/locations/global/vpcFlowLogsConfigs/alchemy-missing`, |
| 39 | }), |
| 40 | ); |
| 41 | expect(error._tag).toEqual("NotFound"); |
| 42 | |
| 43 | yield* stack.destroy(); |
| 44 | }).pipe(logLevel), |
| 45 | { |
| 46 | tags: ["provider:gcp", "provider:gcp:networkmanagement", "live"], |
| 47 | timeout: 90_000, |
| 48 | }, |
| 49 | ); |
| 50 | |
| 51 | test.provider.skipIf(!runLifecycle)( |
| 52 | "create, update, and delete a vpc flow logs config", |
| 53 | (stack) => |
| 54 | Effect.gen(function* () { |
| 55 | yield* stack.destroy(); |
| 56 | |
| 57 | const created = yield* stack.deploy( |
| 58 | Effect.gen(function* () { |
| 59 | const network = yield* GCP.Compute.Network("FlowVpc", { |
| 60 | autoCreateSubnetworks: false, |
| 61 | }); |
| 62 | const logs = yield* GCP.NetworkManagement.VpcFlowLogsConfig("VpcLogs", { |
| 63 | network: network.selfLink ?? network.networkName, |
| 64 | description: "flow logs a", |
| 65 | labels: { env: "test" }, |
| 66 | aggregationInterval: "INTERVAL_5_SEC", |
| 67 | flowSampling: 1, |
| 68 | }); |
| 69 | return { network, logs }; |
| 70 | }), |
| 71 | ); |
| 72 | |
| 73 | expect(created.logs.name).toContain("/vpcFlowLogsConfigs/"); |
| 74 | expect(created.logs.name).toContain("/locations/global/"); |
| 75 | expect(created.logs.vpcFlowLogsConfigId).toEqual(expect.any(String)); |
| 76 | expect(created.logs.location).toEqual("global"); |
| 77 | expect(created.logs.description).toEqual("flow logs a"); |
| 78 | expect(created.logs.labels).toMatchObject({ env: "test" }); |
| 79 | expect(created.logs.state).toEqual("ENABLED"); |
| 80 | expect(created.logs.createTime).toEqual(expect.any(String)); |
| 81 | |
| 82 | const fetched = yield* networkmanagement.getProjectsLocationsVpcFlowLogsConfigs({ |
| 83 | name: created.logs.name, |
| 84 | }); |
| 85 | expect(fetched.name).toEqual(created.logs.name); |
| 86 | expect(fetched.labels?.env).toEqual("test"); |
| 87 | expect(fetched.description).toEqual("flow logs a"); |
| 88 | expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual( |
| 89 | true, |
| 90 | ); |
| 91 | |
| 92 | const updated = yield* stack.deploy( |
| 93 | Effect.gen(function* () { |
| 94 | const network = yield* GCP.Compute.Network("FlowVpc", { |
| 95 | autoCreateSubnetworks: false, |
| 96 | networkName: created.network.networkName, |
| 97 | }); |
| 98 | const logs = yield* GCP.NetworkManagement.VpcFlowLogsConfig("VpcLogs", { |
| 99 | vpcFlowLogsConfigId: created.logs.vpcFlowLogsConfigId, |
| 100 | network: network.selfLink ?? network.networkName, |
| 101 | description: "flow logs b", |
| 102 | labels: { env: "prod", role: "logs" }, |
| 103 | aggregationInterval: "INTERVAL_1_MIN", |
| 104 | flowSampling: 0.5, |
| 105 | }); |
| 106 | return { network, logs }; |
| 107 | }), |
| 108 | ); |
| 109 | |
| 110 | expect(updated.logs.name).toEqual(created.logs.name); |
| 111 | expect(updated.logs.description).toEqual("flow logs b"); |
| 112 | expect(updated.logs.labels).toMatchObject({ env: "prod", role: "logs" }); |
| 113 | expect(updated.logs.aggregationInterval).toEqual("INTERVAL_1_MIN"); |
| 114 | expect(updated.logs.flowSampling).toEqual(0.5); |
| 115 | |
| 116 | const refetched = yield* networkmanagement.getProjectsLocationsVpcFlowLogsConfigs({ |
| 117 | name: created.logs.name, |
| 118 | }); |
| 119 | expect(refetched.description).toEqual("flow logs b"); |
| 120 | expect(refetched.aggregationInterval).toEqual("INTERVAL_1_MIN"); |
| 121 | expect(refetched.labels?.env).toEqual("prod"); |
| 122 | expect(refetched.labels?.role).toEqual("logs"); |
| 123 | |
| 124 | yield* stack.destroy(); |
| 125 | |
| 126 | const gone = yield* waitUntilGone(created.logs.name); |
| 127 | expect(gone).toEqual("gone"); |
| 128 | }).pipe(logLevel, withNetworkSlot), |
| 129 | { |
| 130 | tags: ["provider:gcp", "provider:gcp:networkmanagement", "live"], |
| 131 | timeout: 600_000, |
| 132 | }, |
| 133 | ); |