@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 85 lines 3.49 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Filter } from "@alchemy.run/aws/Inspector2/Filter";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as inspector2 from "@distilled.cloud/aws/inspector2";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // The findings-filter APIs work regardless of Inspector enablement, so the
12 // Filter lifecycle always runs live and may overlap the enablement tests in
13 // Enabler.test.ts. The CIS scan tests live there because the CIS APIs depend
14 // on the account/region enablement singleton.
15 test.provider(
16 "lifecycle: findings filter create, update, destroy",
17 (stack) =>
18 Effect.gen(function* () {
19 yield* stack.destroy();
20
21 // Self-heal: an interrupted previous run can orphan the live filter
22 // (state lost, so the cloud resource is unadoptable under a fresh
23 // stage). Delete any filter this test's logical id created before.
24 const orphans = (yield* inspector2.listFilters({})).filters.filter(
25 (f) => f.tags?.["alchemy::id"] === "SuppressInfo",
26 );
27 yield* Effect.forEach(orphans, (f) =>
28 inspector2
29 .deleteFilter({ arn: f.arn })
30 .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.void)),
31 );
32
33 const deploy = (props: { action: "NONE" | "SUPPRESS"; reason: string }) =>
34 stack.deploy(
35 Effect.gen(function* () {
36 const filter = yield* Filter("SuppressInfo", {
37 action: props.action,
38 reason: props.reason,
39 description: "created by alchemy Inspector2 resource test",
40 filterCriteria: { severity: [{ comparison: "EQUALS", value: "INFORMATIONAL" }] },
41 tags: { env: "test" },
42 });
43 return {
44 arn: filter.arn,
45 name: filter.name,
46 action: filter.action,
47 reason: filter.reason,
48 };
49 }),
50 );
51
52 // Create.
53 const created = yield* deploy({
54 action: "SUPPRESS",
55 reason: "informational findings are tracked elsewhere",
56 });
57 expect(created.arn).toContain("/filter/");
58 expect(created.action).toBe("SUPPRESS");
59
60 // Out-of-band verification via distilled.
61 const live = (yield* inspector2.listFilters({ arns: [created.arn] })).filters[0];
62 expect(live?.action).toBe("SUPPRESS");
63 expect(live?.tags?.["env"]).toBe("test");
64 expect(live?.tags?.["alchemy::id"]).toBe("SuppressInfo");
65
66 // Canonical list() coverage.
67 const provider = yield* Provider.findProvider(Filter);
68 const all = yield* provider.list();
69 expect(all.some((f) => f.arn === created.arn)).toBe(true);
70
71 // Update in place — the ARN is stable.
72 const updated = yield* deploy({ action: "NONE", reason: "keep them visible after all" });
73 expect(updated.arn).toBe(created.arn);
74 expect(updated.action).toBe("NONE");
75 const liveUpdated = (yield* inspector2.listFilters({ arns: [created.arn] })).filters[0];
76 expect(liveUpdated?.action).toBe("NONE");
77 expect(liveUpdated?.reason).toBe("keep them visible after all");
78
79 // Destroy — the filter is gone.
80 yield* stack.destroy();
81 const gone = yield* inspector2.listFilters({ arns: [created.arn] });
82 expect(gone.filters).toHaveLength(0);
83 }),
84 { tags: ["provider:aws", "provider:aws:inspector2", "live"], timeout: 120_000 },
85 );