The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: fold the symlinked-hint cases into two invariants
teknium10418acfb199a
diff --git a/tests/agent/test_subdirectory_hints.py b/tests/agent/test_subdirectory_hints.pyindex 9eccd89514a..6973d748296 100644--- a/tests/agent/test_subdirectory_hints.py+++ b/tests/agent/test_subdirectory_hints.py@@ -379,93 +379,46 @@ class TestExcludedDirectories:class TestSymlinkedHintTargets:"""A hint file's resolved target must stay inside the working tree and off- the read deny-list; the link's in-tree name does not sanitize its target."""+ the read deny-list; the link's in-tree name does not sanitize its target (#116429)."""- def test_symlinked_hint_outside_tree_not_loaded(self, tmp_path):+ def test_escaping_or_denied_symlink_is_never_injected(self, tmp_path):outside = tmp_path / "outside"outside.mkdir()(outside / "secret.md").write_text("OUTSIDE-MARKER-9f3a", encoding="utf-8")-- workspace = tmp_path / "workspace"- workspace.mkdir()- sub = workspace / "sub"- sub.mkdir()- (sub / "AGENTS.md").symlink_to(outside / "secret.md")-- tracker = SubdirectoryHintTracker(working_dir=str(workspace))- assert tracker.check_tool_call("read_file", {"path": str(sub / "f.py")}) is None-- def test_symlink_to_denied_file_inside_tree_not_loaded(self, tmp_path):- """In-tree containment is not enough: a symlink to the project .env- still hits the canonical read deny-list."""workspace = tmp_path / "workspace"workspace.mkdir()(workspace / ".env").write_text("API_KEY=SECRET-VALUE-7b2d", encoding="utf-8")+ # CWD-level escaping link: the __init__ digest seed must skip it too.+ (workspace / "AGENTS.md").symlink_to(outside / "secret.md")sub = workspace / "sub"sub.mkdir()- (sub / "AGENTS.md").symlink_to(workspace / ".env")+ (sub / "AGENTS.md").symlink_to(outside / "secret.md")+ envlink = workspace / "envlink"+ envlink.mkdir()+ (envlink / "AGENTS.md").symlink_to(workspace / ".env")tracker = SubdirectoryHintTracker(working_dir=str(workspace))+ assert tracker._loaded_digests == set()assert tracker.check_tool_call("read_file", {"path": str(sub / "f.py")}) is None+ assert tracker.check_tool_call("read_file", {"path": str(envlink / "f.py")}) is None+ assert SubdirectoryHintTracker(working_dir=str(workspace)).check_tool_call(+ "terminal", {"command": f"cd {sub}"}) is None- def test_in_tree_symlink_still_loads(self, tmp_path):- """A symlink whose resolved target stays inside the tree keeps working."""+ def test_in_tree_hint_files_still_load(self, tmp_path):+ """A plain hint file and a symlink whose target stays inside the tree keep working."""workspace = tmp_path / "workspace"docs = workspace / "docs"docs.mkdir(parents=True)(docs / "AGENTS.md").write_text("Shared in-tree instructions", encoding="utf-8")- sub = workspace / "sub"- sub.mkdir()- (sub / "AGENTS.md").symlink_to(docs / "AGENTS.md")+ linked = workspace / "linked"+ linked.mkdir()+ (linked / "AGENTS.md").symlink_to(docs / "AGENTS.md")+ plain = workspace / "plain"+ plain.mkdir()+ (plain / "AGENTS.md").write_text("Legit subdirectory rules", encoding="utf-8")tracker = SubdirectoryHintTracker(working_dir=str(workspace))- result = tracker.check_tool_call("read_file", {"path": str(sub / "f.py")})+ result = tracker.check_tool_call("read_file", {"path": str(linked / "f.py")})assert result is not None and "Shared in-tree instructions" in result-- def test_working_dir_seed_skips_outside_symlink(self, tmp_path):- """_first_hint_file applies the same policy: an escaping CWD-level- symlink seeds no digest."""- outside = tmp_path / "outside"- outside.mkdir()- (outside / "shared.md").write_text("OUTSIDE-MARKER-9f3a", encoding="utf-8")-- workspace = tmp_path / "workspace"- workspace.mkdir()- (workspace / "AGENTS.md").symlink_to(outside / "shared.md")-- tracker = SubdirectoryHintTracker(working_dir=str(workspace))- assert tracker._loaded_digests == set()- # Same content dropped in a subdirectory is not deduped against a file- # that was never legitimately loaded.- sub = workspace / "sub"- sub.mkdir()- (sub / "AGENTS.md").write_text("OUTSIDE-MARKER-9f3a", encoding="utf-8")- assert tracker.check_tool_call("read_file", {"path": str(sub / "f.py")}) is not None-- def test_symlink_escape_via_cd_navigation(self, tmp_path):- """The realistic route: a terminal cd into a checked-out dir whose- planted symlink escapes the tree."""- outside = tmp_path / "outside"- outside.mkdir()- (outside / "loot.md").write_text("OUTSIDE-MARKER-9f3a", encoding="utf-8")-- workspace = tmp_path / "workspace"- workspace.mkdir()- sub = workspace / "sub"- sub.mkdir()- (sub / "AGENTS.md").symlink_to(outside / "loot.md")-- tracker = SubdirectoryHintTracker(working_dir=str(workspace))- assert tracker.check_tool_call("terminal", {"command": f"cd {sub}"}) is None-- def test_real_hint_file_unaffected_by_target_check(self, tmp_path):- """A plain (non-symlink) in-tree hint file still loads."""- workspace = tmp_path / "workspace"- workspace.mkdir()- sub = workspace / "sub"- sub.mkdir()- (sub / "AGENTS.md").write_text("Legit subdirectory rules", encoding="utf-8")-- tracker = SubdirectoryHintTracker(working_dir=str(workspace))- result = tracker.check_tool_call("read_file", {"path": str(sub / "f.py")})+ result = tracker.check_tool_call("read_file", {"path": str(plain / "f.py")})assert result is not None and "Legit subdirectory rules" in result