Implementation layer for the supported @scramjet/sequence-test package (scoped local sequence fixture/harness validation).
The source tree is organized around composable harness primitives:
index.ts: top-level public API surface,createSequenceTest,runSequence, and barrel re-exports of all harness primitives and types.runner-launcher.ts: runner env/launch abstraction.fake-instances-server.ts: low-level transport shim for runner instance channels.hub-harness.ts: full mock Hub API + timeline/recording/assertion engine (1246 lines — largest file).hub-mock.ts: thin compatibility facade exportingcreateHubMockascreateHubHarness().hub.fixtures.ts: sequence fixture creation and metadata validation.captures.ts: byte-stream and monitoring frame capture utilities.input-driver.ts: write helpers for sequence input payloads.request-client.ts: tiny HTTP helper used for sequence HTTP checks.
createRunnerEnv builds process env values expected by runner runtime (SEQUENCE_PATH, SEQUENCE_INFO, RUNNER_CONNECT_INFO, INSTANCES_SERVER_HOST/PORT, INSTANCE_ID).
createRunnerLaunchPlan adds process.execPath + resolved start-runner script path (resolveRunnerEntry) and stdio wiring for test transport interception.
Engine requirements are either:
- explicit in options (
engines), validated as string map, or - resolved by runtime (
node >=16,python3 >=3.8,bun >=1).
createSequenceTest returns a SequenceTestHarness with:
- lifecycle control methods (
start,close,waitForCompletion) - I/O and monitoring bridges (
input,output,logs,monitoring) - assertion accessor (
assert)
runSequence composes these primitives and currently short-circuits to direct execution for node mode (dynamic require, function invocation, ndjson-style output writing, monitoring frame injection).
createByteCapture-> in-memory chunk store (write,capture,raw,text,lines).createOutputCaptureextends output capture withndjson()parsing.createMonitoringCaptureparses framed lines intounknown[][], supports completion waiters throughwaitForCompletion, and emitsframes()snapshots.createSequenceAssertionsgives lightweight checks for completion + runtime error conditions in monitoring frames.
createInputDriver turns a writable stream into content-type aware input APIs:
text,bytes,ndjson,stream- emits
content-typeheader only on first payload - enforces idempotent
end().
- Implements a TCP server that parses Scramjet channel framing (header + payload).
- Tracks connected sockets/channels, raw buffers per channel, parsed monitoring frames, and harness-side errors.
- Patches
net.connect/createConnectionto map ephemeral client sockets by local port for richer socket correlation. - Exposes
awaitChannel(idx, timeout)to synchronize tests waiting on protocol channels.
createHubHarnesstracks:- registered routes
- full request/response timeline
- localStorage operations
- logs/events/lifecycle/api routes/space calls
- Supports assertions over timeline (
called,callCount,body,order) and returns canned/default API behavior. - Normalizes method/path, body parsing (JSON/buffers/streams), and response helpers (text/json, optional stream body).
- V2 client integration: provides
hubClient()andspaceClient()onHubContext, withv2HubClient/v2SpaceClientimplementations that delegate tohub.handle(). Default responses forGET /api/v2/status({ status: "ok" }) andGET /api/v1/cpm/api/v2/hubs({ items: [...] }). createHubMockis a minimal convenience wrapper aroundcreateHubHarness().hub.
createSequenceFixturewrites provided file map to temp fixture directory.createNodeSequenceFixture/createPythonSequenceFixture/createBunSequenceFixtureset defaults.resolveSequenceFixtureMetadatareads and validates fixturepackage.json, resolvesmainpath safely, and returns normalizedruntimeKindviaselectRuntimeKind.
createSequenceRequestClientprovides tiny HTTPfetch/get/posthelper over host+port.createSequenceRequestClientFromMonitoringderives API host/port from a monitoring frame payload (exposeHost,exposePort).
sequence-testis designed to plug into tests that would otherwise require a live runner process + hub infrastructure.- It intentionally reuses runner protocol constants/types and mirrors existing runner endpoint conventions for compatibility.
- The package is supported for scoped local sequence fixture/harness validation and is not a full parity replacement for a real Hub + runner deployment.
- 12 test fixtures exist including
v2-client-calls/(new — exerciseshubClient().status.get()andspaceClient().hubs.get()via the v2 canonical API). - Harness tests (14 spec files in
test/harness/) cover all primitives with Node, Python, and Bun runtime variants.