Skip to content

feat: add test infrastructure and initial test coverage#71

Merged
evaline-ju merged 4 commits intomainfrom
orchestrate/tests
Mar 19, 2026
Merged

feat: add test infrastructure and initial test coverage#71
evaline-ju merged 4 commits intomainfrom
orchestrate/tests

Conversation

@pdettori
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 the refactor update! A couple more minor comments for consideration

Comment thread tests/test_tool_pre_invoke.py Outdated
Comment thread tests/test_helpers.py
…hen assertion

- Move _make_result helper to conftest.py as make_hook_result, removing
  duplication between test_tool_pre_invoke.py and test_prompt_pre_fetch.py
- Strengthen test_get_modified_response to verify serialized JSON body
  content instead of only checking response is not None

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <dettori@us.ibm.com>
@pdettori pdettori requested a review from a team as a code owner March 19, 2026 16:00
Remove unused json import from conftest.py, fix import sort order
in test_tool_pre_invoke.py and test_prompt_pre_fetch.py.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Paolo Dettori <dettori@us.ibm.com>
Copy link
Copy Markdown
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 the updates!
/lgtm

@evaline-ju evaline-ju merged commit 390e165 into main Mar 19, 2026
12 checks passed
@evaline-ju evaline-ju deleted the orchestrate/tests branch March 19, 2026 16:23
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