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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as compute from "@distilled.cloud/gcp/compute_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 12 | |
| 13 | const zone = "us-central1-a"; |
| 14 | |
| 15 | const waitUntilGone = (project: string, zoneName: string, instantSnapshot: string) => |
| 16 | compute.getInstantSnapshots({ project, zone: zoneName, instantSnapshot }).pipe( |
| 17 | Effect.as("found" as const), |
| 18 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 19 | Effect.repeat({ |
| 20 | schedule: Schedule.spaced("1 second"), |
| 21 | until: (status) => status === "gone", |
| 22 | times: 10, |
| 23 | }), |
| 24 | ); |
| 25 | |
| 26 | test.provider.skipIf(!!process.env.FAST)( |
| 27 | "create, update labels, replace, and delete an instant snapshot", |
| 28 | (stack) => |
| 29 | Effect.gen(function* () { |
| 30 | yield* stack.destroy(); |
| 31 | |
| 32 | const created = yield* stack.deploy( |
| 33 | Effect.gen(function* () { |
| 34 | const disk = yield* GCP.Compute.Disk("Data", { |
| 35 | zone, |
| 36 | type: "pd-balanced", |
| 37 | sizeGb: 10, |
| 38 | }); |
| 39 | const snapshot = yield* GCP.Compute.InstantSnapshot("Checkpoint", { |
| 40 | zone, |
| 41 | sourceDisk: disk.selfLink.as<string>(), |
| 42 | description: "first checkpoint", |
| 43 | labels: { env: "test" }, |
| 44 | }); |
| 45 | return { disk, snapshot }; |
| 46 | }), |
| 47 | ); |
| 48 | |
| 49 | expect(created.snapshot.instantSnapshotName).toEqual(expect.any(String)); |
| 50 | expect(created.snapshot.zone).toEqual(zone); |
| 51 | expect(created.snapshot.status).toEqual("READY"); |
| 52 | expect(created.snapshot.labels).toMatchObject({ env: "test" }); |
| 53 | expect(created.snapshot.description).toEqual("first checkpoint"); |
| 54 | |
| 55 | const fetched = yield* compute.getInstantSnapshots({ |
| 56 | project: created.snapshot.project, |
| 57 | zone, |
| 58 | instantSnapshot: created.snapshot.instantSnapshotName, |
| 59 | }); |
| 60 | expect(fetched.name).toEqual(created.snapshot.instantSnapshotName); |
| 61 | expect(fetched.labels?.env).toEqual("test"); |
| 62 | expect(fetched.status).toEqual("READY"); |
| 63 | |
| 64 | const updated = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | const disk = yield* GCP.Compute.Disk("Data", { |
| 67 | diskName: created.disk.diskName, |
| 68 | zone, |
| 69 | type: "pd-balanced", |
| 70 | sizeGb: 10, |
| 71 | }); |
| 72 | const snapshot = yield* GCP.Compute.InstantSnapshot("Checkpoint", { |
| 73 | instantSnapshotName: created.snapshot.instantSnapshotName, |
| 74 | zone, |
| 75 | sourceDisk: disk.selfLink.as<string>(), |
| 76 | description: "first checkpoint", |
| 77 | labels: { env: "prod", role: "data" }, |
| 78 | }); |
| 79 | return { disk, snapshot }; |
| 80 | }), |
| 81 | ); |
| 82 | |
| 83 | expect(updated.snapshot.instantSnapshotName).toEqual(created.snapshot.instantSnapshotName); |
| 84 | expect(updated.snapshot.labels).toMatchObject({ |
| 85 | env: "prod", |
| 86 | role: "data", |
| 87 | }); |
| 88 | |
| 89 | const nextName = `r${created.snapshot.instantSnapshotName}`.slice(0, 63).replace(/-+$/, "x"); |
| 90 | const replaced = yield* stack.deploy( |
| 91 | Effect.gen(function* () { |
| 92 | const disk = yield* GCP.Compute.Disk("Data", { |
| 93 | diskName: created.disk.diskName, |
| 94 | zone, |
| 95 | type: "pd-balanced", |
| 96 | sizeGb: 10, |
| 97 | }); |
| 98 | const snapshot = yield* GCP.Compute.InstantSnapshot("Checkpoint", { |
| 99 | instantSnapshotName: nextName, |
| 100 | zone, |
| 101 | sourceDisk: disk.selfLink.as<string>(), |
| 102 | description: "replaced checkpoint", |
| 103 | }); |
| 104 | return { disk, snapshot }; |
| 105 | }), |
| 106 | ); |
| 107 | |
| 108 | expect(replaced.snapshot.instantSnapshotName).toEqual(nextName); |
| 109 | expect(replaced.snapshot.description).toEqual("replaced checkpoint"); |
| 110 | |
| 111 | const oldGone = yield* waitUntilGone( |
| 112 | created.snapshot.project, |
| 113 | zone, |
| 114 | created.snapshot.instantSnapshotName, |
| 115 | ); |
| 116 | expect(oldGone).toEqual("gone"); |
| 117 | |
| 118 | yield* stack.destroy(); |
| 119 | |
| 120 | const gone = yield* waitUntilGone( |
| 121 | replaced.snapshot.project, |
| 122 | zone, |
| 123 | replaced.snapshot.instantSnapshotName, |
| 124 | ); |
| 125 | expect(gone).toEqual("gone"); |
| 126 | }).pipe(logLevel), |
| 127 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 180_000 }, |
| 128 | ); |