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