Skip to content

Commit fe55636

Browse files
committed
test(harness): narrow content types in the Gemini CLI tests for pyright
pyright 1.1.399 (the locked version `scripts/lint` runs) reported six errors in the Gemini CLI tests: attribute access on a content union after a list-comprehension filter, which does not narrow the indexed element, and aclose() on the tap's AsyncIterator return type. Assert the concrete content type before reading it, and cast the tap to AsyncGenerator where the test closes it. Test behaviour is unchanged.
1 parent 583856c commit fe55636

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎tests/lib/adk/test_gemini_cli_sync.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import json
6-
from typing import Any, AsyncIterator
6+
from typing import Any, AsyncIterator, AsyncGenerator, cast
77

88
from agentex.types.text_content import TextContent
99
from agentex.types.task_message_delta import TextDelta
@@ -135,6 +135,7 @@ async def test_error_tool_result_sets_is_error_and_uses_message(self):
135135
]
136136
out = await _collect(convert_gemini_cli_to_agentex_events(_aiter(events)))
137137
full = [e for e in out if isinstance(e, StreamTaskMessageFull)][0]
138+
assert isinstance(full.content, ToolResponseContent)
138139
assert full.content.content == {"result": "denied", "is_error": True}
139140

140141
async def test_missing_tool_id_gets_a_synthetic_one(self):
@@ -233,7 +234,7 @@ async def __anext__(self):
233234
async def aclose(self) -> None:
234235
closed["v"] = True
235236

236-
gen = convert_gemini_cli_to_agentex_events(_Src())
237+
gen = cast(AsyncGenerator[Any, None], convert_gemini_cli_to_agentex_events(_Src()))
237238
await gen.__anext__()
238239
await gen.aclose()
239240
assert closed["v"] is True

‎tests/lib/core/harness/test_harness_gemini_cli_sync.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ async def test_tool_request_precedes_tool_response_then_text(self) -> None:
6565
kinds = [type(e).__name__ for e in out]
6666
assert kinds.index("StreamTaskMessageFull") > kinds.index("StreamTaskMessageStart")
6767
req = [e for e in out if isinstance(e, StreamTaskMessageStart) and isinstance(e.content, ToolRequestContent)][0]
68+
assert isinstance(req.content, ToolRequestContent)
6869
res = [e for e in out if isinstance(e, StreamTaskMessageFull)][0]
6970
assert isinstance(res.content, ToolResponseContent)
7071
assert req.content.tool_call_id == res.content.tool_call_id == "call-1"
@@ -97,8 +98,8 @@ async def test_failed_turn_reaches_the_caller(self) -> None:
9798
},
9899
]
99100
out, turn = await _run_yield_turn(events)
100-
errors = [e for e in out if isinstance(e, StreamTaskMessageFull) and isinstance(e.content, TextContent)]
101-
assert [e.content.content for e in errors] == ["Error: Gemini CLI turn failed: Reached max session turns"]
101+
errors = [e.content.content for e in out if isinstance(e, StreamTaskMessageFull) and isinstance(e.content, TextContent)]
102+
assert errors == ["Error: Gemini CLI turn failed: Reached max session turns"]
102103
starts = {e.index for e in out if isinstance(e, StreamTaskMessageStart)}
103104
dones = {e.index for e in out if isinstance(e, StreamTaskMessageDone)}
104105
assert starts == dones

0 commit comments

Comments
 (0)