1import * as AWS from "@/AWS";
2import { LaunchTemplate } from "@/AWS/AutoScaling";
3import { amazonLinux2023 } from "@/AWS/EC2";
4import * as Provider from "@/Provider";
5import * as Test from "@/Test/Alchemy";
6import * as ec2 from "@distilled.cloud/aws/ec2";
7import { expect } from "alchemy-test";
8import * as Effect from "effect/Effect";
9
10const { test } = Test.make({ providers: AWS.providers() });
11
12// `list()` enumerates every launch template in the account/region via the
13// paginated `ec2.describeLaunchTemplates` op. Deploy a real launch template,
14// resolve the provider from context via the typed `findProvider`, call
15// `list()`, and assert the deployed template appears in the exhaustively
16// paginated result. (The greenfield read path depends on the distilled `ec2`
17// patch that types `InvalidLaunchTemplateName.NotFoundException` on
18// `describeLaunchTemplates` — landed in patches/ec2.json.)
19test.provider(
20 "list enumerates the deployed launch template",
21 (stack) =>
22 Effect.gen(function* () {
23 yield* stack.destroy();
24
25 // Launch templates do not validate the AMI at creation time; fall back to a
26 // syntactically valid id if the lookup returns nothing.
27 const imageId = amazonLinux2023();
28
29 const template = yield* stack.deploy(
30 Effect.gen(function* () {
31 return yield* LaunchTemplate("ListLaunchTemplate", {
32 launchTemplateName: "alchemy-test-lt-list",
33 imageId,
34 instanceType: "t3.micro",
35 });
36 }),
37 );
38
39 const provider = yield* Provider.findProvider(LaunchTemplate);
40 const all = yield* provider.list();
41
42 expect(
43 all.some((t) => t.launchTemplateId === template.launchTemplateId),
44 ).toBe(true);
45
46 yield* stack.destroy();
47
48 // Out-of-band proof the template is gone: describing the deleted name
49 // raises the typed `InvalidLaunchTemplateName.NotFoundException`.
50 const remaining = yield* ec2
51 .describeLaunchTemplates({
52 LaunchTemplateNames: ["alchemy-test-lt-list"],
53 } as any)
54 .pipe(
55 Effect.map((r) => (r.LaunchTemplates ?? []).length),
56 Effect.catchTag("InvalidLaunchTemplateName.NotFoundException", () =>
57 Effect.succeed(0),
58 ),
59 );
60 expect(remaining).toBe(0);
61 }),
62 {
63 tags: [
64 "provider:aws",
65 "provider:aws:autoscaling",
66 "provider:aws:ec2",
67 "live",
68 ],
69 },
70);