Skip to content

test(middleware): add unit tests for AgentMiddleware helper functions#29

Open
caoergou wants to merge 2 commits into
UnicomAI:mainfrom
caoergou:test/middleware-coverage
Open

test(middleware): add unit tests for AgentMiddleware helper functions#29
caoergou wants to merge 2 commits into
UnicomAI:mainfrom
caoergou:test/middleware-coverage

Conversation

@caoergou

@caoergou caoergou commented Jun 8, 2026

Copy link
Copy Markdown

Summary

  • Adds 22 unit tests to tests/unit_tests/middleware/test_middleware.py, filling the gap in the previously-empty middleware/ test directory.
  • Covers _supports_tool_images, _extract_tool_images, _detect_skill_call, and AgentMiddleware.awrap_tool_call permission gating — none of which had any existing coverage.
  • All tests follow project conventions: pytest-asyncio with asyncio_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→True
  • TestExtractToolImages — covers empty list, string content, no images, image extraction, idempotency marker, placeholder for image-only content, tool_call_id/id preservation
  • TestDetectSkillCall — covers empty list, last tool message detection, non-skill tool, already-injected (user message follows), invalid JSON arguments
  • TestAwrapToolCallPermissionGating — covers ALLOWED passthrough, DENIED error response, NEEDS_APPROVAL without callback, NEEDS_APPROVAL approved, NEEDS_APPROVAL rejected

caoergou added 2 commits June 8, 2026 16:47
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
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.

test(langchain): add unit tests for AgentMiddleware — core runtime has no test coverage

1 participant