1import { Task } from "@/AWS/ECS/Task.ts";
2import * as Effect from "effect/Effect";
3import pg from "pg";
4
5/**
6 * Regression fixture for CommonJS dual-package resolution in bundled
7 * programs: `pg` is a CJS consumer whose `require("pg-pool")` used to
8 * receive pg-pool's ESM namespace (the bundlers' `conditionNames` listed
9 * `"import"`, which applies to BOTH import kinds, and pg-pool's `exports`
10 * lists `import` first) — the module then died AT LOAD with
11 * `TypeError: The superclass is not a constructor`, before any user code.
12 *
13 * Importing `pg` and constructing a Pool in a deployed task pins the whole
14 * path behaviorally: a mis-resolved bundle exits 1 at boot; a correct one
15 * logs the marker and exits 0.
16 */
17export class CjsDualPackageTask extends Task<CjsDualPackageTask>()(
18 "EcsCjsDualPackageTask",
19) {}
20
21export default CjsDualPackageTask.make(
22 {
23 main: import.meta.filename,
24 // Docker Hub's `oven/bun`; the public.ecr.aws default mirror rate-limits
25 // anonymous pulls during local builds (see fixtures/task.ts).
26 image: "oven/bun:1",
27 cpu: 256,
28 memory: 512,
29 // Build/run on ARM64 so an image built on an Apple Silicon host matches
30 // the Fargate runtime architecture (Graviton).
31 runtimePlatform: {
32 cpuArchitecture: "ARM64",
33 operatingSystemFamily: "LINUX",
34 },
35 taskName: "alchemy-test-ecs-cjs-dual",
36 },
37 Effect.gen(function* () {
38 return {
39 run: Effect.gen(function* () {
40 // Constructing (not connecting) exercises pg-pool's BoundPool class
41 // — the exact site that died when Pool was a module namespace.
42 const pool = new pg.Pool({
43 connectionString: "postgres://user:pass@localhost:5432/db",
44 });
45 yield* Effect.log(
46 `alchemy-cjs-dual-ran: query=${typeof pool.query === "function"}`,
47 );
48 yield* Effect.promise(() => pool.end());
49 }),
50 };
51 }),
52);