The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Cluster } from "@alchemy.run/aws/ECS/Cluster"; |
| 3 | import { Service } from "@alchemy.run/aws/ECS/Service"; |
| 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 ecs from "@distilled.cloud/aws/ecs"; |
| 8 | import * as sd from "@distilled.cloud/aws/servicediscovery"; |
| 9 | import * as Effect from "effect/Effect"; |
| 10 | import { getDefaultVpcNetwork } from "../DefaultVpc.ts"; |
| 11 | |
| 12 | const { test } = Test.make({ providers: AWS.providers() }); |
| 13 | |
| 14 | // Describe-level coverage for the Phase-2 config sugar that doesn't need a |
| 15 | // running task: `serviceRegistry` (composed Cloud Map service wired into |
| 16 | // `serviceRegistries`), the `{ efs, path }` volume sugar, and the |
| 17 | // container-level `healthCheck`. `desiredCount: 0` keeps it fast — the task |
| 18 | // definition and service wiring are fully observable without placement. |
| 19 | // |
| 20 | // Requires a local Docker daemon (the `image:` source mirrors into ECR). |
| 21 | test.provider.skipIf(!!process.env.FAST)( |
| 22 | "serviceRegistry, EFS volume sugar, and container healthCheck land on the service", |
| 23 | (stack) => |
| 24 | Effect.gen(function* () { |
| 25 | yield* stack.destroy(); |
| 26 | const net = yield* getDefaultVpcNetwork; |
| 27 | |
| 28 | const azSubnets = yield* ec2 |
| 29 | .describeSubnets({ |
| 30 | Filters: [ |
| 31 | { Name: "vpc-id", Values: [net.vpcId] }, |
| 32 | { Name: "default-for-az", Values: ["true"] }, |
| 33 | ], |
| 34 | }) |
| 35 | .pipe( |
| 36 | Effect.map((r) => (r.Subnets ?? []).flatMap((s) => (s.SubnetId ? [s.SubnetId] : []))), |
| 37 | ); |
| 38 | |
| 39 | const deployed = yield* stack.deploy( |
| 40 | Effect.gen(function* () { |
| 41 | const cluster = yield* Cluster("ConfigCluster", { |
| 42 | clusterName: "alchemy-test-ecs-phase2-config", |
| 43 | }); |
| 44 | const namespace = yield* AWS.CloudMap.PrivateDnsNamespace("ConfigNamespace", { |
| 45 | name: "phase2-config.alchemy-test.internal", |
| 46 | vpc: net.vpcId, |
| 47 | }); |
| 48 | const fileSystem = yield* AWS.EFS.FileSystem("ConfigFs", {}); |
| 49 | const service = yield* Service("ConfigSvc", { |
| 50 | cluster, |
| 51 | image: "busybox:stable", |
| 52 | command: ["sh", "-c", "while true; do sleep 30; done"], |
| 53 | port: 8080, |
| 54 | desiredCount: 0, |
| 55 | vpcId: net.vpcId as string, |
| 56 | subnets: azSubnets, |
| 57 | serviceRegistry: { namespace }, |
| 58 | volumes: [{ efs: fileSystem, path: "/mnt/data" }], |
| 59 | healthCheck: { |
| 60 | command: ["CMD-SHELL", "exit 0"], |
| 61 | interval: "30 seconds", |
| 62 | timeout: "5 seconds", |
| 63 | retries: 3, |
| 64 | startPeriod: "10 seconds", |
| 65 | }, |
| 66 | }); |
| 67 | return { |
| 68 | serviceName: service.serviceName.as<string>(), |
| 69 | clusterArn: service.clusterArn.as<string>(), |
| 70 | taskDefinitionArn: service.taskDefinitionArn.as<string>(), |
| 71 | fileSystemId: fileSystem.fileSystemId.as<string>(), |
| 72 | namespaceId: namespace.namespaceId.as<string>(), |
| 73 | }; |
| 74 | }), |
| 75 | ); |
| 76 | |
| 77 | // ── serviceRegistry: the composed Cloud Map service is wired in ─── |
| 78 | const services = yield* ecs.describeServices({ |
| 79 | cluster: deployed.clusterArn, |
| 80 | services: [deployed.serviceName], |
| 81 | }); |
| 82 | const registryArn = services.services?.[0]?.serviceRegistries?.[0]?.registryArn; |
| 83 | expect(registryArn).toContain(":servicediscovery:"); |
| 84 | const cloudMapServiceId = registryArn!.split("/").pop()!; |
| 85 | const cloudMapService = yield* sd.getService({ Id: cloudMapServiceId }); |
| 86 | expect(cloudMapService.Service?.NamespaceId).toBe(deployed.namespaceId); |
| 87 | expect(cloudMapService.Service?.DnsConfig?.DnsRecords?.map((r) => r.Type)).toEqual(["A"]); |
| 88 | |
| 89 | // ── volumes + healthCheck sugar on the task definition ──────────── |
| 90 | const described = yield* ecs.describeTaskDefinition({ |
| 91 | taskDefinition: deployed.taskDefinitionArn, |
| 92 | }); |
| 93 | const volume = described.taskDefinition?.volumes?.[0]; |
| 94 | expect(volume?.name).toBe("efs-0"); |
| 95 | expect(volume?.efsVolumeConfiguration?.fileSystemId).toBe(deployed.fileSystemId); |
| 96 | expect(volume?.efsVolumeConfiguration?.transitEncryption).toBe("ENABLED"); |
| 97 | const container = described.taskDefinition?.containerDefinitions?.[0]; |
| 98 | const mountPoint = container?.mountPoints?.[0]; |
| 99 | expect(container?.mountPoints?.length).toBe(1); |
| 100 | expect(mountPoint?.sourceVolume).toBe("efs-0"); |
| 101 | expect(mountPoint?.containerPath).toBe("/mnt/data"); |
| 102 | expect(container?.healthCheck?.command).toEqual(["CMD-SHELL", "exit 0"]); |
| 103 | expect(container?.healthCheck?.interval).toBe(30); |
| 104 | expect(container?.healthCheck?.timeout).toBe(5); |
| 105 | expect(container?.healthCheck?.retries).toBe(3); |
| 106 | expect(container?.healthCheck?.startPeriod).toBe(10); |
| 107 | |
| 108 | // ── destroy + zero-orphan proofs ────────────────────────────────── |
| 109 | yield* stack.destroy(); |
| 110 | |
| 111 | const cloudMapGone = yield* sd.getService({ Id: cloudMapServiceId }).pipe( |
| 112 | Effect.map(() => false), |
| 113 | Effect.catchTag("ServiceNotFound", () => Effect.succeed(true)), |
| 114 | ); |
| 115 | expect(cloudMapGone).toBe(true); |
| 116 | |
| 117 | const namespaceGone = yield* sd.getNamespace({ Id: deployed.namespaceId }).pipe( |
| 118 | Effect.map(() => false), |
| 119 | Effect.catchTag("NamespaceNotFound", () => Effect.succeed(true)), |
| 120 | ); |
| 121 | expect(namespaceGone).toBe(true); |
| 122 | }), |
| 123 | { |
| 124 | tags: [ |
| 125 | "provider:aws", |
| 126 | "provider:aws:cloudmap", |
| 127 | "provider:aws:ec2", |
| 128 | "provider:aws:ecs", |
| 129 | "provider:aws:efs", |
| 130 | "live", |
| 131 | ], |
| 132 | timeout: 600_000, |
| 133 | }, |
| 134 | ); |