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 artifactregistry from "@distilled.cloud/gcp/artifactregistry_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 waitUntilGone = (name: string) => |
| 14 | artifactregistry.getProjectsLocationsRepositoriesRules({ 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 repository download rule", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | const created = yield* stack.deploy( |
| 31 | Effect.gen(function* () { |
| 32 | const images = yield* GCP.ArtifactRegistry.Repository("Images", { |
| 33 | location: "us-central1", |
| 34 | format: "DOCKER", |
| 35 | description: "rule parent", |
| 36 | }); |
| 37 | const rule = yield* GCP.ArtifactRegistry.RepositoriesRule("Deny", { |
| 38 | repository: images.name, |
| 39 | location: "us-central1", |
| 40 | action: "ALLOW", |
| 41 | }); |
| 42 | return { images, rule }; |
| 43 | }), |
| 44 | ); |
| 45 | |
| 46 | expect(created.rule.name).toContain("/rules/"); |
| 47 | expect(created.rule.repository).toEqual(created.images.name); |
| 48 | expect(created.rule.action).toEqual("ALLOW"); |
| 49 | expect(created.rule.operation).toEqual("DOWNLOAD"); |
| 50 | expect(created.rule.location).toEqual("us-central1"); |
| 51 | |
| 52 | const fetched = yield* artifactregistry.getProjectsLocationsRepositoriesRules({ |
| 53 | name: created.rule.name, |
| 54 | }); |
| 55 | expect(fetched.name).toEqual(created.rule.name); |
| 56 | expect(fetched.action).toEqual("ALLOW"); |
| 57 | expect(fetched.condition?.title).toContain("[alchemy "); |
| 58 | |
| 59 | const updated = yield* stack.deploy( |
| 60 | Effect.gen(function* () { |
| 61 | const images = yield* GCP.ArtifactRegistry.Repository("Images", { |
| 62 | repositoryId: created.images.repositoryId, |
| 63 | location: "us-central1", |
| 64 | format: "DOCKER", |
| 65 | description: "rule parent", |
| 66 | }); |
| 67 | const rule = yield* GCP.ArtifactRegistry.RepositoriesRule("Deny", { |
| 68 | repository: images.name, |
| 69 | ruleId: created.rule.ruleId, |
| 70 | location: "us-central1", |
| 71 | action: "DENY", |
| 72 | condition: { expression: "pkg.version.id != '9.9.9'" }, |
| 73 | }); |
| 74 | return { images, rule }; |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | expect(updated.rule.name).toEqual(created.rule.name); |
| 79 | expect(updated.rule.action).toEqual("DENY"); |
| 80 | expect(updated.rule.condition?.expression).toEqual("pkg.version.id != '9.9.9'"); |
| 81 | |
| 82 | const refetched = yield* artifactregistry.getProjectsLocationsRepositoriesRules({ |
| 83 | name: created.rule.name, |
| 84 | }); |
| 85 | expect(refetched.action).toEqual("DENY"); |
| 86 | expect(refetched.condition?.expression).toEqual("pkg.version.id != '9.9.9'"); |
| 87 | |
| 88 | yield* stack.destroy(); |
| 89 | |
| 90 | const gone = yield* waitUntilGone(created.rule.name); |
| 91 | expect(gone).toEqual("gone"); |
| 92 | }).pipe(logLevel), |
| 93 | { |
| 94 | tags: ["provider:gcp", "provider:gcp:artifactregistry", "live"], |
| 95 | timeout: 90_000, |
| 96 | }, |
| 97 | ); |