feat: add test infrastructure and initial test coverage#71
feat: add test infrastructure and initial test coverage#71
Conversation
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>
evaline-ju
left a comment
There was a problem hiding this comment.
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>
pdettori
left a comment
There was a problem hiding this comment.
Thanks for the feedback @evaline-ju!
Both issues are addressed in the latest commit:
- CI lint failure: removed the unused
import pytestfromtest_helpers.py(ruff F401) - Fixture duplication / navigability: renamed
test_server.py→test_tool_post_invoke.pyso all hook tests now follow a consistent naming convention alongsidetest_tool_pre_invoke.pyandtest_prompt_pre_fetch.py. The three locally-duplicated fixtures (mock_envoy_modules,mock_manager,sample_tool_result_body) have been removed from that file andsample_tool_result_bodypromoted toconftest.pyfor shared use.
All 22 tests pass.
pdettori
left a comment
There was a problem hiding this comment.
Thanks for the feedback @evaline-ju!
Both issues are addressed in the latest commit:
- CI lint failure: removed the unused
import pytestfromtest_helpers.py(ruff F401) - Fixture duplication / navigability: renamed
test_server.py→test_tool_post_invoke.pyso all hook tests now follow a consistent naming convention alongsidetest_tool_pre_invoke.pyandtest_prompt_pre_fetch.py. The three locally-duplicated fixtures (mock_envoy_modules,mock_manager,sample_tool_result_body) have been removed from that file andsample_tool_result_bodypromoted toconftest.pyfor shared use.
All 22 tests pass.
Summary
Phase 3 of repo orchestration — adds test infrastructure and coverage for previously untested critical paths.
New files:
tests/__init__.py: package markertests/conftest.py: sharedmock_envoy_modulesandmock_managerfixtures, eliminating duplicationtests/test_tool_pre_invoke.py: 4 tests forgetToolPreInvokeResponse(previously 0 coverage)tests/test_prompt_pre_fetch.py: 3 tests forgetPromptPreFetchResponse(previously 0 coverage)tests/test_helpers.py: 6 tests for helper functions (previously 0 coverage)set_result_in_body: mutates and replaces argumentsget_modified_response: returns BodyResponsecreate_mcp_immediate_error_response: default code, violation reason, mcp_error_code overrideTest plan
test_server.pystill pass (no regressions)