The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): stamp a saved update check with the installs read before it ran
alt-glitch5a00d0dd451c
diff --git a/hermes_cli/plugins_cadence.py b/hermes_cli/plugins_cadence.pyindex 54db20a6979..9c2d2b21de8 100644--- a/hermes_cli/plugins_cadence.py+++ b/hermes_cli/plugins_cadence.py@@ -35,23 +35,28 @@ def _results_path() -> Path:return _marker_path().parent / "results.json"-def record_check_results(results: list, plugins_dir: Path) -> None:+def snapshot_installs(plugins_dir: Path) -> dict:+ """The install records an update check is about to compare against. Take it BEFORE the check runs:+ a record read afterwards may already include an update that finished during the check."""+ from hermes_cli.plugins_provenance import read_sidecar_rows++ return read_sidecar_rows(plugins_dir)+++def record_check_results(results: list, checked_installs: dict) -> None:"""Persist a completed check so surfaces that list plugins (the Desktop Plugins tab) can show anupdate without a network call per listing. Each row carries the install record it was checked- against (source, revision, pin), so a later reader can tell whether the result still applies.- Never raises."""+ against (*checked_installs*, from :func:`snapshot_installs` before the check), so a later reader+ can tell whether the result still applies. Never raises."""import jsonfrom utils import atomic_write_texttry:- from hermes_cli.plugins_provenance import read_sidecar_rows-- installed = read_sidecar_rows(plugins_dir)rows = []for r in results:row = r.to_json() if hasattr(r, "to_json") else dict(r)- rows.append({**row, "checked_install": _install_fingerprint(installed.get(row.get("name")))})+ rows.append({**row, "checked_install": _install_fingerprint(checked_installs.get(row.get("name")))})atomic_write_text(_markers_dir() / "results.json", json.dumps(rows, indent=2) + "\n")except (OSError, TypeError, ValueError):pass@@ -195,6 +200,7 @@ def _run_check_locked() -> list:check_ok = Truewarning = ""+ checked_installs = snapshot_installs(plugins_dir)try:results = run_checks_fn(plugins_dir)except Exception:@@ -204,7 +210,7 @@ def _run_check_locked(check_ok = Falseif check_ok:- record_check_results(results, plugins_dir)+ record_check_results(results, checked_installs)try:from pm import receiptdiff --git a/hermes_cli/plugins_cmd_update.py b/hermes_cli/plugins_cmd_update.pyindex a02c6d4f07c..2af5d26651f 100644--- a/hermes_cli/plugins_cmd_update.py+++ b/hermes_cli/plugins_cmd_update.py@@ -271,9 +271,11 @@ def cmd_check_updates(args: Any | None = None) -> None:from hermes_cli.plugins_updates import run_checks+ from hermes_cli.plugins_cadence import record_check_results, snapshot_installs++ checked_installs = snapshot_installs(plugins_dir)results = run_checks(plugins_dir)- from hermes_cli.plugins_cadence import record_check_results- record_check_results(results, plugins_dir)+ record_check_results(results, checked_installs)if getattr(args, "json", False):print(json.dumps([r.to_json() for r in results], indent=2))diff --git a/tests/hermes_cli/test_plugin_update_scan_override.py b/tests/hermes_cli/test_plugin_update_scan_override.pyindex ca51c43dbe8..b46e7fa3033 100644--- a/tests/hermes_cli/test_plugin_update_scan_override.py+++ b/tests/hermes_cli/test_plugin_update_scan_override.py@@ -108,20 +108,24 @@ def test_desktop_rows_offer_a_git_update_only_while_the_check_still_matches_the_that revision, reinstalled from another source, or pinned with ``--ref`` (which ``update`` refuses)."""import json- from hermes_cli.plugins_cadence import cached_git_updates, record_check_results+ from hermes_cli.plugins_cadence import cached_git_updates, record_check_results, snapshot_installsfrom hermes_cli.plugins_updates import CheckResultchecked = {"source": "https://example.invalid/tern.git", "revision": "a" * 40, "pinned": False}- (tmp_path / ".install-metadata.json").write_text(json.dumps({"tern": checked, "feed": checked}), encoding="utf-8")+ sidecar = tmp_path / ".install-metadata.json"+ sidecar.write_text(json.dumps({"tern": checked, "feed": checked}), encoding="utf-8")+ before_check = snapshot_installs(tmp_path)+ # An update that finishes while the check is still running must not be stamped onto its own result.+ sidecar.write_text(json.dumps({"tern": {**checked, "revision": "b" * 40}, "feed": checked}), encoding="utf-8")record_check_results([CheckResult(name="tern", klass="git", current="a" * 40, latest="b" * 40, update_available=True),# An approved update_url feed reports versions, not commits; the target is still offered.CheckResult(name="feed", klass="git", current="1.0.0", latest="1.1.0", update_available=True),CheckResult(name="spotify", klass="catalog", current="c" * 40, latest="d" * 40, update_available=True),- ], tmp_path)+ ], before_check)assert cached_git_updates({"tern": checked, "feed": checked}) == {"tern": "b" * 40, "feed": "1.1.0"}- assert cached_git_updates({"tern": {**checked, "revision": "b" * 40}}) == {}+ assert cached_git_updates({"tern": {**checked, "revision": "b" * 40}}) == {}, "an update that landed mid-check"assert cached_git_updates({"tern": {**checked, "source": "https://example.invalid/fork.git"}}) == {}assert cached_git_updates({"tern": {**checked, "pinned": True}}) == {}