Skip to content

The agent that grows with you

refactor(tests): resolve a guarded path once; tripwire test runs without symlinks

kshitijk4poor2b98a469d398
diff --git a/tests/hermes_cli/test_real_home_tripwire.py b/tests/hermes_cli/test_real_home_tripwire.py
index c6d5d10fbbc..5cd3d1bbd09 100644
--- a/tests/hermes_cli/test_real_home_tripwire.py
+++ b/tests/hermes_cli/test_real_home_tripwire.py
@@ -91,12 +91,16 @@ def test_installed_desktop_app_can_be_read_but_never_changed(tmp_path, monkeypat
plist.write_text("unchanged", encoding="utf-8")
replacement = tmp_path / "Hermes.app.new"
replacement.mkdir()
- (tmp_path / "linked").symlink_to(app.parent, target_is_directory=True)
- monkeypatch.setattr(conftest, "_REAL_INSTALLED_GUI_APPS", [app])
+ changes = [lambda: shutil.rmtree(app), plist.unlink, lambda: replacement.replace(app),
+ lambda: plist.write_text("clobbered", encoding="utf-8")]
+ try: # Windows without Developer Mode cannot create symlinks
+ (tmp_path / "linked").symlink_to(app.parent, target_is_directory=True)
+ changes.append(lambda: shutil.rmtree(tmp_path / "linked" / "Hermes.app"))
+ except OSError:
+ pass
+ monkeypatch.setattr(conftest, "_REAL_INSTALLED_GUI_APPS", [os.path.normcase(os.path.realpath(app))])
assert plist.read_text(encoding="utf-8") == "unchanged"
- for change in (lambda: shutil.rmtree(app), plist.unlink, lambda: replacement.replace(app),
- lambda: plist.write_text("clobbered", encoding="utf-8"),
- lambda: shutil.rmtree(tmp_path / "linked" / "Hermes.app")):
+ for change in changes:
with pytest.raises(pytest.fail.Exception, match="REAL installed Hermes desktop app"):
change()
assert plist.read_text(encoding="utf-8") == "unchanged"
diff --git a/tests/home_io_guard.py b/tests/home_io_guard.py
index 4c5d915fa91..4169099e1da 100644
--- a/tests/home_io_guard.py
+++ b/tests/home_io_guard.py
@@ -80,8 +80,7 @@ class HomeIOGuard:
# which is not I/O against the home.
if metadata and (absolute == "/proc" or absolute.startswith("/proc" + os.sep)):
return
- if destructive:
- self._refuse_installed_app_change(value, absolute)
+ resolved = self._refuse_installed_app_change(value, absolute) if destructive else None
roots = tuple(_normcase(os.fspath(r)) for r in self.roots())
# Resolving the root itself (get_default_hermes_root's relative_to
# probe) reads no state; only its contents are guarded.
@@ -106,7 +105,8 @@ class HomeIOGuard:
for root in roots:
if _within(absolute, root):
self.refuse(value)
- resolved = _normcase(os.path.realpath(absolute))
+ if resolved is None:
+ resolved = _normcase(os.path.realpath(absolute))
if metadata and resolved in roots:
return
# A fixture symlink to the running interpreter resolves into its installation.
@@ -120,17 +120,20 @@ class HomeIOGuard:
self.checking.active = False
def _refuse_installed_app_change(self, value, absolute):
- apps = [_normcase(os.path.abspath(app)) for app in self.installed_apps()]
+ """Fail on a change to an installed app (already normalized, literal and resolved);
+ returns the resolved path so check() does not resolve it again, or None."""
+ apps = self.installed_apps()
if not apps:
- return
- paths = (absolute, _normcase(os.path.realpath(absolute)))
+ return None
+ resolved = _normcase(os.path.realpath(absolute))
for app in apps:
- if any(_within(path, app) for path in paths):
+ if _within(absolute, app) or _within(resolved, app):
import pytest # noqa: PLC0415
# pytest.fail, not AssertionError: removal helpers catch Exception and would log
# the refusal as a warning while the test passed.
pytest.fail(f"TEST BUG: changing the REAL installed Hermes desktop app: {value}\n"
"Stub hermes_cli.gui_uninstall.packaged_gui_app_paths to a temporary path.")
+ return resolved
@staticmethod
def refuse(value):