The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { LaunchTemplate } from "@alchemy.run/aws/AutoScaling"; |
| 3 | import { amazonLinux2023 } from "@alchemy.run/aws/EC2"; |
| 4 | import { expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as ec2 from "@distilled.cloud/aws/ec2"; |
| 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 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.) |
| 19 | test.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(all.some((t) => t.launchTemplateId === template.launchTemplateId)).toBe(true); |
| 43 | |
| 44 | yield* stack.destroy(); |
| 45 | |
| 46 | // Out-of-band proof the template is gone: describing the deleted name |
| 47 | // raises the typed `InvalidLaunchTemplateName.NotFoundException`. |
| 48 | const remaining = yield* ec2 |
| 49 | .describeLaunchTemplates({ LaunchTemplateNames: ["alchemy-test-lt-list"] } as any) |
| 50 | .pipe( |
| 51 | Effect.map((r) => (r.LaunchTemplates ?? []).length), |
| 52 | Effect.catchTag("InvalidLaunchTemplateName.NotFoundException", () => Effect.succeed(0)), |
| 53 | ); |
| 54 | expect(remaining).toBe(0); |
| 55 | }), |
| 56 | { tags: ["provider:aws", "provider:aws:autoscaling", "provider:aws:ec2", "live"] }, |
| 57 | ); |
| 58 | |
| 59 | // Metadata options land in the template data; a change publishes a new |
| 60 | // default version carrying the new options. |
| 61 | test.provider( |
| 62 | "metadataOptions land in the default template version", |
| 63 | (stack) => |
| 64 | Effect.gen(function* () { |
| 65 | yield* stack.destroy(); |
| 66 | |
| 67 | const imageId = amazonLinux2023(); |
| 68 | |
| 69 | const program = (httpPutResponseHopLimit: number) => |
| 70 | Effect.gen(function* () { |
| 71 | return yield* LaunchTemplate("MetadataLaunchTemplate", { |
| 72 | imageId, |
| 73 | instanceType: "t3.micro", |
| 74 | metadataOptions: { httpTokens: "required", httpPutResponseHopLimit }, |
| 75 | }); |
| 76 | }); |
| 77 | |
| 78 | const observeMetadata = (launchTemplateId: string) => |
| 79 | ec2 |
| 80 | .describeLaunchTemplateVersions({ |
| 81 | LaunchTemplateId: launchTemplateId, |
| 82 | Versions: ["$Default"], |
| 83 | }) |
| 84 | .pipe( |
| 85 | Effect.map((r) => r.LaunchTemplateVersions?.[0]?.LaunchTemplateData?.MetadataOptions), |
| 86 | ); |
| 87 | |
| 88 | const first = yield* stack.deploy(program(1)); |
| 89 | expect(yield* observeMetadata(first.launchTemplateId)).toMatchObject({ |
| 90 | HttpTokens: "required", |
| 91 | HttpPutResponseHopLimit: 1, |
| 92 | }); |
| 93 | |
| 94 | const second = yield* stack.deploy(program(2)); |
| 95 | expect(second.launchTemplateId).toBe(first.launchTemplateId); |
| 96 | expect(second.defaultVersionNumber).toBeGreaterThan(first.defaultVersionNumber); |
| 97 | expect(yield* observeMetadata(second.launchTemplateId)).toMatchObject({ |
| 98 | HttpTokens: "required", |
| 99 | HttpPutResponseHopLimit: 2, |
| 100 | }); |
| 101 | |
| 102 | yield* stack.destroy(); |
| 103 | |
| 104 | const remaining = yield* ec2 |
| 105 | .describeLaunchTemplates({ LaunchTemplateIds: [second.launchTemplateId] }) |
| 106 | .pipe( |
| 107 | Effect.map((r) => (r.LaunchTemplates ?? []).length), |
| 108 | Effect.catchTag("InvalidLaunchTemplateId.NotFound", () => Effect.succeed(0)), |
| 109 | ); |
| 110 | expect(remaining).toBe(0); |
| 111 | }), |
| 112 | { tags: ["provider:aws", "provider:aws:autoscaling", "provider:aws:ec2", "live"] }, |
| 113 | ); |