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