Skip to content

feat: add test infrastructure and initial test coverage#71

Open
pdettori wants to merge 2 commits intomainfrom
orchestrate/tests
Open

feat: add test infrastructure and initial test coverage#71
pdettori wants to merge 2 commits intomainfrom
orchestrate/tests

Conversation

@pdettori
Copy link
Collaborator

Summary

Phase 3 of repo orchestration — adds test infrastructure and coverage for previously untested critical paths.

New files:

  • tests/__init__.py: package marker
  • tests/conftest.py: shared mock_envoy_modules and mock_manager fixtures, eliminating duplication
  • tests/test_tool_pre_invoke.py: 4 tests for getToolPreInvokeResponse (previously 0 coverage)
    • Allow with no modification
    • Allow with modified arguments forwarded
    • Block with violation details in MCP error response
    • Payload carries correct tool name
  • tests/test_prompt_pre_fetch.py: 3 tests for getPromptPreFetchResponse (previously 0 coverage)
    • Allow with no modification
    • Allow with modified arguments forwarded
    • Block with MCP error response
  • tests/test_helpers.py: 6 tests for helper functions (previously 0 coverage)
    • set_result_in_body: mutates and replaces arguments
    • get_modified_response: returns BodyResponse
    • create_mcp_immediate_error_response: default code, violation reason, mcp_error_code override

Test plan

  • All 13 new tests pass locally
  • All 9 existing tests in test_server.py still pass (no regressions)
  • CI passes
uv run pytest tests/ -v

Add shared conftest.py fixtures and tests for three previously uncovered
critical paths in src/server.py:

- tests/__init__.py: package marker
- tests/conftest.py: shared mock_envoy_modules and mock_manager fixtures,
  eliminating duplication across test modules
- tests/test_tool_pre_invoke.py: 4 tests for getToolPreInvokeResponse
  (continue, modified args, blocked with violation, payload naming)
- tests/test_prompt_pre_fetch.py: 3 tests for getPromptPreFetchResponse
  (continue, modified args, blocked)
- tests/test_helpers.py: 6 tests for helper functions
  (set_result_in_body, get_modified_response,
  create_mcp_immediate_error_response with/without violation and mcp_error_code)

All 22 tests (13 new + 9 existing) pass.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <dettori@us.ibm.com>
Copy link
Contributor

@evaline-ju evaline-ju left a comment

Choose a reason for hiding this comment

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

Thanks for more tests, @pdettori ! I see that the conftest may have overlap with existing server tests https://github.com/kagenti/plugins-adapter/blob/main/tests/test_server.py . Perhaps we can help refactor usage with the conftest instead of duplication? It might be worth organizing the existing tests a bit for navigability since already existent "tool_post_invoke" tests aren't really discoverable w.r.t. these other "hook" (prompt_pre_fetch and tool_pre_invoke) new test files

…lity

Remove unused `import pytest` from test_helpers.py (ruff F401 fix).

Rename test_server.py → test_tool_post_invoke.py so all hook tests share
a consistent naming convention (test_tool_pre_invoke, test_tool_post_invoke,
test_prompt_pre_fetch). Remove the three locally-duplicated fixtures
(mock_envoy_modules, mock_manager, sample_tool_result_body) from the renamed
file and promote sample_tool_result_body to conftest.py, where it is now
shared across all post-invoke test cases.

No test logic changed — all 22 tests still pass.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <dettori@us.ibm.com>
Copy link
Collaborator Author

@pdettori pdettori left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback @evaline-ju!

Both issues are addressed in the latest commit:

  • CI lint failure: removed the unused import pytest from test_helpers.py (ruff F401)
  • Fixture duplication / navigability: renamed test_server.pytest_tool_post_invoke.py so all hook tests now follow a consistent naming convention alongside test_tool_pre_invoke.py and test_prompt_pre_fetch.py. The three locally-duplicated fixtures (mock_envoy_modules, mock_manager, sample_tool_result_body) have been removed from that file and sample_tool_result_body promoted to conftest.py for shared use.

All 22 tests pass.

Copy link
Collaborator Author

@pdettori pdettori left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback @evaline-ju!

Both issues are addressed in the latest commit:

  • CI lint failure: removed the unused import pytest from test_helpers.py (ruff F401)
  • Fixture duplication / navigability: renamed test_server.pytest_tool_post_invoke.py so all hook tests now follow a consistent naming convention alongside test_tool_pre_invoke.py and test_prompt_pre_fetch.py. The three locally-duplicated fixtures (mock_envoy_modules, mock_manager, sample_tool_result_body) have been removed from that file and sample_tool_result_body promoted to conftest.py for shared use.

All 22 tests pass.

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.

2 participants