The best way to control Claude Code, Codex and more from any computer or phone

main
ts 61 lines 2.39 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Alarm, CompositeAlarm } from "@alchemy.run/aws/CloudWatch";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as cloudwatch from "@distilled.cloud/aws/cloudwatch";
6 import * as Output from "alchemy/Output";
7 import * as Provider from "alchemy/Provider";
8 import * as Effect from "effect/Effect";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 // list() enumerates every CompositeAlarm in the account/region via
13 // `describeAlarms` (AlarmTypes filtered to CompositeAlarm). We deploy a real
14 // composite alarm (referencing a real metric alarm so the rule validates),
15 // resolve the provider from context via the typed `findProvider`, call
16 // `list()`, and assert the deployed alarm appears in the exhaustively
17 // paginated result.
18 test.provider(
19 "list enumerates the deployed composite alarm",
20 (stack) =>
21 Effect.gen(function* () {
22 yield* stack.destroy();
23
24 const deployed = yield* stack.deploy(
25 Effect.gen(function* () {
26 const metric = yield* Alarm("ListMetricAlarm", {
27 name: "alchemy-test-composite-list-metric",
28 MetricName: "Errors",
29 Namespace: "AWS/Lambda",
30 Statistic: "Sum",
31 Period: 60,
32 EvaluationPeriods: 1,
33 Threshold: 1,
34 ComparisonOperator: "GreaterThanOrEqualToThreshold",
35 });
36 const composite = yield* CompositeAlarm("ListCompositeAlarm", {
37 name: "alchemy-test-composite-list",
38 AlarmRule: Output.interpolate`ALARM("${metric.alarmName}")`,
39 });
40 return composite;
41 }),
42 );
43
44 const provider = yield* Provider.findProvider(CompositeAlarm);
45 const all = yield* provider.list();
46
47 expect(all.some((a) => a.alarmName === deployed.alarmName)).toBe(true);
48
49 yield* stack.destroy();
50
51 // Out-of-band assert-gone: both the composite alarm and its member
52 // metric alarm are deleted after the final destroy.
53 const gone = yield* cloudwatch.describeAlarms({
54 AlarmNames: ["alchemy-test-composite-list", "alchemy-test-composite-list-metric"],
55 AlarmTypes: ["CompositeAlarm", "MetricAlarm"],
56 });
57 expect(gone.CompositeAlarms ?? []).toEqual([]);
58 expect(gone.MetricAlarms ?? []).toEqual([]);
59 }),
60 { tags: ["provider:aws", "provider:aws:cloudwatch", "live"] },
61 );