Skip to content

feat(test): add @zigordev/test with a real postgresql per test file - #64

Merged
zigordev merged 2 commits into
mainfrom
feat/test-package
Nov 23, 2026
Merged

zigordev merged 2 commits into
mainfrom
feat/test-package

Conversation

@zigordev

@zigordev zigordev commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

What

Step 4.1 of the build plan: the new package @zigordev/test, private for now.

  • @zigordev/test/postgres: one PostgreSQL 18 container per test run, started through Testcontainers. A global setup migrates a template database once, and useTestDatabase() gives each test file its own copy, dropped after the file.
  • @zigordev/test/app: the harness for API tests. useApp() builds an app once per file and closes it after. captureLogs() keeps the log lines and finds events. expectProblem() checks an error answer: the status, application/problem+json, the code, and exactly the fields of the platform's error format.
  • Tests that need a container live in *.db.test.ts, in a Vitest project named <name>:db from a vitest.db.config.ts. pnpm check runs them. pnpm check:quick, which the push hook runs, now leaves them out with --project '!*:db'.

Why

The test rules ask for API tests on a real PostgreSQL, and for every test file to get its own copy of the migrated database. Without one shared package, each service would write its own container start, copies and clean-up. Steps 4.2 and 4.3 build on it.

The override, and the owner's exception

Testcontainers 12.2.2, the newest release, brings glob 10.5.0 through archiver 7 and archiver-utils, with the flaw GHSA-3g3m-2fjr-6pw4, medium, published 2026-10-30. Record 0033 was followed in its order:

  1. Update the package that brings it in. Not possible yet. The maintainer's own fix, Replace archiver with tar-fs and tar-stream testcontainers/testcontainers-node#1652, replaces archiver. It was still open on 2026-11-23.
  2. Do without it. Not possible. Testcontainers loads archiver when it starts: an override that removed it failed every test with MODULE_NOT_FOUND. archiver 8 drops archiver-utils, but brings minimatch 10.2.6, which has its own flaw, GHSA-g3hv-75wg-m249.
  3. Replace the flawed package. archiver-utils>glob: 14.0.6 under overrides. pnpm audit then finds nothing, and every test passes.

This is an exception to the one-month rule. glob 14 is a new major version, first released on 2026-10-27, so the override would have waited until 2026-11-27. On 2026-11-23 the owner was asked "Let toolkit#64 wait until 2026-11-27, keeping the one-month rule?" and answered, in their words: "Merge it now".

Why the risk is low: Testcontainers uses archiver, and through it glob, only to copy files into a container, which nothing here does. Every test of the package passes with glob 14, on this Mac and in CI.

When the line goes: when a release of Testcontainers drops archiver. From 2026-11-27 it is no longer an exception. The README of @zigordev/test and the new table "The overrides in force" on the handbook page Dependency updates both say so.

How it was tested

  • pnpm check passes: 665 tests, 99.3% of lines covered, in 29 seconds on this Mac with Docker Desktop.
  • The database tests ask the server for its version, and pass only on PostgreSQL 18. They prove that copies never see each other's rows, that five copies can be made at once, that a copy drops while a client still holds it, that the template refuses clients, that a client left open by prepare does not block a copy, and that a failing prepare stops its container.
  • vitest list --project '!*:db' lists 536 tests and none from a *.db.test.ts file.
  • The package was packed and installed into an empty folder outside the repo, with the README's settings. Its example ran there: a copy of the template, and expectProblem on an answer. That trial found that Testcontainers also needs protobufjs: false under allowBuilds, and the README now names all three.

Observability

Nothing runs in production. A test run starts one PostgreSQL container and Testcontainers' clean-up container, and both are removed when the run ends.

Docs

  • packages/test/README.md, with the five headings.
  • A new handbook page, docs/handbook/tests.md, listed as page 14 of the reading order.
  • CLAUDE.md: the new folder, and what check:quick leaves out.
  • docs/handbook/dependency-updates.md: a table of the overrides in force, and when each goes.

Follow-ups

  • Remove the override once Testcontainers drops archiver.
  • A repo that installs @zigordev/test needs three lines under allowBuilds and, until then, the override line. The README says so.

Step 4.1 of the build plan. Every service needs the same two things for
its API tests: a real PostgreSQL 18, and test files that never see each
other's rows. The package starts one container per run through
Testcontainers, migrates a template database once, and gives each test
file its own copy. Its app harness builds an app once per file, captures
its log lines, and checks an error answer against the platform's format.

Tests that need a container live in files named *.db.test.ts, in a
Vitest project of their own named <name>:db. pnpm check runs them, and
pnpm check:quick, which the push hook runs, leaves them out, as the test
rules ask.

Testcontainers 12.2.2 brings glob 10.5.0 through archiver-utils, with
the flaw GHSA-3g3m-2fjr-6pw4. Record 0033 applies: no release of
Testcontainers asks for a fixed version yet, so glob is replaced under
overrides at 14.0.6. The package stays private.
@zigordev
zigordev marked this pull request as ready for review November 23, 2026 14:19
@zigordev
zigordev enabled auto-merge (squash) November 23, 2026 14:19
@zigordev
zigordev merged commit 4d1904c into main Nov 23, 2026
10 of 15 checks passed
@zigordev
zigordev deleted the feat/test-package branch November 23, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant