Skip to content

Commit fa07c91

Browse files
committed
chore: address coverage issues
Clean up flow in of handling named tool call part. Add no branch comments to the adapter and test files for cases which only test one branch of the code and have no impact.
1 parent 206acb2 commit fa07c91

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

adapter_ag_ui/adapter_ag_ui/adapter.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ async def _tool_events(
313313
pass
314314
case Iterable() as iter:
315315
for item in iter:
316-
if isinstance(item, BaseEvent):
316+
if isinstance(item, BaseEvent): # pragma: no branch
317317
self.logger.debug('ag-ui event: %s', item)
318318
yield encoder.encode(item)
319319
case _: # pragma: no cover
@@ -481,11 +481,8 @@ async def _handle_agent_event(
481481
tool_call_id=agent_event.part.tool_call_id,
482482
),
483483
),
484+
None, # Signal continuation of the stream.
484485
]
485-
486-
# TODO(steve): Merge with above list if we don't remove the local_tool_calls case.
487-
if tool_name:
488-
stream_ctx.part_ends.append(None) # Signal continuation of the stream.
489486
case ThinkingPart(): # pragma: no cover
490487
# No equivalent AG-UI event yet.
491488
pass
@@ -574,7 +571,7 @@ def _convert_history(messages: list[Message]) -> list[ModelMessage]:
574571
]
575572
)
576573
)
577-
case DeveloperMessage():
574+
case DeveloperMessage(): # pragma: no branch
578575
# TODO(steve): Should these be handled differently?
579576
result.append(ModelRequest(parts=[SystemPromptPart(content=msg.content)]))
580577

pydantic_ai_slim/pydantic_ai/models/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,21 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
265265
event = self._parts_manager.handle_tool_call_delta(
266266
vendor_part_id=i, tool_name=part.tool_name, args='', tool_call_id=part.tool_call_id
267267
)
268-
if event is not None:
268+
if event is not None: # pragma: no branch
269269
yield event
270270

271271
# Stream the args as JSON string in chunks.
272272
args_json = pydantic_core.to_json(part.args).decode()
273273
*chunks, last_chunk = args_json.split(',') if ',' in args_json else [args_json]
274274
chunks = [f'{chunk},' for chunk in chunks] if chunks else []
275-
if last_chunk:
275+
if last_chunk: # pragma: no branch
276276
chunks.append(last_chunk)
277277

278278
for chunk in chunks:
279279
event = self._parts_manager.handle_tool_call_delta(
280280
vendor_part_id=i, tool_name=None, args=chunk, tool_call_id=part.tool_call_id
281281
)
282-
if event is not None:
282+
if event is not None: # pragma: no branch
283283
yield event
284284
else:
285285
yield self._parts_manager.handle_tool_call_part(

0 commit comments

Comments
 (0)