The best way to control Claude Code, Codex and more from any computer or phone

main
ts 116 lines 3.95 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 location = "us-central1";
15
16 const hybridInspect = (infoTypes: string[]) => ({
17 inspectConfig: {
18 infoTypes: infoTypes.map((name) => ({ name })),
19 includeQuote: true,
20 },
21 storageConfig: { hybridOptions: { description: "hybrid inbox" } },
22 });
23
24 const waitUntilGone = (name: string) =>
25 dlp.getProjectsLocationsJobTriggers({ 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(
36 "getProjectsLocationsJobTriggers on a missing trigger fails with a typed tag",
37 (stack) =>
38 Effect.gen(function* () {
39 const { project } = yield* GcpEnvironment.current;
40 yield* stack.destroy();
41
42 const error = yield* Effect.flip(
43 dlp.getProjectsLocationsJobTriggers({
44 name: `projects/${project}/locations/${location}/jobTriggers/alchemy-missing`,
45 }),
46 );
47 expect(error._tag).toEqual("NotFound");
48
49 yield* stack.destroy();
50 }).pipe(logLevel),
51 { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 },
52 );
53
54 test.provider(
55 "create, update, and delete a location job trigger",
56 (stack) =>
57 Effect.gen(function* () {
58 const { project } = yield* GcpEnvironment.current;
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 return yield* GCP.DLP.LocationsJobTrigger("Inbox", {
64 location,
65 displayName: "inbox scan",
66 description: "paused hybrid inspect",
67 status: "PAUSED",
68 inspectJob: hybridInspect(["EMAIL_ADDRESS"]),
69 triggers: [{ manual: {} }],
70 });
71 }),
72 );
73
74 expect(created.triggerId).toEqual(expect.any(String));
75 expect(created.location).toEqual(location);
76 expect(created.name).toEqual(
77 `projects/${project}/locations/${location}/jobTriggers/${created.triggerId}`,
78 );
79 expect(created.project).toEqual(project);
80 expect(created.displayName).toEqual("inbox scan");
81 expect(created.description).toEqual("paused hybrid inspect");
82 expect(created.status).toEqual("PAUSED");
83
84 const fetched = yield* dlp.getProjectsLocationsJobTriggers({
85 name: created.name,
86 });
87 expect(fetched.name).toEqual(created.name);
88 expect(fetched.description).toContain("alchemy-id=");
89 expect(fetched.description).toContain("paused hybrid inspect");
90 expect(fetched.status).toEqual("PAUSED");
91
92 const updated = yield* stack.deploy(
93 Effect.gen(function* () {
94 return yield* GCP.DLP.LocationsJobTrigger("Inbox", {
95 triggerId: created.triggerId,
96 location,
97 displayName: "inbox scan v2",
98 description: "paused hybrid inspect v2",
99 status: "PAUSED",
100 inspectJob: hybridInspect(["EMAIL_ADDRESS", "PHONE_NUMBER"]),
101 triggers: [{ manual: {} }],
102 });
103 }),
104 );
105
106 expect(updated.name).toEqual(created.name);
107 expect(updated.displayName).toEqual("inbox scan v2");
108 expect(updated.description).toEqual("paused hybrid inspect v2");
109
110 yield* stack.destroy();
111
112 const gone = yield* waitUntilGone(created.name);
113 expect(gone).toEqual("gone");
114 }).pipe(logLevel),
115 { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 },
116 );