Home / File/ test_bash.py — langchain Source File

test_bash.py — langchain Source File

Architecture documentation for test_bash.py, a python file in the langchain codebase. 4 imports, 0 dependents.

File python LangChainCore ApiManagement 4 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  19d3e6c3_6baa_fc3d_b762_dd47791fe238["test_bash.py"]
  23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"]
  19d3e6c3_6baa_fc3d_b762_dd47791fe238 --> 23cb242e_1754_041d_200a_553fcb8abe1b
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  19d3e6c3_6baa_fc3d_b762_dd47791fe238 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  aa9b49b5_3613_d123_f82b_dc299f3e480e["langchain_anthropic.middleware.bash"]
  19d3e6c3_6baa_fc3d_b762_dd47791fe238 --> aa9b49b5_3613_d123_f82b_dc299f3e480e
  a681398d_ed44_c914_1a44_5d174223b069["langchain.agents.middleware.types"]
  19d3e6c3_6baa_fc3d_b762_dd47791fe238 --> a681398d_ed44_c914_1a44_5d174223b069
  style 19d3e6c3_6baa_fc3d_b762_dd47791fe238 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

from unittest.mock import MagicMock

import pytest

pytest.importorskip(
    "anthropic", reason="Anthropic SDK is required for Claude middleware tests"
)

from langchain_anthropic.middleware.bash import ClaudeBashToolMiddleware


def test_creates_bash_tool(monkeypatch: pytest.MonkeyPatch) -> None:
    """Test that ClaudeBashToolMiddleware creates a tool named 'bash'."""
    middleware = ClaudeBashToolMiddleware()

    # Should have exactly one tool registered (from parent)
    assert len(middleware.tools) == 1

    # Tool is named "bash" (via tool_name parameter)
    bash_tool = middleware.tools[0]
    assert bash_tool.name == "bash"


def test_replaces_tool_with_claude_descriptor() -> None:
    """Test wrap_model_call replaces bash tool with Claude's bash descriptor."""
    from langchain.agents.middleware.types import ModelRequest

    middleware = ClaudeBashToolMiddleware()

    # Create a mock request with the bash tool (inherited from parent)
    bash_tool = middleware.tools[0]
    request = ModelRequest(
        model=MagicMock(),
        system_prompt=None,
        messages=[],
        tool_choice=None,
        tools=[bash_tool],
        response_format=None,
        state={"messages": []},
        runtime=MagicMock(),
    )

    # Mock handler that captures the modified request
    captured_request = None

    def handler(req: ModelRequest) -> MagicMock:
        nonlocal captured_request
        captured_request = req
        return MagicMock()

    middleware.wrap_model_call(request, handler)

    # The bash tool should be replaced with Claude's native bash descriptor
    assert captured_request is not None
    assert len(captured_request.tools) == 1
    assert captured_request.tools[0] == {
        "type": "bash_20250124",
        "name": "bash",
    }

Domain

Subdomains

Dependencies

  • langchain.agents.middleware.types
  • langchain_anthropic.middleware.bash
  • pytest
  • unittest.mock

Frequently Asked Questions

What does test_bash.py do?
test_bash.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in test_bash.py?
test_bash.py defines 2 function(s): test_creates_bash_tool, test_replaces_tool_with_claude_descriptor.
What does test_bash.py depend on?
test_bash.py imports 4 module(s): langchain.agents.middleware.types, langchain_anthropic.middleware.bash, pytest, unittest.mock.
Where is test_bash.py in the architecture?
test_bash.py is located at libs/partners/anthropic/tests/unit_tests/middleware/test_bash.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/partners/anthropic/tests/unit_tests/middleware).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free