Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions python/packages/ag-ui/tests/ag_ui/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

"""Tests for orchestration helper functions."""

from typing import Any

from agent_framework import Content, Message

from agent_framework_ag_ui._orchestration._helpers import (
Expand Down Expand Up @@ -137,13 +139,13 @@ def test_creates_new_entry(self):

def test_returns_existing_entry(self):
"""Returns existing entry when ID found."""
existing_entry = {
existing_entry: dict[str, Any] = {
"id": "call_123",
"type": "function",
"function": {"name": "get_weather", "arguments": '{"city": "NYC"}'},
}
tool_calls_by_id = {"call_123": existing_entry}
pending_tool_calls: list = []
tool_calls_by_id: dict[str, dict[str, Any]] = {"call_123": existing_entry}
pending_tool_calls: list[dict[str, Any]] = []

entry = ensure_tool_call_entry("call_123", tool_calls_by_id, pending_tool_calls)

Expand Down
4 changes: 2 additions & 2 deletions python/packages/azurefunctions/tests/test_orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def executor_with_uuid() -> tuple[Any, Mock, str]:

executor = AzureFunctionsAgentExecutor(context)
test_uuid_hex = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
executor.generate_unique_id = Mock(return_value=test_uuid_hex) # type: ignore[method-assign] # ty: ignore[invalid-assignment]
executor.generate_unique_id = Mock(return_value=test_uuid_hex) # type: ignore[method-assign]

return executor, context, test_uuid_hex

Expand All @@ -112,7 +112,7 @@ def executor_with_multiple_uuids() -> tuple[Any, Mock, list[str]]:
"dddddddd-dddd-dddd-dddd-dddddddddddd",
"eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee",
]
executor.generate_unique_id = Mock(side_effect=uuid_hexes) # type: ignore[method-assign] # ty: ignore[invalid-assignment]
executor.generate_unique_id = Mock(side_effect=uuid_hexes) # type: ignore[method-assign]

return executor, context, uuid_hexes

Expand Down
6 changes: 3 additions & 3 deletions python/packages/core/tests/core/test_embedding_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ async def get_embeddings(
*,
options: EmbeddingGenerationOptions | None = None,
) -> GeneratedEmbeddings[list[float]]:
return GeneratedEmbeddings( # ty: ignore[invalid-return-type]
return GeneratedEmbeddings(
[Embedding(vector=[0.1, 0.2, 0.3], model="mock-model") for _ in values],
usage={"prompt_tokens": len(values), "total_tokens": len(values)}, # type: ignore[arg-type] # ty: ignore[invalid-argument-type, invalid-key]
usage={"prompt_tokens": len(values), "total_tokens": len(values)}, # type: ignore[arg-type]
)


Expand All @@ -52,7 +52,7 @@ async def test_base_get_embeddings_usage() -> None:
client = MockEmbeddingClient()
result = await client.get_embeddings(["a", "b", "c"])
assert result.usage is not None
assert result.usage["prompt_tokens"] == 3 # type: ignore[typeddict-item] # ty: ignore[invalid-key]
assert result.usage["prompt_tokens"] == 3 # type: ignore[typeddict-item]


def test_base_additional_properties_default() -> None:
Expand Down
2 changes: 1 addition & 1 deletion python/packages/core/tests/core/test_embedding_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_generated_construction_with_usage() -> None:
usage=usage, # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
)
assert embeddings.usage == usage
assert embeddings.usage["prompt_tokens"] == 10 # type: ignore[index, typeddict-item] # pyrefly: ignore[unsupported-operation] # ty: ignore[invalid-key, not-subscriptable]
assert embeddings.usage["prompt_tokens"] == 10 # type: ignore[index, typeddict-item] # pyrefly: ignore[unsupported-operation] # ty: ignore[not-subscriptable]


def test_generated_construction_with_additional_properties() -> None:
Expand Down
88 changes: 44 additions & 44 deletions python/packages/core/tests/core/test_mcp.py

Large diffs are not rendered by default.

48 changes: 25 additions & 23 deletions python/packages/core/tests/core/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,35 +572,35 @@ def test_usage_details_addition():
input_token_count=5,
output_token_count=10,
total_token_count=15,
test1=10, # ty: ignore[invalid-key]
test2=20, # ty: ignore[invalid-key]
test1=10,
test2=20,
)
usage2 = UsageDetails( # type: ignore[typeddict-unknown-key]
input_token_count=3,
output_token_count=6,
total_token_count=9,
test1=10, # ty: ignore[invalid-key]
test3=30, # ty: ignore[invalid-key]
test1=10,
test3=30,
)

combined_usage = add_usage_details(usage1, usage2)
assert combined_usage["input_token_count"] == 8
assert combined_usage["output_token_count"] == 16
assert combined_usage["total_token_count"] == 24
assert combined_usage["test1"] == 20 # type: ignore[typeddict-item] # ty: ignore[invalid-key]
assert combined_usage["test2"] == 20 # type: ignore[typeddict-item] # ty: ignore[invalid-key]
assert combined_usage["test3"] == 30 # type: ignore[typeddict-item] # ty: ignore[invalid-key]
assert combined_usage["test1"] == 20 # type: ignore[typeddict-item]
assert combined_usage["test2"] == 20 # type: ignore[typeddict-item]
assert combined_usage["test3"] == 30 # type: ignore[typeddict-item]


def test_usage_details_fail():
# TypedDict doesn't validate types at runtime, so this test no longer applies
# Creating UsageDetails with wrong types won't raise ValueError
usage = UsageDetails(input_token_count=5, output_token_count=10, total_token_count=15, wrong_type="42.923") # type: ignore[typeddict-item, typeddict-unknown-key] # pyrefly: ignore[bad-argument-type] # ty: ignore[invalid-key]
assert usage["wrong_type"] == "42.923" # type: ignore[typeddict-item] # ty: ignore[invalid-key]
usage = cast(UsageDetails, {"input_token_count": 5, "output_token_count": 10, "total_token_count": 15, "wrong_type": "42.923"})
assert usage["wrong_type"] == "42.923" # type: ignore[typeddict-item]


def test_usage_details_additional_counts():
usage = UsageDetails(input_token_count=5, output_token_count=10, total_token_count=15, **{"test": 1}) # type: ignore[call-arg, typeddict-unknown-key] # ty: ignore[invalid-key]
usage = UsageDetails(input_token_count=5, output_token_count=10, total_token_count=15, **{"test": 1}) # type: ignore[call-arg, typeddict-unknown-key]
assert usage.get("test") == 1


Expand All @@ -616,8 +616,8 @@ def test_usage_details_add_with_none_and_type_errors():


def test_usage_details_add_skips_non_int():
u1 = UsageDetails(input_token_count=10, other="test") # type: ignore[typeddict-item, typeddict-unknown-key] # pyrefly: ignore[bad-argument-type] # ty: ignore[invalid-key]
u2 = UsageDetails(input_token_count=10, another="test") # type: ignore[typeddict-item, typeddict-unknown-key] # pyrefly: ignore[bad-argument-type] # ty: ignore[invalid-key]
u1 = cast(UsageDetails, {"input_token_count": 10, "other": "test"})
u2 = cast(UsageDetails, {"input_token_count": 10, "another": "test"})
u3 = add_usage_details(u1, u2)
assert len(u3.keys()) == 1
assert "input_token_count" in u3
Expand Down Expand Up @@ -1758,9 +1758,9 @@ def test_comprehensive_to_dict_exclude_options():
assert "text" in text_dict_exclude

# Test UsageDetails - it's a TypedDict now, not a class with to_dict
usage = UsageDetails(input_token_count=5, custom_count=10) # type: ignore[typeddict-unknown-key] # ty: ignore[invalid-key]
usage = UsageDetails(input_token_count=5, custom_count=10) # type: ignore[typeddict-unknown-key]
assert usage["input_token_count"] == 5
assert usage["custom_count"] == 10 # type: ignore[typeddict-item] # ty: ignore[invalid-key]
assert usage["custom_count"] == 10 # type: ignore[typeddict-item]

# Test UsageDetails exclude_none behavior isn't applicable to TypedDict
# TypedDict doesn't have a to_dict method
Expand All @@ -1769,8 +1769,8 @@ def test_comprehensive_to_dict_exclude_options():
def test_usage_details_iadd_edge_cases():
"""Test UsageDetails addition with edge cases for better coverage."""
# Test with None values
u1 = UsageDetails(input_token_count=None, output_token_count=5, custom1=10) # type: ignore[typeddict-unknown-key] # ty: ignore[invalid-key]
u2 = UsageDetails(input_token_count=3, output_token_count=None, custom2=20) # type: ignore[typeddict-unknown-key] # ty: ignore[invalid-key]
u1 = UsageDetails(input_token_count=None, output_token_count=5, custom1=10) # type: ignore[typeddict-unknown-key]
u2 = UsageDetails(input_token_count=3, output_token_count=None, custom2=20) # type: ignore[typeddict-unknown-key]

result = add_usage_details(u1, u2)
assert result["input_token_count"] == 3
Expand All @@ -1779,8 +1779,8 @@ def test_usage_details_iadd_edge_cases():
assert result.get("custom2") == 20

# Test merging additional counts
u3 = UsageDetails(input_token_count=1, shared_count=5) # type: ignore[typeddict-unknown-key] # ty: ignore[invalid-key]
u4 = UsageDetails(input_token_count=2, shared_count=15) # type: ignore[typeddict-unknown-key] # ty: ignore[invalid-key]
u3 = UsageDetails(input_token_count=1, shared_count=5) # type: ignore[typeddict-unknown-key]
u4 = UsageDetails(input_token_count=2, shared_count=15) # type: ignore[typeddict-unknown-key]

result2 = add_usage_details(u3, u4)
assert result2["input_token_count"] == 3
Expand Down Expand Up @@ -2013,7 +2013,7 @@ def test_usage_content_serialization_with_details():
usage_content = Content(**usage_data) # type: ignore[arg-type] # pyrefly: ignore[bad-argument-type] # ty: ignore[invalid-argument-type]
assert isinstance(usage_content.usage_details, dict)
assert usage_content.usage_details["input_token_count"] == 10
assert usage_content.usage_details["custom_count"] == 5 # type: ignore[typeddict-item] # ty: ignore[invalid-argument-type, invalid-key] # Custom fields go directly in UsageDetails
assert usage_content.usage_details["custom_count"] == 5 # type: ignore[typeddict-item] # Custom fields go directly in UsageDetails

# Test to_dict with UsageDetails object
usage_dict = usage_content.to_dict()
Expand Down Expand Up @@ -2692,6 +2692,7 @@ def test_text_content_with_annotations_serialization():

# Verify reconstruction
assert len(reconstructed.annotations) == 2 # type: ignore[arg-type] # pyrefly: ignore[bad-argument-type] # ty: ignore[invalid-argument-type]
assert reconstructed.annotations is not None
# Annotation are TypedDicts (dicts at runtime)
assert all(isinstance(ann, dict) for ann in reconstructed.annotations) # type: ignore[union-attr] # pyrefly: ignore[not-iterable]
assert reconstructed.annotations[0]["title"] == "Citation 1" # type: ignore[index] # pyrefly: ignore[unsupported-operation]
Expand Down Expand Up @@ -3039,19 +3040,20 @@ def test_content_add_usage_content_non_integer_values():
"""Test adding usage content with non-integer values."""
usage1 = Content(
type="usage",
usage_details={"model": "gpt-4", "count": 10}, # type: ignore[arg-type, typeddict-item] # pyrefly: ignore[bad-argument-type] # ty: ignore[invalid-argument-type, invalid-key]
usage_details=cast(UsageDetails, {"model": "gpt-4", "count": 10}),
)
usage2 = Content(
type="usage",
usage_details={"model": "gpt-3.5", "count": 20}, # type: ignore[arg-type, typeddict-item] # pyrefly: ignore[bad-argument-type] # ty: ignore[invalid-argument-type, invalid-key]
usage_details=cast(UsageDetails, {"model": "gpt-3.5", "count": 20}),
)

result = usage1 + usage2

# Non-integer "model" should take first non-None value
assert "model" not in result.usage_details # type: ignore[operator] # pyrefly: ignore[not-iterable] # ty: ignore[unsupported-operator]
assert result.usage_details is not None
assert "model" not in result.usage_details # type: ignore[operator] # pyrefly: ignore[not-iterable]
# Integer "count" should be summed
assert result.usage_details["count"] == 30 # type: ignore[index, typeddict-item] # pyrefly: ignore[unsupported-operation] # ty: ignore[invalid-key, not-subscriptable]
assert result.usage_details["count"] == 30 # type: ignore[index, typeddict-item] # pyrefly: ignore[unsupported-operation]


# endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ def test_usage_from_usage_details_with_extension_fields(self) -> None:
"total_token_count": 300,
}
# Add provider-specific fields (UsageDetails is a TypedDict but allows extra keys)
usage_details["prompt_tokens"] = 100 # type: ignore[typeddict-unknown-key] # ty: ignore[invalid-key]
usage_details["completion_tokens"] = 200 # type: ignore[typeddict-unknown-key] # ty: ignore[invalid-key]
usage_details["prompt_tokens"] = 100 # type: ignore[typeddict-unknown-key]
usage_details["completion_tokens"] = 200 # type: ignore[typeddict-unknown-key]

usage = DurableAgentStateUsage.from_usage(usage_details)

Expand Down
6 changes: 3 additions & 3 deletions python/packages/foundry_hosting/tests/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ async def test_close_closes_owned_http_client() -> None:
)
client = toolbox._httpx_client # pyright: ignore[reportPrivateUsage]
assert client is not None
client.aclose = AsyncMock() # ty: ignore # zuban: ignore
client.aclose = AsyncMock() # zuban: ignore

await toolbox.close()

client.aclose.assert_awaited_once() # ty: ignore
client.aclose.assert_awaited_once()
# Idempotent: a second close does not re-close the client.
await toolbox.close()
client.aclose.assert_awaited_once() # ty: ignore
client.aclose.assert_awaited_once()


def test_as_skills_provider_returns_provider() -> None:
Expand Down
2 changes: 1 addition & 1 deletion python/packages/ollama/tests/test_ollama_chat_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ async def test_cmc_with_invalid_data_content_media_type(
)

ollama_client = OllamaChatClient()
ollama_client.client.chat = AsyncMock(return_value=mock_streaming_chat_completion_response) # type: ignore[method-assign] # ty: ignore[invalid-assignment]
ollama_client.client.chat = AsyncMock(return_value=mock_streaming_chat_completion_response) # type: ignore[method-assign]

await ollama_client.get_response(messages=chat_history)

Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dev = [
"mypy==1.20.0",
"pyright==1.1.410",
"pyrefly==1.0.0",
"ty==0.0.46",
"ty==0.0.55",
"zuban==0.8.2",
"mcp[ws]==1.27.2",
"opentelemetry-sdk==1.40.0",
Expand Down
Loading