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 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 13 | |
| 14 | // A sole-tenant node bills for the whole host (several dollars per hour). |
| 15 | // Set GCP_TEST_COMPUTE_NODE=1 to opt in. |
| 16 | const runLifecycle = !!process.env.GCP_TEST_COMPUTE_NODE && !process.env.FAST; |
| 17 | |
| 18 | const zone = "us-central1-a"; |
| 19 | const region = "us-central1"; |
| 20 | |
| 21 | const waitUntilGone = (nodeGroup: string) => |
| 22 | GcpEnvironment.current.pipe( |
| 23 | Effect.flatMap(({ project }) => |
| 24 | compute.getNodeGroups({ project, zone, nodeGroup }).pipe( |
| 25 | Effect.as("found" as const), |
| 26 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 27 | Effect.repeat({ |
| 28 | schedule: Schedule.spaced("1 second"), |
| 29 | until: (status) => status === "gone", |
| 30 | times: 10, |
| 31 | }), |
| 32 | ), |
| 33 | ), |
| 34 | ); |
| 35 | |
| 36 | test.provider( |
| 37 | "getNodeGroups on a missing group fails with NotFound", |
| 38 | (stack) => |
| 39 | Effect.gen(function* () { |
| 40 | const { project } = yield* GcpEnvironment.current; |
| 41 | yield* stack.destroy(); |
| 42 | |
| 43 | const error = yield* Effect.flip( |
| 44 | compute.getNodeGroups({ |
| 45 | project, |
| 46 | zone, |
| 47 | nodeGroup: "alchemy-missing-ng", |
| 48 | }), |
| 49 | ); |
| 50 | expect(error._tag).toBe("NotFound"); |
| 51 | |
| 52 | yield* stack.destroy(); |
| 53 | }).pipe(logLevel), |
| 54 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 55 | ); |
| 56 | |
| 57 | test.provider( |
| 58 | "insertNodeGroups with a malformed node template fails with BadRequest", |
| 59 | () => |
| 60 | Effect.gen(function* () { |
| 61 | const { project } = yield* GcpEnvironment.current; |
| 62 | const error = yield* Effect.flip( |
| 63 | compute.insertNodeGroups({ |
| 64 | project, |
| 65 | zone, |
| 66 | initialNodeCount: 0, |
| 67 | body: { |
| 68 | name: "alchemy-ng-probe", |
| 69 | description: "alchemy entitlement probe", |
| 70 | nodeTemplate: "does-not-exist", |
| 71 | }, |
| 72 | }), |
| 73 | ); |
| 74 | expect(error._tag).toEqual("BadRequest"); |
| 75 | }).pipe(logLevel), |
| 76 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 60_000 }, |
| 77 | ); |
| 78 | |
| 79 | test.provider.skipIf(!runLifecycle)( |
| 80 | "create, update, and delete a node group", |
| 81 | (stack) => |
| 82 | Effect.gen(function* () { |
| 83 | yield* stack.destroy(); |
| 84 | |
| 85 | const created = yield* stack.deploy( |
| 86 | Effect.gen(function* () { |
| 87 | const template = yield* GCP.Compute.NodeTemplate("SoleTenant", { |
| 88 | region, |
| 89 | nodeType: "n2-node-80-640", |
| 90 | description: "prod sole tenant", |
| 91 | }); |
| 92 | const group = yield* GCP.Compute.NodeGroup("SoleTenant", { |
| 93 | zone, |
| 94 | nodeTemplate: template.nodeTemplateName, |
| 95 | initialNodeCount: 0, |
| 96 | description: "prod sole tenant", |
| 97 | }); |
| 98 | return { template, group }; |
| 99 | }), |
| 100 | ); |
| 101 | |
| 102 | expect(created.group.nodeGroupName).toEqual(expect.any(String)); |
| 103 | expect(created.group.zone).toEqual(zone); |
| 104 | expect(created.group.description).toEqual("prod sole tenant"); |
| 105 | |
| 106 | const fetched = yield* compute.getNodeGroups({ |
| 107 | project: created.group.project, |
| 108 | zone, |
| 109 | nodeGroup: created.group.nodeGroupName, |
| 110 | }); |
| 111 | expect(fetched.name).toEqual(created.group.nodeGroupName); |
| 112 | expect(fetched.description).toContain("[alchemy "); |
| 113 | |
| 114 | const updated = yield* stack.deploy( |
| 115 | Effect.gen(function* () { |
| 116 | const template = yield* GCP.Compute.NodeTemplate("SoleTenant", { |
| 117 | nodeTemplateName: created.template.nodeTemplateName, |
| 118 | region, |
| 119 | nodeType: "n2-node-80-640", |
| 120 | description: "prod sole tenant", |
| 121 | }); |
| 122 | return yield* GCP.Compute.NodeGroup("SoleTenant", { |
| 123 | nodeGroupName: created.group.nodeGroupName, |
| 124 | zone, |
| 125 | nodeTemplate: template.nodeTemplateName, |
| 126 | initialNodeCount: 0, |
| 127 | description: "updated sole tenant", |
| 128 | }); |
| 129 | }), |
| 130 | ); |
| 131 | expect(updated.description).toEqual("updated sole tenant"); |
| 132 | |
| 133 | yield* stack.destroy(); |
| 134 | const gone = yield* waitUntilGone(created.group.nodeGroupName); |
| 135 | expect(gone).toEqual("gone"); |
| 136 | }).pipe(logLevel), |
| 137 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 }, |
| 138 | ); |