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 | import { DEFAULT_NETWORK } 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.GCP_TEST_COMPUTE_INTERCONNECT && !process.env.FAST; |
| 16 | |
| 17 | const region = "us-central1"; |
| 18 | |
| 19 | const waitUntilGone = (interconnectAttachment: string) => |
| 20 | GcpEnvironment.current.pipe( |
| 21 | Effect.flatMap(({ project }) => |
| 22 | compute |
| 23 | .getInterconnectAttachments({ |
| 24 | project, |
| 25 | region, |
| 26 | interconnectAttachment, |
| 27 | }) |
| 28 | .pipe( |
| 29 | Effect.as("found" as const), |
| 30 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 31 | Effect.repeat({ |
| 32 | schedule: Schedule.spaced("1 second"), |
| 33 | until: (status) => status === "gone", |
| 34 | times: 10, |
| 35 | }), |
| 36 | ), |
| 37 | ), |
| 38 | ); |
| 39 | |
| 40 | test.provider( |
| 41 | "getInterconnectAttachments on a missing attachment fails with NotFound", |
| 42 | (stack) => |
| 43 | Effect.gen(function* () { |
| 44 | const { project } = yield* GcpEnvironment.current; |
| 45 | yield* stack.destroy(); |
| 46 | |
| 47 | const error = yield* Effect.flip( |
| 48 | compute.getInterconnectAttachments({ |
| 49 | project, |
| 50 | region, |
| 51 | interconnectAttachment: "alchemy-missing-vlan", |
| 52 | }), |
| 53 | ); |
| 54 | expect(error._tag).toBe("NotFound"); |
| 55 | |
| 56 | yield* stack.destroy(); |
| 57 | }).pipe(logLevel), |
| 58 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 59 | ); |
| 60 | |
| 61 | test.provider( |
| 62 | "insertInterconnectAttachments with a malformed router fails with BadRequest", |
| 63 | () => |
| 64 | Effect.gen(function* () { |
| 65 | const { project } = yield* GcpEnvironment.current; |
| 66 | const error = yield* Effect.flip( |
| 67 | compute.insertInterconnectAttachments({ |
| 68 | project, |
| 69 | region, |
| 70 | body: { |
| 71 | name: "alchemy-vlan-probe", |
| 72 | description: "alchemy entitlement probe", |
| 73 | router: "does-not-exist", |
| 74 | type: "PARTNER", |
| 75 | }, |
| 76 | }), |
| 77 | ); |
| 78 | expect(error._tag).toEqual("BadRequest"); |
| 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 an interconnect attachment", |
| 85 | (stack) => |
| 86 | Effect.gen(function* () { |
| 87 | yield* stack.destroy(); |
| 88 | |
| 89 | const created = yield* stack.deploy( |
| 90 | Effect.gen(function* () { |
| 91 | const router = yield* GCP.Compute.Router("Edge", { |
| 92 | region, |
| 93 | network: DEFAULT_NETWORK, |
| 94 | description: "interconnect router", |
| 95 | }); |
| 96 | const attachment = yield* GCP.Compute.InterconnectAttachment("Vlan", { |
| 97 | region, |
| 98 | router: router.routerName, |
| 99 | type: "PARTNER", |
| 100 | description: "partner vlan", |
| 101 | }); |
| 102 | return { router, attachment }; |
| 103 | }), |
| 104 | ); |
| 105 | |
| 106 | expect(created.attachment.interconnectAttachmentName).toEqual(expect.any(String)); |
| 107 | expect(created.attachment.region).toEqual(region); |
| 108 | expect(created.attachment.description).toEqual("partner vlan"); |
| 109 | |
| 110 | const fetched = yield* compute.getInterconnectAttachments({ |
| 111 | project: created.attachment.project, |
| 112 | region, |
| 113 | interconnectAttachment: created.attachment.interconnectAttachmentName, |
| 114 | }); |
| 115 | expect(fetched.name).toEqual(created.attachment.interconnectAttachmentName); |
| 116 | expect(fetched.description).toContain("[alchemy "); |
| 117 | |
| 118 | const updated = yield* stack.deploy( |
| 119 | Effect.gen(function* () { |
| 120 | const router = yield* GCP.Compute.Router("Edge", { |
| 121 | routerName: created.router.routerName, |
| 122 | region, |
| 123 | network: DEFAULT_NETWORK, |
| 124 | description: "interconnect router", |
| 125 | }); |
| 126 | return yield* GCP.Compute.InterconnectAttachment("Vlan", { |
| 127 | interconnectAttachmentName: created.attachment.interconnectAttachmentName, |
| 128 | region, |
| 129 | router: router.routerName, |
| 130 | type: "PARTNER", |
| 131 | description: "updated partner vlan", |
| 132 | adminEnabled: false, |
| 133 | }); |
| 134 | }), |
| 135 | ); |
| 136 | expect(updated.description).toEqual("updated partner vlan"); |
| 137 | |
| 138 | yield* stack.destroy(); |
| 139 | const gone = yield* waitUntilGone(created.attachment.interconnectAttachmentName); |
| 140 | expect(gone).toEqual("gone"); |
| 141 | }).pipe(logLevel), |
| 142 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 143 | ); |