API Reference: Deterministic Testing (@siglo/testing)
The @siglo/testing package provides a zero-flake, deterministic test harness for Siglo workflows. It eliminates reliance on flaky timers, live databases, and manual mocking setups by providing virtual clocks (FakeClock), step spies, deterministic step mocking, event injection for durable waits, execution tracing, and replay tooling.
Table of Contents
- Overview and Installation
- Workflow Test Harness
- Harness Assertions
- Virtual Clock (
FakeClock) - In-Memory Storage Fake (
InMemoryStorageFake) - Execution Fixtures and Replay
- Full Test Suite Example
Overview and Installation
Workflow Test Harness
createWorkflowHarness(flow, options?)
Factory creating an isolated WorkflowHarness with virtual clocks, storage, step mocking, and execution telemetry.
Signatures
Example
harness.run and harness.execute
Executes the workflow through the instrumented harness, automatically recording step trace records, timings, and outputs.
Signature
harness.mockStep(stepName, mockImpl)
Overrides a step’s action with a deterministic mock implementation. Useful for third-party HTTP requests, credit card processors, or slow I/O.
Signature
Example
harness.spyStep(stepName)
Attaches a StepSpy tracking invocation count, inputs, outputs, errors, and timestamps without overriding the step’s implementation.
Signature
Example
harness.injectEvent(eventName, correlationKey, payload?)
Simulates the arrival of an external event to resume a durable waiting workflow in test scenarios without requiring network infrastructure.
Signature
Example
harness.getTrace()
Returns the recorded chronological execution trace across all steps and phases.
Signature
Harness Properties: clock and storage
The harness directly exposes its configured virtual clock and storage fake:
harness.clock: The activeFakeClockinstance used for timestamp tracking.harness.storage: The activeInMemoryStorageFakeadapter used to store checkpoints during durable test runs.
Harness Assertions
The harness provides high-level assertion helpers:harness.assertStepExecuted(stepName, times?)
Asserts that a step executed and completed successfully a specific number of times (or at least once if times is omitted).
harness.assertStepRetried(stepName, minAttempts?)
Asserts that a step failed and executed retries, verifying that total attempts met or exceeded minAttempts (default: 2).
harness.assertStepFailed(stepName, errorPattern?)
Asserts that a step failed, optionally matching against an error string substring or regular expression pattern.
Virtual Clock (FakeClock)
FakeClock controls timestamps recorded in harness execution traces deterministically. Note that FakeClock advances its own timestamp counter and tick() waits for setImmediate; it does not mock Node’s global Date.now, setTimeout, or runtime sleep loops:
Example
In-Memory Storage Fake (InMemoryStorageFake)
Implements StorageAdapter completely in memory for fast, zero-dependency unit and integration tests.
Execution Fixtures and Replay
harness.exportExecutionRecord(options?)
Exports a sanitized execution record fixture containing initial inputs, outputs, errors, and complete trace data. Secret keys (e.g. password, token, secret, cvv) are automatically redacted.
replayExecution(record, flow, options?)
Replays a recorded test fixture against a workflow to verify output parity, ensuring bug fixes or refactors do not introduce regressions.
Signature
Example
sanitizeExecutionRecord(record, options?)
Sanitizes an ExecutionRecord by recursively redacting sensitive keys (e.g. passwords, API keys, tokens, credit card numbers) from input, output, and trace steps.
