Skip to content

The agent that grows with you

fix(profiles): remove Windows alias on profile delete

rcktmonk6090407840a4
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.py
index 1bcb57a01a1..6b52218cc5e 100644
--- a/hermes_cli/profiles.py
+++ b/hermes_cli/profiles.py
@@ -1831,7 +1831,15 @@ 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 = _get_wrapper_dir() / canon
+ wrapper_dir = _get_wrapper_dir()
+ wrapper_candidates = (
+ wrapper_dir / canon,
+ wrapper_dir / f"{canon}.bat",
+ )
+ wrapper_path = next(
+ (candidate for candidate in wrapper_candidates if candidate.exists()),
+ wrapper_candidates[0],
+ )
has_wrapper = wrapper_path.exists()
_print_delete_summary(canon, profile_dir, gw_running, wrapper_path if has_wrapper else None)
if not yes:
diff --git a/tests/hermes_cli/test_profiles.py b/tests/hermes_cli/test_profiles.py
index 740e188d21c..b2d7bedd570 100644
--- a/tests/hermes_cli/test_profiles.py
+++ b/tests/hermes_cli/test_profiles.py
@@ -544,6 +544,31 @@ class TestBackfillProfileEnvs:
class TestDeleteProfile:
"""Tests for delete_profile()."""
+ def test_delete_removes_windows_bat_wrapper(self, profile_env, monkeypatch):
+ """Deleting an imported/created profile removes its Windows alias."""
+ monkeypatch.setattr("hermes_cli.profiles.sys.platform", "win32")
+ profile_dir = create_profile("imported", no_alias=True)
+ wrapper = create_wrapper_script("imported")
+ assert wrapper is not None
+ assert wrapper.name == "imported.bat"
+ assert wrapper.exists()
+
+ monkeypatch.setattr(
+ "hermes_cli.profiles._cleanup_gateway_service", lambda *a, **k: None
+ )
+ monkeypatch.setattr(
+ "hermes_cli.profiles._maybe_unregister_gateway_service",
+ lambda *a, **k: None,
+ )
+ monkeypatch.setattr(
+ "hermes_cli.profiles._stop_profile_backends", lambda *a, **k: None
+ )
+
+ delete_profile("imported", yes=True)
+
+ assert not profile_dir.exists()
+ assert not wrapper.exists()
+
def test_rmtree_failure_raises(self, profile_env):
profile_dir = create_profile("coder", no_alias=True)