1import * as AWS from "@/AWS";
2import { InsightRule } from "@/AWS/CloudWatch";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7
8const { test } = Test.make({ providers: AWS.providers() });
9
10// list() enumerates every Contributor Insights rule in the account/region via
11// `describeInsightRules`. We deploy a real rule, resolve the provider from
12// context via the typed `findProvider`, call `list()`, and assert the deployed
13// rule appears in the exhaustively paginated result.
14test.provider(
15 "list enumerates the deployed insight rule",
16 (stack) =>
17 Effect.gen(function* () {
18 yield* stack.destroy();
19
20 const deployed = yield* stack.deploy(
21 Effect.gen(function* () {
22 return yield* InsightRule("ListInsightRule", {
23 name: "alchemy-test-insight-rule-list",
24 RuleState: "ENABLED",
25 RuleDefinition: {
26 Schema: {
27 Name: "CloudWatchLogRule",
28 Version: 1,
29 },
30 LogGroupNames: ["alchemy-test-insight-rule-list-log-group"],
31 LogFormat: "JSON",
32 Contribution: {
33 Keys: ["$.ip"],
34 Filters: [],
35 },
36 AggregateOn: "Count",
37 },
38 });
39 }),
40 );
41
42 const provider = yield* Provider.findProvider(InsightRule);
43 const all = yield* provider.list();
44
45 expect(all.some((r) => r.ruleName === deployed.ruleName)).toBe(true);
46
47 yield* stack.destroy();
48
49 // Out-of-band assert-gone: the exhaustively-paginated live listing no
50 // longer contains the rule after the final destroy.
51 const after = yield* provider.list();
52 expect(after.some((r) => r.ruleName === deployed.ruleName)).toBe(false);
53 }),
54 { tags: ["provider:aws", "provider:aws:cloudwatch", "live"] },
55);