"""Tests for fixture-file glob expansion and the sandbox guard.""" from pathlib import Path from skill_eval_runner.files import expand_files def test_expand_files_glob_and_literal(tmp_path: Path) -> None: """Globs and literal paths both resolve to (relative_path, content) pairs.""" (tmp_path / "a.py").write_text("AAA") (tmp_path / "sub").mkdir() (tmp_path / "sub" / "b.py").write_text("BBB") result = dict(expand_files(["a.py", "sub/*.py"], tmp_path)) assert result == {"a.py": "AAA", "sub/b.py": "BBB"} def test_expand_files_dedupes(tmp_path: Path) -> None: """A file matched by two patterns appears only once.""" (tmp_path / "a.py").write_text("AAA") result = expand_files(["a.py", "*.py"], tmp_path) assert result == [("a.py", "AAA")] def test_expand_files_skips_outside_base(tmp_path: Path) -> None: """A pattern escaping the base directory is skipped.""" base = tmp_path / "base" base.mkdir() (tmp_path / "secret.txt").write_text("nope") assert expand_files(["../secret.txt"], base) == [] def test_expand_files_skips_sibling_with_shared_prefix(tmp_path: Path) -> None: """A sibling dir whose name shares the base's prefix (base vs base2) is not readable.""" base = tmp_path / "base" base.mkdir() sibling = tmp_path / "base2" sibling.mkdir() (sibling / "secret.txt").write_text("nope") assert expand_files(["../base2/secret.txt"], base) == []