diff --git a/eval_protocol/cli_commands/local_test.py b/eval_protocol/cli_commands/local_test.py index 68b3938a..97e02e9f 100644 --- a/eval_protocol/cli_commands/local_test.py +++ b/eval_protocol/cli_commands/local_test.py @@ -9,13 +9,11 @@ def _find_dockerfiles(root: str) -> List[str]: - skip_dirs = {".venv", "venv", "node_modules", "dist", "build", "__pycache__", ".git", "vendor"} + """Return Dockerfiles in the project root only (no recursive search).""" dockerfiles: List[str] = [] - for dirpath, dirnames, filenames in os.walk(root): - dirnames[:] = [d for d in dirnames if d not in skip_dirs and not d.startswith(".")] - for name in filenames: - if name == "Dockerfile": - dockerfiles.append(os.path.join(dirpath, name)) + root_dockerfile = os.path.join(root, "Dockerfile") + if os.path.isfile(root_dockerfile): + dockerfiles.append(root_dockerfile) return dockerfiles diff --git a/tests/test_cli_local_test.py b/tests/test_cli_local_test.py index 0be9c2fa..37d63b30 100644 --- a/tests/test_cli_local_test.py +++ b/tests/test_cli_local_test.py @@ -253,3 +253,33 @@ def _fake_host(target: str) -> int: # Expect project-relative path plus selector rel = os.path.relpath(str(test_file), str(project)) assert captured["target"] == f"{rel}::test_dummy" + + +def test_find_dockerfiles_top_level_only(tmp_path, monkeypatch): + # Project root with both top-level and nested Dockerfiles – only top-level should be returned. + project = tmp_path / "proj" + project.mkdir() + top_level = project / "Dockerfile" + top_level.write_text("FROM python:3.11-slim\n", encoding="utf-8") + nested_dir = project / "nested" + nested_dir.mkdir() + (nested_dir / "Dockerfile").write_text("FROM python:3.11-slim\n", encoding="utf-8") + + from eval_protocol.cli_commands import local_test as lt + + dockerfiles = lt._find_dockerfiles(str(project)) + assert dockerfiles == [str(top_level)] + + +def test_find_dockerfiles_ignores_nested_only(tmp_path, monkeypatch): + # Project root without top-level Dockerfile but with nested ones – should return empty. + project = tmp_path / "proj" + project.mkdir() + nested_dir = project / "nested" + nested_dir.mkdir() + (nested_dir / "Dockerfile").write_text("FROM python:3.11-slim\n", encoding="utf-8") + + from eval_protocol.cli_commands import local_test as lt + + dockerfiles = lt._find_dockerfiles(str(project)) + assert dockerfiles == []