| 1 | import * as AWS from "@/AWS"; |
| 2 | import { ComputeEnvironment } from "@/AWS/Batch/ComputeEnvironment.ts"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import * as batch from "@distilled.cloud/aws/batch"; |
| 6 | import { expect } from "alchemy-test"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { BatchTestNetwork } from "./TestNetwork.ts"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | const ceName = "alchemy-test-batch-ce-lifecycle"; |
| 13 | |
| 14 | const describeCe = batch |
| 15 | .describeComputeEnvironments({ computeEnvironments: [ceName] }) |
| 16 | .pipe( |
| 17 | Effect.map((res) => |
| 18 | res.computeEnvironments?.find((ce) => ce.status !== "DELETED"), |
| 19 | ), |
| 20 | ); |
| 21 | |
| 22 | test.provider( |
| 23 | "lifecycle: create with stack-owned networking, update, destroy", |
| 24 | (stack) => |
| 25 | Effect.gen(function* () { |
| 26 | yield* stack.destroy(); |
| 27 | |
| 28 | // Create with a stack-owned network. Creating an ambient default VPC |
| 29 | // leaves AWS-generated resources outside this stack's state. |
| 30 | const deployed = yield* stack.deploy( |
| 31 | Effect.gen(function* () { |
| 32 | const network = yield* BatchTestNetwork; |
| 33 | return yield* ComputeEnvironment("LifecycleCE", { |
| 34 | computeEnvironmentName: ceName, |
| 35 | subnets: network.subnetIds, |
| 36 | securityGroupIds: network.securityGroupIds, |
| 37 | }); |
| 38 | }), |
| 39 | ); |
| 40 | expect(deployed.computeEnvironmentArn).toContain( |
| 41 | `compute-environment/${ceName}`, |
| 42 | ); |
| 43 | |
| 44 | // Out-of-band verification via distilled. |
| 45 | const created = yield* describeCe; |
| 46 | expect(created?.type).toBe("MANAGED"); |
| 47 | expect(created?.status).toBe("VALID"); |
| 48 | expect(created?.state).toBe("ENABLED"); |
| 49 | expect(created?.computeResources?.type).toBe("FARGATE"); |
| 50 | expect(created?.computeResources?.maxvCpus).toBe(4); |
| 51 | expect(created?.computeResources?.subnets?.length).toBeGreaterThan(0); |
| 52 | expect( |
| 53 | created?.computeResources?.securityGroupIds?.length, |
| 54 | ).toBeGreaterThan(0); |
| 55 | |
| 56 | // Canonical list() coverage. |
| 57 | const provider = yield* Provider.findProvider(ComputeEnvironment); |
| 58 | const all = yield* provider.list(); |
| 59 | expect(all.some((ce) => ce.computeEnvironmentName === ceName)).toBe(true); |
| 60 | |
| 61 | // Update — maxvCpus and state sync in place (no replacement). |
| 62 | yield* stack.deploy( |
| 63 | Effect.gen(function* () { |
| 64 | const network = yield* BatchTestNetwork; |
| 65 | return yield* ComputeEnvironment("LifecycleCE", { |
| 66 | computeEnvironmentName: ceName, |
| 67 | maxvCpus: 8, |
| 68 | state: "DISABLED", |
| 69 | subnets: network.subnetIds, |
| 70 | securityGroupIds: network.securityGroupIds, |
| 71 | }); |
| 72 | }), |
| 73 | ); |
| 74 | const updated = yield* describeCe; |
| 75 | expect(updated?.computeResources?.maxvCpus).toBe(8); |
| 76 | expect(updated?.state).toBe("DISABLED"); |
| 77 | expect(updated?.status).toBe("VALID"); |
| 78 | |
| 79 | // Destroy — provider disables, deletes, and waits until gone. |
| 80 | yield* stack.destroy(); |
| 81 | const after = yield* describeCe; |
| 82 | expect(after).toBeUndefined(); |
| 83 | }), |
| 84 | { |
| 85 | tags: ["provider:aws", "provider:aws:batch", "provider:aws:ec2", "live"], |
| 86 | timeout: 240_000, |
| 87 | }, |
| 88 | ); |