Skip to content

The agent that grows with you

fix(pm): only live profiles feed the shared dependency union

ethernet547ad0ab18bb
diff --git a/pm/plugins_state.py b/pm/plugins_state.py
index 87a8796404b..af30c531e83 100644
--- a/pm/plugins_state.py
+++ b/pm/plugins_state.py
@@ -88,8 +88,14 @@ def _is_directory(path: Path) -> bool:
def dependency_homes() -> list[Path]:
- """Every home whose selection feeds the shared venv: the default home plus each profile.
- Enumerates the complete union or refuses; a partial scan cannot remove members."""
+ """Every home whose selection feeds the shared venv: the default home plus each LIVE profile.
+ Enumerates the complete union or refuses; a partial scan cannot remove members.
+
+ Live means what ``hermes profile`` lists (hermes_constants): a valid id carrying an identity
+ marker and no tombstone. Staging dirs (``.work.staging-*``), deleted profiles and stray
+ marker-less dirs must not put plugins into the shared environment.
+ """
+ from hermes_constants import PROFILE_ID_RE, named_profile_is_live
from pm.environments import dependency_home_root
homes = [dependency_home_root()]
@@ -100,7 +106,9 @@ def dependency_homes() -> list[Path]:
return homes
except OSError as exc:
raise ValueError(f"could not enumerate profiles: {root}") from exc
- homes.extend(profile for profile in profiles if _is_directory(profile))
+ homes.extend(profile for profile in profiles
+ if _is_directory(profile) and profile.name != "default"
+ and PROFILE_ID_RE.match(profile.name) and named_profile_is_live(profile))
return homes
diff --git a/tests/pm/test_plugins_state.py b/tests/pm/test_plugins_state.py
index 023aabd0c3f..ea9c6dc1590 100644
--- a/tests/pm/test_plugins_state.py
+++ b/tests/pm/test_plugins_state.py
@@ -45,6 +45,25 @@ def test_enabled_plugins_ordered_reads_all_homes(homes):
assert by_root.get(profile_home / "plugins") == ["c-plug"]
+def test_only_live_profiles_join_the_dependency_union(homes):
+ from hermes_constants import mark_named_profile_deleted
+
+ default_home, profile_home = homes
+ profiles = profile_home.parent
+ _write_config(default_home, ["a-plug"])
+ _write_config(profile_home, ["live-plug"])
+ for name in (".work.staging-123", "Bad Name", "retired", "ghost"):
+ (profiles / name).mkdir()
+ for name in (".work.staging-123", "Bad Name", "retired"):
+ _write_config(profiles / name, [f"{name}-plug"])
+ mark_named_profile_deleted(profiles / "retired")
+ (profiles / "ghost" / "plugins").mkdir() # runtime side-effect dir, no identity marker
+
+ assert pstate.dependency_homes() == [default_home, profile_home]
+ by_root = pstate.enabled_plugins_ordered()
+ assert set(by_root) == {default_home / "plugins", profile_home / "plugins"}
+
+
@pytest.mark.parametrize("boundary", ["profile-listing", "profile-stat", "config-read", "plugin-stat", "manifest-read", "manifest-stat", "provider-stat"])
def test_unreadable_profile_state_is_not_an_empty_selection(homes, monkeypatch, boundary):
from pm.workspace import enabled_member_dirs