7.7 KiB
7.7 KiB
Tasks — surrealdb-integration-tests
1. Wiring scaffolding
- 1.1 Add
@suaveplan/testing-integrationand@suaveplan/testing-integration-surrealdbasdevDependencies(workspace:^) of@suaveplan/database/surrealdb. Verify peer-deptestcontainersresolves at the root. - 1.2 Create
packages/database/surrealdb/tests/integration/directory. - 1.3 Create
packages/database/surrealdb/vitest.integration.config.ts:- Reuses
createTestConfig()from@suaveplan/testing/config(pool: forks, polyfills loaded). - Registers
SurrealDBFixtureviacreateIntegrationSetup({ surrealdb: new SurrealDBFixture() }). test.globalSetuppoints at the returnedglobalSetuppath.test.includescoped totests/integration/**/*.integration.test.tsonly.test.excludeexcludessrc/**andtests/*.test.ts(unit suite stays untouched).
- Reuses
- 1.4 Add
"test:integration": "vitest run --config vitest.integration.config.ts"topackages/database/surrealdb/package.jsonscripts. - 1.5 Add
test:integrationtoturbo.jsonpipeline at the repo root:dependsOn: ["^build"],outputs: [],cache: false(real-services tests are not cacheable).
2. Shared integration test utilities
- 2.1 Create
tests/integration/helpers/connect.ts:- Exports
connectAdapter(inject)that callsskipIfUnavailable("surrealdb", inject), reads the injectedSurrealDBConfig, instantiatesSurrealAdapter, callsconnect()+use({ namespace, database })+signin({ username, password }), and returns{ adapter, config }. - Each test wraps its work in a try/finally that calls
adapter.close()so a failed assertion never leaks a WS.
- Exports
- 2.2 Create
tests/integration/helpers/random-ns.ts:- Exports
randomNamespace()returningtest_${crypto.randomUUID().replace(/-/g, "_")}for per-test isolation against a shared SurrealDB container. Avoids cross-test bleed without container churn.
- Exports
3. Adapter integration tests
- 3.1
tests/integration/surreal-adapter.integration.test.ts:connect → use → signin → query "SELECT 1 AS n" → closereturns[{ n: 1 }].- Parameterised query (
"SELECT $val AS v",{ val: "abc" }) round-trips the param, proving passthrough is intact and not silently dropped (companion to thedb.create()drop-content bug). execute("DEFINE TABLE t SCHEMAFULL")followed byquery("INFO FOR DB")confirms the DDL took effect on the live engine.transaction(tx => …)commits when the callback resolves; rollback occurs when it throws (verified by reading the row back outside the transaction).- Calling any data method before
connect()throwsDB.NOT_CONNECTED.
- 3.2
tests/integration/connection.integration.test.ts:- Pointing the adapter at
ws://127.0.0.1:1(an unbound port) surfaces an error matchingerror?.code === "ConnectionRefused" || error?.message?.includes("Unable to connect"). This is the exact branch the project-memorysurrealdb-create-content-drop/connection-refused note documents. - The error is wrapped as
DB.CONNECTION_FAILEDvia@suaveplan/error.
- Pointing the adapter at
4. Lifecycle integration tests
- 4.1
tests/integration/singleton.integration.test.ts:getSingleton("a", factory, config, _, registry)returns the same connectedDatabaseAdapterinstance on the second call within the sameregistryMap.closeSingleton("a", _, registry)closes the WS — verified by attemptingadapter.query()on the previously-returned reference and observingDB.NOT_CONNECTED.closeAllSingletons(_, registry)closes registered singletons in reverse insertion order (assert ordering via close-spies wrapping the adapter).- Two different
registrymaps stay isolated (passing the explicit Map per the public API).
- 4.2
tests/integration/version-detector.integration.test.ts:- Detector returns a non-empty version string from the live
INFO FOR ROOT(or equivalent); parsed major matches3for the pinnedsurrealdb:v3.0.4image.
- Detector returns a non-empty version string from the live
- 4.3
tests/integration/init.integration.test.ts:- Initialise a fresh randomised namespace + database; insert a row via the documented
INSERT INTOworkaround (NOTdb.create()), assert the row reads back unchanged. This is the regression test for the content-drop bug from feedback memory.
- Initialise a fresh randomised namespace + database; insert a row via the documented
- 4.4
tests/integration/discovery.integration.test.ts:- Define two tables with explicit fields, run schema discovery, assert returned shape lists both tables and every field with the expected type.
5. Skip / docker-down behaviour
- 5.1 Each integration test's first line is
if (skipIfUnavailable("surrealdb", inject)) return;so a fully-untouched developer machine (no docker, no env-bridge vars) seesSKIPPEDinstead of a hang or a failure. - 5.2 Manual verification: with the test stack down,
bun run test:integration --filter=@suaveplan/database/surrealdbexits 0 with every test reporting skipped. - 5.3 With docker up (
docker compose -f docker/docker-compose.test.yml up -d) andSURREALDB_URL=ws://localhost:7004 SURREALDB_USERNAME=root SURREALDB_PASSWORD=rootexported, the suite runs against the compose container via env-bridge (no testcontainers spin-up). - 5.4 Without env-bridge vars, the suite spins up its own ephemeral container via testcontainers and tears it down on teardown.
6. CI integration
- 6.1 Add a CI job step that runs before
test:integration:docker compose -f docker/docker-compose.test.yml up -d --wait(relies on the existing healthchecks). - 6.2 Export the env-bridge variables in CI so testcontainers passthrough is taken (faster, single shared instance per job).
- 6.3 Add a final
docker compose -f docker/docker-compose.test.yml down -vstep inif: always()to guarantee teardown. - 6.4 Confirm
bunx turbo test:coverage --filter=@suaveplan/database/surrealdbis unchanged: integration tests are not counted toward Istanbul coverage ofsrc/.
7. Documentation
- 7.1 Add an "Integration tests" section to
packages/database/surrealdb/README.mdcovering: how to run locally with docker up, how the env-bridge passthrough works, what skipping looks like. - 7.2 Co-located
.mdsiblings for any new helper modules intests/integration/helpers/per the doc-coverage rule.
8. OpenSpec gate
- 8.1 Run
openspec validate surrealdb-integration-tests --strict; resolve any errors. - 8.2 On ship: fold
specs/database-surrealdb-integration/spec.mdintoopenspec/specs/database-surrealdb-integration/spec.mdand move the change folder toopenspec/archive/<yyyy-mm-dd>-surrealdb-integration-tests/.
Audit Note (2026-05-02)
Status: DEFERRED.
State at audit:
- The bulk of the implementation has landed:
packages/database/surrealdb/tests/integration/containssurreal-adapter.integration.test.ts,connection.integration.test.ts,singleton.integration.test.ts,version-detector.integration.test.ts,init.integration.test.ts,discovery.integration.test.ts,global-setup.ts,integration-setup.ts, plus ahelpers/dir. vitest.integration.config.tsexists;package.jsoncarries thetest:integrationscript and the two@suaveplan/testing-integration*devDependencies.- Unit-suite remains green (
bunx turbo test --filter=@suaveplan/surrealdb→ 167 tests across 10 files).
Outstanding to ship:
- Task 1.5 — wire
test:integrationintoturbo.json(dependsOn: ["^build"],outputs: [],cache: false). Currently absent. - Task 6 — add the CI job step (
docker compose up -d --wait, env-bridge export,down -vonif: always()). - Task 7.1 — add an "Integration tests" section to
packages/database/surrealdb/README.md(current README has none). - Task 8 —
openspec validate surrealdb-integration-tests --strict, then fold spec deltas + archive.