@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 109 lines 3.73 KB
Raw
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 redact = (infoTypes: string[]) => ({
15 infoTypeTransformations: {
16 transformations: [
17 {
18 infoTypes: infoTypes.map((name) => ({ name })),
19 primitiveTransformation: { replaceWithInfoTypeConfig: {} },
20 },
21 ],
22 },
23 });
24
25 const waitUntilGone = (name: string) =>
26 dlp.getProjectsLocationsDeidentifyTemplates({ name }).pipe(
27 Effect.as("found" as const),
28 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
29 Effect.repeat({
30 schedule: Schedule.spaced("1 second"),
31 until: (status) => status === "gone",
32 times: 10,
33 }),
34 );
35
36 test.provider(
37 "getProjectsLocationsDeidentifyTemplates on a missing template fails with a typed tag",
38 (stack) =>
39 Effect.gen(function* () {
40 const { project } = yield* GcpEnvironment.current;
41 yield* stack.destroy();
42
43 const error = yield* Effect.flip(
44 dlp.getProjectsLocationsDeidentifyTemplates({
45 name: `projects/${project}/locations/global/deidentifyTemplates/alchemy-missing`,
46 }),
47 );
48 expect(error._tag).toEqual("NotFound");
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 },
53 );
54
55 test.provider(
56 "create, update, and delete a location deidentify template",
57 (stack) =>
58 Effect.gen(function* () {
59 const { project } = yield* GcpEnvironment.current;
60 yield* stack.destroy();
61
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 return yield* GCP.DLP.LocationsDeidentifyTemplate("Emails", {
65 location: "global",
66 displayName: "redact emails",
67 description: "replace email findings",
68 deidentifyConfig: redact(["EMAIL_ADDRESS"]),
69 });
70 }),
71 );
72
73 expect(created.templateId).toEqual(expect.any(String));
74 expect(created.location).toEqual("global");
75 expect(created.name).toEqual(
76 `projects/${project}/locations/global/deidentifyTemplates/${created.templateId}`,
77 );
78 expect(created.displayName).toEqual("redact emails");
79 expect(created.description).toEqual("replace email findings");
80
81 const fetched = yield* dlp.getProjectsLocationsDeidentifyTemplates({
82 name: created.name,
83 });
84 expect(fetched.name).toEqual(created.name);
85 expect(fetched.description).toContain("alchemy-id=");
86
87 const updated = yield* stack.deploy(
88 Effect.gen(function* () {
89 return yield* GCP.DLP.LocationsDeidentifyTemplate("Emails", {
90 templateId: created.templateId,
91 location: "global",
92 displayName: "redact emails and phones",
93 description: "replace email and phone findings",
94 deidentifyConfig: redact(["EMAIL_ADDRESS", "PHONE_NUMBER"]),
95 });
96 }),
97 );
98
99 expect(updated.name).toEqual(created.name);
100 expect(updated.displayName).toEqual("redact emails and phones");
101 expect(updated.description).toEqual("replace email and phone findings");
102
103 yield* stack.destroy();
104
105 const gone = yield* waitUntilGone(created.name);
106 expect(gone).toEqual("gone");
107 }).pipe(logLevel),
108 { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 },
109 );