Skip to content

The agent that grows with you

fix(profiles): doctor counts a pre-.bat Windows wrapper as the profile's alias

kshitijk4poorea356bc11181
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.py
index 02b3f434327..6f4645db154 100644
--- a/hermes_cli/profiles.py
+++ b/hermes_cli/profiles.py
@@ -627,10 +627,8 @@ def build_alias_map() -> dict[str, str]:
for entry in sorted(wrapper_dir.iterdir()):
if not entry.is_file():
continue
- # Our wrappers are named after the alias and (on Windows only) carry .bat.
- if is_windows and entry.suffix != ".bat":
- continue
- if not is_windows and entry.suffix:
+ # Our wrappers are named after the alias; Windows ones carry .bat (none before #34796).
+ if entry.suffix and not (is_windows and entry.suffix == ".bat"):
continue
try:
with open(entry, "r", encoding="utf-8-sig", errors="strict") as f:
@@ -1031,9 +1029,7 @@ def _profile_info(name: str, path: Path, *, is_default: bool, alias_name: Option
model, provider = _read_config_model(path)
dist_name, dist_version, dist_source = _read_distribution_meta(path)
meta = read_profile_meta(path)
- alias_path = _wrapper_path(alias_name) if alias_name else None
- if alias_path is not None and not alias_path.exists():
- alias_path = None
+ alias_path = next((p for p in _wrapper_candidates(alias_name) if p.exists()), None) if alias_name else None
gateway_running = _check_gateway_running(path)
if not is_default:
gateway_running = gateway_running or _served_by_running_multiplexer(name)
@@ -1832,7 +1828,7 @@ def delete_profile(name: str, yes: bool = False) -> Path:
raise ValueError("Cannot delete the default profile (~/.hermes).\nTo remove everything, use: hermes uninstall")
canon, profile_dir = _existing_profile_dir(canon)
gw_running = _check_gateway_running(profile_dir)
- wrapper_path = next((p for p in _wrapper_candidates(canon) if p.exists()), None)
+ wrapper_path = next((p for p in _wrapper_candidates(canon) if p.exists() and _is_our_wrapper(p)), None)
_print_delete_summary(canon, profile_dir, gw_running, wrapper_path)
if not yes:
print()
diff --git a/tests/hermes_cli/test_doctor.py b/tests/hermes_cli/test_doctor.py
index a2453355abf..9a0d311fb19 100644
--- a/tests/hermes_cli/test_doctor.py
+++ b/tests/hermes_cli/test_doctor.py
@@ -1637,7 +1637,7 @@ def test_cron_store_check_reports_writability_and_low_space(
@pytest.mark.parametrize("platform", ["win32", "darwin"])
def test_profile_alias_status_follows_the_wrapper_the_profile_really_has(monkeypatch, tmp_path, platform):
"""#131753: doctor said "no alias" for every Windows profile (``.bat`` wrapper) and for any
- profile reachable only through a custom alias name."""
+ profile reachable only through a custom alias name; a bare pre-``.bat`` wrapper still counts."""
import hermes_cli.gateway_migrate as gm
from hermes_cli import profiles
@@ -1646,17 +1646,18 @@ def test_profile_alias_status_follows_the_wrapper_the_profile_really_has(monkeyp
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"):
+ 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")
out = io.StringIO()
with contextlib.redirect_stdout(out):
doctor_state._check_profiles(False)
lines = out.getvalue().splitlines()
- status = {name: next(ln for ln in lines if f" {name}:" in ln) for name in ("dev", "ops", "work")}
+ status = {name: next(ln for ln in lines if f" {name}:" in ln) for name in ("dev", "ops", "work", "old")}
- assert "no alias" not in status["dev"] and "no alias" not in status["work"]
+ assert not any("no alias" in status[n] for n in ("dev", "work", "old"))
assert "no alias" in status["ops"]