Skip to content

The agent that grows with you

fix(pm): carry the libatomic remedy as InstallError's remedy

kshitijk4poor7159021d1eb6
diff --git a/pm/install.py b/pm/install.py
index 50208660424..f8281131da1 100644
--- a/pm/install.py
+++ b/pm/install.py
@@ -447,11 +447,11 @@ def _install(
raise DownloadPaused("install paused")
if progress is not None:
progress("verify", 0, 0, "")
- reason = package.verify(staged, target)
+ reason, remedy = package.verify(staged, target), ""
if reason:
- reason = package.repair_staged_verification(staged, target, reason)
+ reason, remedy = package.repair_staged_verification(staged, target, reason)
if reason:
- raise InstallError(package.name, f"staged entry failed verification: {reason}")
+ raise InstallError(package.name, f"staged entry failed verification: {reason}", remedy)
if facts is None:
(staged / ".pm-stage-pin.json").write_text(pin, encoding="utf-8")
with _publish_entry(package, store, staged, entry, previous_entry, target):
diff --git a/pm/package.py b/pm/package.py
index bb8fa8e2902..600cb1f461e 100644
--- a/pm/package.py
+++ b/pm/package.py
@@ -150,16 +150,16 @@ class Package:
return ""
return self._binary_reason(binary, entry, target)
- def repair_staged_verification(self, entry: Path, target: str, reason: str) -> str:
+ def repair_staged_verification(self, entry: Path, target: str, reason: str) -> tuple[str, str]:
"""Install-time remediation for a failed staged verification.
verify() is also used by read-only inspection paths such as
hermes pm doctor and must stay side-effect free. The installer
calls this hook only after a freshly staged entry fails verification.
- Return the remaining failure reason, or an empty string when
- remediation made the staged entry usable.
+ Return (remaining reason, remedy): an empty reason when remediation
+ made the staged entry usable; an empty remedy keeps InstallError's.
"""
- return reason
+ return reason, ""
def _binary_reason(self, binary: Path, entry: Path, target: str) -> str:
"""'' when the binary is present and arch-plausible on target."""
diff --git a/pm/packages.py b/pm/packages.py
index 1cb4422cab2..d975f9e2776 100644
--- a/pm/packages.py
+++ b/pm/packages.py
@@ -483,23 +483,23 @@ class Nodejs(_BionicDebArm, BinaryPackage, DebPackage):
# lockfile is written rather than selecting glibc bytes on musl.
return node_latest_versions()
- def repair_staged_verification(self, entry: Path, target: str, reason: str) -> str:
+ def repair_staged_verification(self, entry: Path, target: str, reason: str) -> tuple[str, str]:
"""Repair the host library needed by official Linux Node, then re-probe.
Keep this out of verify(): doctor/status checks call verify and must
never gain permission to install host packages.
"""
if target != current_target() or not target.startswith("linux") or "libatomic.so.1" not in reason:
- return reason
+ return reason, ""
from pm.libatomic import try_install_libatomic
installed, remedy = try_install_libatomic()
- if installed:
- retried = self.verify(entry, target)
- if "libatomic.so.1" not in retried:
- return retried
- reason = retried
- return reason if not remedy or remedy in reason else f"{reason} — {remedy}"
+ if not installed:
+ return reason, remedy
+ retried = self.verify(entry, target)
+ if "libatomic.so.1" in retried:
+ return retried, "the libatomic package installed, but Node still cannot load libatomic.so.1; check the loader path"
+ return retried, ""
@register
diff --git a/tests/pm/test_node_libatomic_install_boundary.py b/tests/pm/test_node_libatomic_install_boundary.py
index 2c8db8287e3..60b97de7a05 100644
--- a/tests/pm/test_node_libatomic_install_boundary.py
+++ b/tests/pm/test_node_libatomic_install_boundary.py
@@ -38,12 +38,13 @@ def test_staged_repair_installs_libatomic_then_reprobes(tmp_path, monkeypatch):
repaired = package.repair_staged_verification(tmp_path, "linux-x64", first)
assert calls["n"] == 1
- assert repaired == ""
+ assert repaired == ("", "")
def test_auto_repair_never_reads_a_tty(monkeypatch):
from pm import libatomic
+ monkeypatch.setattr(libatomic, "_ATTEMPT", None)
monkeypatch.setattr(libatomic, "_is_root", lambda: False)
monkeypatch.setattr(libatomic, "_host_install_command", lambda: ("dnf", "install", "-y", "libatomic"))
monkeypatch.setattr(libatomic.shutil, "which", lambda name: "/usr/bin/sudo" if name == "sudo" else None)