test_anthropic_tools.py — langchain Source File
Architecture documentation for test_anthropic_tools.py, a python file in the langchain codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 11d9fa3b_8111_96f5_4533_c0ec52020ae0["test_anthropic_tools.py"] 525a7d6f_f455_56e3_854a_c8a7da4a1417["unittest.mock"] 11d9fa3b_8111_96f5_4533_c0ec52020ae0 --> 525a7d6f_f455_56e3_854a_c8a7da4a1417 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] 11d9fa3b_8111_96f5_4533_c0ec52020ae0 --> 120e2591_3e15_b895_72b6_cb26195e40a6 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] 11d9fa3b_8111_96f5_4533_c0ec52020ae0 --> d758344f_537f_649e_f467_b9d7442e86df 0e93d2ee_1fb2_3a0f_5a76_8aba32d0d4ed["langgraph.types"] 11d9fa3b_8111_96f5_4533_c0ec52020ae0 --> 0e93d2ee_1fb2_3a0f_5a76_8aba32d0d4ed d03d9663_5201_66f4_af13_03c9f4d7984d["langchain_anthropic.middleware.anthropic_tools"] 11d9fa3b_8111_96f5_4533_c0ec52020ae0 --> d03d9663_5201_66f4_af13_03c9f4d7984d 50acc543_e5f0_2162_cf07_c2bf50723e0c["langchain.agents.middleware.types"] 11d9fa3b_8111_96f5_4533_c0ec52020ae0 --> 50acc543_e5f0_2162_cf07_c2bf50723e0c style 11d9fa3b_8111_96f5_4533_c0ec52020ae0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Unit tests for Anthropic text editor and memory tool middleware."""
from unittest.mock import MagicMock
import pytest
from langchain_core.messages import SystemMessage, ToolMessage
from langgraph.types import Command
from langchain_anthropic.middleware.anthropic_tools import (
AnthropicToolsState,
StateClaudeMemoryMiddleware,
StateClaudeTextEditorMiddleware,
_validate_path,
)
class TestPathValidation:
"""Test path validation and security."""
def test_basic_path_normalization(self) -> None:
"""Test basic path normalization."""
assert _validate_path("/foo/bar") == "/foo/bar"
assert _validate_path("foo/bar") == "/foo/bar"
assert _validate_path("/foo//bar") == "/foo/bar"
assert _validate_path("/foo/./bar") == "/foo/bar"
def test_path_traversal_blocked(self) -> None:
"""Test that path traversal attempts are blocked."""
with pytest.raises(ValueError, match="Path traversal not allowed"):
_validate_path("/foo/../etc/passwd")
with pytest.raises(ValueError, match="Path traversal not allowed"):
_validate_path("../etc/passwd")
with pytest.raises(ValueError, match="Path traversal not allowed"):
_validate_path("~/.ssh/id_rsa")
def test_allowed_prefixes(self) -> None:
"""Test path prefix validation."""
# Should pass
assert (
_validate_path("/workspace/file.txt", allowed_prefixes=["/workspace"])
== "/workspace/file.txt"
)
# Should fail
with pytest.raises(ValueError, match="Path must start with"):
_validate_path("/etc/passwd", allowed_prefixes=["/workspace"])
with pytest.raises(ValueError, match="Path must start with"):
_validate_path(
"/workspacemalicious/file.txt", allowed_prefixes=["/workspace/"]
)
def test_memories_prefix(self) -> None:
"""Test /memories prefix validation for memory tools."""
assert (
_validate_path("/memories/notes.txt", allowed_prefixes=["/memories"])
== "/memories/notes.txt"
)
// ... (392 more lines)
Domain
Subdomains
Classes
Dependencies
- langchain.agents.middleware.types
- langchain_anthropic.middleware.anthropic_tools
- langchain_core.messages
- langgraph.types
- pytest
- unittest.mock
Source
Frequently Asked Questions
What does test_anthropic_tools.py do?
test_anthropic_tools.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What does test_anthropic_tools.py depend on?
test_anthropic_tools.py imports 6 module(s): langchain.agents.middleware.types, langchain_anthropic.middleware.anthropic_tools, langchain_core.messages, langgraph.types, pytest, unittest.mock.
Where is test_anthropic_tools.py in the architecture?
test_anthropic_tools.py is located at libs/partners/anthropic/tests/unit_tests/middleware/test_anthropic_tools.py (domain: CoreAbstractions, subdomain: RunnableInterface, 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