test_file_search.py — langchain Source File
Architecture documentation for test_file_search.py, a python file in the langchain codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR fd751914_766d_3dc6_73f9_3e0a51985938["test_file_search.py"] 927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"] fd751914_766d_3dc6_73f9_3e0a51985938 --> 927570d8_11a6_5c17_0f0d_80baae0c733e feec1ec4_6917_867b_d228_b134d0ff8099["typing"] fd751914_766d_3dc6_73f9_3e0a51985938 --> feec1ec4_6917_867b_d228_b134d0ff8099 f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"] fd751914_766d_3dc6_73f9_3e0a51985938 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba 121262a1_0bd6_d637_bce3_307ab6b3ecd4["langchain_core.tools"] fd751914_766d_3dc6_73f9_3e0a51985938 --> 121262a1_0bd6_d637_bce3_307ab6b3ecd4 6f1d0bc2_4351_a28c_699c_027808c74c1d["langchain.agents.middleware.file_search"] fd751914_766d_3dc6_73f9_3e0a51985938 --> 6f1d0bc2_4351_a28c_699c_027808c74c1d style fd751914_766d_3dc6_73f9_3e0a51985938 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Unit tests for file search middleware."""
from pathlib import Path
from typing import Any
import pytest
from langchain_core.tools import StructuredTool
from langchain.agents.middleware.file_search import (
FilesystemFileSearchMiddleware,
_expand_include_patterns,
_is_valid_include_pattern,
_match_include_pattern,
)
class TestFilesystemGrepSearch:
"""Tests for filesystem-backed grep search."""
def test_grep_invalid_include_pattern(self, tmp_path: Path) -> None:
"""Return error when include glob cannot be parsed."""
(tmp_path / "example.py").write_text("print('hello')\n", encoding="utf-8")
middleware = FilesystemFileSearchMiddleware(root_path=str(tmp_path), use_ripgrep=False)
assert isinstance(middleware.grep_search, StructuredTool)
assert middleware.grep_search.func is not None
result = middleware.grep_search.func(pattern="print", include="*.{py")
assert result == "Invalid include pattern"
def test_ripgrep_command_uses_literal_pattern(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Ensure ripgrep receives pattern after ``--`` to avoid option parsing."""
(tmp_path / "example.py").write_text("print('hello')\n", encoding="utf-8")
middleware = FilesystemFileSearchMiddleware(root_path=str(tmp_path), use_ripgrep=True)
captured: dict[str, list[str]] = {}
class DummyResult:
stdout = ""
def fake_run(*args: Any, **kwargs: Any) -> DummyResult:
cmd = args[0]
captured["cmd"] = cmd
return DummyResult()
monkeypatch.setattr("langchain.agents.middleware.file_search.subprocess.run", fake_run)
middleware._ripgrep_search("--pattern", "/", None)
assert "cmd" in captured
cmd = captured["cmd"]
assert cmd[:2] == ["rg", "--json"]
assert "--" in cmd
separator_index = cmd.index("--")
assert cmd[separator_index + 1] == "--pattern"
// ... (346 more lines)
Domain
Subdomains
Classes
Dependencies
- langchain.agents.middleware.file_search
- langchain_core.tools
- pathlib
- pytest
- typing
Source
Frequently Asked Questions
What does test_file_search.py do?
test_file_search.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What does test_file_search.py depend on?
test_file_search.py imports 5 module(s): langchain.agents.middleware.file_search, langchain_core.tools, pathlib, pytest, typing.
Where is test_file_search.py in the architecture?
test_file_search.py is located at libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_file_search.py (domain: LangChainCore, subdomain: MessageInterface, directory: libs/langchain_v1/tests/unit_tests/agents/middleware/implementations).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free