Skip to content

The agent that grows with you

fix(pm): member stamp includes pyproject CONTENT — dep bumps re-sync

ethernet9ba553870fe1
diff --git a/pm/workspace.py b/pm/workspace.py
index 1df2e25a404..5ab7708899c 100644
--- a/pm/workspace.py
+++ b/pm/workspace.py
@@ -45,11 +45,23 @@ def _member_rel(root: Path, plugin_dir: Path) -> str:
def members_stamp(plugin_dirs: list[Path]) -> str:
"""Content hash of the member SET — order-independent, so venv stamps
- compare the set of unioned plugins, not the discovery order."""
- resolved = sorted({str(p.resolve()) for p in plugin_dirs})
+ compare the set of unioned plugins, not the discovery order.
+
+ Includes each member's pyproject.toml CONTENT: a plugin update that
+ changes its pins must re-sync the union even when the member set is
+ unchanged (Task 4 of the plugin auto-update plan — path-only hashing
+ left pulled-plugin dep bumps invisible to expected_stamp)."""
+ resolved = sorted({p.resolve() for p in plugin_dirs})
h = hashlib.sha256()
for entry in resolved:
- h.update(entry.encode("utf-8"))
+ h.update(str(entry).encode("utf-8"))
+ h.update(b"\0")
+ pyproject = entry / "pyproject.toml"
+ if pyproject.is_file():
+ try:
+ h.update(pyproject.read_bytes())
+ except OSError:
+ pass
h.update(b"\0")
return h.hexdigest()
diff --git a/tests/pm/test_workspace.py b/tests/pm/test_workspace.py
index 2eb3201e5e3..a041d99897a 100644
--- a/tests/pm/test_workspace.py
+++ b/tests/pm/test_workspace.py
@@ -148,6 +148,38 @@ def test_member_stamp_hash_changes_with_plugin_set(layout):
assert stamp_a == stamp_b
+def test_member_stamp_changes_when_pyproject_content_changes(tmp_path):
+ """Task 4 contract: a pulled plugin with changed pins must move the
+ stamp — path-only hashing left dep bumps invisible to the venv sync."""
+ plug = tmp_path / "plug"
+ plug.mkdir()
+ (plug / "pyproject.toml").write_text(
+ 'dependencies = ["pkg==1.0.0"]\n', encoding="utf-8"
+ )
+ before = ws.members_stamp([plug])
+ # the plugin update: same dir, new pins
+ (plug / "pyproject.toml").write_text(
+ 'dependencies = ["pkg==2.0.0"]\n', encoding="utf-8"
+ )
+ after = ws.members_stamp([plug])
+ assert before != after
+ # no pyproject at all: still hashable (the dir identity carries it)
+ bare = tmp_path / "bare"
+ bare.mkdir()
+ assert ws.members_stamp([bare]) != before
+
+
+def test_member_stamp_missing_pyproject_does_not_crash(tmp_path):
+ """A member dir whose pyproject vanished mid-scan hashes on path only."""
+ plug = tmp_path / "ghost"
+ plug.mkdir()
+ (plug / "pyproject.toml").write_text("x\n", encoding="utf-8")
+ first = ws.members_stamp([plug])
+ (plug / "pyproject.toml").unlink()
+ second = ws.members_stamp([plug])
+ assert first != second # content term dropped out, stamp moved
+
+
def test_enabled_member_dirs_finds_enabled_dep_plugins(tmp_path, monkeypatch):
plugins = tmp_path / "plugins"
plugins.mkdir(parents=True)