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 dlp from "@distilled.cloud/gcp/dlp_v2"; |
| 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 | // Organization-scoped: set GOOGLE_ORGANIZATION_ID when the credentials |
| 12 | // administer the organization (the testing service account does not). |
| 13 | const organizationId = process.env.GOOGLE_ORGANIZATION_ID?.trim().replace(/^organizations\//, ""); |
| 14 | const organization = `organizations/${organizationId}`; |
| 15 | |
| 16 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 17 | |
| 18 | const waitUntilGone = (name: string) => |
| 19 | dlp.getOrganizationsInspectTemplates({ name }).pipe( |
| 20 | Effect.as("found" as const), |
| 21 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 22 | Effect.repeat({ |
| 23 | schedule: Schedule.spaced("1 second"), |
| 24 | until: (status) => status === "gone", |
| 25 | times: 10, |
| 26 | }), |
| 27 | ); |
| 28 | |
| 29 | test.provider.skipIf(!organizationId)( |
| 30 | "getOrganizationsInspectTemplates on a missing template fails with a typed tag", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const error = yield* Effect.flip( |
| 36 | dlp.getOrganizationsInspectTemplates({ |
| 37 | name: `${organization}/inspectTemplates/alchemy-missing`, |
| 38 | }), |
| 39 | ); |
| 40 | expect(error._tag).toEqual("NotFound"); |
| 41 | |
| 42 | yield* stack.destroy(); |
| 43 | }).pipe(logLevel), |
| 44 | { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 }, |
| 45 | ); |
| 46 | |
| 47 | test.provider.skipIf(!organizationId)( |
| 48 | "create, update, and delete an organization inspect template", |
| 49 | (stack) => |
| 50 | Effect.gen(function* () { |
| 51 | yield* stack.destroy(); |
| 52 | |
| 53 | const created = yield* stack.deploy( |
| 54 | Effect.gen(function* () { |
| 55 | return yield* GCP.DLP.OrganizationsInspectTemplate("Emails", { |
| 56 | organization, |
| 57 | displayName: "emails", |
| 58 | description: "detect emails", |
| 59 | inspectConfig: { |
| 60 | infoTypes: [{ name: "EMAIL_ADDRESS" }], |
| 61 | includeQuote: true, |
| 62 | }, |
| 63 | }); |
| 64 | }), |
| 65 | ); |
| 66 | |
| 67 | expect(created.templateId).toEqual(expect.any(String)); |
| 68 | expect(created.name).toEqual(`${organization}/inspectTemplates/${created.templateId}`); |
| 69 | expect(created.description).toEqual("detect emails"); |
| 70 | |
| 71 | const fetched = yield* dlp.getOrganizationsInspectTemplates({ |
| 72 | name: created.name, |
| 73 | }); |
| 74 | expect(fetched.name).toEqual(created.name); |
| 75 | expect(fetched.description).toContain("alchemy-id="); |
| 76 | expect(fetched.inspectConfig?.includeQuote).toEqual(true); |
| 77 | |
| 78 | const updated = yield* stack.deploy( |
| 79 | Effect.gen(function* () { |
| 80 | return yield* GCP.DLP.OrganizationsInspectTemplate("Emails", { |
| 81 | organization, |
| 82 | templateId: created.templateId, |
| 83 | displayName: "emails-v2", |
| 84 | description: "detect emails and phones", |
| 85 | inspectConfig: { |
| 86 | infoTypes: [{ name: "EMAIL_ADDRESS" }, { name: "PHONE_NUMBER" }], |
| 87 | includeQuote: false, |
| 88 | }, |
| 89 | }); |
| 90 | }), |
| 91 | ); |
| 92 | |
| 93 | expect(updated.name).toEqual(created.name); |
| 94 | expect(updated.displayName).toEqual("emails-v2"); |
| 95 | expect(updated.description).toEqual("detect emails and phones"); |
| 96 | |
| 97 | yield* stack.destroy(); |
| 98 | |
| 99 | const gone = yield* waitUntilGone(created.name); |
| 100 | expect(gone).toEqual("gone"); |
| 101 | }).pipe(logLevel), |
| 102 | { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 }, |
| 103 | ); |