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 { Cluster } from "@alchemy.run/aws/ECS/Cluster"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as ecs from "@distilled.cloud/aws/ecs"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { getDefaultVpcNetwork } from "../DefaultVpc.ts"; |
| 9 | import CjsDualPackageTaskLive, { CjsDualPackageTask } from "./fixtures/pg-task.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: AWS.providers() }); |
| 12 | |
| 13 | // Live behavioral proof for CommonJS dual-package resolution: a deployed |
| 14 | // task whose program imports `pg` (a CJS consumer of the dual-package |
| 15 | // `pg-pool`, whose exports list `import` before `require`). With the former |
| 16 | // bundler conditions (`"import"` in the set for both import kinds) the |
| 17 | // bundle died AT LOAD with `TypeError: The superclass is not a constructor` |
| 18 | // and the container exited 1; the fixture must boot, construct a Pool, and |
| 19 | // exit 0. The unit-level pin is test/Bundle/ConditionNames.test.ts — this |
| 20 | // is the same defect observed from the cloud. |
| 21 | // |
| 22 | // Docker + ECR + Fargate placement is ~1 minute of wall clock, so it is |
| 23 | // skipped under --fast like the Task e2e smoke test. |
| 24 | test.provider.skipIf(!!process.env.FAST)( |
| 25 | "task importing a CJS dual-package consumer (pg) boots and exits 0", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | // Reuse the standing default VPC: a public subnet + public IP is |
| 31 | // required for the task ENI to pull the image from ECR. |
| 32 | const { subnetIds } = yield* getDefaultVpcNetwork; |
| 33 | const subnetId = subnetIds[0]; |
| 34 | expect(subnetId).toBeTruthy(); |
| 35 | |
| 36 | const { clusterArn, taskDefinitionArn } = yield* stack.deploy( |
| 37 | Effect.gen(function* () { |
| 38 | const cluster = yield* Cluster("CjsDualCluster", { |
| 39 | clusterName: "alchemy-test-cjs-dual", |
| 40 | }); |
| 41 | const task = yield* CjsDualPackageTask; |
| 42 | return { |
| 43 | clusterArn: cluster.clusterArn, |
| 44 | taskDefinitionArn: task.taskDefinitionArn, |
| 45 | }; |
| 46 | }).pipe(Effect.provide(CjsDualPackageTaskLive)), |
| 47 | ); |
| 48 | expect(taskDefinitionArn).toBeTruthy(); |
| 49 | |
| 50 | // Launch once, out-of-band; retry the IAM-propagation rejection. |
| 51 | const started = yield* ecs |
| 52 | .runTask({ |
| 53 | cluster: clusterArn, |
| 54 | taskDefinition: taskDefinitionArn!, |
| 55 | launchType: "FARGATE", |
| 56 | count: 1, |
| 57 | startedBy: "alchemy-cjs-dual-test", |
| 58 | networkConfiguration: { |
| 59 | awsvpcConfiguration: { |
| 60 | subnets: [subnetId!], |
| 61 | assignPublicIp: "ENABLED", |
| 62 | }, |
| 63 | }, |
| 64 | }) |
| 65 | .pipe( |
| 66 | Effect.retry({ |
| 67 | while: (e) => |
| 68 | e._tag === "ClientException" && |
| 69 | (e.message ?? "").includes("unable to assume the role"), |
| 70 | schedule: Schedule.spaced("5 seconds"), |
| 71 | times: 12, |
| 72 | }), |
| 73 | ); |
| 74 | expect(started.failures ?? []).toEqual([]); |
| 75 | const taskArn = started.tasks?.[0]?.taskArn; |
| 76 | expect(taskArn).toBeTruthy(); |
| 77 | |
| 78 | const stopped = yield* ecs.describeTasks({ cluster: clusterArn, tasks: [taskArn!] }).pipe( |
| 79 | Effect.flatMap((result) => { |
| 80 | const task = result.tasks?.[0]; |
| 81 | return task?.lastStatus === "STOPPED" |
| 82 | ? Effect.succeed(task) |
| 83 | : Effect.fail(new Error(`task not stopped yet: ${task?.lastStatus}`)); |
| 84 | }), |
| 85 | Effect.tapError((error) => Effect.logInfo(String(error))), |
| 86 | Effect.retry({ schedule: Schedule.spaced("6 seconds"), times: 50 }), |
| 87 | ); |
| 88 | |
| 89 | // Exit 0 = pg loaded, BoundPool constructed. A mis-resolved bundle |
| 90 | // dies at module load and exits 1. |
| 91 | expect(stopped.stoppedReason ?? "").not.toContain("CannotPullContainer"); |
| 92 | expect(stopped.containers?.[0]?.exitCode).toBe(0); |
| 93 | |
| 94 | yield* stack.destroy(); |
| 95 | }), |
| 96 | { |
| 97 | tags: ["provider:aws", "provider:aws:ec2", "provider:aws:ecs", "live"], |
| 98 | timeout: 900_000, |
| 99 | }, |
| 100 | ); |