Skip to content

Improving test coverage and adding coverage reporting script#451

Merged
kylerohn-msft merged 11 commits into
mainfrom
users/robrandao/test-coverage
Jul 10, 2026
Merged

Improving test coverage and adding coverage reporting script#451
kylerohn-msft merged 11 commits into
mainfrom
users/robrandao/test-coverage

Conversation

@rodrigobr-msft

@rodrigobr-msft rodrigobr-msft commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces several improvements and fixes across the codebase, primarily focused on the microsoft-agents-activity library. 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:

  • Added extensive unit tests for 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]
  • Enhanced tests for Activity to 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:

  • Updated field definitions in ConversationReference and TokenExchangeState to use Annotated for 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:

  • Refactored the internal activity type comparison logic in Activity to more robustly handle both enum and string representations and to support slash-qualified activity types (activity.py).

Test and coverage tooling:

  • Added a .coveragerc file 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:

  • Removed unused imports and logging setup from conversation_reference.py for clarity (microsoft_agents/activity/conversation_reference.py).

These changes collectively improve code quality, maintainability, and confidence in correctness through better testing and type handling.

Copilot AI review requested due to automatic review settings July 8, 2026 18:44
@rodrigobr-msft
rodrigobr-msft marked this pull request as ready for review July 8, 2026 18:47
@rodrigobr-msft
rodrigobr-msft requested a review from a team as a code owner July 8, 2026 18:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 improved Activity type-discrimination to support enum/string and slash-qualified types.
  • Added .coveragerc plus 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.

Comment thread scripts/coverage.ps1 Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 18:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 21 changed files in this pull request and generated 6 comments.

Comment thread scripts/coverage.ps1 Outdated
Comment thread .coveragerc
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 19:16
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_telemetry is 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,
)

Comment thread tests/activity/test_token_exchange_state.py
Copilot AI review requested due to automatic review settings July 8, 2026 19:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 21 changed files in this pull request and generated 4 comments.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 19:30
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread .coveragerc
Copilot AI review requested due to automatic review settings July 8, 2026 19:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 21 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings July 10, 2026 17:29
@kylerohn-msft
kylerohn-msft enabled auto-merge (squash) July 10, 2026 17:29
@kylerohn-msft
kylerohn-msft merged commit 12f88a6 into main Jul 10, 2026
11 of 12 checks passed
@kylerohn-msft
kylerohn-msft deleted the users/robrandao/test-coverage branch July 10, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_telemetry is 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,
)

Comment on lines +796 to +803
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}/"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants