Skip to content

The agent that grows with you

fix(plugins): a damaged install-metadata file no longer stops the scheduled check

alt-glitch300a3977ed7a
diff --git a/hermes_cli/plugins_cadence.py b/hermes_cli/plugins_cadence.py
index 9c2d2b21de8..260d7806d7a 100644
--- a/hermes_cli/plugins_cadence.py
+++ b/hermes_cli/plugins_cadence.py
@@ -200,8 +200,9 @@ def _run_check_locked(
) -> list:
check_ok = True
warning = ""
- checked_installs = snapshot_installs(plugins_dir)
+ checked_installs: dict = {}
try:
+ checked_installs = snapshot_installs(plugins_dir)
results = run_checks_fn(plugins_dir)
except Exception:
warning = "plugin update check failed"
diff --git a/hermes_cli/plugins_provenance.py b/hermes_cli/plugins_provenance.py
index c753fe00b0e..200ff0ebcc2 100644
--- a/hermes_cli/plugins_provenance.py
+++ b/hermes_cli/plugins_provenance.py
@@ -50,7 +50,7 @@ def read_sidecar_rows(plugins_dir: Path) -> dict:
return {}
try:
data = json.loads(sidecar.read_text(encoding="utf-8-sig"))
- except (OSError, json.JSONDecodeError):
+ except (OSError, ValueError): # ValueError: bad JSON and bytes that are not UTF-8
return {}
return data if isinstance(data, dict) else {}
diff --git a/tests/hermes_cli/test_plugins_cadence.py b/tests/hermes_cli/test_plugins_cadence.py
index 94222a5eda3..ca22a120760 100644
--- a/tests/hermes_cli/test_plugins_cadence.py
+++ b/tests/hermes_cli/test_plugins_cadence.py
@@ -73,6 +73,27 @@ def test_run_writes_receipt_and_marker(homed):
assert len(calls) == 1
+def test_damaged_install_records_do_not_stop_the_scheduled_check(homed):
+ """An install-metadata file that is not valid UTF-8 used to raise out of the pre-check snapshot,
+ before the check could write its receipt or marker, so every housekeeping tick retried silently.
+ A damaged file now reads as no records: the check still runs, records its receipt and backs off."""
+ import pm.receipt as receipts
+
+ plugins = homed / "plugins"
+ plugins.mkdir()
+ (plugins / ".install-metadata.json").write_bytes(b"\xff\xfe{not utf-8")
+ calls = []
+
+ def checks(directory):
+ calls.append(directory)
+ return [_Result("plug", update_available=True)]
+
+ assert cad.run_scheduled_check(run_checks_fn=checks, plugins_dir=plugins)[0].name == "plug"
+ assert receipts.latest()["outcome"] == "updates-available"
+ assert cad.run_scheduled_check(run_checks_fn=checks, plugins_dir=plugins) is None
+ assert len(calls) == 1
+
+
@pytest.mark.parametrize('enabled', [False, True])
def test_auto_apply_selects_only_updateable_git_and_persists_receipt(homed, enabled, caplog):
from pm import receipt