6.9 KiB
Why
We have a complete real-services test harness (docker/docker-compose.test.yml + the seven @suaveplan/testing-integration-* fixtures) and zero consumers wired to it. grep -rln "testing-integration-" packages apps outside packages/dev/testing-integration* returns nothing. Meanwhile @suaveplan/database/surrealdb ships its adapter tests against an in-suite makeFakeClient() DI fake (src/adapter/surreal-adapter.test.ts). That fake validates the adapter's shape against the SurrealClientLike port; it does not verify that the real surrealdb.js v2 client + SurrealDB v3.0.4 server actually behave the way the adapter assumes.
The db.create() drops content in surrealdb.js v2 + SurrealDB v3 issue we already burned on (forced the workaround INSERT INTO query) is exactly the class of bug a fake client cannot catch. Adapter assumptions about session use-NS/DB binding, query parameter passthrough, transaction semantics, version detection, and singleton lifecycle all need to be exercised against the real engine — that is the whole point of the docker-compose stack.
This change wires @suaveplan/database/surrealdb to @suaveplan/testing-integration-surrealdb as the first real consumer of the integration harness, establishing the pattern the remaining I/O packages will follow (db-sqlite against postgres, storage-s3 against garage, email-* against mailpit, search-* against typesense, etc.). Scope is intentionally narrow: surrealdb only, no sweep yet.
What Changes
New integration-test surface in @suaveplan/database/surrealdb
- New
tests/integration/directory (sibling oftests/), separated from the unit suite. Per the project's hybrid placement rule (per-feature unit tests co-located insrc/; cross-cutting tests intests/), real-DB tests live intests/integration/because they are cross-cutting (depend on a backing service rather than a single feature module). - New
vitest.integration.config.tsextending the package's existing config, registeringSurrealDBFixtureviacreateIntegrationSetup({ surrealdb: new SurrealDBFixture() }). - New script entry in
package.json:"test:integration": "vitest run --config vitest.integration.config.ts". - Default unit suite (
bunx turbo test --filter=@suaveplan/database/surrealdb) does not run integration tests — they are opt-in via the new script and CI gate. - Each integration test calls
skipIfUnavailable("surrealdb", inject)at the top so the suite is skipped (not failed) when docker is not running locally.
Integration test coverage (real SurrealDB v3.0.4 container)
surreal-adapter.integration.test.ts— connect / use(ns,db) / signin / query SELECT 1 / disconnect, asserting against the live engine, not a fake.singleton.integration.test.ts—getSingletonreturns the same connected adapter instance for the same name,closeSingletonactually closes the WS,closeAllSingletonsis reverse-order safe, registry isolation when an explicitMapis passed.version-detector.integration.test.ts— version detector returns the real server version string and parses it correctly.init.integration.test.ts— namespace + database creation flow against the live engine, including thedb.create()drop-content workaround path documented in feedback memorysurrealdb-create-content-drop.connection.integration.test.ts—'ConnectionRefused'error code surfacing matches the documented branch (error?.code === 'ConnectionRefused' || error?.message?.includes('Unable to connect')).discovery.integration.test.ts— schema discovery against a real fresh database with seeded tables/fields.
CI gate
- New turbo task
test:integrationthat runs only on the integration entry script. Wired in CI behinddocker compose -f docker/docker-compose.test.yml up -d+ the env-bridge variables fromdocker/README.md. - Unit-coverage gate (
test:coverage) is unchanged — integration tests do not count toward Istanbul 100% onsrc/. They verify behaviour against real I/O, which is orthogonal to source coverage.
Out of scope
- Sweeping the same pattern across the other six fixtures (postgres, redis, mailpit, typesense, garage-s3, step-ca). That follows in separate per-package changes after surrealdb proves the wiring.
- Replacing the existing
makeFakeClient()adapter unit tests. The fake-client suite stays — it pins the port contract and runs in milliseconds without docker. Integration tests are additive. - Changes to
@suaveplan/testing-integration-surrealdbitself. The fixture is already shipped and conformant. - Changes to the docker-compose stack itself.
Capabilities
New Capabilities
database-surrealdb-integration— defines the integration-test contract for@suaveplan/database/surrealdb: which adapter behaviours MUST be verified against a real container, the env-bridge passthrough rule, the local-skip rule when docker is unavailable, and the CI gate.
Modified Capabilities
- None.
testing-integration-surrealdbis consumed unmodified.
Dependencies
This change is the consumer wire-up; it depends on three upstream fixes landing first:
testing-integration-vite-entry-fix— without it,@suaveplan/testing-integration-surrealdbcannot be imported by name (itsdist/index.jsis not emitted).testing-integration-build-fix(Option A) — without it,createIntegrationSetup()returns adata:video/mp2t;base64,…URL forglobalSetup, which Vitest cannot load.surrealdb-integration-testsconsumes the publiccreateIntegrationSetupAPI and would otherwise have to hand-roll aTestEnvironmentdriver (the rebel pattern instorage-s3that this stack eliminates).testing-integration-bun-runtime-compat(Option B) — without it,bunx vitest runpanics inuv_version_stringbefore any container starts; this monorepo runs every test under Bun perCLAUDE.md.
surrealdb-integration-tests MUST NOT be archived until all three upstream changes have shipped and the suite has been observed actually starting a real SurrealDB container under Bun.
Impact
- Affected code:
packages/database/surrealdb/tests/integration/**(new),packages/database/surrealdb/vitest.integration.config.ts(new),packages/database/surrealdb/package.json(new script + dev dep on@suaveplan/testing-integration-surrealdband@suaveplan/testing-integration). - Affected consumers: none — this is additive test coverage on a leaf package.
- CI: new job step that brings up
docker-compose.test.ymland runsbunx turbo test:integration --filter=@suaveplan/database/surrealdb. Local developers can either run docker first or rely onskipIfUnavailable()to no-op the suite. - Documentation: README of
@suaveplan/database/surrealdbgets a new "Integration tests" section.docker/README.mdalready covers the env-bridge — no change needed there. - CLAUDE.md / MANIFEST.md: no new package, so no manifest regeneration. The surrealdb package description in
CLAUDE.mddoes not need to change.