The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): record a partial pm update as failed in the pm receipt
Tekniumde06a61c51ef
diff --git a/pm/cli.py b/pm/cli.pyindex 471f9a6e761..3ef9ef6d038 100644--- a/pm/cli.py+++ b/pm/cli.py@@ -590,7 +590,7 @@ def _apply_pins(changed: list, lockfile) -> int:print("pm update: nothing to update")return 0pinned: list[str] = []- failed: list[str] = []+ failed: dict[str, str] = {}for d in changed:package = get_package(d.name)try:@@ -600,22 +600,29 @@ def _apply_pins(changed: list, lockfile) -> int:# pool skew (rolling Termux pool 404 while nodejs.org is ahead) — must# not zero out the whole run. Pin the rest, report the failure (#125386).print(f"✗ {d.name} pin failed: {e}")- failed.append(d.name)+ failed[d.name] = f"{type(e).__name__}: {e}"continuelockfile.set_pin(d.name, d.version, artifacts)pinned.append(d.name)print(f"✓ {d.name} pinned {d.locked or '—'} → {d.version}")- if not pinned:+ if pinned:+ lockfile.save()+ rc = 1 if _install_names(pinned) or not _sync_venv_step() else 0+ else:print("pm update: every pin failed; lockfile untouched")- return 1- lockfile.save()- if _install_names(pinned):- return 1- rc = 0 if _sync_venv_step() else 1- if failed:- print(f"pm update: pinned {len(pinned)}, failed {len(failed)}: {', '.join(failed)}")- return 1- return rc+ rc = 1+ if not failed:+ return rc+ print(f"pm update: pinned {len(pinned)}, failed {len(failed)}: {', '.join(failed)}")+ # The venv sync above leaves an `ok` sync receipt as latest; `hermes pm+ # status` and the desktop read latest, so the partial run must land last.+ from pm import receipt++ token = receipt.begin("update")+ for name, error in failed.items():+ receipt.record_step(f"pin {name}", False, error)+ receipt.finalize("failed", 1, token=token)+ return 1def _refresh_uv_lock() -> int:diff --git a/tests/pm/test_update_pin_isolation.py b/tests/pm/test_update_pin_isolation.pyindex 4044b5dbfc0..084881c068c 100644--- a/tests/pm/test_update_pin_isolation.py+++ b/tests/pm/test_update_pin_isolation.py@@ -4,12 +4,13 @@resolution bug or one target's rolling-pool 404), so `lockfile.save()`never ran and every unrelated package stayed un-updated. Pins are nowisolated per package: successes are pinned and saved, failures are-reported and summarized, exit stays non-zero.+reported and summarized, exit stays non-zero, and the latest pm receipt+(`hermes pm status`, the desktop) records the run as failed."""import pytest-from pm import cli, paths, registry+from pm import cli, paths, receipt, registryfrom pm.lock import Lockfilefrom pm.package import Packagefrom pm.store import current_target@@ -62,7 +63,9 @@ def prepare(tmp_path, monkeypatch):monkeypatch.setattr(cli, "_pin_artifacts", pin_artifacts_or_raise)monkeypatch.setattr(cli, "_install_names", lambda names: None)- monkeypatch.setattr(cli, "_sync_venv_step", lambda: True)+ # Like the real sync, the venv step finalizes an `ok` receipt as latest.+ monkeypatch.setattr(cli, "_sync_venv_step",+ lambda: receipt.finalize("ok", 0, token=receipt.begin("sync")) and True)return lock, broken, healthy@@ -77,6 +80,9 @@ def test_one_failing_pin_does_not_block_the_rest(tmp_path, monkeypatch, capsys):# The healthy pin survived to disk; the broken row kept its old version.assert lock.version("healthy-pin") == "3.0"assert lock.version("broken-pin") == "1.0"+ latest = receipt.latest()+ assert (latest["outcome"], latest["exit_code"]) == ("failed", 1)+ assert [s["name"] for s in latest["steps"]] == ["pin broken-pin"]def test_all_pins_failing_leaves_lockfile_untouched(tmp_path, monkeypatch, capsys):@@ -89,12 +95,3 @@ def test_all_pins_failing_leaves_lockfile_untouched(tmp_path, monkeypatch, capsyassert "every pin failed; lockfile untouched" in outassert lock.path.read_bytes() == before--def test_clean_run_still_succeeds(tmp_path, monkeypatch, capsys):- lock, broken, healthy = prepare(tmp_path, monkeypatch)- changed = [_decision(healthy, "3.0")]- assert cli._apply_pins(changed, lock) == 0- out = capsys.readouterr().out- assert "✓ healthy-pin pinned 1.0 → 3.0" in out- assert "failed" not in out- assert lock.version("healthy-pin") == "3.0"