@@ -4393,6 +4393,57 @@ async def wf(ctx: RunContext) -> str:
43934393 assert wf is not None
43944394
43954395
4396+ class TestKeywordOnlyRunContext :
4397+ """Regression tests for Issue #9324: keyword-only RunContext parameter injection."""
4398+
4399+ async def test_workflow_with_keyword_only_run_context (self ):
4400+ """A @workflow function with a keyword-only RunContext parameter injects properly."""
4401+
4402+ @built_workflow
4403+ async def wf (text : str , * , ctx : RunContext ) -> str :
4404+ ctx .set_state ("text" , text )
4405+ return ctx .get_state ("text" )
4406+
4407+ result = await wf .run ("hello" )
4408+ assert result .get_outputs () == ["hello" ]
4409+
4410+ async def test_workflow_with_both_keyword_only_parameters (self ):
4411+ """A @workflow function with both message and context keyword-only injects properly."""
4412+
4413+ @built_workflow
4414+ async def wf (* , text : str , ctx : RunContext ) -> str :
4415+ ctx .set_state ("text" , text )
4416+ return ctx .get_state ("text" )
4417+
4418+ result = await wf .run ("hello" )
4419+ assert result .get_outputs () == ["hello" ]
4420+
4421+ async def test_workflow_with_keyword_only_ctx_named_param (self ):
4422+ """An unannotated keyword-only ctx parameter is injected properly."""
4423+
4424+ @built_workflow
4425+ async def wf (text : str , * , ctx ) -> str :
4426+ ctx .set_state ("val" , text )
4427+ return ctx .get_state ("val" )
4428+
4429+ result = await wf .run ("world" )
4430+ assert result .get_outputs () == ["world" ]
4431+
4432+ async def test_workflow_streaming_with_keyword_only_run_context (self ):
4433+ """Streaming mode properly passes keyword-only RunContext parameter."""
4434+
4435+ @built_workflow
4436+ async def wf (text : str , * , ctx : RunContext ) -> str :
4437+ ctx .set_state ("text" , text )
4438+ return ctx .get_state ("text" )
4439+
4440+ stream = wf .run ("hello" , stream = True )
4441+ async for _ in stream :
4442+ pass
4443+ result = await stream .get_final_response ()
4444+ assert result .get_outputs () == ["hello" ]
4445+
4446+
43964447class TestStaleResponsesRejected :
43974448 """Regression for bug_014: stale responses after clean completion must be rejected."""
43984449
0 commit comments