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 bne from "@distilled.cloud/gcp/blockchainnodeengine_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 | // Blockchain nodes bill hourly and take 15-45 minutes to provision, so the |
| 15 | // lifecycle is opt-in: set GCP_TEST_BLOCKCHAIN_NODE=1 together with |
| 16 | // GCP_TEST_SLOW. |
| 17 | const runLifecycle = |
| 18 | !!process.env.GCP_TEST_BLOCKCHAIN_NODE && !!process.env.GCP_TEST_SLOW && !process.env.FAST; |
| 19 | |
| 20 | const waitUntilGone = (name: string) => |
| 21 | bne.getProjectsLocationsBlockchainNodes({ name }).pipe( |
| 22 | Effect.as("found" as const), |
| 23 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 24 | Effect.repeat({ |
| 25 | schedule: Schedule.spaced("2 seconds"), |
| 26 | until: (status) => status === "gone", |
| 27 | times: 10, |
| 28 | }), |
| 29 | ); |
| 30 | |
| 31 | test.provider( |
| 32 | "getProjectsLocationsBlockchainNodes on a missing node fails with a typed tag", |
| 33 | (stack) => |
| 34 | Effect.gen(function* () { |
| 35 | const { project } = yield* GcpEnvironment.current; |
| 36 | const parent = `projects/${project}/locations/us-central1`; |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const error = yield* Effect.flip( |
| 40 | bne.getProjectsLocationsBlockchainNodes({ |
| 41 | name: `${parent}/blockchainNodes/alchemy-bne-missing`, |
| 42 | }), |
| 43 | ); |
| 44 | expect(error._tag).toEqual("NotFound"); |
| 45 | |
| 46 | yield* stack.destroy(); |
| 47 | }).pipe(logLevel), |
| 48 | { |
| 49 | tags: ["provider:gcp", "provider:gcp:blockchainnodeengine", "live"], |
| 50 | timeout: 90_000, |
| 51 | }, |
| 52 | ); |
| 53 | |
| 54 | test.provider.skipIf(!runLifecycle)( |
| 55 | "create, update, and delete a blockchain node", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | const { project } = yield* GcpEnvironment.current; |
| 59 | yield* stack.destroy(); |
| 60 | |
| 61 | const created = yield* stack.deploy( |
| 62 | Effect.gen(function* () { |
| 63 | return yield* GCP.BlockchainNodeEngine.BlockchainNode("Sepolia", { |
| 64 | location: "us-central1", |
| 65 | blockchainType: "ETHEREUM", |
| 66 | ethereumDetails: { |
| 67 | network: "TESTNET_SEPOLIA", |
| 68 | nodeType: "FULL", |
| 69 | executionClient: "GETH", |
| 70 | consensusClient: "LIGHTHOUSE", |
| 71 | }, |
| 72 | labels: { env: "test" }, |
| 73 | }); |
| 74 | }), |
| 75 | ); |
| 76 | |
| 77 | expect(created.name).toContain("/blockchainNodes/"); |
| 78 | expect(created.blockchainNodeId).toEqual(expect.any(String)); |
| 79 | expect(created.location).toEqual("us-central1"); |
| 80 | expect(created.project).toEqual(project); |
| 81 | expect(created.blockchainType).toEqual("ETHEREUM"); |
| 82 | expect(created.labels).toMatchObject({ env: "test" }); |
| 83 | expect(created.ethereumDetails?.network).toEqual("TESTNET_SEPOLIA"); |
| 84 | |
| 85 | const fetched = yield* bne.getProjectsLocationsBlockchainNodes({ |
| 86 | name: created.name, |
| 87 | }); |
| 88 | expect(fetched.name).toEqual(created.name); |
| 89 | expect(fetched.labels?.env).toEqual("test"); |
| 90 | expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String)); |
| 91 | expect(fetched.ethereumDetails?.network).toEqual("TESTNET_SEPOLIA"); |
| 92 | |
| 93 | const updated = yield* stack.deploy( |
| 94 | Effect.gen(function* () { |
| 95 | return yield* GCP.BlockchainNodeEngine.BlockchainNode("Sepolia", { |
| 96 | blockchainNodeId: created.blockchainNodeId, |
| 97 | location: "us-central1", |
| 98 | blockchainType: "ETHEREUM", |
| 99 | ethereumDetails: { |
| 100 | network: "TESTNET_SEPOLIA", |
| 101 | nodeType: "FULL", |
| 102 | executionClient: "GETH", |
| 103 | consensusClient: "LIGHTHOUSE", |
| 104 | }, |
| 105 | labels: { env: "prod", role: "node" }, |
| 106 | }); |
| 107 | }), |
| 108 | ); |
| 109 | |
| 110 | expect(updated.name).toEqual(created.name); |
| 111 | expect(updated.blockchainNodeId).toEqual(created.blockchainNodeId); |
| 112 | expect(updated.labels).toMatchObject({ env: "prod", role: "node" }); |
| 113 | |
| 114 | const refetched = yield* bne.getProjectsLocationsBlockchainNodes({ |
| 115 | name: created.name, |
| 116 | }); |
| 117 | expect(refetched.labels?.env).toEqual("prod"); |
| 118 | expect(refetched.labels?.role).toEqual("node"); |
| 119 | |
| 120 | yield* stack.destroy(); |
| 121 | |
| 122 | const gone = yield* waitUntilGone(created.name); |
| 123 | expect(gone).toEqual("gone"); |
| 124 | }).pipe(logLevel), |
| 125 | { |
| 126 | tags: ["provider:gcp", "provider:gcp:blockchainnodeengine", "live"], |
| 127 | timeout: 3_600_000, |
| 128 | }, |
| 129 | ); |