The best way to control Claude Code, Codex and more from any computer or phone
| 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 vault from "@distilled.cloud/gcp/vault_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import { logLevel, runLifecycle } from "./common.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const waitUntilGone = (matterId: string) => |
| 12 | vault.getMatters({ matterId }).pipe( |
| 13 | Effect.map((matter) => (matter.state === "DELETED" ? ("gone" as const) : ("found" as const))), |
| 14 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 15 | Effect.repeat({ |
| 16 | schedule: Schedule.spaced("1 second"), |
| 17 | until: (status) => status === "gone", |
| 18 | times: 10, |
| 19 | }), |
| 20 | ); |
| 21 | |
| 22 | test.provider( |
| 23 | "getMatters on a missing matter fails with a typed tag", |
| 24 | (stack) => |
| 25 | Effect.gen(function* () { |
| 26 | yield* stack.destroy(); |
| 27 | |
| 28 | const error = yield* Effect.flip(vault.getMatters({ matterId: "alchemy-missing-matter" })); |
| 29 | expect(error._tag).toEqual("VaultScopeInsufficient"); |
| 30 | |
| 31 | yield* stack.destroy(); |
| 32 | }).pipe(logLevel), |
| 33 | { tags: ["provider:gcp", "provider:gcp:vault", "live"], timeout: 90_000 }, |
| 34 | ); |
| 35 | |
| 36 | test.provider.skipIf(!!process.env.GCP_TEST_VAULT)( |
| 37 | "createMatters without the Vault OAuth scope fails with VaultScopeInsufficient", |
| 38 | (stack) => |
| 39 | Effect.gen(function* () { |
| 40 | yield* stack.destroy(); |
| 41 | |
| 42 | const error = yield* Effect.flip( |
| 43 | vault.createMatters({ |
| 44 | body: { |
| 45 | name: "Alchemy Vault Probe", |
| 46 | description: "alchemy probe", |
| 47 | }, |
| 48 | }), |
| 49 | ); |
| 50 | expect(error._tag).toEqual("VaultScopeInsufficient"); |
| 51 | |
| 52 | yield* stack.destroy(); |
| 53 | }).pipe(logLevel), |
| 54 | { tags: ["provider:gcp", "provider:gcp:vault", "live"], timeout: 90_000 }, |
| 55 | ); |
| 56 | |
| 57 | test.provider.skipIf(!runLifecycle)( |
| 58 | "create, update, and delete a matter", |
| 59 | (stack) => |
| 60 | Effect.gen(function* () { |
| 61 | yield* stack.destroy(); |
| 62 | |
| 63 | const created = yield* stack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | return yield* GCP.Vault.Matter("Case", { |
| 66 | name: "Acme v Contoso", |
| 67 | description: "litigation hold", |
| 68 | }); |
| 69 | }), |
| 70 | ); |
| 71 | |
| 72 | expect(created.matterId.length).toBeGreaterThan(0); |
| 73 | expect(created.name).toEqual("Acme v Contoso"); |
| 74 | expect(created.description).toEqual("litigation hold"); |
| 75 | expect(created.state).toEqual("OPEN"); |
| 76 | |
| 77 | const fetched = yield* vault.getMatters({ |
| 78 | matterId: created.matterId, |
| 79 | view: "FULL", |
| 80 | }); |
| 81 | expect(fetched.matterId).toEqual(created.matterId); |
| 82 | expect(fetched.description).toContain("[alchemy "); |
| 83 | |
| 84 | const updated = yield* stack.deploy( |
| 85 | Effect.gen(function* () { |
| 86 | return yield* GCP.Vault.Matter("Case", { |
| 87 | matterId: created.matterId, |
| 88 | name: "Acme v Contoso 2026", |
| 89 | description: "litigation hold extended", |
| 90 | }); |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | expect(updated.matterId).toEqual(created.matterId); |
| 95 | expect(updated.name).toEqual("Acme v Contoso 2026"); |
| 96 | expect(updated.description).toEqual("litigation hold extended"); |
| 97 | |
| 98 | yield* stack.destroy(); |
| 99 | |
| 100 | const gone = yield* waitUntilGone(created.matterId); |
| 101 | expect(gone).toEqual("gone"); |
| 102 | }).pipe(logLevel), |
| 103 | { tags: ["provider:gcp", "provider:gcp:vault", "live"], timeout: 90_000 }, |
| 104 | ); |