@@ -234,6 +234,65 @@ def make_response(text: str):
234234 {'role' : 'user' , 'content' : 'Second question' },
235235 ]
236236
237+ @pytest .mark .asyncio
238+ async def test_multi_turn_false_does_not_accumulate_history (self , mock_client ):
239+ """When multi_turn=False the runner must not append to history on success."""
240+ def make_response (text : str ):
241+ r = MagicMock ()
242+ r .context_wrapper = None
243+ r .choices = [MagicMock ()]
244+ r .choices [0 ].message = MagicMock ()
245+ r .choices [0 ].message .content = text
246+ r .usage = None
247+ return r
248+
249+ mock_client .chat = MagicMock ()
250+ mock_client .chat .completions = MagicMock ()
251+ mock_client .chat .completions .create = AsyncMock (side_effect = [
252+ make_response ('First response' ),
253+ make_response ('Second response' ),
254+ ])
255+
256+ provider = OpenAIModelRunner (mock_client , 'gpt-4o' , {}, multi_turn = False )
257+ baseline_len = len (provider ._history )
258+
259+ await provider .run ('First question' )
260+ assert len (provider ._history ) == baseline_len
261+
262+ await provider .run ('Second question' )
263+ assert len (provider ._history ) == baseline_len
264+
265+ # Each call must see only the configured baseline, never the prior turn.
266+ second_call_messages = mock_client .chat .completions .create .call_args_list [1 ].kwargs ['messages' ]
267+ assert second_call_messages == [{'role' : 'user' , 'content' : 'Second question' }]
268+
269+ @pytest .mark .asyncio
270+ async def test_multi_turn_default_accumulates_history (self , mock_client ):
271+ """Default behavior (multi_turn omitted) still accumulates history (preserves PR #166)."""
272+ def make_response (text : str ):
273+ r = MagicMock ()
274+ r .context_wrapper = None
275+ r .choices = [MagicMock ()]
276+ r .choices [0 ].message = MagicMock ()
277+ r .choices [0 ].message .content = text
278+ r .usage = None
279+ return r
280+
281+ mock_client .chat = MagicMock ()
282+ mock_client .chat .completions = MagicMock ()
283+ mock_client .chat .completions .create = AsyncMock (side_effect = [
284+ make_response ('First response' ),
285+ make_response ('Second response' ),
286+ ])
287+
288+ provider = OpenAIModelRunner (mock_client , 'gpt-4o' , {})
289+ baseline_len = len (provider ._history )
290+
291+ await provider .run ('First question' )
292+ await provider .run ('Second question' )
293+
294+ assert len (provider ._history ) == baseline_len + 4
295+
237296 @pytest .mark .asyncio
238297 async def test_does_not_accumulate_history_on_failed_call (self , mock_client ):
239298 """Should not add to history when the call fails."""
0 commit comments