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 dlp from "@distilled.cloud/gcp/dlp_v2"; |
| 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 location = "us-central1"; |
| 15 | |
| 16 | const inspect = (infoTypes: string[]) => ({ |
| 17 | infoTypes: infoTypes.map((name) => ({ name })), |
| 18 | includeQuote: true, |
| 19 | }); |
| 20 | |
| 21 | const waitUntilGone = (name: string) => |
| 22 | dlp.getProjectsLocationsInspectTemplates({ name }).pipe( |
| 23 | Effect.as("found" as const), |
| 24 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 25 | Effect.repeat({ |
| 26 | schedule: Schedule.spaced("1 second"), |
| 27 | until: (status) => status === "gone", |
| 28 | times: 10, |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | test.provider( |
| 33 | "getProjectsLocationsInspectTemplates on a missing template fails with a typed tag", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const { project } = yield* GcpEnvironment.current; |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const error = yield* Effect.flip( |
| 40 | dlp.getProjectsLocationsInspectTemplates({ |
| 41 | name: `projects/${project}/locations/${location}/inspectTemplates/alchemy-missing`, |
| 42 | }), |
| 43 | ); |
| 44 | expect(error._tag).toEqual("NotFound"); |
| 45 | |
| 46 | yield* stack.destroy(); |
| 47 | }).pipe(logLevel), |
| 48 | { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 }, |
| 49 | ); |
| 50 | |
| 51 | test.provider( |
| 52 | "create, update, replace, and delete a location inspect template", |
| 53 | (stack) => |
| 54 | Effect.gen(function* () { |
| 55 | const { project } = yield* GcpEnvironment.current; |
| 56 | yield* stack.destroy(); |
| 57 | |
| 58 | const created = yield* stack.deploy( |
| 59 | Effect.gen(function* () { |
| 60 | return yield* GCP.DLP.LocationsInspectTemplate("Emails", { |
| 61 | location, |
| 62 | displayName: "emails", |
| 63 | description: "find email addresses", |
| 64 | inspectConfig: inspect(["EMAIL_ADDRESS"]), |
| 65 | }); |
| 66 | }), |
| 67 | ); |
| 68 | |
| 69 | expect(created.templateId).toEqual(expect.any(String)); |
| 70 | expect(created.location).toEqual(location); |
| 71 | expect(created.name).toEqual( |
| 72 | `projects/${project}/locations/${location}/inspectTemplates/${created.templateId}`, |
| 73 | ); |
| 74 | expect(created.project).toEqual(project); |
| 75 | expect(created.displayName).toEqual("emails"); |
| 76 | expect(created.description).toEqual("find email addresses"); |
| 77 | expect(created.allowLimitedAvailabilityInfoTypes).toEqual(false); |
| 78 | |
| 79 | const fetched = yield* dlp.getProjectsLocationsInspectTemplates({ |
| 80 | name: created.name, |
| 81 | }); |
| 82 | expect(fetched.name).toEqual(created.name); |
| 83 | expect(fetched.description).toContain("alchemy-id="); |
| 84 | expect(fetched.description).toContain("find email addresses"); |
| 85 | |
| 86 | const updated = yield* stack.deploy( |
| 87 | Effect.gen(function* () { |
| 88 | return yield* GCP.DLP.LocationsInspectTemplate("Emails", { |
| 89 | templateId: created.templateId, |
| 90 | location, |
| 91 | displayName: "emails and phones", |
| 92 | description: "find emails and phones", |
| 93 | inspectConfig: inspect(["EMAIL_ADDRESS", "PHONE_NUMBER"]), |
| 94 | }); |
| 95 | }), |
| 96 | ); |
| 97 | |
| 98 | expect(updated.name).toEqual(created.name); |
| 99 | expect(updated.displayName).toEqual("emails and phones"); |
| 100 | expect(updated.description).toEqual("find emails and phones"); |
| 101 | |
| 102 | const last = created.templateId.at(-1) ?? "a"; |
| 103 | const nextId = `${created.templateId.slice(0, -1)}${last === "z" ? "0" : "z"}`; |
| 104 | |
| 105 | const replaced = yield* stack.deploy( |
| 106 | Effect.gen(function* () { |
| 107 | return yield* GCP.DLP.LocationsInspectTemplate("Emails", { |
| 108 | templateId: nextId, |
| 109 | location, |
| 110 | displayName: "replaced", |
| 111 | inspectConfig: inspect(["EMAIL_ADDRESS"]), |
| 112 | }); |
| 113 | }), |
| 114 | ); |
| 115 | |
| 116 | expect(replaced.templateId).not.toEqual(created.templateId); |
| 117 | |
| 118 | const previousGone = yield* waitUntilGone(created.name); |
| 119 | expect(previousGone).toEqual("gone"); |
| 120 | |
| 121 | yield* stack.destroy(); |
| 122 | |
| 123 | const gone = yield* waitUntilGone(replaced.name); |
| 124 | expect(gone).toEqual("gone"); |
| 125 | }).pipe(logLevel), |
| 126 | { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 }, |
| 127 | ); |