@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 115 lines 3.79 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 runLifecycle = !process.env.FAST;
15
16 const pausedTarget = () => ({
17 cloudStorageTarget: {
18 filter: { others: {} },
19 disabled: {},
20 },
21 });
22
23 const waitUntilGone = (name: string) =>
24 dlp.getProjectsLocationsDiscoveryConfigs({ name }).pipe(
25 Effect.as("found" as const),
26 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
27 Effect.repeat({
28 schedule: Schedule.spaced("1 second"),
29 until: (status) => status === "gone",
30 times: 10,
31 }),
32 );
33
34 test.provider(
35 "getProjectsLocationsDiscoveryConfigs on a missing config fails with a typed tag",
36 (stack) =>
37 Effect.gen(function* () {
38 const { project } = yield* GcpEnvironment.current;
39 yield* stack.destroy();
40
41 const error = yield* Effect.flip(
42 dlp.getProjectsLocationsDiscoveryConfigs({
43 name: `projects/${project}/locations/us/discoveryConfigs/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(!runLifecycle)(
54 "create, update, and delete a paused discovery config",
55 (stack) =>
56 Effect.gen(function* () {
57 yield* stack.destroy();
58
59 const created = yield* stack.deploy(
60 Effect.gen(function* () {
61 const template = yield* GCP.DLP.LocationsInspectTemplate("EmailInspect", {
62 location: "us",
63 displayName: "emails",
64 inspectConfig: { infoTypes: [{ name: "EMAIL_ADDRESS" }] },
65 });
66 return yield* GCP.DLP.DiscoveryConfig("Profiles", {
67 location: "us",
68 displayName: "paused storage",
69 status: "PAUSED",
70 inspectTemplates: [template.name],
71 targets: [pausedTarget()],
72 });
73 }),
74 );
75
76 expect(created.configId).toEqual(expect.any(String));
77 expect(created.location).toEqual("us");
78 expect(created.name).toContain("/discoveryConfigs/");
79 expect(created.displayName).toEqual("paused storage");
80 expect(created.status).toEqual("PAUSED");
81
82 const fetched = yield* dlp.getProjectsLocationsDiscoveryConfigs({
83 name: created.name,
84 });
85 expect(fetched.name).toEqual(created.name);
86 expect(fetched.displayName).toContain("alchemy-");
87
88 const updated = yield* stack.deploy(
89 Effect.gen(function* () {
90 const template = yield* GCP.DLP.LocationsInspectTemplate("EmailInspect", {
91 location: "us",
92 displayName: "emails",
93 inspectConfig: { infoTypes: [{ name: "EMAIL_ADDRESS" }] },
94 });
95 return yield* GCP.DLP.DiscoveryConfig("Profiles", {
96 configId: created.configId,
97 location: "us",
98 displayName: "paused storage v2",
99 status: "PAUSED",
100 inspectTemplates: [template.name],
101 targets: [pausedTarget()],
102 });
103 }),
104 );
105
106 expect(updated.name).toEqual(created.name);
107 expect(updated.displayName).toEqual("paused storage v2");
108
109 yield* stack.destroy();
110
111 const gone = yield* waitUntilGone(created.name);
112 expect(gone).toEqual("gone");
113 }).pipe(logLevel),
114 { tags: ["provider:gcp", "provider:gcp:dlp", "live"], timeout: 90_000 },
115 );