1import * as Cloudflare from "@/Cloudflare";
2import * as Planetscale from "@/Planetscale";
3import * as Test from "@/Test/Alchemy";
4import { describe, expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import * as Layer from "effect/Layer";
7import { MinimumLogLevel } from "effect/References";
8import { expectDatabaseReachable } from "./fixtures/sqlreach/expect.ts";
9import PlanetscaleHostStack from "./fixtures/pshost/stack.ts";
10
11const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
12 providers: Layer.merge(Cloudflare.providers(), Planetscale.providers()),
13 state: Cloudflare.state(),
14 dev: true,
15});
16
17const logLevel = Effect.provideService(
18 MinimumLogLevel,
19 process.env.DEBUG ? "Debug" : "Info",
20);
21
22const HOOK_TIMEOUT = 300_000;
23const TEST_TIMEOUT = 240_000;
24
25/**
26 * PlanetScale is mode-agnostic like Neon: `alchemy dev` still points the
27 * container at `*.psdb.cloud` (pooled PSBouncer). Same #1334 path as Prisma
28 * and Neon — rewrite must be a no-op, TCP from the container must succeed.
29 */
30describe.skipIf(!process.env.PLANETSCALE_TEST)(
31 "local container reaches PlanetScale Postgres",
32 {
33 tags: [
34 "provider:cloudflare",
35 "provider:cloudflare:container",
36 "provider:cloudflare:worker",
37 "provider:planetscale",
38 "provider:planetscale:postgres",
39 "live",
40 ],
41 },
42 () => {
43 const stack = beforeAll(deploy(PlanetscaleHostStack), {
44 timeout: HOOK_TIMEOUT,
45 });
46 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(PlanetscaleHostStack), {
47 timeout: HOOK_TIMEOUT,
48 });
49
50 test(
51 "container DATABASE_URL keeps the PlanetScale host and reaches it",
52 Effect.gen(function* () {
53 const { url } = yield* stack;
54 yield* expectDatabaseReachable(url, (hostname) => {
55 expect(hostname).not.toBe("localhost");
56 expect(hostname).not.toBe("127.0.0.1");
57 expect(hostname).not.toContain("host.docker.localhost");
58 expect(hostname).toMatch(/psdb\.cloud$/);
59 });
60 }).pipe(logLevel),
61 { timeout: TEST_TIMEOUT },
62 );
63 },
64);