test(middleware): add unit tests for AgentMiddleware helper functions#29
Open
caoergou wants to merge 2 commits into
Open
test(middleware): add unit tests for AgentMiddleware helper functions#29caoergou wants to merge 2 commits into
caoergou wants to merge 2 commits into
Conversation
Adds coverage for _extract_tool_images, _detect_skill_call, _supports_tool_images, and awrap_tool_call permission gating. Closes UnicomAI#27
…nctions - Move `import uniharness.langchain.middleware as mod` before try block so `mod` is always bound in the finally clause - Use `lambda *_: None` for unused ChatAnthropic.__init__ patch - Add `# noqa: ARG002` on SafetyRule test doubles to match project style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/unit_tests/middleware/test_middleware.py, filling the gap in the previously-emptymiddleware/test directory._supports_tool_images,_extract_tool_images,_detect_skill_call, andAgentMiddleware.awrap_tool_callpermission gating — none of which had any existing coverage.pytest-asynciowithasyncio_mode = "auto", mypy strict, ruff clean, Google-style docstrings.Closes #27
Test plan
make lint— ruff + mypy strict both pass (verified locally)make test— all 1079 unit tests pass, including the 22 new ones (verified locally)TestSupportsToolImages— covers MagicMock→False, import-error→False, ChatAnthropic instance→TrueTestExtractToolImages— covers empty list, string content, no images, image extraction, idempotency marker, placeholder for image-only content, tool_call_id/id preservationTestDetectSkillCall— covers empty list, last tool message detection, non-skill tool, already-injected (user message follows), invalid JSON argumentsTestAwrapToolCallPermissionGating— covers ALLOWED passthrough, DENIED error response, NEEDS_APPROVAL without callback, NEEDS_APPROVAL approved, NEEDS_APPROVAL rejected