test(acms): cover ignored directory traversal

This commit is contained in:
2026-06-16 22:34:42 -04:00
committed by Forgejo
parent abffbebf15
commit cfadb68f5a
3 changed files with 29 additions and 2 deletions
+5
View File
@@ -49,6 +49,11 @@ Feature: ACMS context add command with --tag and --policy flags
When I traverse the directory recursively with ChunkedFileTraverser
Then the acms traversal should yield only the Python file
Scenario: ChunkedFileTraverser skips files inside ignored directories
Given a temporary directory with a Python file and an ignored __pycache__ file
When I traverse the directory recursively with ChunkedFileTraverser
Then the acms traversal should yield only the visible Python file
Scenario: ChunkedFileTraverser raises FileNotFoundError for missing path
When I traverse a non-existent path with ChunkedFileTraverser
Then an acms FileNotFoundError should be raised
+22
View File
@@ -92,6 +92,18 @@ def step_acms_py_and_pyc(context: Context) -> None:
context.acms_target_path = tmpdir
@given("a temporary directory with a Python file and an ignored __pycache__ file")
def step_acms_py_and_ignored_cache_dir(context: Context) -> None:
"""Create a temp dir with a visible file and a file under __pycache__."""
context.acms_tmpdir = tempfile.mkdtemp()
tmpdir = Path(context.acms_tmpdir)
(tmpdir / "module.py").write_text("# module\n", encoding="utf-8")
cache_dir = tmpdir / "__pycache__"
cache_dir.mkdir()
(cache_dir / "cached.py").write_text("# ignored cache module\n", encoding="utf-8")
context.acms_target_path = tmpdir
@when("I traverse the file with ChunkedFileTraverser")
def step_acms_traverse_file(context: Context) -> None:
"""Traverse a single file with ChunkedFileTraverser."""
@@ -295,6 +307,16 @@ def step_acms_only_py_file(context: Context) -> None:
)
@then("the acms traversal should yield only the visible Python file")
def step_acms_only_visible_py_file(context: Context) -> None:
assert len(context.acms_entries) == 1, (
f"Expected 1 visible Python file, got {len(context.acms_entries)}"
)
assert context.acms_entries[0].path.name == "module.py", (
f"Expected module.py, got {context.acms_entries[0].path}"
)
@then("an acms FileNotFoundError should be raised")
def step_acms_file_not_found(context: Context) -> None:
assert isinstance(context.acms_error, FileNotFoundError), (
+2 -2
View File
@@ -676,11 +676,11 @@ class ChunkedFileTraverser:
# ---------------------------------------------------------------------------
__all__: list[str] = [
"DEFAULT_CHUNK_SIZE",
"DEFAULT_IGNORE_PATTERNS",
"ACMSIndex",
"AcmsIndexEntry",
"ChunkedFileTraverser",
"DEFAULT_CHUNK_SIZE",
"DEFAULT_IGNORE_PATTERNS",
"FileTraversalEngine",
"FileType",
"IndexEntry",