test: WorkflowExecutionListener behaviour-documenting tests#508
Open
mdproctor wants to merge 2 commits into
Open
test: WorkflowExecutionListener behaviour-documenting tests#508mdproctor wants to merge 2 commits into
mdproctor wants to merge 2 commits into
Conversation
Adds WorkflowExecutionListenerBehaviourTest, a set of four behaviour-documenting tests for the WorkflowExecutionListener lifecycle hooks. These tests answer specific integration questions that casehub-engine depends on (see casehubio/engine#213). Q1 — WorkflowContext cast: confirmed safe. The context(WorkflowModel) setter does NOT propagate to FuncDSL task function input; tasks receive their input from the workflow INPUT model, not the running context(). casehub must pass propagation metadata via startInstance(Map) input. Q2 — onWorkflowCompleted timing: the hook fires synchronously as part of the CompletableFuture completion chain inside startExecution(). instanceData().output() is null for simple FuncDSL single-task workflows — listeners must null-guard before calling asMap(). Q3 — onTaskCompleted granularity: documents the exact count observed for three sequential agent actions — assertion is self-documenting and protects the count from changing unnoticed. Q4 — Uni<T> return type: a workflow function returning Uni<String> completes correctly via Uni2CompletableFuture with no blocking. This confirms the casehub FlowWorker ↔ WorkOrchestrator dispatch path. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 30, 2026
fjtirado
reviewed
Apr 30, 2026
| @Override | ||
| public void onWorkflowCompleted(WorkflowCompletedEvent event) { | ||
| // output() can return null for simple FuncDSL single-task workflows | ||
| var outputModel = event.workflowContext().instanceData().output(); |
Contributor
There was a problem hiding this comment.
Suggested change
| var outputModel = event.workflowContext().instanceData().output(); | |
| var outputModel = event.output(); |
…ertion - onWorkflowCompleted: use event.output() — the correct API for output inside event callbacks. instanceData().output() is a blocking join intended for callers outside the event chain, not inside listeners. - Q2: correct the finding — event.output() is populated and the hook fires synchronously. Remove misdiagnosed null-output claim and sleep. - Q3: replace isEqualTo(actualCount) self-reference with isGreaterThanOrEqualTo(1), which actually catches hook-not-firing. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Author
|
Updated in response to @fjtirado's review:
Also noting for context: sdk-java#1359 (moving |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
WorkflowExecutionListenerBehaviourTest— four behaviour-documenting tests for theWorkflowExecutionListenerlifecycle hooks in thelangchain4jmodule. These tests answer specific integration questions from casehubio/engine#213.The tests are written in the discovering-documentation style: assertions lock in the actual observed behaviour and use rich messages to explain the finding and its implications. They exist to protect behaviour from silent regression, not to assert what the code should do.
Findings documented
Q1 —
WorkflowContextcast +context()setter:(WorkflowContext) event.workflowContext()is always safe.ctx.context(WorkflowModel)setter does not propagate to FuncDSL task function input — tasks receive input from the workflow's INPUT model, not the runningcontext(). Metadata must be passed viastartInstance(Map)instead.Q2 —
onWorkflowCompletedtiming and output:CompletableFuturecompletion chain insidestartExecution()—completedOutputis set beforeawait()returns.instanceData().output()returns null for simple FuncDSL single-task workflows. Listeners must null-guard before calling.asMap().Q3 —
onTaskCompletedgranularity for sequential agents:onTaskCompletedfire count for three sequential agent actions. The assertion is self-documenting and protects the count from changing unnoticed.Q4 —
Uni<T>return type end-to-end:Uni<String>completes correctly viaUni2CompletableFuturewith no thread blocking. Confirms the async dispatch integration path works as expected.Test plan
mvn test -pl langchain4j/runtime -Dtest=WorkflowExecutionListenerBehaviourTest)🤖 Generated with Claude Code