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 resourcemanager from "@distilled.cloud/gcp/cloudresourcemanager_v3"; |
| 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 | const waitUntilGone = (name: string) => |
| 15 | resourcemanager.getLiens({ name }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("1 second"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | test.provider( |
| 26 | "getLiens on a missing lien fails with NotFound", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | const { project } = yield* GcpEnvironment.current; |
| 30 | yield* stack.destroy(); |
| 31 | |
| 32 | // Lien names are `liens/p{projectNumber}-l{uuid}`. |
| 33 | const resource = yield* resourcemanager.getProjects({ |
| 34 | name: `projects/${project}`, |
| 35 | }); |
| 36 | const projectNumber = (resource.name ?? "").split("/").pop(); |
| 37 | const error = yield* Effect.flip( |
| 38 | resourcemanager.getLiens({ |
| 39 | name: `liens/p${projectNumber}-l00000000-0000-0000-0000-000000000000`, |
| 40 | }), |
| 41 | ); |
| 42 | expect(error._tag).toEqual("NotFound"); |
| 43 | |
| 44 | yield* stack.destroy(); |
| 45 | }).pipe(logLevel), |
| 46 | { |
| 47 | tags: ["provider:gcp", "provider:gcp:resourcemanager", "live"], |
| 48 | timeout: 90_000, |
| 49 | }, |
| 50 | ); |
| 51 | |
| 52 | test.provider( |
| 53 | "create, replace, and delete a lien", |
| 54 | (stack) => |
| 55 | Effect.gen(function* () { |
| 56 | yield* stack.destroy(); |
| 57 | |
| 58 | const created = yield* stack.deploy( |
| 59 | Effect.gen(function* () { |
| 60 | return yield* GCP.ResourceManager.Lien("Hold", { |
| 61 | reason: "production API key", |
| 62 | }); |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(created.name).toMatch(/^liens\//); |
| 67 | expect(created.parent).toContain("projects/"); |
| 68 | expect(created.origin).toEqual("alchemy.effect"); |
| 69 | expect(created.reason).toEqual("production API key"); |
| 70 | expect(created.restrictions).toContain("resourcemanager.projects.delete"); |
| 71 | |
| 72 | const fetched = yield* resourcemanager.getLiens({ |
| 73 | name: created.name, |
| 74 | }); |
| 75 | expect(fetched.name).toEqual(created.name); |
| 76 | expect(fetched.reason).toEqual("production API key"); |
| 77 | |
| 78 | const replaced = yield* stack.deploy( |
| 79 | Effect.gen(function* () { |
| 80 | return yield* GCP.ResourceManager.Lien("Hold", { |
| 81 | parent: created.parent, |
| 82 | origin: created.origin, |
| 83 | reason: "holds billing export", |
| 84 | restrictions: created.restrictions, |
| 85 | }); |
| 86 | }), |
| 87 | ); |
| 88 | |
| 89 | expect(replaced.name).not.toEqual(created.name); |
| 90 | expect(replaced.reason).toEqual("holds billing export"); |
| 91 | expect(replaced.parent).toEqual(created.parent); |
| 92 | |
| 93 | const fetchedReplace = yield* resourcemanager.getLiens({ |
| 94 | name: replaced.name, |
| 95 | }); |
| 96 | expect(fetchedReplace.reason).toEqual("holds billing export"); |
| 97 | |
| 98 | const oldGone = yield* waitUntilGone(created.name); |
| 99 | expect(oldGone).toEqual("gone"); |
| 100 | |
| 101 | yield* stack.destroy(); |
| 102 | |
| 103 | const gone = yield* waitUntilGone(replaced.name); |
| 104 | expect(gone).toEqual("gone"); |
| 105 | }).pipe(logLevel), |
| 106 | { |
| 107 | tags: ["provider:gcp", "provider:gcp:resourcemanager", "live"], |
| 108 | timeout: 90_000, |
| 109 | }, |
| 110 | ); |