@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 110 lines 3.52 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 = "global";
15
16 const hybridInspect = {
17 inspectConfig: {
18 infoTypes: [{ name: "EMAIL_ADDRESS" }],
19 includeQuote: true,
20 },
21 storageConfig: { hybridOptions: { description: "hybrid scan" } },
22 };
23
24 const waitUntilGone = (name: string) =>
25 dlp.getProjectsLocationsDlpJobs({ 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 "getProjectsLocationsDlpJobs on a missing job 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.getProjectsLocationsDlpJobs({
44 name: `projects/${project}/locations/${location}/dlpJobs/i-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, refresh, and delete a location dlp job",
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.LocationsDlpJob("Scan", {
64 location,
65 inspectJob: hybridInspect,
66 });
67 }),
68 );
69
70 expect(created.jobId.startsWith("i-")).toEqual(true);
71 expect(created.location).toEqual(location);
72 expect(created.name).toEqual(
73 `projects/${project}/locations/${location}/dlpJobs/${created.jobId}`,
74 );
75 expect(created.project).toEqual(project);
76 expect(created.type).toEqual("INSPECT_JOB");
77 expect(created.state).toEqual(expect.any(String));
78
79 const fetched = yield* dlp.getProjectsLocationsDlpJobs({
80 name: created.name,
81 });
82 expect(fetched.name).toEqual(created.name);
83 expect(fetched.type).toEqual("INSPECT_JOB");
84 const hybrid =
85 fetched.inspectDetails?.requestedOptions?.jobConfig?.storageConfig?.hybridOptions;
86 expect(Object.keys(hybrid?.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
87 true,
88 );
89 expect(hybrid?.description).toContain("alchemy-id=");
90
91 const refreshed = yield* stack.deploy(
92 Effect.gen(function* () {
93 return yield* GCP.DLP.LocationsDlpJob("Scan", {
94 jobId: created.jobId,
95 location,
96 inspectJob: hybridInspect,
97 });
98 }),
99 );
100
101 expect(refreshed.name).toEqual(created.name);
102 expect(refreshed.jobId).toEqual(created.jobId);
103
104 yield* stack.destroy();
105
106 const gone = yield* waitUntilGone(created.name);
107 expect(gone).toEqual("gone");
108 }).pipe(logLevel),
109 { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 },
110 );