Connect SDK
Testing
Use the transport-neutral client and deterministic sandbox for feature tests, then reserve the real connector for CEL, authorization, encryption, and route behavior.Test feature logic through MdbaseCollectionClient
import { createSandbox } from "@mdbase/connect-dev";
import type { JsonObject } from "@mdbase/connect";
interface Task extends JsonObject {
type: "task";
title: string;
status: "open" | "done";
}
const { client, transport } = createSandbox<Task>({
records: [{
path: "tasks/first.md",
types: ["task"],
frontmatter: {
type: "task",
title: "First",
status: "open"
}
}]
});
const result = await listOpenTasks(client);
expect(result.results).toHaveLength(1);
expect(transport.snapshot()[0].path).toBe("tasks/first.md");The sandbox implements the same small MdbaseCollectionTransport seam used by MdbaseCollectionClient. It is deterministic, requires no browser authorization, and exposes a snapshot helper for assertions.
What the sandbox covers
| Covered | Test with the real stack |
|---|---|
| Typed CRUD and operation envelopes | CEL expression semantics |
| Revision preconditions | Query ordering semantics |
| Type filtering and pagination | OAuth, PKCE, and grant approval |
| Read defaults | Direct and encrypted relay routing |
| Change cursors | Filesystem and hosted-provider behavior |
The sandbox rejects where and order_by. Run CEL expression and ordering tests against a conforming collection authority.
Use the real stack at system boundaries
Run integration tests against the local Connect stack for:
- manifest registration and callback validation;
- OAuth with PKCE and refresh-token rotation;
- portable short-code approval, expiry, polling limits, cancellation, and key binding;
file://memory isolation, popup blocking, and exactOrigin: nullgrants;- grant narrowing, pausing, revocation, and operation gaps;
- CEL filters, ordering, links, saved views, and type behavior;
- direct-to-relay failover and durable mutation receipts;
- hosted capabilities, sync, notifications, and authority timers.
Package tests should also build the dependency-free browser artifact, recalculate its SHA-384 value, compare it with integrity.json, and load the bundle from a real local file.
Recommended CI sequence
pnpm exec mdbase-connect-dev validate-manifest \
public/.well-known/mdbase-app.json
pnpm test
# Run semantic and route tests against the real local stack.
pnpm e2eValidate the manifest before tests so a callback or requirement error is reported as a declaration problem. Keep deterministic feature tests fast, then run the real-stack suite as the release boundary.