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
| 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.getFoldersMuteConfigs({ 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 | // Folder-level Security Command Center needs a folder under an organization |
| 25 | // with SCC activated and folder-level SCC roles for the test identity. Set |
| 26 | // GCP_TEST_SECURITY_CENTER=1 and GOOGLE_FOLDER_ID when both hold. |
| 27 | const folderId = process.env.GOOGLE_FOLDER_ID; |
| 28 | const runLifecycle = !!process.env.GCP_TEST_SECURITY_CENTER && !!folderId; |
| 29 | |
| 30 | const folderOf = () => |
| 31 | Effect.succeed( |
| 32 | folderId === undefined |
| 33 | ? "" |
| 34 | : folderId.startsWith("folders/") |
| 35 | ? folderId |
| 36 | : `folders/${folderId}`, |
| 37 | ); |
| 38 | |
| 39 | test.provider( |
| 40 | "getFoldersMuteConfigs on a missing config fails with a typed tag", |
| 41 | (stack) => |
| 42 | Effect.gen(function* () { |
| 43 | yield* stack.destroy(); |
| 44 | |
| 45 | const folder = (yield* folderOf()) || "folders/0"; |
| 46 | const error = yield* Effect.flip( |
| 47 | scc.getFoldersMuteConfigs({ |
| 48 | name: `${folder}/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 a folder mute config", |
| 63 | (stack) => |
| 64 | Effect.gen(function* () { |
| 65 | yield* stack.destroy(); |
| 66 | |
| 67 | const folder = yield* folderOf(); |
| 68 | |
| 69 | const created = yield* stack.deploy( |
| 70 | Effect.gen(function* () { |
| 71 | return yield* GCP.SecurityCenter.FolderMuteConfig("Low", { |
| 72 | folder, |
| 73 | filter: 'severity="LOW"', |
| 74 | description: "mute low findings", |
| 75 | }); |
| 76 | }), |
| 77 | ); |
| 78 | |
| 79 | expect(created.muteConfigId).toEqual(expect.any(String)); |
| 80 | expect(created.folder).toEqual(folder); |
| 81 | expect(created.name).toEqual(`${folder}/muteConfigs/${created.muteConfigId}`); |
| 82 | expect(created.filter).toEqual('severity="LOW"'); |
| 83 | expect(created.description).toEqual("mute low findings"); |
| 84 | |
| 85 | const fetched = yield* scc.getFoldersMuteConfigs({ name: created.name }); |
| 86 | expect(fetched.name).toEqual(created.name); |
| 87 | expect(fetched.description).toContain("alchemy-id="); |
| 88 | |
| 89 | const updated = yield* stack.deploy( |
| 90 | Effect.gen(function* () { |
| 91 | return yield* GCP.SecurityCenter.FolderMuteConfig("Low", { |
| 92 | folder, |
| 93 | muteConfigId: created.muteConfigId, |
| 94 | filter: 'severity="MEDIUM"', |
| 95 | description: "mute medium findings", |
| 96 | }); |
| 97 | }), |
| 98 | ); |
| 99 | |
| 100 | expect(updated.name).toEqual(created.name); |
| 101 | expect(updated.filter).toEqual('severity="MEDIUM"'); |
| 102 | expect(updated.description).toEqual("mute medium findings"); |
| 103 | |
| 104 | yield* stack.destroy(); |
| 105 | |
| 106 | const gone = yield* waitUntilGone(created.name); |
| 107 | expect(gone).toEqual("gone"); |
| 108 | }).pipe(logLevel), |
| 109 | { |
| 110 | tags: ["provider:gcp", "provider:gcp:securitycenter", "live"], |
| 111 | timeout: 90_000, |
| 112 | }, |
| 113 | ); |