java.lang.Object
com.agentforge4j.testkit.assertion.WorkflowRunAssert
Fluent, framework-agnostic assertions over a
WorkflowRunResult. Every verb is a pure
projection over the captured event stream, captured files, and the final state; on a failed
expectation a plain AssertionError is thrown, so the engine carries no test-framework
dependency. All verbs return this for chaining.-
Method Summary
Modifier and TypeMethodDescriptionapprovalDecision(String stepId, ApprovalOutcome outcome) Asserts an approval decision with a non-empty reason/note was recorded at the given step.approvalRequested(String stepId) Asserts an approval was requested at the given step.artifactAbsent(String path) Asserts no file was created at the given path.artifactPresent(String path) Alias ofcreatedFile(String).static WorkflowRunAssertassertThat(WorkflowRunResult result) Begins an assertion chain over a run result.contextEquals(String key, String expected) Asserts a context value equals the expected control value.contextHas(String key) Asserts a context key is present.contextHasField(String key, String field) Asserts a JSON context value has the given top-level field.contextMatchesRegex(String key, String regex) Asserts a context value matches the given regular expression.contextMissing(String key) Asserts a context key is absent.contextNonEmpty(String key) Asserts a context key is present and its value is non-empty.createdFile(String path) Asserts a file was created at the given path.Asserts no event of the given type was emitted.didNotInvokeTool(String capabilityId) Asserts the given tool capability was never invoked.didNotVisitStep(String stepId) Asserts the step was never visited.Asserts an event of the given type was emitted.eventCount(WorkflowEventType type, int expected) Asserts the exact number of events of the given type.eventsInOrder(WorkflowEventType... types) Asserts the given event types occur, in order, as a subsequence of the emitted events.failedBecause(String fragment) Asserts the run failed and its recorded failure reason contains the given fragment.failedWith(FailureKind kind) Asserts the run failed with the given failure kind.forEachIterations(int expected) Asserts the iteration count; an alias ofloopIterations(int)over the single canonicalLOOP_ITERATION_STARTEDsource.hasStatus(WorkflowStatus expected) Asserts the run's final status.inputRequested(String stepId) Asserts input was requested at the given step.invokedTool(String capabilityId) Asserts the given tool capability was invoked.Asserts the run completed.isFailed()Asserts the run failed.loopIterations(int expected) Asserts the iteration count, counted fromLOOP_ITERATION_STARTED.outputsHaveNoForbiddenTerms(Collection<String> forbiddenTerms) Asserts that no forbidden term appears in any generated run output — neither in a context value nor in a captured file's content.providerCallCount(int expected) Asserts the number of provider (LLM) calls (counted fromLLM_CALL_COMPLETED).providerCallCountForStep(String stepId, int expected) Asserts the number of provider (LLM) calls recorded for a specific step, regardless of dispatch or attempt.providerCallTier(ModelTier tier) Asserts at least one provider call resolved its model from the given tier.reachedPendingState(WorkflowStatus status) Asserts the run is in the given pending state.stepsInOrderedSubsequence(String... stepIds) Asserts the given step ids occur, in order, as a subsequence of the visited steps.stepVisitCount(String stepId, int expected) Asserts the step was visited exactly the expected number of times.tokenTotals(int expectedTotal) Asserts the deterministic total token usage recorded on the run.toolCallCount(int expected) Asserts the number of tool invocations (counted fromTOOL_INVOCATION_REQUESTED).visitedStep(String stepId) Asserts the step was visited at least once.
-
Method Details
-
assertThat
Begins an assertion chain over a run result.- Parameters:
result- the run result; must not benull- Returns:
- a new assertion
-
hasStatus
Asserts the run's final status.- Parameters:
expected- the expected status; must not benull- Returns:
- this
-
isCompleted
Asserts the run completed.- Returns:
- this
-
isFailed
Asserts the run failed.- Returns:
- this
-
failedWith
Asserts the run failed with the given failure kind.- Parameters:
kind- the expected failure kind; must not benull- Returns:
- this
-
failedBecause
Asserts the run failed and its recorded failure reason contains the given fragment. Use this to pin the specific rejection a negative scenario provokes (a parse error, a path-escape, a fail-closed miss) rather than merely that the run endedFAILED.- Parameters:
fragment- expected substring of the failure reason; must not be blank- Returns:
- this
-
visitedStep
Asserts the step was visited at least once.- Parameters:
stepId- the step id; must not be blank- Returns:
- this
-
didNotVisitStep
Asserts the step was never visited.- Parameters:
stepId- the step id; must not be blank- Returns:
- this
-
stepVisitCount
Asserts the step was visited exactly the expected number of times.- Parameters:
stepId- the step id; must not be blankexpected- the expected visit count- Returns:
- this
-
stepsInOrderedSubsequence
Asserts the given step ids occur, in order, as a subsequence of the visited steps.- Parameters:
stepIds- the ordered step ids; must not benull- Returns:
- this
-
contextHas
Asserts a context key is present.- Parameters:
key- the context key; must not be blank- Returns:
- this
-
contextMissing
Asserts a context key is absent.- Parameters:
key- the context key; must not be blank- Returns:
- this
-
contextNonEmpty
Asserts a context key is present and its value is non-empty.- Parameters:
key- the context key; must not be blank- Returns:
- this
-
contextEquals
Asserts a context value equals the expected control value. Reserve this for deterministic control values, never for LLM prose.- Parameters:
key- the context key; must not be blankexpected- the expected value; must not benull- Returns:
- this
-
contextMatchesRegex
Asserts a context value matches the given regular expression.- Parameters:
key- the context key; must not be blankregex- the regular expression; must not be blank- Returns:
- this
-
contextHasField
Asserts a JSON context value has the given top-level field.- Parameters:
key- the context key; must not be blankfield- the JSON field name; must not be blank- Returns:
- this
-
outputsHaveNoForbiddenTerms
Asserts that no forbidden term appears in any generated run output — neither in a context value nor in a captured file's content. Matching is case-insensitive and substring-based, so it catches currency codes, money words, and other terms an OSS output must never carry. All violations are reported together.- Parameters:
forbiddenTerms- the terms that must be absent; must not be empty- Returns:
- this
-
createdFile
Asserts a file was created at the given path.- Parameters:
path- the requested path; must not be blank- Returns:
- this
-
artifactPresent
Alias ofcreatedFile(String).- Parameters:
path- the requested path; must not be blank- Returns:
- this
-
artifactAbsent
Asserts no file was created at the given path.- Parameters:
path- the requested path; must not be blank- Returns:
- this
-
emittedEvent
Asserts an event of the given type was emitted.- Parameters:
type- the event type; must not benull- Returns:
- this
-
didNotEmitEvent
Asserts no event of the given type was emitted.- Parameters:
type- the event type; must not benull- Returns:
- this
-
eventCount
Asserts the exact number of events of the given type.- Parameters:
type- the event type; must not benullexpected- the expected count- Returns:
- this
-
eventsInOrder
Asserts the given event types occur, in order, as a subsequence of the emitted events.- Parameters:
types- the ordered event types; must not benull- Returns:
- this
-
reachedPendingState
Asserts the run is in the given pending state.- Parameters:
status- the pending status; must not benull- Returns:
- this
-
approvalRequested
Asserts an approval was requested at the given step.- Parameters:
stepId- the step id; must not be blank- Returns:
- this
-
approvalDecision
Asserts an approval decision with a non-empty reason/note was recorded at the given step.- Parameters:
stepId- the step id; must not be blankoutcome- the expected outcome; must not benull- Returns:
- this
-
inputRequested
Asserts input was requested at the given step.- Parameters:
stepId- the step id; must not be blank- Returns:
- this
-
loopIterations
Asserts the iteration count, counted fromLOOP_ITERATION_STARTED. This asserts the number of iterations, not the loop strategy — the event stream carries no strategy discriminator, so loop andforEachcannot be told apart here.- Parameters:
expected- the expected iteration count- Returns:
- this
-
forEachIterations
Asserts the iteration count; an alias ofloopIterations(int)over the single canonicalLOOP_ITERATION_STARTEDsource. This asserts the number of iterations, not the loop strategy — the event stream does not distinguish aforEachloop from any other, so the two names imply no distinction the events can back.- Parameters:
expected- the expected iteration count- Returns:
- this
-
invokedTool
Asserts the given tool capability was invoked.- Parameters:
capabilityId- the capability id; must not be blank- Returns:
- this
-
didNotInvokeTool
Asserts the given tool capability was never invoked.- Parameters:
capabilityId- the capability id; must not be blank- Returns:
- this
-
toolCallCount
Asserts the number of tool invocations (counted fromTOOL_INVOCATION_REQUESTED).- Parameters:
expected- the expected count- Returns:
- this
-
providerCallCount
Asserts the number of provider (LLM) calls (counted fromLLM_CALL_COMPLETED).- Parameters:
expected- the expected count- Returns:
- this
-
providerCallCountForStep
Asserts the number of provider (LLM) calls recorded for a specific step, regardless of dispatch or attempt. Useful for proving a looping or parse-retried step made the expected number of real, metered provider calls — each carries its ownstepUid/callAttemptdiscriminator in itsLLM_CALL_COMPLETEDpayload, but this assertion only needs the step id.- Parameters:
stepId- the step id to filter on; must not be blankexpected- the expected count- Returns:
- this
-
providerCallTier
Asserts at least one provider call resolved its model from the given tier.- Parameters:
tier- the expected model tier; must not benull- Returns:
- this
-
tokenTotals
Asserts the deterministic total token usage recorded on the run. Fails when no token total was recorded at all — an absentLLM_TOKENS_TOTALmeans token tracking never ran, which must not satisfy an expectation of0(a genuinely-tracked zero and a missing tracker are different facts).- Parameters:
expectedTotal- the expected total- Returns:
- this
-