Test a provider
Prove contract behavior before testing real infrastructure.
Provider tests must cover the public contract, race boundaries, and native failure modes. A happy-path task run is not enough.
Storage conformance requires profile.contractVersion: 2. When observeBackgroundFailures is present, it checks registration, repeated unsubscribe, and exclusion of caller transaction failures. Test actual detached failures at the provider boundary too: synchronous throws, rejected I/O, independent observers, observer errors, and close draining. A successful commit must remain successful.
Start with the shared suite
The raw storage conformance suite works with any test runner. Vitest users can register it with the helpers below.
The optional Vitest integration supports Vitest ^4.1.5 || ^5.1.0.
@runlane/testing/vitest is ESM-only because Vitest is ESM-only. Use import, even in a CommonJS project. Vitest transforms your test files before it runs them. Calling require('@runlane/testing/vitest') throws a RunlaneError with code configuration_invalid and steps to fix the import.
import { createLocalStorageDriver } from '@runlane/local-adapters'
import { describeStorageDriverConformance } from '@runlane/testing/vitest'
import { expect, test } from 'vitest'
test('creates an isolated provider instance', async () => {
// Given / When
const driver = createLocalStorageDriver()
// Then
expect(driver.name).toBe('local-memory-record-storage')
await driver.close?.()
})
// Replace createLocalStorageDriver with the factory exported by your provider.
describeStorageDriverConformance({
createDriver: createLocalStorageDriver,
name: 'my provider',
})Run the suite against an isolated provider instance. Cleanup must leave no state for the next case.
Set append: true in the conformance options when the provider implements ordered append. Set exclusiveCandidates: true when its profile advertises exclusive selection. These flags enable required behavioral checks for those optional features; leave them omitted for providers without them. Local implements append. PostgreSQL implements both.
For a driver with a transaction record-count limit, set oversizeTransactionRecords to a count it cannot commit. The suite requires non-retryable storage_limit_exceeded, one callback invocation, and no partial write. With append: true, the same option also tests rejected append capacity, including its stream head, and checks that no head or records persist. Omit it for drivers without that limit, such as PostgreSQL.
CommonJS and other test runners
The root @runlane/testing entry supports both CommonJS and ESM. Use runConformanceSuite with a suite from defineStorageDriverConformanceSuite or defineTransportDriverConformanceSuite and your runner's describe and test functions.
ConformanceRunner.test takes (name, callback, timeoutMs?). Adapt runners with a different signature. For example, node:test takes timeout options before the callback:
const { describe, test } = require('node:test')
const { createLocalStorageDriver } = require('@runlane/local-adapters')
const { defineStorageDriverConformanceSuite, runConformanceSuite } = require('@runlane/testing')
const runner = {
describe,
test(name, runTest, timeoutMs) {
test(name, { timeout: timeoutMs }, runTest)
},
}
runConformanceSuite(
runner,
defineStorageDriverConformanceSuite({
createDriver: createLocalStorageDriver,
name: 'my provider',
}),
)The require types for @runlane/testing/vitest expose no helpers. TypeScript reports an error when you access them through a typed CommonJS import. Use the root entry for CommonJS suites.
Simulate provider limits
Use withStorageLimits(driver, limits) from @runlane/testing to test how code handles a bounded provider:
import { createLocalStorageDriver } from '@runlane/local-adapters'
import { withStorageLimits } from '@runlane/testing'
const storage = withStorageLimits(createLocalStorageDriver(), {
maxTransactionRecords: 100,
})StorageSimulatedLimits accepts optional positive safe integers: maxRecordBytes, maxTransactionBytes, and maxTransactionRecords. Omitted fields are unbounded. maxTransactionRecords counts distinct point dependencies and mutation keys, plus append heads and values. maxRecordBytes measures the largest record in UTF-8 bytes; maxTransactionBytes measures their total. meta.actual and meta.limit use records for the count limit and bytes for either byte limit. It rejects a mutating attempt above a limit with storage_limit_exceeded before the driver commits. Read-only attempts and query pages remain unrestricted. The wrapper shares the underlying driver's data and preserves its other methods.
Use the wrapper for Local storage limits. The OCC fixture's limits option uses the same simulator, including point dependencies in mutating attempts.
Reuse test fixtures
Import these helpers from @runlane/testing:
| Helper | Role |
|---|---|
createRunStorageValue(run, overrides?) | Adds empty storage bookkeeping and visible status to a public RunRecord. Explicit overrides model the scenario. |
createStorageDriverCounterRecord(id, count?) | Creates a raw counter record, starting at zero when count is omitted. |
readStorageDriverCounter(record) | Reads its safe-integer count and rejects malformed values. |
assertStressScenarioSucceeded(result) | Requires an empty captured-failure list and succeeded === iterations. Use it after runStressScenario(). |
These helpers provide test data and assertions. They do not add runtime workflow policy.
Storage checklist
Prove:
- exact point-read positions, duplicates, misses, and defensive copies.
- create, replace, and delete atomicity.
- callback replay, rollback, version fencing, and read-only conflicts.
- no partial write when any mutation fails.
- frozen transaction time and rejection of reads after sealing.
- every range bound in both sort directions.
- equal-sort key ordering and scoped pagination, including U+E000, U+FFFF, supplementary characters, and prefix pairs in both directions.
- native code-point/UTF-8 byte order without JavaScript result re-sorting; invalid identifier strings rejected before discovery or writes.
- the shared record size and atomic capacity floors.
- large point reads and large-limit queries that continue through capped pages with cursors.
storage_limit_exceededwith no durable effect for attempts the driver cannot commit.- optional operator filters, sorts, cursors, and tombstone visibility.
- optional append ordering, defensive copies, position bounds, atomic rollback, and combined transaction limits.
- optional exclusive selection across overlapping transactions, including release after rollback.
Run the same behavioral suite against more than one provider when possible. Parity catches assumptions hidden by one database.
Transport checklist
Prove:
- canonical byte preservation.
- one same-index outcome per input.
- native batch splitting and reconstruction.
- request-level versus item-level failure mapping.
handled,retry, andrejectsettlement.- cancellation, visibility or lock refresh, and shutdown.
- poison-message handling and terminal-policy failure.
- ordering within a partition and progress across partitions.
Test real infrastructure
Mocks cannot prove how a real service handles isolation, locks, clocks, batch errors, or redelivery. Add an opt-in suite for the real service. A supported compatible implementation is also useful.
Exercise at least:
- startup and compatibility checks.
- concurrent writers or consumers.
- process interruption during an owned operation.
- provider timeout and reconnect behavior.
- clean and repeated shutdown.
Run the package gates
Before release, run the package's typecheck, lint, tests, build, and publint. Then run its documented live-provider command.
Do not weaken a shared assertion to fit a provider. If the infrastructure cannot meet a contract, report a weaker profile where the contract allows it or do not expose that capability.