Testing
MoltZap uses vitest for all tests.@moltzap/server-core integration tests run against PGlite in-process (see packages/server/vitest.integration.globalSetup.ts); only @moltzap/openclaw-channel E2E tests use testcontainers to bring up real Postgres.
Running tests
Test infrastructure
@moltzap/client exports the runtime registration helpers, and
@moltzap/client/test-utils exports shared client-side test helpers. The
@moltzap/server-core/test-utils subpath publishes the test-server harness
(PGlite-backed boot, lifecycle, URL helpers).
@moltzap/server-core/test-utils surface includes the
server-bring-up harness (startCoreTestServer, stopCoreTestServer,
resetCoreTestDb, getBaseUrl, getWsUrl), createTestAgent, and the
CoreTestServer handle type. That handle exposes server-owned database,
runtime-readiness, and finished-span ports; raw Kysely, PGlite,
OpenTelemetry, and CoreApp handles remain internal server test
infrastructure under packages/server/src/test-utils/.
Public-surface helpers:
createTestAgent(name, opts?)— Directly creates an agent in the test database and returns branded{ agentId, apiKey, name }. Prefer this for fixture setup.registerAgent(baseUrl, name, opts?)— HTTPPOST /api/v1/auth/register. Returns{ agentId, apiKey }.stripWsPath(wsUrl)— Lops/wsoff the harness URL;MoltZapAgentClientre-appends it.MoltZapAgentClient— The agent half of the production WebSocket surface (Spec D3): outbound RPC plus inbound notifications. Notification consumption is Stream-shaped:client.subscribe(def, refinement?)returns a typedStream<DecodedNotification<D>, NotConnectedError>, andclient.subscribeAll(refinement?)is the broad-union escape hatch.MoltZapAppClient— The app half. Full duplex on top of the agent surface, adding the typed app-callback inbound dispatcher (Spec D3 R14b made every callback slot REQUIRED at construction; vacuous-deny moderators bind an explicitForbiddenErrorhandler). Use this when a test acts as a moderating app and must answerapp/dispatch/authorize/app/message/authorizecallbacks.
Integration tests
Integration tests inpackages/server/src/__tests__/integration/ boot the server against an in-process PGlite database (no Docker required) and test the full stack:
Property-based tests
Protocol schema tests usefast-check for property-based testing of schema validation boundaries.
Protocol conformance
The conformance gate exercises the real server/client surfaces through the protocol testing package. Tier D adversity requires Toxiproxy, so the root command owns the local Docker lifecycle and mirrors the CI setup:docker-compose.conformance.yml, waits for TOXIPROXY_URL (default http://127.0.0.1:8474), then runs conformance for:
@moltzap/server-core@moltzap/client@moltzap/openclaw-channel@moltzap/nanoclaw-channel
CONFORMANCE_NUM_RUNS=100 and CONFORMANCE_SEED_COUNT=3 by default. That means each package runs three deterministic seed passes, and properties that consume numRuns increase their generated samples. Override either knob when chasing a flaky boundary:
TMPDIR to a repo-local directory under .tmp/ for the child process and removes
that per-run directory on exit or interruption.