Skip to content

Commit 3165912

Browse files
CopilotCopilot
andcommitted
test: add continuation_token + context_providers coverage (microsoft#4754)
Add two tests exercising the non-streaming continuation_token path: - test_resume_via_continuation_token_with_context_providers: validates that before_run/after_run are invoked when resuming with providers - test_resume_via_continuation_token_no_context_providers: validates no crash when resuming without providers (exercises the guard at line 314) Co-authored-by: Copilot <[email protected]>
1 parent eb986bd commit 3165912

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎python/packages/a2a/tests/test_a2a_agent.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,4 +1084,49 @@ async def test_mixed_providers_with_history_load_messages_false(mock_a2a_client:
10841084
assert history_provider.after_run_called
10851085

10861086

1087+
async def test_resume_via_continuation_token_with_context_providers(mock_a2a_client: MockA2AClient) -> None:
1088+
"""Test that non-streaming run() with continuation_token correctly invokes context providers."""
1089+
provider = TrackingContextProvider()
1090+
agent = A2AAgent(name="Test Agent", client=mock_a2a_client, http_client=None, context_providers=[provider])
1091+
1092+
status = TaskStatus(state=TaskState.completed, message=None)
1093+
artifact = Artifact(
1094+
artifact_id="art-ctx-resume",
1095+
name="result",
1096+
parts=[Part(root=TextPart(text="Resumed with providers"))],
1097+
)
1098+
task = Task(id="task-ctx-resume", context_id="ctx-cr", status=status, artifacts=[artifact])
1099+
mock_a2a_client.resubscribe_responses.append((task, None))
1100+
1101+
token = A2AContinuationToken(task_id="task-ctx-resume", context_id="ctx-cr")
1102+
response = await agent.run(continuation_token=token)
1103+
1104+
assert isinstance(response, AgentResponse)
1105+
assert response.messages[0].text == "Resumed with providers"
1106+
assert provider.before_run_called
1107+
assert provider.after_run_called
1108+
assert provider.after_run_response is not None
1109+
1110+
1111+
async def test_resume_via_continuation_token_no_context_providers(mock_a2a_client: MockA2AClient) -> None:
1112+
"""Test that run() with continuation_token and no context_providers works without crash."""
1113+
agent = A2AAgent(name="Test Agent", client=mock_a2a_client, http_client=None)
1114+
1115+
status = TaskStatus(state=TaskState.completed, message=None)
1116+
artifact = Artifact(
1117+
artifact_id="art-no-ctx",
1118+
name="result",
1119+
parts=[Part(root=TextPart(text="Resumed no providers"))],
1120+
)
1121+
task = Task(id="task-no-ctx", context_id="ctx-nc", status=status, artifacts=[artifact])
1122+
mock_a2a_client.resubscribe_responses.append((task, None))
1123+
1124+
token = A2AContinuationToken(task_id="task-no-ctx", context_id="ctx-nc")
1125+
response = await agent.run(continuation_token=token)
1126+
1127+
assert isinstance(response, AgentResponse)
1128+
assert response.messages[0].text == "Resumed no providers"
1129+
assert response.continuation_token is None
1130+
1131+
10871132
# endregion

0 commit comments

Comments
 (0)