The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(backup): propagate refused auth snapshot restore
Lion-Leporidae7ec4cd212323
diff --git a/hermes_cli/backup.py b/hermes_cli/backup.pyindex 1c75ed8fd73..9e24f2435cc 100644--- a/hermes_cli/backup.py+++ b/hermes_cli/backup.py@@ -1529,6 +1529,7 @@ def restore_quick_snapshot(meta = json.load(f)restored = 0+ auth_restore_failed = Falsefor rel in meta.get("files", {}):# Security: reject absolute paths and traversals in manifest entriessrc = snap_dir / rel@@ -1572,6 +1573,7 @@ def restore_quick_snapshot(# while retaining that live single-use grant under the auth-store lock.if not _restore_auth_json(src, dst):logger.error("Failed to restore %s safely", rel)+ auth_restore_failed = Truecontinueelse:shutil.copy2(src, dst)@@ -1580,7 +1582,7 @@ def restore_quick_snapshot(logger.error("Failed to restore %s: %s", rel, exc)logger.info("Restored %d files from snapshot %s", restored, snapshot_id)- return restored > 0+ return restored > 0 and not auth_restore_faileddef _count_cron_jobs(path: Path) -> Optional[int]:diff --git a/tests/hermes_cli/test_snapshot_restore_oauth.py b/tests/hermes_cli/test_snapshot_restore_oauth.pyindex bb2880c8a2c..5c135234115 100644--- a/tests/hermes_cli/test_snapshot_restore_oauth.py+++ b/tests/hermes_cli/test_snapshot_restore_oauth.py@@ -524,3 +524,35 @@ def test_invalid_snapshot_auth_never_replaces_live_store(tmp_path, monkeypatch):assert restore_quick_snapshot("bad", hermes_home=home) is Falseassert live_path.read_bytes() == before++[email protected]("refusal", ["invalid-json", "hardlinked-store"])+def test_auth_refusal_is_not_hidden_by_another_restored_file(tmp_path, monkeypatch, refusal):+ """A partial restore must not report success after refusing the auth store (#127010)."""+ from hermes_cli.backup import restore_quick_snapshot++ home = tmp_path / "home"+ snap_dir = home / "state-snapshots" / "partial"+ snap_dir.mkdir(parents=True)+ monkeypatch.setenv("HERMES_HOME", str(home))+ live_path = home / "auth.json"+ live_path.write_text(json.dumps({"providers": {}, "sentinel": "live"}), encoding="utf-8")+ before = live_path.read_bytes()+ if refusal == "hardlinked-store":+ try:+ os.link(live_path, home / "shared-auth.json")+ except (OSError, NotImplementedError) as exc:+ pytest.skip(f"hardlink unavailable: {exc}")++ (home / "config.yaml").write_text("model: live\n", encoding="utf-8")+ (snap_dir / "config.yaml").write_text("model: snapshot\n", encoding="utf-8")+ snapshot_auth = "{invalid-json" if refusal == "invalid-json" else json.dumps({"providers": {}})+ (snap_dir / "auth.json").write_text(snapshot_auth, encoding="utf-8")+ files = {name: (snap_dir / name).stat().st_size for name in ("auth.json", "config.yaml")}+ (snap_dir / "manifest.json").write_text(json.dumps({"files": files}), encoding="utf-8")++ result = restore_quick_snapshot("partial", hermes_home=home)++ assert live_path.read_bytes() == before+ assert (home / "config.yaml").read_text(encoding="utf-8") == "model: snapshot\n"+ assert result is False