From cfadb68f5a16555910c8abc23e8282094cf8283e Mon Sep 17 00:00:00 2001 From: drew Date: Tue, 16 Jun 2026 22:34:42 -0400 Subject: [PATCH] test(acms): cover ignored directory traversal --- features/acms_context_add.feature | 5 +++++ features/steps/acms_context_add_steps.py | 22 ++++++++++++++++++++++ src/cleveragents/acms/index.py | 4 ++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/features/acms_context_add.feature b/features/acms_context_add.feature index 012af1670..0c2af4c62 100644 --- a/features/acms_context_add.feature +++ b/features/acms_context_add.feature @@ -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 diff --git a/features/steps/acms_context_add_steps.py b/features/steps/acms_context_add_steps.py index e344bc4f0..68060eeea 100644 --- a/features/steps/acms_context_add_steps.py +++ b/features/steps/acms_context_add_steps.py @@ -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), ( diff --git a/src/cleveragents/acms/index.py b/src/cleveragents/acms/index.py index 32b46cbad..f2658f717 100644 --- a/src/cleveragents/acms/index.py +++ b/src/cleveragents/acms/index.py @@ -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",