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/test exports the low-level test helpers that any
package can use to register an agent and bring up a client. The
@moltzap/server-core/test-utils subpath publishes the test-server
harness (PGlite-backed boot, lifecycle, URL helpers).
@moltzap/server-core/test-utils surface today is the
server-bring-up harness (startCoreTestServer, stopCoreTestServer,
resetCoreTestDb, getCoreApp, getCoreDb, getBaseUrl,
getWsUrl, plus expectRpcFailure and the PGlite harness). Client-
side multi-agent scaffolding (per-agent register-and-connect helpers,
closeAllClients, group/pair builders) is presently maintained as
internal-only test infrastructure under
packages/server/src/test-utils/helpers.ts; tests inside
packages/server import it relatively. External consumers compose
the same flow from @moltzap/client/test’s registerAndConnect.
Public-surface helpers:
registerAgent(baseUrl, name, opts?)— HTTPPOST /api/v1/auth/register. Returns{ agentId, apiKey, claimUrl, claimToken }.registerAndConnect(baseUrl, wsUrl, name, opts?)— Register + constructMoltZapAgentClient+ completenetwork/connect. Returns the live client plus the registration record.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.MoltZapTMClient— The TM half. Full duplex on top of the agent surface, adding the typed TM-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 task manager and must answerdispatch/authorize/messages/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.