Improving test coverage and adding coverage reporting script#451
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves reliability of the Agents-for-python SDK by expanding unit test coverage (especially around activity/state models), tightening model field aliasing/type handling, and adding basic coverage-report tooling.
Changes:
- Added/expanded unit tests for activity models and hosting-core state/telemetry behaviors.
- Refined Pydantic field aliasing (via
Annotated) and improvedActivitytype-discrimination to support enum/string and slash-qualified types. - Added
.coveragercplus a PowerShell script to generate HTML coverage reports.
Reviewed changes
Copilot reviewed 18 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/hosting_core/telemetry/test_simple_span_wrapper.py | Adds tests for using SimpleSpanWrapper directly and ensuring attributes are set on failed spans; removes unused imports. |
| tests/hosting_core/app/state/test_turn_state.py | New tests covering TurnState default scopes, path operations, load/save behavior, and error handling. |
| tests/hosting_core/app/state/test_temp_state.py | New tests covering TempState caching, typed values, input file convenience property, and async no-op semantics. |
| tests/hosting_core/app/state/test_state.py | Expands State behavior tests (missing attributes, private/callable handling, deleted tracking cleanup, string serialization). |
| tests/hosting_core/app/state/test_conversation_state.py | New tests for storage key generation and clear/change tracking behavior. |
| tests/hosting_core/app/state/init.py | Adds package marker for hosting-core state tests. |
| tests/activity/test_tools.py | Removes legacy model-utils tests (superseded by the new test_model_utils.py). |
| tests/activity/test_token_response.py | Adds JWT-shape tests for TokenResponse.is_exchangeable(). |
| tests/activity/test_token_exchange_state.py | New tests ensuring encoded state uses aliases and supports bot_url aliasing. |
| tests/activity/test_model_utils.py | New, more complete test suite for _model_utils helpers and pick_model behavior. |
| tests/activity/test_conversation_reference.py | New tests for continuation activity creation and required user validation. |
| tests/activity/test_activity.py | Adds coverage for “as_*_activity” helpers, slash-qualified types, and agentic tenant-id selection logic. |
| tests/activity/entity/test_entity.py | Adds tests for extra-field handling, camel/snake conversion, and schema “@” field preservation. |
| tests/activity/config/test_load_configuration.py | Adds tests ensuring env var parsing yields the expected nested config structure. |
| tests/activity/config/init.py | Adds package marker for activity config tests. |
| scripts/coverage.ps1 | Adds a script to run coverage and generate HTML output. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/state/temp_state.py | Extends TempState.get_value signature (adds target_cls). |
| libraries/microsoft-agents-activity/microsoft_agents/activity/token_exchange_state.py | Uses Annotated + Field for explicit aliasing of agent_url as bot_url. |
| libraries/microsoft-agents-activity/microsoft_agents/activity/conversation_reference.py | Uses Annotated + Field for explicit aliasing of agent as bot; removes unused imports/logging. |
| libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py | Refactors internal activity-type comparison to robustly support enum/string and slash-qualified activity types. |
| .coveragerc | Adds coverage configuration to omit the microsoft-agents-testing library from coverage collection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 21 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
tests/hosting_core/telemetry/test_simple_span_wrapper.py:15
agents_telemetryis imported but never used in this test module, which will typically trigger flake8 F401 unused-import failures.
from microsoft_agents.hosting.core.telemetry import (
agents_telemetry,
SimpleSpanWrapper,
)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 21 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/state/temp_state.py:78
- TempState.get_value accepts target_cls but never uses it. This means TurnState.get_value(..., target_cls=...) will silently skip deserialization when the path resolves to the temp scope, yielding inconsistent behavior vs AgentState.get_value.
def get_value(
self,
name: str,
default_value_factory: Optional[Callable[[], T]] = None,
*,
target_cls: type[T] | None = None,
) -> T | None:
"""Gets a value from state, using a factory if not found."""
if name not in self._state and default_value_factory is not None:
value = default_value_factory()
self.set_value(name, value)
return value
return self._state.get(name)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 21 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
tests/hosting_core/telemetry/test_simple_span_wrapper.py:15
- Unused import:
agents_telemetryis imported but never referenced in this test module. This will fail Flake8 (F401) if linting includes tests.
from microsoft_agents.hosting.core.telemetry import (
agents_telemetry,
SimpleSpanWrapper,
)
| type_value = str(getattr(self.type, "value", self.type)).lower() | ||
| activity_type_value = str( | ||
| getattr(activity_type, "value", activity_type) | ||
| ).lower() | ||
|
|
||
| result = type_attribute.startswith(activity_type) | ||
|
|
||
| if result: | ||
| result = len(type_attribute) == len(activity_type) | ||
|
|
||
| if not result: | ||
| result = ( | ||
| len(type_attribute) > len(activity_type) | ||
| and type_attribute[len(activity_type)] == "/" | ||
| ) | ||
|
|
||
| return result | ||
| return type_value == activity_type_value or type_value.startswith( | ||
| f"{activity_type_value}/" | ||
| ) |
This pull request introduces several improvements and fixes across the codebase, primarily focused on the
microsoft-agents-activitylibrary. The main themes are enhanced test coverage, improvements to type handling and serialization, and minor refactoring for clarity and maintainability. Key changes include the addition of comprehensive unit tests, improvements to type annotations and field aliasing, and updates to activity type handling logic.Test coverage and validation improvements:
Entity,ConversationReference, and model utility functions to ensure correct validation, serialization, and field processing behavior. This includes tests for required fields, alias handling, and serialization edge cases (tests/activity/entity/test_entity.py,tests/activity/test_conversation_reference.py,tests/activity/test_model_utils.py). [1] [2] [3]Activityto cover type helper methods and agentic tenant ID retrieval logic, increasing confidence in correct type discrimination and role handling (tests/activity/test_activity.py). [1] [2] [3] [4]Type annotations and field aliasing:
ConversationReferenceandTokenExchangeStateto useAnnotatedfor improved type clarity and explicit aliasing, aligning with modern Pydantic practices (microsoft_agents/activity/conversation_reference.py,microsoft_agents/activity/token_exchange_state.py). [1] [2] [3] [4]Activity type handling logic:
Activityto more robustly handle both enum and string representations and to support slash-qualified activity types (activity.py).Test and coverage tooling:
.coveragercfile to omit testing package modules from coverage reports and updated the coverage script to generate HTML reports (.coveragerc,scripts/coverage.ps1). [1] [2]Minor refactoring and cleanup:
conversation_reference.pyfor clarity (microsoft_agents/activity/conversation_reference.py).These changes collectively improve code quality, maintainability, and confidence in correctness through better testing and type handling.