Skip to main content

server-core/test-utils

packages/server/src/test-utils

Purpose

Shared server-core test utility exports.

Public surface

AppEndpointHandlers

TypeAlias
Mapped over the closed AnyAppCallbackRpcDefinition union, keyed by each definition’s wire name. Mandates one handler per task-callback RPC at construction time — adding a new entry to appCallbackMethods becomes a compile error at every endpoint construction site.

AwaitNotificationError

TypeAlias

awaitOneNotification

Function
Stream-based one-shot waiter. Consumes client.subscribe(def) via Stream.runHead, failing with AwaitNotificationTimeoutError on timeout and AwaitNotificationClosedError when the transport closed before a matching frame arrived. Distinguishing close from timeout keeps a dead connection from masquerading as a missing notification.

closeAllClients

Function

connectAppClient

Function

ConnectedAgent

Interface

connectTestClient

Function

CoreSchemaSqlLoadError

TypeAlias

CoreTestDatabasePort

Interface
Database operations available to consumers of the published test harness.

CoreTestReadyOutcome

TypeAlias

CoreTestRuntimeServerHandle

Interface
Process capabilities needed by in-process runtime tests.

CoreTestServer

TypeAlias
Canonical published handle for a running core test server.

CoreTestServerHandle

Interface

CoreTestServerPort

Interface
Published server handle composed only from server-owned test ports.

CoreTestSpan

Interface
Stable projection of a finished server trace span.

CoreTestSpanExporterPort

Interface
Trace-capture operations available to test-harness consumers.

createTestAgent

Function

DEFAULT_TEST_ADMIN_USER_ID

Variable

getBaseUrl

Function

getCoreDb

Function

getCoreEncryptionEnvelope

Function

getWsUrl

Function

loadCoreSchemaSql

Function

makeFakeService

Function
Build a typed test double for an interface S from a partial implementation. The cast is intentional: tests typically implement only the methods the system under test actually calls. Unused methods throw at runtime via the Proxy trap so a missing implementation becomes a clear test failure instead of undefined is not a function. Because the generic parameter S is invariant, TypeScript still enforces that every method you do implement matches the real signature — this is the compile-time contract-drift insurance. Adding a field to the real interface does NOT fail compilation (tests are a Partial), but changing an existing field’s signature does.

makeHandlerAppEndpoint

Function
Build an AppEndpoint whose outbound originator.call dispatches to in-process handlers instead of going over a WebSocket. The endpoint satisfies the same { connId, originator } shape a connected app’s arm carries so AppEndpointRegistry, AppRegistry, and sendRpcToClient see ONE shape.
  • originator.callback({ definition, params }) indexes handlers by definition.name. The mapped type guarantees every member of AnyAppCallbackRpcDefinition has a handler — no runtime “method not found” branch exists.
  • originator.notify / failAllPending are no-ops.
  • originator.handle / originator.resolve defect — an in-process endpoint never receives inbound frames; a call here is a wiring bug.

makePgliteHarness

Function
Spin up a fresh PGlite instance with the core schema loaded.

PGLITE_HOOK_TIMEOUT_MS

Variable
Suggested timeout for pglite-backed beforeEach/afterEach hooks.

PgliteHarness

Interface

PgliteHarnessError

TypeAlias

postJson

Function
POST body as JSON to ${baseUrl}${path} and resolve with {status, json}. HTTP integration tests import this helper to avoid repeated request/JSON boilerplate.

registerAgent

Function

registerAndConnect

Function
Register and connect an agent. Tracked for automatic cleanup.

registerApp

Function

resetCoreTestDb

Function

setupAgentGroup

Function
Create N agents, all connected. Optionally create a group conversation.

setupAgentPair

Function
Create two agents, both connected. No contacts needed (core has open access).

startCoreTestServer

Function
Start a test server and expose its package-owned integration ports. Returns: A promise for the running server’s integration ports.

startCoreTestServerEffect

Function

startCoreTestServerFull

Function

StartCoreTestServerOptions

Interface

stopCoreTestServer

Function

trackClient

Function

Files

  • app-endpoint.ts
  • core-schema-sql.ts
  • fakes.ts
  • helpers.ts
  • index.ts
  • pglite-harness.ts
  • ports.ts
  • server.ts