/** * End-to-end verification for #566: all three presets run to completion * through the real interpret driver (../driver.ts), dispatching to real * capability implementations wired to a `MockCloudExecutor` — no live AWS, no * live docker — mirroring ../pilots/pilots-e2e.test.ts's pattern for the * hand-composed pilots. * * Also proves the acceptance criterion "a preset-based and a hand-composed * component produce equivalent contracts and both run through the driver": * `EcsFargateComponent`'s expansion and `alb-ecs.pilot.ts`'s hand-composed * `searchService` are run through the same driver instance side by side and * assert identical dispatch behavior. */ import { describe, expect, it } from "vitest"; import { CapabilityRegistry } from "@intentius/chant/components/capability"; import { runInterpretDriver, type DriverComponent } from "@intentius/chant/components/driver"; import { projectToJson } from "@intentius/chant/components/component"; import { searchService } from "@intentius/chant/components/pilots/alb-ecs.pilot"; import { EcsFargateComponent } from "@intentius/chant/components/presets/ecs-fargate"; import { LambdaComponent } from "@intentius/chant/components/presets/lambda"; import { SingleHostComposeComponent } from "@intentius/chant/components/presets/single-host-compose"; import { createMockCloudExecutor, type MockCloudExecutor } from "./__tests__/mock-cloud-executor"; import { createDockerBuildCapability } from "@intentius/chant/components/verbs/build"; import { createPublishImageCapability, createLoadImageOnHostCapability } from "./publish"; import { createCfnDeployCapability, createEcsUpdateServiceCapability, createLambdaDeployCapability } from "./apply"; import { createWaitSteadyStateCapability } from "./wait-aws"; /** Same registry-building convention as ../pilots/pilots-e2e.test.ts: real capabilities wired to one shared mock executor, plus fakes for verbs this suite's presets reference but that stay typed stubs (out of scope for #566, matching the pilots' own accounting). */ function buildRegistry(mock: MockCloudExecutor): CapabilityRegistry { const registry = new CapabilityRegistry(); registry.register(createDockerBuildCapability(mock.executor)); registry.register(createPublishImageCapability(mock.executor)); registry.register(createLoadImageOnHostCapability(mock.executor)); registry.register(createCfnDeployCapability(mock.executor)); registry.register(createEcsUpdateServiceCapability(mock.executor)); registry.register(createLambdaDeployCapability(mock.executor)); registry.register(createWaitSteadyStateCapability(mock.executor)); registry.register({ kind: "health-gate", run: async () => ({ healthy: true }) }); registry.register({ kind: "rollback-previous", run: async () => ({ restored: true }) }); registry.register({ kind: "copy-to-host", run: async () => ({ bytesCopied: 128 }) }); registry.register({ kind: "remote-exec", run: async () => ({ exitCode: 0, stdout: "" }) }); registry.register({ kind: "wait-endpoint", run: async () => ({ status: 200 }) }); return registry; } describe("Preset library end-to-end through the real interpret driver (#566 acceptance criteria)", () => { it("EcsFargateComponent expands to a component that runs to completion, dispatching every step to its real capability", async () => { const mock = createMockCloudExecutor({ stacks: { "shared-alb": { outputs: {} }, "search-service-preset": { outputs: {} } }, ecsServices: { "prod-cluster/search": { runningCount: 2, desiredCount: 2, stable: true } }, }); const registry = buildRegistry(mock); const sharedAlb: DriverComponent = { name: "shared-alb", dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "cfn-deploy", stack: "shared-alb", template: "archive:alb.json" }] }], }; const service = projectToJson( EcsFargateComponent({ name: "search-service-preset", service: "search", healthPath: "/healthz", sharedAlbStack: "shared-alb", cluster: "prod-cluster", }), ) as unknown as DriverComponent; const result = await runInterpretDriver([sharedAlb, service], registry, { env: "dev", vars: { registry: "123.dkr.ecr.us-east-1.amazonaws.com" }, }); expect(result.ok).toBe(true); const callsByClient = mock.calls.map((c) => `${c.client}.${c.method}`); expect(callsByClient).toContain("docker.push"); // publish-image expect(callsByClient).toContain("ecs.updateService"); // ecs-update-service expect(callsByClient).toContain("ecs.describeService"); // wait-steady-state }); it("a preset-based EcsFargateComponent and the hand-composed alb-ecs.pilot.ts searchService drive identical capability dispatch through the same registry", async () => { const mock = createMockCloudExecutor({ stacks: { "shared-alb": { outputs: {} }, "search-service": { outputs: {} } }, ecsServices: { "prod-cluster/search": { runningCount: 2, desiredCount: 2, stable: true } }, }); const registry = buildRegistry(mock); const sharedAlb: DriverComponent = { name: "shared-alb", dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "cfn-deploy", stack: "shared-alb", template: "archive:alb.json" }] }], }; const handComposed = projectToJson(searchService) as unknown as DriverComponent; const handComposedResolved: DriverComponent = { ...handComposed, deploy: handComposed.deploy.map((p) => ({ ...p, steps: p.steps.map((s) => (s as { kind?: string }).kind === "ecs-update-service" ? { ...s, cluster: "prod-cluster" } : s, ), })), rollback: handComposed.rollback?.map((p) => ({ ...p, steps: p.steps.map((s) => ({ ...s, cluster: "cluster" in s ? "prod-cluster" : undefined })), })), }; const result = await runInterpretDriver([sharedAlb, handComposedResolved], registry, { env: "dev", vars: { registry: "123.dkr.ecr.us-east-1.amazonaws.com" }, }); expect(result.ok).toBe(true); // The same dispatch shape the preset-based run above exercises: both the // preset expansion and the hand-composed pilot are, underneath, the exact // same contract driving the exact same driver — Level 2 convenience over // Level 1 primitives, never a second orchestrator behavior. const callsByClient = mock.calls.map((c) => `${c.client}.${c.method}`); expect(callsByClient).toContain("docker.push"); expect(callsByClient).toContain("ecs.updateService"); expect(callsByClient).toContain("ecs.describeService"); }); it("LambdaComponent expands to a component that runs to completion, dispatching to lambda-deploy (no cfn-deploy at all)", async () => { const mock = createMockCloudExecutor({}); const registry = buildRegistry(mock); const component = projectToJson( LambdaComponent({ name: "thumbnailer-preset", functionName: "thumbnailer" }), ) as unknown as DriverComponent; const result = await runInterpretDriver([component], registry, { env: "dev", vars: { registry: "123.dkr.ecr.us-east-1.amazonaws.com" }, }); expect(result.ok).toBe(true); const callsByClient = mock.calls.map((c) => `${c.client}.${c.method}`); expect(callsByClient).toContain("lambda.updateFunctionCode"); expect(callsByClient).toContain("lambda.publishVersion"); expect(callsByClient).toContain("lambda.updateAlias"); expect(callsByClient.some((c) => c.startsWith("cloudformation."))).toBe(false); }); it("SingleHostComposeComponent expands to a component that runs to completion, dispatching to load-image-on-host (registry-less) and remote-exec", async () => { const mock = createMockCloudExecutor({}); const registry = buildRegistry(mock); const component = projectToJson( SingleHostComposeComponent({ name: "monitoring-host-preset", healthPath: "/-/healthy", healthPort: 9090 }), ) as unknown as DriverComponent; const result = await runInterpretDriver([component], registry, { env: "dev", vars: { host: "10.0.0.5" }, }); expect(result.ok).toBe(true); const callsByClient = mock.calls.map((c) => `${c.client}.${c.method}`); expect(callsByClient).toContain("host.copyFile"); // load-image-on-host expect(callsByClient).toContain("host.dockerLoad"); // load-image-on-host expect(callsByClient.some((c) => c.startsWith("docker.push"))).toBe(false); // never touches a registry expect(callsByClient.some((c) => c.startsWith("ecr."))).toBe(false); }); });