@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 { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as scc from "@distilled.cloud/gcp/securitycenter_v1";
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 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (name: string) =>
14 scc.getOrganizationsMuteConfigs({ name }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 // Organization-level Security Command Center needs SCC activated on the
25 // organization and org-level SCC roles for the test identity. Set
26 // GCP_TEST_SECURITY_CENTER=1 and GOOGLE_ORGANIZATION_ID when both hold.
27 const organizationId = process.env.GOOGLE_ORGANIZATION_ID;
28 const runLifecycle = !!process.env.GCP_TEST_SECURITY_CENTER && !!organizationId;
29
30 const organizationOf = () =>
31 Effect.succeed(
32 organizationId === undefined
33 ? ""
34 : organizationId.startsWith("organizations/")
35 ? organizationId
36 : `organizations/${organizationId}`,
37 );
38
39 test.provider(
40 "getOrganizationsMuteConfigs on a missing config fails with a typed tag",
41 (stack) =>
42 Effect.gen(function* () {
43 yield* stack.destroy();
44
45 const organization = (yield* organizationOf()) || "organizations/0";
46 const error = yield* Effect.flip(
47 scc.getOrganizationsMuteConfigs({
48 name: `${organization}/muteConfigs/alchemy-missing`,
49 }),
50 );
51 expect(["ServiceDisabled", "Forbidden"]).toContain(error._tag);
52
53 yield* stack.destroy();
54 }).pipe(logLevel),
55 {
56 tags: ["provider:gcp", "provider:gcp:securitycenter", "live"],
57 timeout: 90_000,
58 },
59 );
60
61 test.provider.skipIf(!runLifecycle)(
62 "create, update, and delete an organization mute config",
63 (stack) =>
64 Effect.gen(function* () {
65 yield* stack.destroy();
66
67 const organization = yield* organizationOf();
68
69 const created = yield* stack.deploy(
70 Effect.gen(function* () {
71 return yield* GCP.SecurityCenter.OrganizationMuteConfig("Low", {
72 organization,
73 filter: 'severity="LOW"',
74 description: "mute low findings",
75 });
76 }),
77 );
78
79 expect(created.muteConfigId).toEqual(expect.any(String));
80 expect(created.organization).toEqual(organization);
81 expect(created.name).toEqual(`${organization}/muteConfigs/${created.muteConfigId}`);
82 expect(created.filter).toEqual('severity="LOW"');
83 expect(created.description).toEqual("mute low findings");
84
85 const fetched = yield* scc.getOrganizationsMuteConfigs({
86 name: created.name,
87 });
88 expect(fetched.name).toEqual(created.name);
89 expect(fetched.description).toContain("alchemy-id=");
90
91 const updated = yield* stack.deploy(
92 Effect.gen(function* () {
93 return yield* GCP.SecurityCenter.OrganizationMuteConfig("Low", {
94 organization,
95 muteConfigId: created.muteConfigId,
96 filter: 'severity="MEDIUM"',
97 description: "mute medium findings",
98 });
99 }),
100 );
101
102 expect(updated.name).toEqual(created.name);
103 expect(updated.filter).toEqual('severity="MEDIUM"');
104 expect(updated.description).toEqual("mute medium findings");
105
106 yield* stack.destroy();
107
108 const gone = yield* waitUntilGone(created.name);
109 expect(gone).toEqual("gone");
110 }).pipe(logLevel),
111 {
112 tags: ["provider:gcp", "provider:gcp:securitycenter", "live"],
113 timeout: 90_000,
114 },
115 );