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 waitUntilGone = (name: string) => |
| 15 | dlp.getProjectsLocationsContentPolicies({ name }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("1 second"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | test.provider( |
| 26 | "getProjectsLocationsContentPolicies on a missing policy fails with a typed tag", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | const { project } = yield* GcpEnvironment.current; |
| 30 | yield* stack.destroy(); |
| 31 | |
| 32 | const error = yield* Effect.flip( |
| 33 | dlp.getProjectsLocationsContentPolicies({ |
| 34 | name: `projects/${project}/locations/us/contentPolicies/alchemy-missing`, |
| 35 | }), |
| 36 | ); |
| 37 | expect(error._tag).toEqual("NotFound"); |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | }).pipe(logLevel), |
| 41 | { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 }, |
| 42 | ); |
| 43 | |
| 44 | test.provider( |
| 45 | "create, update, and delete a content policy", |
| 46 | (stack) => |
| 47 | Effect.gen(function* () { |
| 48 | yield* stack.destroy(); |
| 49 | |
| 50 | const created = yield* stack.deploy( |
| 51 | Effect.gen(function* () { |
| 52 | return yield* GCP.DLP.ContentPolicy("BlockEmail", { |
| 53 | location: "us", |
| 54 | displayName: "email", |
| 55 | inspectConfig: { infoTypes: [{ name: "EMAIL_ADDRESS" }] }, |
| 56 | rules: [ |
| 57 | { |
| 58 | conditions: [ |
| 59 | { |
| 60 | infoTypeCondition: { |
| 61 | infoTypes: { infoTypeNames: ["EMAIL_ADDRESS"] }, |
| 62 | }, |
| 63 | }, |
| 64 | ], |
| 65 | action: { returnVerdict: "BLOCK" }, |
| 66 | }, |
| 67 | ], |
| 68 | defaultAction: { returnVerdict: "ALLOW" }, |
| 69 | }); |
| 70 | }), |
| 71 | ); |
| 72 | |
| 73 | expect(created.contentPolicyId).toEqual(expect.any(String)); |
| 74 | expect(created.location).toEqual("us"); |
| 75 | expect(created.name).toContain("/contentPolicies/"); |
| 76 | expect(created.displayName).toEqual("email"); |
| 77 | expect(created.rules.length).toBeGreaterThan(0); |
| 78 | |
| 79 | const fetched = yield* dlp.getProjectsLocationsContentPolicies({ |
| 80 | name: created.name, |
| 81 | }); |
| 82 | expect(fetched.name).toEqual(created.name); |
| 83 | expect(fetched.displayName).toContain("alchemy-"); |
| 84 | |
| 85 | const updated = yield* stack.deploy( |
| 86 | Effect.gen(function* () { |
| 87 | return yield* GCP.DLP.ContentPolicy("BlockEmail", { |
| 88 | contentPolicyId: created.contentPolicyId, |
| 89 | location: "us", |
| 90 | displayName: "email2", |
| 91 | inspectConfig: { infoTypes: [{ name: "EMAIL_ADDRESS" }] }, |
| 92 | rules: [ |
| 93 | { |
| 94 | conditions: [ |
| 95 | { |
| 96 | infoTypeCondition: { |
| 97 | infoTypes: { infoTypeNames: ["EMAIL_ADDRESS"] }, |
| 98 | }, |
| 99 | }, |
| 100 | ], |
| 101 | action: { returnVerdict: "BLOCK" }, |
| 102 | }, |
| 103 | ], |
| 104 | defaultAction: { returnVerdict: "ALLOW" }, |
| 105 | }); |
| 106 | }), |
| 107 | ); |
| 108 | |
| 109 | expect(updated.name).toEqual(created.name); |
| 110 | expect(updated.displayName).toEqual("email2"); |
| 111 | |
| 112 | yield* stack.destroy(); |
| 113 | |
| 114 | const gone = yield* waitUntilGone(created.name); |
| 115 | expect(gone).toEqual("gone"); |
| 116 | }).pipe(logLevel), |
| 117 | { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 }, |
| 118 | ); |