| 1 | import * as Cloudflare from "@/Cloudflare"; |
| 2 | import * as Prisma from "@/Prisma"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import { describe, expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Layer from "effect/Layer"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import PrismaHostStack, { state } from "./fixtures/prismahost/stack.ts"; |
| 9 | import { expectDatabaseReachable } from "./fixtures/sqlreach/expect.ts"; |
| 10 | |
| 11 | const { test, beforeAll, afterAll, deploy, destroy } = Test.make({ |
| 12 | providers: Layer.merge(Cloudflare.providers(), Prisma.providers()), |
| 13 | state, |
| 14 | dev: true, |
| 15 | }); |
| 16 | |
| 17 | const logLevel = Effect.provideService( |
| 18 | MinimumLogLevel, |
| 19 | process.env.DEBUG ? "Debug" : "Info", |
| 20 | ); |
| 21 | |
| 22 | const HOOK_TIMEOUT = 300_000; |
| 23 | const TEST_TIMEOUT = 240_000; |
| 24 | |
| 25 | /** |
| 26 | * Regression for alchemy-run/alchemy#1334 on Linux: an arbitrary image given |
| 27 | * a local Prisma `DATABASE_URL` (`postgres://…@127.0.0.1:…`) must be able to |
| 28 | * reach `@prisma/dev` from inside the container. host-gateway rewrites the |
| 29 | * hostname, but the server still has to accept connections on the Docker |
| 30 | * bridge — a 127.0.0.1 listener times out with |
| 31 | * `dial error: timeout` to `172.17.0.1`. |
| 32 | */ |
| 33 | describe( |
| 34 | "local container reaches Prisma Postgres", |
| 35 | { |
| 36 | tags: [ |
| 37 | "provider:cloudflare", |
| 38 | "provider:cloudflare:container", |
| 39 | "provider:cloudflare:worker", |
| 40 | "provider:prisma", |
| 41 | "provider:prisma:connection", |
| 42 | "provider:prisma:project", |
| 43 | ], |
| 44 | }, |
| 45 | () => { |
| 46 | const stack = beforeAll(deploy(PrismaHostStack), { timeout: HOOK_TIMEOUT }); |
| 47 | afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(PrismaHostStack), { |
| 48 | timeout: HOOK_TIMEOUT, |
| 49 | }); |
| 50 | |
| 51 | test( |
| 52 | "container DATABASE_URL is rewritten once and reaches the host Prisma", |
| 53 | Effect.gen(function* () { |
| 54 | const { url } = yield* stack; |
| 55 | yield* expectDatabaseReachable(url, (hostname) => { |
| 56 | expect(hostname).not.toBe("localhost"); |
| 57 | expect(hostname).not.toBe("127.0.0.1"); |
| 58 | expect(hostname).toContain("localhost"); |
| 59 | }); |
| 60 | }).pipe(logLevel), |
| 61 | { tags: ["local"], timeout: TEST_TIMEOUT }, |
| 62 | ); |
| 63 | }, |
| 64 | ); |