@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 103 lines 3.59 KB
Raw
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 redactConfig = {
19 infoTypeTransformations: {
20 transformations: [{ primitiveTransformation: { replaceWithInfoTypeConfig: {} } }],
21 },
22 };
23
24 const waitUntilGone = (name: string) =>
25 dlp.getOrganizationsDeidentifyTemplates({ name }).pipe(
26 Effect.as("found" as const),
27 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
28 Effect.repeat({
29 schedule: Schedule.spaced("1 second"),
30 until: (status) => status === "gone",
31 times: 10,
32 }),
33 );
34
35 test.provider.skipIf(!organizationId)(
36 "getOrganizationsDeidentifyTemplates on a missing template fails with a typed tag",
37 (stack) =>
38 Effect.gen(function* () {
39 yield* stack.destroy();
40
41 const error = yield* Effect.flip(
42 dlp.getOrganizationsDeidentifyTemplates({
43 name: `${organization}/deidentifyTemplates/alchemy-missing`,
44 }),
45 );
46 expect(error._tag).toEqual("NotFound");
47
48 yield* stack.destroy();
49 }).pipe(logLevel),
50 { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 },
51 );
52
53 test.provider.skipIf(!organizationId)(
54 "create, update, and delete an organization deidentify template",
55 (stack) =>
56 Effect.gen(function* () {
57 yield* stack.destroy();
58
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 return yield* GCP.DLP.OrganizationsDeidentifyTemplate("RedactEmail", {
62 organization,
63 displayName: "redact-email",
64 description: "redact emails",
65 deidentifyConfig: redactConfig,
66 });
67 }),
68 );
69
70 expect(created.templateId).toEqual(expect.any(String));
71 expect(created.organization).toEqual(organization);
72 expect(created.name).toEqual(`${organization}/deidentifyTemplates/${created.templateId}`);
73 expect(created.description).toEqual("redact emails");
74
75 const fetched = yield* dlp.getOrganizationsDeidentifyTemplates({
76 name: created.name,
77 });
78 expect(fetched.name).toEqual(created.name);
79 expect(fetched.description).toContain("alchemy-id=");
80
81 const updated = yield* stack.deploy(
82 Effect.gen(function* () {
83 return yield* GCP.DLP.OrganizationsDeidentifyTemplate("RedactEmail", {
84 organization,
85 templateId: created.templateId,
86 displayName: "redact-email-v2",
87 description: "redact emails and phones",
88 deidentifyConfig: redactConfig,
89 });
90 }),
91 );
92
93 expect(updated.name).toEqual(created.name);
94 expect(updated.displayName).toEqual("redact-email-v2");
95 expect(updated.description).toEqual("redact 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 );