The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): trim the PermissionError guard salvage to two live tests
teknium1787b261ff836
diff --git a/agent/prompt_builder.py b/agent/prompt_builder.pyindex 8be187a650b..149530df1e2 100644--- a/agent/prompt_builder.py+++ b/agent/prompt_builder.py@@ -1583,10 +1583,7 @@ def _cursorrules_candidates(cwd_path: Path) -> list[tuple[str, Path, str]]:candidates: list[tuple[str, Path]] = [(".cursorrules", cwd_path / ".cursorrules")]cursor_rules_dir = cwd_path / ".cursor" / "rules"if _is_dir_or_denied(cursor_rules_dir):- try:- candidates += [(f".cursor/rules/{f.name}", f) for f in sorted(cursor_rules_dir.glob("*.mdc"))]- except OSError:- pass+ candidates += [(f".cursor/rules/{f.name}", f) for f in sorted(cursor_rules_dir.glob("*.mdc"))]return [(label, path, _read_context_file(path)) for label, path in candidates if _exists_or_denied(path)]diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..df9b2e60e78--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1 @@+officialasishkumardiff --git a/tests/agent/test_prompt_builder.py b/tests/agent/test_prompt_builder.pyindex 5f89066698d..194aeb6b271 100644--- a/tests/agent/test_prompt_builder.py+++ b/tests/agent/test_prompt_builder.py@@ -629,46 +629,19 @@ class TestFindHermesMd:with patch("agent.prompt_builder._find_git_root", return_value=None):assert _find_hermes_md(cwd) is None- def test_unreadable_candidate_is_treated_as_not_found(self, tmp_path, monkeypatch):- """A candidate the process cannot stat must not raise out of prompt construction.-- Regression for the crash that took down every Hermes surface (terminal,- TUI, dashboard, gateway messaging) at once: TERMINAL_CWD pointed at an- SSH backend's remote home (``/root``) while the gateway ran as a non-root- local user, and ``.is_file()`` on the candidate raised PermissionError- with no guard, unlike every sibling finder in this module (see #8751,- which explicitly listed this exact function as affected but whose merged- fix only covered ``_find_git_root``).- """+ @pytest.mark.skipif(os.geteuid() == 0, reason="root bypasses directory permissions")+ def test_unreadable_cwd_is_treated_as_not_found(self, tmp_path):+ """A cwd the process cannot stat yields "no context file" instead of a PermissionError+ escaping prompt construction and taking down every surface sharing the gateway (#112430:+ TERMINAL_CWD pointed at an SSH backend's remote ``/root`` while the local user was non-root)."""locked = tmp_path / "root"locked.mkdir()- real_is_file = Path.is_file-- def _is_file(self):- if self.parent == locked and self.name in (".hermes.md", "HERMES.md"):- raise PermissionError(13, "Permission denied", str(self))- return real_is_file(self)-- monkeypatch.setattr(Path, "is_file", _is_file)- assert _find_hermes_md(locked) is None-- def test_walk_continues_past_unreadable_directory(self, tmp_path, monkeypatch):- """An unreadable intermediate directory must not stop the upward walk."""- (tmp_path / ".git").mkdir()- (tmp_path / ".hermes.md").write_text("root rules")- blocked = tmp_path / "blocked"- blocked.mkdir()- sub = blocked / "work"- sub.mkdir()- real_is_file = Path.is_file-- def _is_file(self):- if self.parent == blocked:- raise PermissionError(13, "Permission denied", str(self))- return real_is_file(self)-- monkeypatch.setattr(Path, "is_file", _is_file)- assert _find_hermes_md(sub) == tmp_path / ".hermes.md"+ locked.chmod(0)+ try:+ assert _find_hermes_md(locked) is None+ assert isinstance(build_context_files_prompt(cwd=str(locked)), str)+ finally:+ locked.chmod(0o700)class TestFindGitRoot:@@ -698,23 +671,21 @@ class TestFindGitRoot:class TestCursorrulesCandidates:- def test_finds_cursorrules_file(self, tmp_path):- (tmp_path / ".cursorrules").write_text("rules")- labels = [label for label, _path, _content in _cursorrules_candidates(tmp_path)]- assert ".cursorrules" in labels-- def test_unreadable_rules_dir_is_treated_as_absent(self, tmp_path, monkeypatch):- """Same crash shape as _find_hermes_md: an unreadable .cursor/rules dir- must not raise out of prompt construction."""- real_is_dir = Path.is_dir-- def _is_dir(self):- if self.name == "rules" and self.parent.name == ".cursor":- raise PermissionError(13, "Permission denied", str(self))- return real_is_dir(self)-- monkeypatch.setattr(Path, "is_dir", _is_dir)- assert _cursorrules_candidates(tmp_path) == []+ @pytest.mark.skipif(os.geteuid() == 0, reason="root bypasses directory permissions")+ def test_unreadable_cwd_is_treated_as_absent(self, tmp_path):+ """Same crash shape as ``_find_hermes_md``: ``.is_dir()`` on ``<cwd>/.cursor/rules`` inside an+ unreadable cwd must not raise; a readable sibling project still yields its rules."""+ locked = tmp_path / "root"+ locked.mkdir()+ proj = tmp_path / "proj"+ (proj / ".cursor" / "rules").mkdir(parents=True)+ (proj / ".cursor" / "rules" / "a.mdc").write_text("cursor rule")+ locked.chmod(0)+ try:+ assert _cursorrules_candidates(locked) == []+ finally:+ locked.chmod(0o700)+ assert [label for label, _p, _c in _cursorrules_candidates(proj)] == [".cursor/rules/a.mdc"]class TestStripYamlFrontmatter: