The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(profiles): alias_path never names a foreign same-named command; tests run on the real host
kshitijk4poor9c8cefe3664b
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.pyindex 6f4645db154..aa269debc93 100644--- a/hermes_cli/profiles.py+++ b/hermes_cli/profiles.py@@ -1029,7 +1029,7 @@ def _profile_info(name: str, path: Path, *, is_default: bool, alias_name: Optionmodel, provider = _read_config_model(path)dist_name, dist_version, dist_source = _read_distribution_meta(path)meta = read_profile_meta(path)- alias_path = next((p for p in _wrapper_candidates(alias_name) if p.exists()), None) if alias_name else None+ alias_path = next((p for p in _wrapper_candidates(alias_name) if p.exists() and _is_our_wrapper(p)), None) if alias_name else Nonegateway_running = _check_gateway_running(path)if not is_default:gateway_running = gateway_running or _served_by_running_multiplexer(name)diff --git a/tests/hermes_cli/test_doctor.py b/tests/hermes_cli/test_doctor.pyindex 9a0d311fb19..b8ffe1caf8e 100644--- a/tests/hermes_cli/test_doctor.py+++ b/tests/hermes_cli/test_doctor.py@@ -1634,10 +1634,10 @@ def test_cron_store_check_reports_writability_and_low_space(assert len(finding.issues) == len(issues) and all(any(s in i for i in finding.issues) for s in issues)[email protected]("platform", ["win32", "darwin"])-def test_profile_alias_status_follows_the_wrapper_the_profile_really_has(monkeypatch, tmp_path, platform):[email protected]("any") # the wrapper name differs per host (.bat on Windows)+def test_profile_alias_status_follows_the_wrapper_the_profile_really_has(monkeypatch, tmp_path):"""#131753: doctor said "no alias" for every Windows profile (``.bat`` wrapper) and for any- profile reachable only through a custom alias name; a bare pre-``.bat`` wrapper still counts."""+ profile reachable only through a custom alias name; a bare (pre-``.bat`` on Windows) wrapper counts."""import hermes_cli.gateway_migrate as gmfrom hermes_cli import profiles@@ -1645,13 +1645,14 @@ def test_profile_alias_status_follows_the_wrapper_the_profile_really_has(monkeypmonkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))monkeypatch.setattr(hermes_constants, "_default_hermes_root_memo", None)monkeypatch.setattr(gm, "duplicate_credential_findings", list)- monkeypatch.setattr(profiles, "sys", SimpleNamespace(**{**vars(sys), "platform": platform}))for name in ("dev", "ops", "work", "old"):(tmp_path / ".hermes" / "profiles" / name).mkdir(parents=True)(tmp_path / ".hermes" / "profiles" / name / "config.yaml").write_text("model: m\n", encoding="utf-8")profiles.create_wrapper_script("dev")profiles.create_wrapper_script("w", target="work")(tmp_path / ".local" / "bin" / "old").write_text('#!/bin/sh\nexec hermes -p old "$@"\n', encoding="utf-8")+ for foreign in ("ops.bat", "old.bat"): # same-named non-Hermes commands+ (tmp_path / ".local" / "bin" / foreign).write_text("@echo off\r\nnotepad %*\r\n", encoding="utf-8")out = io.StringIO()with contextlib.redirect_stdout(out):@@ -1660,4 +1661,6 @@ def test_profile_alias_status_follows_the_wrapper_the_profile_really_has(monkeypstatus = {name: next(ln for ln in lines if f" {name}:" in ln) for name in ("dev", "ops", "work", "old")}assert not any("no alias" in status[n] for n in ("dev", "work", "old"))- assert "no alias" in status["ops"]+ assert "no alias" in status["ops"] # a foreign ops.bat is not ops's alias+ old = next(p for p in profiles.list_profiles() if p.name == "old")+ assert old.alias_path == tmp_path / ".local" / "bin" / "old" # never the foreign old.bat (uninstall unlinks it)diff --git a/tests/hermes_cli/test_profile_delete_wrapper.py b/tests/hermes_cli/test_profile_delete_wrapper.pyindex 016894ca0c7..f24380e8389 100644--- a/tests/hermes_cli/test_profile_delete_wrapper.py+++ b/tests/hermes_cli/test_profile_delete_wrapper.py@@ -1,12 +1,10 @@-"""`hermes profile delete` removes the profile's wrapper on Windows (#131753).+"""`hermes profile delete` removes the profile's wrapper (#131753).Windows wrappers are ``<alias>.bat``; delete used to look only for the bare name, so the-``.bat`` survived as an orphan alias. A wrapper written before Windows wrappers became-``.bat`` (#34796) is bare-named and must still go.+``.bat`` survived as an orphan alias. A Windows wrapper written before ``.bat`` (#34796) is+bare-named and must still go."""-import sys-import typesfrom pathlib import Pathimport pytest@@ -15,26 +13,34 @@ from hermes_cli import profilesfrom hermes_cli.profiles import create_profile, create_wrapper_script, delete_profile[email protected]("legacy", [False, True], ids=["bat", "pre-bat-bare-name"])-def test_delete_removes_the_windows_wrapper(tmp_path, monkeypatch, legacy):+def home(tmp_path, monkeypatch):monkeypatch.setattr(Path, "home", lambda: tmp_path)(tmp_path / ".hermes").mkdir()monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))- # profiles.py only: a global sys.platform patch makes modules first imported by- # delete_profile cache a Windows lock backend (msvcrt) for the rest of the run.- monkeypatch.setattr(profiles, "sys", types.SimpleNamespace(**{**vars(sys), "platform": "win32"}))for stub in ("_cleanup_gateway_service", "_maybe_unregister_gateway_service", "_stop_profile_backends"):monkeypatch.setattr(profiles, stub, lambda *a, **k: None)- profile_dir = create_profile("imported", no_alias=True)- if legacy:- wrapper = tmp_path / ".local" / "bin" / "imported"- wrapper.parent.mkdir(parents=True, exist_ok=True)- wrapper.write_text('#!/bin/sh\nexec hermes -p imported "$@"\n', encoding="utf-8")- else:- wrapper = create_wrapper_script("imported")- assert wrapper is not None and wrapper.name == "imported.bat"+ return tmp_path- delete_profile("imported", yes=True)+def _delete_and_check(profile_dir, wrapper):+ delete_profile("imported", yes=True)assert not profile_dir.exists()assert not wrapper.exists()++[email protected]("any") # the wrapper name differs per host (.bat on Windows)+def test_delete_removes_the_profile_wrapper(home):+ profile_dir = create_profile("imported", no_alias=True)+ wrapper = create_wrapper_script("imported")+ assert wrapper is not None+ _delete_and_check(profile_dir, wrapper)++[email protected]("windows")+def test_delete_removes_a_pre_bat_windows_wrapper(home):+ profile_dir = create_profile("imported", no_alias=True)+ wrapper = home / ".local" / "bin" / "imported"+ wrapper.parent.mkdir(parents=True, exist_ok=True)+ wrapper.write_text("@echo off\r\nhermes -p imported %*\r\n", encoding="utf-8")+ _delete_and_check(profile_dir, wrapper)