1import * as AWS from "@/AWS";
2import { Cluster } from "@/AWS/ECS/Cluster.ts";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import * as ecs from "@distilled.cloud/aws/ecs";
6import { expect } from "alchemy-test";
7import * as Effect from "effect/Effect";
8
9const { test } = Test.make({ providers: AWS.providers() });
10
11// Canonical `list()` test (AWS account/region-scoped collection): deploy a real
12// cluster, resolve the provider from context via the typed `findProvider`, call
13// `list()`, and assert the deployed cluster appears in the exhaustively-
14// paginated result (listClusters -> describeClusters hydration).
15test.provider(
16 "list enumerates the deployed cluster",
17 (stack) =>
18 Effect.gen(function* () {
19 yield* stack.destroy();
20
21 const cluster = yield* stack.deploy(
22 Effect.gen(function* () {
23 return yield* Cluster("ListCluster", {
24 clusterName: "alchemy-test-ecs-cluster-list",
25 });
26 }),
27 );
28
29 const provider = yield* Provider.findProvider(Cluster);
30 const all = yield* provider.list();
31
32 expect(all.some((c) => c.clusterArn === cluster.clusterArn)).toBe(true);
33
34 yield* stack.destroy();
35
36 // Out-of-band gone-proof: a deleted cluster is INACTIVE (or absent).
37 const after = yield* ecs.describeClusters({
38 clusters: ["alchemy-test-ecs-cluster-list"],
39 });
40 expect((after.clusters ?? []).some((c) => c.status === "ACTIVE")).toBe(
41 false,
42 );
43
44 // ECS can keep the terminal INACTIVE record discoverable for a while.
45 // Provider inventory (and therefore nuke) must treat it as deleted.
46 const afterList = yield* provider.list();
47 expect(afterList.some((c) => c.clusterArn === cluster.clusterArn)).toBe(
48 false,
49 );
50 }),
51 { tags: ["provider:aws", "provider:aws:ecs", "live"] },
52);