t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/DevOpsGuru/EventSourcesConfig.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

85 lines
2.8 KiB
TypeScript

import * as AWS from "@/AWS";
import { EventSourcesConfig } from "@/AWS/DevOpsGuru/EventSourcesConfig.ts";
import * as Test from "@/Test/Alchemy";
import * as devopsguru from "@distilled.cloud/aws/devops-guru";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
const { test } = Test.make({ providers: AWS.providers() });
// Observe the account's event sources configuration out-of-band.
const observedProfilerStatus = devopsguru
.describeEventSourcesConfig({})
.pipe(
Effect.map(
({ EventSources }) =>
EventSources?.AmazonCodeGuruProfiler?.Status ?? "DISABLED",
),
);
// Ungated typed probe: the describe call always answers with the config.
test.provider(
"describeEventSourcesConfig returns the configuration",
() =>
Effect.gen(function* () {
const status = yield* observedProfilerStatus;
expect(["ENABLED", "DISABLED"]).toContain(status);
}),
{ tags: ["provider:aws", "provider:aws:devopsguru", "live"] },
);
// The configuration is an account/region singleton. Only run the destructive
// lifecycle when the account is at the default (disabled) — never clobber a
// configuration the user already operates.
test.provider(
"lifecycle: enable CodeGuru Profiler event source, disable, destroy",
(stack) =>
Effect.gen(function* () {
const preexisting = yield* observedProfilerStatus;
if (preexisting === "ENABLED") {
yield* Effect.logInfo(
"CodeGuru Profiler event source already enabled — skipping destructive lifecycle test",
);
return;
}
yield* stack.destroy();
// Create — enabled.
const created = yield* stack.deploy(
Effect.gen(function* () {
return yield* EventSourcesConfig("EventSources", {
amazonCodeGuruProfiler: true,
});
}),
);
expect(created.amazonCodeGuruProfiler).toBe(true);
expect(yield* observedProfilerStatus).toBe("ENABLED");
// Update — back to disabled (converges in place).
const updated = yield* stack.deploy(
Effect.gen(function* () {
return yield* EventSourcesConfig("EventSources", {
amazonCodeGuruProfiler: false,
});
}),
);
expect(updated.amazonCodeGuruProfiler).toBe(false);
expect(yield* observedProfilerStatus).toBe("DISABLED");
// Re-enable so destroy has something to restore, then destroy.
yield* stack.deploy(
Effect.gen(function* () {
return yield* EventSourcesConfig("EventSources", {
amazonCodeGuruProfiler: true,
});
}),
);
yield* stack.destroy();
expect(yield* observedProfilerStatus).toBe("DISABLED");
}),
{
tags: ["provider:aws", "provider:aws:devopsguru", "live"],
timeout: 180_000,
},
);