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 monitoring from "@distilled.cloud/gcp/monitoring_v3"; |
| 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 waitUntilGone = (name: string) => |
| 14 | monitoring.getProjectsGroups({ name }).pipe( |
| 15 | Effect.as("found" as const), |
| 16 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 17 | Effect.repeat({ |
| 18 | schedule: Schedule.spaced("1 second"), |
| 19 | until: (status) => status === "gone", |
| 20 | times: 10, |
| 21 | }), |
| 22 | ); |
| 23 | |
| 24 | test.provider( |
| 25 | "create, update, and delete a monitoring group", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | const created = yield* stack.deploy( |
| 31 | Effect.gen(function* () { |
| 32 | return yield* GCP.Monitoring.Group("Prod", { |
| 33 | displayName: "production instances", |
| 34 | filter: 'resource.metadata.region="us-central1"', |
| 35 | }); |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | expect(created.name).toContain("/groups/"); |
| 40 | expect(created.groupId).toEqual(expect.any(String)); |
| 41 | expect(created.displayName).toEqual("production instances"); |
| 42 | expect(created.filter).toEqual('resource.metadata.region="us-central1"'); |
| 43 | expect(created.isCluster).toEqual(false); |
| 44 | expect(created.parentName).toEqual(""); |
| 45 | |
| 46 | const fetched = yield* monitoring.getProjectsGroups({ |
| 47 | name: created.name, |
| 48 | }); |
| 49 | expect(fetched.name).toEqual(created.name); |
| 50 | expect(fetched.filter).toEqual('resource.metadata.region="us-central1"'); |
| 51 | expect(fetched.displayName).toContain("alchemy-id="); |
| 52 | expect(fetched.displayName).toContain("production instances"); |
| 53 | |
| 54 | const updated = yield* stack.deploy( |
| 55 | Effect.gen(function* () { |
| 56 | return yield* GCP.Monitoring.Group("Prod", { |
| 57 | displayName: "east production", |
| 58 | filter: 'resource.metadata.region="us-east1"', |
| 59 | isCluster: true, |
| 60 | }); |
| 61 | }), |
| 62 | ); |
| 63 | |
| 64 | expect(updated.name).toEqual(created.name); |
| 65 | expect(updated.displayName).toEqual("east production"); |
| 66 | expect(updated.filter).toEqual('resource.metadata.region="us-east1"'); |
| 67 | expect(updated.isCluster).toEqual(true); |
| 68 | |
| 69 | const fetchedUpdate = yield* monitoring.getProjectsGroups({ |
| 70 | name: updated.name, |
| 71 | }); |
| 72 | expect(fetchedUpdate.filter).toEqual('resource.metadata.region="us-east1"'); |
| 73 | expect(fetchedUpdate.isCluster).toEqual(true); |
| 74 | expect(fetchedUpdate.displayName).toContain("east production"); |
| 75 | |
| 76 | yield* stack.destroy(); |
| 77 | |
| 78 | const gone = yield* waitUntilGone(created.name); |
| 79 | expect(gone).toEqual("gone"); |
| 80 | }).pipe(logLevel), |
| 81 | { |
| 82 | tags: ["provider:gcp", "provider:gcp:monitoring", "live"], |
| 83 | timeout: 90_000, |
| 84 | }, |
| 85 | ); |