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 region = "us-central1"; |
| 14 | |
| 15 | const waitUntilGone = (project: string, regionName: string, name: string) => |
| 16 | compute |
| 17 | .getRegionBackendBuckets({ |
| 18 | project, |
| 19 | region: regionName, |
| 20 | backendBucket: name, |
| 21 | }) |
| 22 | .pipe( |
| 23 | Effect.as("found" as const), |
| 24 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 25 | Effect.repeat({ |
| 26 | schedule: Schedule.spaced("1 second"), |
| 27 | until: (status) => status === "gone", |
| 28 | times: 10, |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | test.provider( |
| 33 | "create, update, and delete a region backend bucket", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | yield* stack.destroy(); |
| 37 | |
| 38 | const created = yield* stack.deploy( |
| 39 | Effect.gen(function* () { |
| 40 | const assets = yield* GCP.Storage.Bucket("Assets", { |
| 41 | location: "US-CENTRAL1", |
| 42 | forceDestroy: true, |
| 43 | }); |
| 44 | return yield* GCP.Compute.RegionBackendBucket("Cdn", { |
| 45 | region, |
| 46 | bucketName: assets.bucketName, |
| 47 | description: "static assets", |
| 48 | }); |
| 49 | }), |
| 50 | ); |
| 51 | |
| 52 | expect(created.name).toEqual(expect.any(String)); |
| 53 | expect(created.region).toEqual(region); |
| 54 | expect(created.bucketName).toEqual(expect.any(String)); |
| 55 | expect(created.description).toEqual("static assets"); |
| 56 | expect(created.enableCdn).toEqual(false); |
| 57 | |
| 58 | const fetched = yield* compute.getRegionBackendBuckets({ |
| 59 | project: created.project, |
| 60 | region, |
| 61 | backendBucket: created.name, |
| 62 | }); |
| 63 | expect(fetched.name).toEqual(created.name); |
| 64 | expect(fetched.bucketName).toEqual(created.bucketName); |
| 65 | expect(fetched.description).toContain("alchemy-id="); |
| 66 | expect(fetched.description).toContain("static assets"); |
| 67 | |
| 68 | const updated = yield* stack.deploy( |
| 69 | Effect.gen(function* () { |
| 70 | const assets = yield* GCP.Storage.Bucket("Assets", { |
| 71 | bucketName: created.bucketName, |
| 72 | location: "US-CENTRAL1", |
| 73 | forceDestroy: true, |
| 74 | }); |
| 75 | return yield* GCP.Compute.RegionBackendBucket("Cdn", { |
| 76 | name: created.name, |
| 77 | region, |
| 78 | bucketName: assets.bucketName, |
| 79 | description: "cdn origin", |
| 80 | }); |
| 81 | }), |
| 82 | ); |
| 83 | |
| 84 | expect(updated.name).toEqual(created.name); |
| 85 | expect(updated.description).toEqual("cdn origin"); |
| 86 | expect(updated.enableCdn).toEqual(false); |
| 87 | |
| 88 | const refetched = yield* compute.getRegionBackendBuckets({ |
| 89 | project: updated.project, |
| 90 | region, |
| 91 | backendBucket: updated.name, |
| 92 | }); |
| 93 | expect(refetched.enableCdn).toEqual(false); |
| 94 | expect(refetched.description).toContain("cdn origin"); |
| 95 | |
| 96 | yield* stack.destroy(); |
| 97 | |
| 98 | const gone = yield* waitUntilGone(created.project, region, created.name); |
| 99 | expect(gone).toEqual("gone"); |
| 100 | }).pipe(logLevel), |
| 101 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 }, |
| 102 | ); |