@flow-state-dev/testing
Namespaces
Classes
StopRefusedError
A route's refusal of an answer, as a screen would be told it.
Extends
Error
Constructors
Constructor
new StopRefusedError(status, message): StopRefusedError;
Parameters
status
number
message
string
Returns
Overrides
Error.constructor
Properties
cause?
cause?: unknown;
Inherited from
Error.cause
message
message: string;
Inherited from
Error.message
name
name: string;
Inherited from
Error.name
stack?
stack?: string;
Inherited from
Error.stack
status
readonly status: number;
The route's HTTP status (404, 409, 400, 410).
Interfaces
AnalyzerScorerConfig
Properties
criteria
criteria: string[];
Evaluation criteria — each becomes a finding in the analyzer output.
model?
model?: ResolvableModel<any, BlockContext<Record<string, unknown>, {
[key: string]: unknown;
}, Record<string, unknown>, Record<string, unknown>, {
[key: string]: ResourceRef<any>;
}, {
[key: string]: unknown;
}, unknown, undefined, {
}, {
[key: string]: unknown;
}, Record<string, unknown>, Readonly<Record<string, unknown>>>>;
Model to use for grading (defaults to analyzer default).
modelResolver?
modelResolver?: ModelResolver;
Real resolver for the judge LLM; when set, the analyzer runs against it instead of the mock/noop path.
name?
name?: string;
Scorer name override.
scoreMapping?
scoreMapping?: ScoreMapping;
How to collapse per-criteria scores into one 0-1 value. Default: "mean".
threshold?
threshold?: number;
Pass/fail threshold (0-1). Default: 0.5.
CsvMapping
Type Parameters
TInput
TInput = unknown
TExpected
TExpected = unknown
Properties
expected?
expected?: (row) => TExpected;
Parameters
row
Record<string, string>
Returns
TExpected
id?
id?: (row) => string;
Parameters
row
Record<string, string>
Returns
string
input
input: (row) => TInput;
Parameters
row
Record<string, string>
Returns
TInput
EvalBlockConfig
Type Parameters
TInput
TInput = unknown
TOutput
TOutput = unknown
Properties
blockOptions?
blockOptions?: Partial<Omit<TestBlockOptions<TInput>, "input">>;
concurrency?
concurrency?: number;
dataset
dataset: EvalCase<TInput, Partial<TOutput>>[];
scorers
scorers: Scorer<TOutput>[];
signal?
signal?: AbortSignal;
EvalCase
Type Parameters
TInput
TInput = unknown
TExpected
TExpected = unknown
Properties
expected?
expected?: TExpected;
id?
id?: string;
input
input: TInput;
metadata?
metadata?: Record<string, unknown>;
EvalCaseResult
Properties
caseId
caseId: string;
durationMs
durationMs: number;
error?
error?: object;
message
message: string;
name
name: string;
expected
expected: unknown;
input
input: unknown;
output
output: unknown;
passed
passed: boolean;
scores
scores: Record<string, ScoreResult>;
EvalFlowConfig
Type Parameters
TInput
TInput = unknown
Properties
action
action: string;
concurrency?
concurrency?: number;
dataset
dataset: EvalCase<TInput, unknown>[];
flowOptions?
flowOptions?: Partial<Omit<TestFlowOptions<TInput>, "input" | "flow" | "action" | "userId">>;
scorers
scorers: Scorer<unknown>[];
signal?
signal?: AbortSignal;
userId?
userId?: string;
EvalReport
Properties
passed
passed: boolean;
results
results: EvalCaseResult[];
summary
summary: Record<string, ScorerSummary>;
timing
timing: object;
meanPerCaseMs
meanPerCaseMs: number;
totalMs
totalMs: number;
LoadDatasetOptions
Type Parameters
T
T = unknown
Properties
schema?
schema?: ZodTypeAny;
transform?
transform?: (raw) => T;
Parameters
raw
unknown
Returns
T
ScoreResult
Properties
costUsd?
costUsd?: number;
Estimated USD cost the scorer itself incurred (e.g. an LLM-judge call). Optional; set by scorers that make model calls so callers can budget.
passed
passed: boolean;
reason?
reason?: string;
score
score: number;
ScorerSummary
Properties
max
max: number;
mean
mean: number;
min
min: number;
passRate
passRate: number;
stddev
stddev: number;
Type Aliases
CreateTestContextOptions
type CreateTestContextOptions<TInput> = Omit<TestBlockOptions<TInput>, "input"> & object;
Public testing utilities for deterministic block/flow assertions.
Type Parameters
TInput
TInput = unknown
Type Declaration
actionName?
actionName?: string;
declaredResources?
declaredResources?: DeclaredResources;
Resources the block-under-test declares on its resources: slots (bubbled
up from descendants). Merged into the synthetic flow's resources so
ctx.resources.X is wired the way production does via flow.resources.
Explicitly-seeded scope resources take precedence on accessor-key conflict.
orgId?
orgId?: string;
requestId?
requestId?: string;
sequencerName?
sequencerName?: string;
sessionId?
sessionId?: string;
userId?
userId?: string;
MockEvaluationAnswer
type MockEvaluationAnswer =
| {
choice: string;
confidence?: number;
probabilities?: Record<string, number>;
type: "choice";
}
| {
confidence?: number;
probabilities?: Record<string, number>;
score: number;
type: "score";
}
| {
confidence?: number;
probability: number;
type: "boolean";
};
One scripted answer, in the SDK's shape, plus an optional reported confidence.
MockEvaluationAnswers
type MockEvaluationAnswers = Record<string, MockEvaluationAnswer>;
Scripted answers, keyed by question id.
MockEvaluationCall
type MockEvaluationCall = object;
What one call to the mock received, its state as the value evaluated.
Properties
abortSignal?
abortSignal?: AbortSignal;
questions
questions: Record<string, unknown>;
state
state: unknown;
MockEvaluationModel
type MockEvaluationModel = EvaluationModel & object;
An evaluation model that records its calls.
Type Declaration
calls
readonly calls: MockEvaluationCall[];
Every call made to the model, in order.
MockEvaluationModelOptions
type MockEvaluationModelOptions = object;
Options for mockEvaluationModel.
Properties
answers?
answers?:
| MockEvaluationAnswers
| ((call) => MockEvaluationAnswers);
Answers returned from every call, keyed by question id. A function is
handed each call's state and questions and answers that call, so one
script can answer differently per state; throwing from it rejects the
call like error does.
error?
error?: Error;
Reject every call with this error.
hold?
hold?: boolean;
Hold every call pending until its abort signal fires.
modelId?
modelId?: string;
Model id. Defaults to "mock-evaluation".
provider?
provider?: string;
Provider id. Defaults to "mock.evaluation".
supportedQuestionTypes?
supportedQuestionTypes?: EvaluationQuestionType[];
Question types the model answers. Defaults to all three.
usage?
usage?: object;
Reported token usage. Defaults to 10 input and 1 output token.
inputTokens?
inputTokens?: number;
outputTokens?
outputTokens?: number;
MockGeneratorInstance
type MockGeneratorInstance = object;
Properties
calls
calls: object[];
blockName?
blockName?: string;
input
input: unknown;
model?
model?: string;
prompt?
prompt?: string;
name
name: string;
Methods
next()
next(input?, context?): MockGeneratorScriptStep | undefined;
Returns the next script step for the given input. The argument is the
resolved input passed to predicate when functions; pass the model
messages or whatever shape the test wants predicates to inspect.
Returns undefined only when the script is empty and no predicate
matched — most scenarios should treat that as an error condition.
context.toolResults holds what the tools this call already ran returned,
oldest first, so a hand-written instance can script a step that depends
on a tool's result. mockGenerator's own instance ignores it.
Parameters
input?
unknown
context?
toolResults
Returns
MockGeneratorScriptStep | undefined
reset()
reset(): void;
Returns
void
MockGeneratorPredicateEntry
type MockGeneratorPredicateEntry = object;
Predicate entry: matches calls whose input satisfies when.
Properties
then
then: MockGeneratorScriptStep;
when
when: (input) => boolean;
Parameters
input
unknown
Returns
boolean
MockGeneratorScriptEntry
type MockGeneratorScriptEntry =
| MockGeneratorScriptStep
| MockGeneratorPredicateEntry;
A script entry — either a plain step (consumed sequentially) or a predicate.
MockGeneratorScriptStep
type MockGeneratorScriptStep = object;
Properties
finishReason?
finishReason?: string;
structuredOutput?
structuredOutput?: unknown;
text?
text?: string;
toolCalls?
toolCalls?: object[];
args
args: unknown;
toolCallId
toolCallId: string;
toolName
toolName: string;
MockToolResult
type MockToolResult = object;
What one tool call returned, in the order the script's tool loop ran it.
Properties
result
result: unknown;
toolCallId
toolCallId: string;
toolName
toolName: string;
ReplayingRef
type ReplayingRef<TState> = object;
A replaying double, plus the state it ended up committing.
Type Parameters
TState
TState extends object
Properties
committed
readonly committed: Readonly<TState>;
The state the winning attempt produced.
state
state: Readonly<TState>;
What a caller reads before starting the write — the pre-conflict snapshot, NOT the state that ends up committing. Reading this and then using the value inside the callback is the stale-read defect; a helper that derives the value from the state the callback receives is immune.
Methods
updateState()
updateState(updater): Promise<void>;
Applies updater to the losing state, discards it, then applies it to the winning state and commits.
Parameters
updater
(state) => TState | Promise<TState>
Returns
Promise<void>
ScoreMapping
type ScoreMapping =
| "mean"
| "min"
| {
strategy: "weighted";
weights: Record<string, number>;
};
Scorer
type Scorer<TOutput> = object;
Type Parameters
TOutput
TOutput = unknown
Properties
name
name: string;
score
score: (args) =>
| ScoreResult
| Promise<ScoreResult>;
Parameters
args
expected?
Partial<TOutput>
input
unknown
output
TOutput
Returns
| ScoreResult
| Promise<ScoreResult>
threshold?
threshold?: number;
SideChainTrace
type SideChainTrace = object;
Properties
blockName
blockName: string;
error
error: Error | null;
items
items: TestItem[];
output
output: unknown;
SnapshotTrace
type SnapshotTrace = object;
Properties
actionName?
actionName?: string;
flowKind?
flowKind?: string;
items
items: object[];
blockName
blockName: string;
itemIndex
itemIndex: number;
phase
phase: "main" | "sideChain";
status
status: OutputItem["status"];
type
type: OutputItem["type"];
requestId
requestId: string;
steps
steps: object[];
blockKind
blockKind: "handler" | "generator" | "evaluator" | "sequencer" | "router";
blockName
blockName: string;
durationMs
durationMs: number;
error?
error?: string;
inputSummary
inputSummary: unknown;
outputSummary
outputSummary: unknown;
phase
phase: "main" | "sideChain";
StateChange
type StateChange = object;
Properties
args
args: unknown[];
operation
operation:
| "patchState"
| "setState"
| "incState"
| "pushState"
| "setStateRecord"
| "deleteStateRecord"
| "atomicState";
resultingState
resultingState: Record<string, unknown>;
scope
scope: "request" | "session" | "user" | "org" | "block_instance";
targetInstanceId?
targetInstanceId?: string;
targetName?
targetName?: string;
StepTrace
type StepTrace = object;
Properties
blockName
blockName: string;
durationMs
durationMs: number;
error
error: Error | null;
input
input: unknown;
items
items: TestItem[];
output
output: unknown;
phase
phase: "main" | "sideChain";
skipped
skipped: boolean;
stepName
stepName: string;
TestBlockOptions
type TestBlockOptions<TInput> = TestStateSeed & object;
Type Parameters
TInput
TInput
Type Declaration
flow?
flow?: FlowInstance;
Optional flow instance. When provided, its resource configs (including resource collections) are used instead of the auto-generated ones.
flowConfig?
flowConfig?: Record<string, unknown>;
The flow copy's create-time config bag, read by the block under test as
ctx.flow.config. Frozen, like production. Omit it and the block reads a
frozen empty object — never undefined.
Ignored when flow is supplied: that instance carries its own bag.
generators?
generators?: Record<string, MockGeneratorInstance>;
input
input: TInput;
modelResolver?
modelResolver?: ModelResolver;
Real resolver to route generation through; overrides the mock resolver when set.
models?
models?: Record<string, MockGeneratorInstance>;
sequencer?
sequencer?: TestSequencerSeed;
signal?
signal?: AbortSignal;
The signal the block runs under, as ctx.signal. Abort it to stop the
run the way a host does (a deadline, a user's stop). Omit it and the
block runs under a signal that never fires.
targets?
targets?: Record<string, TestTargetSeed>;
tools?
tools?: Record<string, (...args) => Promise<any> | any>;
unmockedDefault?
unmockedDefault?: UnmockedDefault;
Fallback script for unmocked generators when policy is "default".
unmockedGeneratorPolicy?
unmockedGeneratorPolicy?: UnmockedGeneratorPolicy;
TestBlockResult
type TestBlockResult<TOutput, TBlock> = object & ([TBlock] extends [SequencerDefinition<any, any, any, any>] ? object : unknown);
What testBlock returns. The fields depend on the block's kind: a
sequencer's result also carries its steps, sideChainResults and
loopIterations, read from the items it emitted, and a router's names the
route it chose in selectedRoute.
Type Parameters
TOutput
TOutput
TBlock
TBlock = BlockDefinition<any, any>
Type Declaration
error
error: Error | null;
items
items: TestItem[];
meta
meta: object;
meta.blockName
blockName: string;
meta.durationMs
durationMs: number;
meta.retryAttempts
retryAttempts: number;
output
output: TOutput;
resources
resources: Record<string, unknown>;
The block's resolved resource registry, after the run.
state covers the scope records; this covers the other half — resource
collections a block declares and writes into. Without it a test that
asserts on written ROWS has to build its own context and dispatch the
block's execute callback by hand, which skips the execution wrapping
every consumer goes through. Reading rows and running the block the real
way stop being mutually exclusive.
Keyed by the accessor names in the block's declaredResources, which
testBlock already wires into the synthetic flow. {} for a block that
declares none.
selectedRoute?
selectedRoute?: string;
The route a router chose, by the chosen block's name. Absent for every other kind, and for a router that chose none.
state
state: object;
state.org
org: Record<string, unknown>;
state.request
request: Record<string, unknown>;
state.sequencer
sequencer: Record<string, unknown>;
state.session
session: Record<string, unknown>;
state.user
user: Record<string, unknown>;
stateChanges
stateChanges: StateChange[];
TestFlowAnswer
type TestFlowAnswer = object;
An answer to a stop, as run.answer and run.resume take it.
Properties
action
action: ResumeAction;
data?
data?: unknown;
headers?
headers?: Record<string, string>;
Headers for the route call, for a flow with its own sign-in: what its
authentication.resolvePrincipal reads, so it resolves the test's user
and the org the run ran in.
suspensionId?
suspensionId?: string;
The stop to answer. Defaults to the run's one pending stop; required when it has several.
TestFlowOptions
type TestFlowOptions<TInput> = object;
Type Parameters
TInput
TInput = unknown
Properties
action
action: string;
durable?
durable?: boolean;
Run with durable execution, as a host whose stores persist does. Default
true: a step that calls ctx.suspendForUser or ctx.suspend stops the
run with status suspended. false runs without it, where such a step
fails the run.
flow
flow: FlowInstance;
generators?
generators?: Record<string, MockGeneratorInstance>;
input
input: TInput;
models?
models?: Record<string, MockGeneratorInstance>;
seed?
seed?: TestStateSeed;
sessionId?
sessionId?: string;
settings?
settings?: FlowStateSettings;
Instance-level settings exposed to blocks via ctx.settings. Mirrors
createFlowState({ settings }) so tests can exercise settings-dependent
behavior without standing up a full FlowState.
stores?
stores?: StoreRegistry;
Reuse an existing in-memory store registry instead of creating a fresh
one. Lets multiple testFlow calls share session, user, org, and
request state — the foundation for session-resume scenarios. Seeding
is idempotent, so repeated runs against the same registry preserve
journal entries and resource state from prior calls.
unmockedDefault?
unmockedDefault?: UnmockedDefault;
Fallback script for unmocked generators when unmockedGeneratorPolicy is
"default" — yields this instead of throwing or emitting empty output.
unmockedGeneratorPolicy?
unmockedGeneratorPolicy?: UnmockedGeneratorPolicy;
userId
userId: string;
TestFlowResult
type TestFlowResult = object;
Properties
error?
error?: Error;
items
items: TestItem[];
output?
output?: unknown;
requestId
requestId: string;
status
status:
| "completed"
| "failed"
| "incomplete"
| "interrupted"
| "aborted"
| "suspended";
suspension?
suspension?: SuspensionItem;
The stop the run is waiting on, as a screen sees it. Absent when nothing waits.
Methods
answer()
answer(answer): Promise<TestFlowResult>;
Answers a user's stop (ctx.suspendForUser) through the engine's answer
route, as a screen does, and returns the run that followed: its status
and the items emitted after the stop. A refusal the route gives a screen
(an action the stop doesn't allow, a second answer, data that fails its
schema) throws a StopRefusedError with the route's status and message.
Parameters
answer
Returns
Promise<TestFlowResult>
resume()
resume(answer): Promise<TestFlowResult>;
Continues a run stopped by a developer's own ctx.suspend through the
engine's resume route, and returns the run that followed.
Parameters
answer
Returns
Promise<TestFlowResult>
TestSequencerSeed
type TestSequencerSeed = TestTargetSeed & object;
Type Declaration
name?
name?: string;
TestStateSeed
type TestStateSeed = object;
Properties
org?
org?: TestScopeSeed;
request?
request?: TestRequestSeed;
session?
session?: TestScopeSeed;
user?
user?: TestScopeSeed;
TestTargetSeed
type TestTargetSeed = object;
Properties
state
state: Record<string, unknown>;
UnmockedDefault
type UnmockedDefault =
| MockGeneratorScriptStep
| ((info) => MockGeneratorScriptStep);
Fallback for an unmocked generator under policy: "default". Either a static
script step or a per-resolve factory keyed on the model / block being
resolved. Omitting it under "default" yields a no-op terminal step.
UnmockedGeneratorPolicy
type UnmockedGeneratorPolicy = "error" | "warn" | "allow" | "default";
Functions
allOf()
function allOf<TOutput>(...scorers): Scorer<TOutput>;
Type Parameters
TOutput
TOutput = unknown
Parameters
scorers
...Scorer<TOutput>[]
Returns
Scorer<TOutput>
analyzerScorer()
function analyzerScorer(config): Scorer<unknown>;
Creates a Scorer that uses a utility.analyzer block to perform LLM-as-judge
evaluation. Each eval case is graded by running the analyzer with the
configured criteria, then mapping the per-criteria scores to a single 0-1 value.
Parameters
config
Returns
Scorer<unknown>
anyOf()
function anyOf<TOutput>(...scorers): Scorer<TOutput>;
Type Parameters
TOutput
TOutput = unknown
Parameters
scorers
...Scorer<TOutput>[]
Returns
Scorer<TOutput>
buildReport()
function buildReport(results, startedAt): EvalReport;
Parameters
results
startedAt
number
Returns
contains()
function contains<TOutput>(substring): Scorer<TOutput>;
Type Parameters
TOutput
TOutput = unknown
Parameters
substring
string
Returns
Scorer<TOutput>
createMockModelResolver()
function createMockModelResolver(options): ModelResolver;
Builds a ModelResolver that delegates to scripted mocks. Per-block mocks
win over per-model mocks. Unmocked generators throw under policy: "error"
(default), produce a no-op model under "warn" | "allow", and yield the
caller-supplied unmockedDefault script under "default" — so a large
e2e flow can fall back for the generators it didn't mock instead of breaking.
evaluators scripts evaluator blocks that name a model string, keyed
by block name like generators (e.g. a mockEvaluationModel). Passing it
gives the resolver its resolveEvaluationModel hook, which refuses a block
with no entry, naming it. Without it the resolver has no hook, so such a
block refuses to run, as a resolver without the hook always does.
Parameters
options
evaluators?
Record<string, EvaluationModel>
generators?
Record<string, MockGeneratorInstance>
models?
Record<string, MockGeneratorInstance>
onUnmocked?
(message) => void
policy?
unmockedDefault?
Returns
ModelResolver
createReplayingRef()
function createReplayingRef<TState>(losing, winning): ReplayingRef<TState>;
Build a replaying updateState double.
Type Parameters
TState
TState extends object
Parameters
losing
TState
State the discarded attempt sees — the pre-conflict snapshot.
winning
TState
State the committing attempt sees — what a concurrent writer left behind.
const ref = createReplayingRef(before, afterConcurrentWriterRemovedIt)
expect(await evict(ref, "wm_1")).toBe(false) // not `true` from the losing attempt
Returns
ReplayingRef<TState>
createTestContext()
function createTestContext<TInput>(options?): Promise<TestContextRuntime>;
Create an isolated execution context with the given flow and scope seeds.
A raw context has no block from which to collect state schemas. Pass a flow
to read its scope defaults, or use testBlock to include a block's declarations.
Type Parameters
TInput
TInput = unknown
Parameters
options?
CreateTestContextOptions<TInput>
Returns
Promise<TestContextRuntime>
custom()
function custom<TOutput>(name, fn): Scorer<TOutput>;
Type Parameters
TOutput
TOutput = unknown
Parameters
name
string
fn
(args) =>
| ScoreResult
| Promise<ScoreResult>
Returns
Scorer<TOutput>
evalBlock()
function evalBlock<TBlock>(block, config): Promise<EvalReport>;
Type Parameters
TBlock
TBlock extends BlockDefinition<any, any, any, any>
Parameters
block
TBlock
config
EvalBlockConfig<BlockInput<TBlock>, BlockOutput<TBlock>>
Returns
Promise<EvalReport>
evalFlow()
function evalFlow<TInput>(flow, config): Promise<EvalReport>;
Type Parameters
TInput
TInput = unknown
Parameters
flow
FlowInstance
config
EvalFlowConfig<TInput>
Returns
Promise<EvalReport>
exactMatch()
function exactMatch<TOutput>(field?): Scorer<TOutput>;
Type Parameters
TOutput
TOutput = unknown
Parameters
field?
string
Returns
Scorer<TOutput>
fromCsv()
function fromCsv<TInput, TExpected>(path, mapping): Promise<EvalCase<TInput, TExpected>[]>;
Type Parameters
TInput
TInput = unknown
TExpected
TExpected = unknown
Parameters
path
string
mapping
CsvMapping<TInput, TExpected>
Returns
Promise<EvalCase<TInput, TExpected>[]>
jsonPath()
function jsonPath<TOutput>(path, expected): Scorer<TOutput>;
Type Parameters
TOutput
TOutput = unknown
Parameters
path
string
expected
unknown
Returns
Scorer<TOutput>
loadDataset()
function loadDataset<TInput, TExpected>(path, options?): Promise<EvalCase<TInput, TExpected>[]>;
Type Parameters
TInput
TInput = unknown
TExpected
TExpected = unknown
Parameters
path
string
options?
LoadDatasetOptions<EvalCase<TInput, TExpected>>
Returns
Promise<EvalCase<TInput, TExpected>[]>
mockEvaluationModel()
function mockEvaluationModel(options?): MockEvaluationModel;
Build a scripted evaluation model.
Parameters
options?
Returns
Example
const model = mockEvaluationModel({
answers: {
team: { type: "choice", choice: "billing", confidence: 0.94 },
urgent: { type: "boolean", probability: 0.2 },
},
});
const triage = evaluator({ name: "triage", model, questions });
// ...run it...
expect(model.calls).toHaveLength(1);
mockGenerator()
function mockGenerator(options): MockGeneratorInstance;
Creates a deterministic scripted generator mock. See module docstring for the full plain-vs-predicate resolution order.
Parameters
options
name
string
script
Returns
runForTest()
function runForTest<TInputSchema, TOutputSchema, TInput, TOutput>(
block,
input,
ctx
): Promise<TOutput>;
Type Parameters
TInputSchema
TInputSchema extends ZodTypeAny
TOutputSchema
TOutputSchema extends ZodTypeAny
TInput
TInput
TOutput
TOutput
Parameters
block
BlockDefinition<TInputSchema, TOutputSchema, TInput, TOutput>
input
TInput
ctx
BlockContext
Returns
Promise<TOutput>
schemaValid()
function schemaValid<TOutput>(schema): Scorer<TOutput>;
Type Parameters
TOutput
TOutput = unknown
Parameters
schema
ZodTypeAny
Returns
Scorer<TOutput>
snapshotTrace()
function snapshotTrace(result): SnapshotTrace;
Produces a stable trace summary shape for snapshot assertions.
Parameters
result
actionName?
string
flowKind?
string
items
OutputItem[]
requestId?
string
steps?
Returns
testBlock()
function testBlock<TBlock>(block, options): Promise<TestBlockResult<BlockOutput<TBlock>, TBlock>>;
Executes one block with seeded scope state and returns deterministic test artifacts.
Types are inferred from the block's Zod schema parameters:
- Input type is derived from the block's
inputSchemaproperty - Output type is derived from the block's
outputSchemaproperty
The result depends on the block's kind: a sequencer's also carries its
steps, sideChainResults and loopIterations; a router's names the
route it chose in selectedRoute.
Type Parameters
TBlock
TBlock extends BlockDefinition<any, any, any, any>
Parameters
block
TBlock
options
TestBlockOptions<BlockInput<TBlock>>
Returns
Promise<TestBlockResult<BlockOutput<TBlock>, TBlock>>
testFlow()
function testFlow<TInput>(options): Promise<TestFlowResult>;
Executes one flow action in an isolated in-memory runtime and returns item/status artifacts.
Type Parameters
TInput
TInput = unknown
Parameters
options
TestFlowOptions<TInput>
Returns
Promise<TestFlowResult>
testItems()
function testItems(items): object;
Builds item-focused query helpers for deterministic test assertions.
Selectors that don't filter by type (all, sideChain, main, byAgent,
byVisibility) return every matching row, trace rows included, so they are
typed RuntimeItem[].
Parameters
items
readonly RuntimeItem[]
Returns
object
all()
all(): RuntimeItem[];
Returns
RuntimeItem[]
blockOutputs()
blockOutputs(blockName?): BlockTraceItem[];
Parameters
blockName?
string
Returns
BlockTraceItem[]
byAgent()
byAgent(agentName): RuntimeItem[];
Parameters
agentName
string
Returns
RuntimeItem[]
byType()
byType<TType>(type): (
| Extract<MessageItem, {
type: TType;
}>
| Extract<ReasoningItem, {
type: TType;
}>
| Extract<ToolOutputItem, {
type: TType;
}>
| Extract<DataItem, {
type: TType;
}>
| Extract<ContainerItem, {
type: TType;
}>
| Extract<SourceItem, {
type: TType;
}>
| Extract<StatusItem, {
type: TType;
}>
| Extract<ErrorItem, {
type: TType;
}>
| Extract<StateChangeItem, {
type: TType;
}>
| Extract<ResourceChangeItem, {
type: TType;
}>
| Extract<SuspensionItem, {
type: TType;
}>
| Extract<SuspensionResumeItem, {
type: TType;
}>
| Extract<ContinuationItem, {
type: TType;
}>)[];
Type Parameters
TType
TType extends
| "message"
| "reasoning"
| "tool_output"
| "data"
| "container"
| "source"
| "status"
| "error"
| "state_change"
| "resource_change"
| "suspension"
| "suspension_resume"
| "continuation"
Parameters
type
TType
Returns
(
| Extract<MessageItem, {
type: TType;
}>
| Extract<ReasoningItem, {
type: TType;
}>
| Extract<ToolOutputItem, {
type: TType;
}>
| Extract<DataItem, {
type: TType;
}>
| Extract<ContainerItem, {
type: TType;
}>
| Extract<SourceItem, {
type: TType;
}>
| Extract<StatusItem, {
type: TType;
}>
| Extract<ErrorItem, {
type: TType;
}>
| Extract<StateChangeItem, {
type: TType;
}>
| Extract<ResourceChangeItem, {
type: TType;
}>
| Extract<SuspensionItem, {
type: TType;
}>
| Extract<SuspensionResumeItem, {
type: TType;
}>
| Extract<ContinuationItem, {
type: TType;
}>)[]
byVisibility()
byVisibility(predicate): RuntimeItem[];
Parameters
predicate
Partial<ItemVisibility>
Returns
RuntimeItem[]
data()
data(dataType?): DataItem[];
Parameters
dataType?
string
Returns
DataItem[]
errors()
errors(): ErrorItem[];
Returns
ErrorItem[]
main()
main(): RuntimeItem[];
Returns
RuntimeItem[]
messages()
messages(): MessageItem[];
Returns
MessageItem[]
sideChain()
sideChain(): RuntimeItem[];
Returns
RuntimeItem[]
threshold()
function threshold<TOutput>(
field,
min,
max?
): Scorer<TOutput>;
Type Parameters
TOutput
TOutput = unknown
Parameters
field
string
min
number
max?
number
Returns
Scorer<TOutput>