mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 14:17:25 +01:00
Routes are built separately and each bundle that imports lib/db gets its own copy of the module. The handle lived in a module variable, so each copy opened its own pool of up to ten connections against a Postgres the box shares between products. The deploy of #299 was refused at its schema step with "too many clients already". The pool now lives on globalThis under a registered symbol (the same fix lib/auth/sender.ts needed), with its ceiling stated. Claude-Session: https://claude.ai/code/session_019MDtmsxWVjuhCQowciDEYR Co-authored-by: Claude <noreply@anthropic.com>
17 lines
858 B
TypeScript
17 lines
858 B
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
|
|
/**
|
|
* A source-level assertion, because the defect is about BUNDLING: under
|
|
* `node:test` there is one copy of every module and a module variable looks
|
|
* like a singleton. In the built site each route bundle has its own copy.
|
|
*/
|
|
test("the pool lives on globalThis, so separately built routes share one", () => {
|
|
const source = readFileSync(new URL("./index.ts", import.meta.url), "utf8");
|
|
assert.match(source, /Symbol\.for\("heidi\.db"\)/);
|
|
assert.match(source, /shared\[SLOT\] = drizzle\(new Pool\(/, "the pool is kept somewhere a second bundle cannot see");
|
|
assert.doesNotMatch(source, /^let instance/m, "a module variable is one pool per bundle");
|
|
assert.match(source, /max: POOL_MAX/, "the pool has no stated ceiling");
|
|
});
|