1import * as AWS from "@/AWS";
2import { EventSourcesConfig } from "@/AWS/DevOpsGuru/EventSourcesConfig.ts";
3import * as Test from "@/Test/Alchemy";
4import * as devopsguru from "@distilled.cloud/aws/devops-guru";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7
8const { test } = Test.make({ providers: AWS.providers() });
9
10// Observe the account's event sources configuration out-of-band.
11const observedProfilerStatus = devopsguru
12 .describeEventSourcesConfig({})
13 .pipe(
14 Effect.map(
15 ({ EventSources }) =>
16 EventSources?.AmazonCodeGuruProfiler?.Status ?? "DISABLED",
17 ),
18 );
19
20// Ungated typed probe: the describe call always answers with the config.
21test.provider(
22 "describeEventSourcesConfig returns the configuration",
23 () =>
24 Effect.gen(function* () {
25 const status = yield* observedProfilerStatus;
26 expect(["ENABLED", "DISABLED"]).toContain(status);
27 }),
28 { tags: ["provider:aws", "provider:aws:devopsguru", "live"] },
29);
30
31// The configuration is an account/region singleton. Only run the destructive
32// lifecycle when the account is at the default (disabled) — never clobber a
33// configuration the user already operates.
34test.provider(
35 "lifecycle: enable CodeGuru Profiler event source, disable, destroy",
36 (stack) =>
37 Effect.gen(function* () {
38 const preexisting = yield* observedProfilerStatus;
39 if (preexisting === "ENABLED") {
40 yield* Effect.logInfo(
41 "CodeGuru Profiler event source already enabled — skipping destructive lifecycle test",
42 );
43 return;
44 }
45
46 yield* stack.destroy();
47
48 // Create — enabled.
49 const created = yield* stack.deploy(
50 Effect.gen(function* () {
51 return yield* EventSourcesConfig("EventSources", {
52 amazonCodeGuruProfiler: true,
53 });
54 }),
55 );
56 expect(created.amazonCodeGuruProfiler).toBe(true);
57 expect(yield* observedProfilerStatus).toBe("ENABLED");
58
59 // Update — back to disabled (converges in place).
60 const updated = yield* stack.deploy(
61 Effect.gen(function* () {
62 return yield* EventSourcesConfig("EventSources", {
63 amazonCodeGuruProfiler: false,
64 });
65 }),
66 );
67 expect(updated.amazonCodeGuruProfiler).toBe(false);
68 expect(yield* observedProfilerStatus).toBe("DISABLED");
69
70 // Re-enable so destroy has something to restore, then destroy.
71 yield* stack.deploy(
72 Effect.gen(function* () {
73 return yield* EventSourcesConfig("EventSources", {
74 amazonCodeGuruProfiler: true,
75 });
76 }),
77 );
78 yield* stack.destroy();
79 expect(yield* observedProfilerStatus).toBe("DISABLED");
80 }),
81 {
82 tags: ["provider:aws", "provider:aws:devopsguru", "live"],
83 timeout: 180_000,
84 },
85);