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 ssm from "@distilled.cloud/gcp/securesourcemanager_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import { currentProject, logLevel, missingRepoOf, runLifecycle } from "./common.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const waitUntilGone = (name: string) => |
| 12 | ssm.getProjectsLocationsRepositoriesHooks({ name }).pipe( |
| 13 | Effect.as("found" as const), |
| 14 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 15 | Effect.repeat({ |
| 16 | schedule: Schedule.spaced("2 seconds"), |
| 17 | until: (status) => status === "gone", |
| 18 | times: 10, |
| 19 | }), |
| 20 | ); |
| 21 | |
| 22 | test.provider( |
| 23 | "getProjectsLocationsRepositoriesHooks on a missing hook fails with a typed tag", |
| 24 | (stack) => |
| 25 | Effect.gen(function* () { |
| 26 | const project = yield* currentProject; |
| 27 | const missingRepo = missingRepoOf(project); |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | const error = yield* Effect.flip( |
| 31 | ssm.getProjectsLocationsRepositoriesHooks({ |
| 32 | name: `${missingRepo}/hooks/alchemy-missing-hook`, |
| 33 | }), |
| 34 | ); |
| 35 | expect(error._tag).toEqual("NotFound"); |
| 36 | |
| 37 | yield* stack.destroy(); |
| 38 | }).pipe(logLevel), |
| 39 | { |
| 40 | tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"], |
| 41 | timeout: 90_000, |
| 42 | }, |
| 43 | ); |
| 44 | |
| 45 | test.provider( |
| 46 | "create against a missing repository is rejected with a typed tag", |
| 47 | (stack) => |
| 48 | Effect.gen(function* () { |
| 49 | const project = yield* currentProject; |
| 50 | const missingRepo = missingRepoOf(project); |
| 51 | yield* stack.destroy(); |
| 52 | |
| 53 | const error = yield* Effect.flip( |
| 54 | stack.deploy( |
| 55 | Effect.gen(function* () { |
| 56 | return yield* GCP.SecureSourceManager.RepositoriesHook("Notify", { |
| 57 | repository: missingRepo, |
| 58 | targetUri: "https://example.com/hooks/ssm", |
| 59 | events: ["PUSH"], |
| 60 | }); |
| 61 | }), |
| 62 | ), |
| 63 | ); |
| 64 | expect(error._tag).toEqual("NotFound"); |
| 65 | |
| 66 | yield* stack.destroy(); |
| 67 | }).pipe(logLevel), |
| 68 | { |
| 69 | tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"], |
| 70 | timeout: 90_000, |
| 71 | }, |
| 72 | ); |
| 73 | |
| 74 | test.provider.skipIf(!runLifecycle)( |
| 75 | "create, update, and delete a hook", |
| 76 | (stack) => |
| 77 | Effect.gen(function* () { |
| 78 | const project = yield* currentProject; |
| 79 | const missingRepo = missingRepoOf(project); |
| 80 | yield* stack.destroy(); |
| 81 | |
| 82 | const created = yield* stack.deploy( |
| 83 | Effect.gen(function* () { |
| 84 | return yield* GCP.SecureSourceManager.RepositoriesHook("Notify", { |
| 85 | repository: process.env.GCP_TEST_SECURE_SOURCE_MANAGER_REPO ?? missingRepo, |
| 86 | targetUri: "https://example.com/hooks/ssm", |
| 87 | events: ["PUSH"], |
| 88 | }); |
| 89 | }), |
| 90 | ); |
| 91 | |
| 92 | expect(created.name).toContain("/hooks/"); |
| 93 | expect(created.targetUri).toEqual("https://example.com/hooks/ssm"); |
| 94 | expect(created.events).toContain("PUSH"); |
| 95 | expect(created.disabled).toEqual(false); |
| 96 | |
| 97 | const fetched = yield* ssm.getProjectsLocationsRepositoriesHooks({ |
| 98 | name: created.name, |
| 99 | }); |
| 100 | expect(fetched.name).toEqual(created.name); |
| 101 | expect(fetched.targetUri).toEqual("https://example.com/hooks/ssm"); |
| 102 | |
| 103 | const updated = yield* stack.deploy( |
| 104 | Effect.gen(function* () { |
| 105 | return yield* GCP.SecureSourceManager.RepositoriesHook("Notify", { |
| 106 | repository: created.repository, |
| 107 | hookId: created.hookId, |
| 108 | targetUri: "https://example.com/hooks/ssm-v2", |
| 109 | events: ["PUSH", "PULL_REQUEST"], |
| 110 | disabled: true, |
| 111 | }); |
| 112 | }), |
| 113 | ); |
| 114 | |
| 115 | expect(updated.hookId).toEqual(created.hookId); |
| 116 | expect(updated.targetUri).toEqual("https://example.com/hooks/ssm-v2"); |
| 117 | expect(updated.disabled).toEqual(true); |
| 118 | expect(updated.events).toEqual(["PULL_REQUEST", "PUSH"]); |
| 119 | |
| 120 | yield* stack.destroy(); |
| 121 | |
| 122 | const gone = yield* waitUntilGone(created.name); |
| 123 | expect(gone).toEqual("gone"); |
| 124 | }).pipe(logLevel), |
| 125 | { |
| 126 | tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"], |
| 127 | timeout: 120_000, |
| 128 | }, |
| 129 | ); |