AvelonDocs

@avelon

conformance

@avelon/conformance

@avelon/conformance is the load-bearing test artifact for Avelon drivers. It ships one suite per frozen contract, written against the contract rather than any implementation, plus in-memory fakes that run those same suites. Reach for this package when you certify a driver: pass a create factory that returns a known-empty instance, and let the suite own the assertions. A passing driver means someone other than the driver author wrote the tests.

Installation

bun add -d @avelon/conformance

Suites import bun:test and live at @avelon/conformance/suites. Fakes stay on the package root so a Next or Node production graph can import FakeMail without loading the test runner. Point a driver package at @avelon/core for the contract and at this package for the suite.

Basic Usage

Wire the shared database suite to an in-memory fake, then swap create for your driver when you certify it.

import { FakeDatabase } from '@avelon/conformance'
import { databaseSuite } from '@avelon/conformance/suites'

databaseSuite({
  name: 'reference fake',
  create: () => new FakeDatabase(),
})

A live driver owns fixture reset and cleanup. The suite still assumes each create() returns a known-empty world.

import { databaseSuite } from '@avelon/conformance/suites'
import { createPostgresDatabase } from '@avelon/postgres'

databaseSuite({
  name: 'live postgres',
  create: async () => {
    const driver = createPostgresDatabase()
    await driver.resetFixtures()
    return driver
  },
  cleanup: (driver) => driver.close(),
})

Shared Suites

Every contract has one suite. You did not write it. That is the point. Call the matching function from a bun test file; the suite registers describe and test blocks itself.

import { FakeMail } from '@avelon/conformance'
import { mailSuite } from '@avelon/conformance/suites'

mailSuite({
  name: 'reference fake',
  create: () => new FakeMail('transactional', 'mailer@example.test'),
})

A driver either passes a capability's tests or declares that capability false. Declaring true and failing, or declaring false while still implementing the method, is a suite failure.

Reference Fakes

Each fake is an in-memory implementation of one contract. Fakes run the same suites as live drivers, so new FakeMail() cannot drift from the mail contract. Use them in application tests and in this package's own certification of the suites.

Capability-narrowed variants exist where a boolean or spectrum can be off: FakeFlagsWithoutTargeting, FakeNotificationsWithoutChannels, FakeQueueWithoutRetries, FakeRateLimitWithoutAlgorithms, and FakeSearchWithoutFacets.

import { FakeFlags, FakeFlagsWithoutTargeting } from '@avelon/conformance'

const withTargeting = new FakeFlags()
const withoutTargeting = new FakeFlagsWithoutTargeting()

const targeted = await withTargeting.evaluate('assay.targeted', false, { actorId: 'actor-enabled' })
const globalOnly = await withoutTargeting.evaluate('assay.enabled', false)

Capability Surfaces

assertCapabilitySurface checks both lies: a declared capability whose method is missing, and an implemented method whose capability is false. Suites call it; you may also call it from a driver test when a surface is method-gated.

import { assertCapabilitySurface, captureFailure, FakeStorage } from '@avelon/conformance'

const storage = new FakeStorage()
assertCapabilitySurface(storage, 'signedUrls', storage.capabilities.signedUrls, ['signedUrl'])

const error = await captureFailure(() => storage.get('missing/avatar.png'))

captureFailure returns the thrown value so suites can assert the framework error taxonomy instead of a vendor code.

Method Reference

Method / exportSignatureDescription
assertCapabilitySurface(driver: object, capability: string, declared: boolean, methods: readonly string[]) => voidFails when a declared method is missing or an undeclared method is present.
captureFailure(operation: () => Promise<unknown>) => Promise<unknown>Runs an operation expected to throw and returns the thrown value.
SuiteContextinterface SuiteContext<TDriver>name, create, optional cleanup, and live-service helpers for one suite.
FakeAIclass FakeAIIn-memory AI driver used as the AI contract reference.
FakeCacheclass FakeCacheIn-memory cache driver used as the cache contract reference.
FakeDatabaseclass FakeDatabaseIn-memory database driver used as the database contract reference.
FakeFlagsclass FakeFlagsIn-memory flags driver with targeting enabled.
FakeFlagsWithoutTargetingclass FakeFlagsWithoutTargetingFlags fake with targeting declared unavailable.
FakeIdentityclass FakeIdentityIn-memory identity driver used as the identity contract reference.
FakeLogsclass FakeLogsIn-memory log driver with traces enabled.
FakeTraceRecordinterfaceObservable span state retained by FakeLogs.
FakeMailclass FakeMailIn-memory mail driver with hosted templates enabled.
FakeNotificationsclass FakeNotificationsIn-memory notifications driver with every channel declared.
FakeNotificationsWithoutChannelsclass FakeNotificationsWithoutChannelsNotifications fake with an empty channel list.
FakeSentNotificationinterfaceOne notification accepted by a notifications fake.
FakePaymentsclass FakePaymentsIn-memory payments driver used as the payments contract reference.
FakeQueueclass FakeQueueIn-memory queue driver with retries enabled.
FakeQueueWithoutRetriesclass FakeQueueWithoutRetriesQueue fake with retries declared unavailable.
FakeRateLimitclass FakeRateLimitIn-memory rate-limit driver with every algorithm declared.
FakeRateLimitWithoutAlgorithmsclass FakeRateLimitWithoutAlgorithmsRate-limit fake with an empty algorithm list.
FakeRealtimeclass FakeRealtimeIn-memory realtime driver used as the realtime contract reference.
FakeSearchclass FakeSearchIn-memory search driver with facets enabled.
FakeSearchWithoutFacetsclass FakeSearchWithoutFacetsSearch fake with facets declared unavailable.
FakeSocialclass FakeSocialIn-memory social identity driver used as the social contract reference.
FakeStorageclass FakeStorageIn-memory storage driver used as the storage contract reference.
FakeTokensclass FakeTokensIn-memory API-token driver used as the tokens contract reference.
aiSuite(context: SuiteContext<TDriver>) => voidShared AI contract suite from @avelon/conformance/suites.
cacheSuite(context: SuiteContext<TDriver>) => voidShared cache contract suite.
databaseSuite(context: SuiteContext<TDriver>) => voidShared database contract suite.
flagsSuite(context: SuiteContext<TDriver>) => voidShared flags contract suite.
identitySuite(context: SuiteContext<IdentityFactory<TDriver>>) => voidShared identity contract suite.
logsSuite(context: SuiteContext<TDriver>) => voidShared logs contract suite.
mailSuite(context: SuiteContext<TDriver>) => voidShared mail contract suite.
notificationsSuite(context: SuiteContext<TDriver>) => voidShared notifications contract suite.
paymentsSuite(context: SuiteContext<TDriver>) => voidShared payments contract suite.
queueSuite(context: SuiteContext<TDriver>) => voidShared queue contract suite.
ratelimitSuite(context: SuiteContext<TDriver>) => voidShared rate-limit contract suite.
realtimeSuite(context: SuiteContext<TDriver>) => voidShared realtime contract suite.
searchSuite(context: SuiteContext<TDriver>) => voidShared search contract suite.
socialSuite(context: SuiteContext<TDriver>) => voidShared social contract suite.
storageSuite(context: SuiteContext<TDriver>) => voidShared storage contract suite.
tokensSuite(context: SuiteContext<TDriver>) => voidShared tokens contract suite.

Testing

This package is the suite. Run it against the shipped fakes here, and again against a real driver in that driver's package. A deliberately broken stub in tests/ proves the suite rejects compiler defects rather than echoing the fake back to itself.

import { FakeStorage } from '@avelon/conformance'
import { storageSuite } from '@avelon/conformance/suites'

storageSuite({
  name: 'reference fake',
  create: () => new FakeStorage(),
})
bun test
bun run typecheck