The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): wire fixup refusal into promotion; name the remedy; order xattr after the identity decision
Yuan Li4bc126d0388a
diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.pyindex 4f2d9a2fbeb..4a6690e04be 100644--- a/hermes_cli/main_desktop.py+++ b/hermes_cli/main_desktop.py@@ -619,16 +619,21 @@ def _macos_signing_downgrade_error(installed: dict, rebuilt: Optional[dict]) ->return Noneif rebuilt is None or not rebuilt["team"]:return (f"publisher-signed app (Team ID {installed['team']}) would be replaced by a "- "locally signed or unreadable build; kept the existing app")+ "locally signed or unreadable build; kept the existing app. To update it, "+ "sign the rebuild with the publisher identity (CSC_LINK / "+ "APPLE_SIGNING_IDENTITY) and update again.")if rebuilt["team"] != installed["team"]:return (f"publisher Team ID {installed['team']} does not match rebuilt "- f"{rebuilt['team']}; kept the existing app")+ f"{rebuilt['team']}; kept the existing app. Check the signing identity "+ f"in desktop.macos_signing_identity and update again.")if (installed["identifier"] and rebuilt["identifier"]and installed["identifier"] != rebuilt["identifier"]):return (f"bundle identifier {installed['identifier']!r} does not match rebuilt "- f"{rebuilt['identifier']!r}; kept the existing app")+ f"{rebuilt['identifier']!r}; kept the existing app. Align the build's "+ f"bundle identifier and update again.")if not rebuilt["verified"]:- return "rebuilt bundle failed strict signature verification; kept the existing app"+ return ("rebuilt bundle failed strict signature verification; kept the existing "+ "app. Re-run the build; if it persists, inspect with `codesign -vvv`.")return None@@ -782,7 +787,6 @@ def _desktop_macos_relaunchable_fixup(return Falseif _desktop_macos_has_valid_real_signature(app):return True- subprocess.run(["xattr", "-cr", str(app)], check=False)configured = _desktop_macos_local_signing_identity()identity = configured or "-"# The existing bundle this build's new signature replaces: the live release bundle the@@ -1486,7 +1490,15 @@ def _promote_staged_desktop_app(# Locally-built apps are ad-hoc signed; make them relaunchable after an# in-place self-update. Signs the STAGED bundle so the live app is never# half-signed. No-op on non-macOS and on real-identity builds.- _desktop_macos_relaunchable_fixup(desktop_dir, release_dir=staging_dir)+ if not _desktop_macos_relaunchable_fixup(desktop_dir, release_dir=staging_dir):+ # #123748: the fixup refused to sign (configured identity failed, codesign+ # missing). Promoting would replace the live app with a bundle whose+ # signature was never established — fold the refusal into the same+ # previous-app-kept error path the integrity check uses.+ _discard_desktop_staging(staging_dir)+ print("✗ The rebuilt desktop app could not be signed with a stable identity; "+ "not promoting it.")+ raise RuntimeError(f"Desktop signing refused the staged build. {_PREVIOUS_APP_KEPT}")# Validate only staging. The swap owns live-app rollback; raw in-place# pack backups are not part of this transaction.diff --git a/tests/hermes_cli/test_gui_command.py b/tests/hermes_cli/test_gui_command.pyindex a12581702fd..6a2ef33bc75 100644--- a/tests/hermes_cli/test_gui_command.py+++ b/tests/hermes_cli/test_gui_command.py@@ -756,8 +756,10 @@ def test_relaunchable_fixup_configured_identity_failure_never_falls_back_to_adho# The old behavior fell through to the legacy deep ad-hoc re-sign — must not happen.assert not any("--deep" in c for c in calls)assert not any("delete-generic-password" in c for c in calls)- # Only the quarantine-xattr hygiene ran; the bundle's signature is untouched.- assert ["xattr", "-cr", str(app)] in calls+ # The refusal decision is made BEFORE the quarantine-xattr hygiene: a failed+ # attempt must not have already stripped attributes off a bundle we then+ # decline to modify.+ assert ["xattr", "-cr", str(app)] not in calls@pytest.mark.platforms("macos")@@ -790,6 +792,45 @@ def test_relaunchable_fixup_configured_identity_success_still_signs(tmp_path, moassert not any("delete-generic-password" in c for c in calls)[email protected]("macos")+def test_promote_staged_desktop_app_refuses_an_unsigned_staging(tmp_path, monkeypatch, capsys):+ """A fixup refusal must stop the promotion, not just log (#123748 review).++ ``_promote_staged_desktop_app`` used to call the fixup for its side effect and+ discard the False, so a configured identity that failed still promoted a staged+ bundle whose signature was never established over the live app. The refusal now+ follows the same previous-app-kept error path as the integrity check.+ """+ root = _make_desktop_tree(tmp_path)+ desktop_dir = root / "apps" / "desktop"+ monkeypatch.setattr(cli_main, "PROJECT_ROOT", root)+ staging = desktop_dir / "release" / ".staging-update"+ exe = _make_packaged_executable(root, monkeypatch)+ # Re-create the same layout inside the staging dir the promoter scans.+ staged_exe = staging / exe.relative_to(exe.parents[4])+ staged_exe.parent.mkdir(parents=True, exist_ok=True)+ staged_exe.write_bytes(exe.read_bytes())++ swapped: list[Path] = []++ def fake_fixup(dir_, *, publisher_signing_configured=None, release_dir=None):+ return False # the refusal under test++ def fake_swap(dir_, st_):+ swapped.append(st_)+ return None++ monkeypatch.setattr(main_desktop, "_desktop_macos_relaunchable_fixup", fake_fixup)+ monkeypatch.setattr(main_desktop, "_swap_staged_desktop_app", fake_swap)++ with pytest.raises(RuntimeError, match="previous desktop app"):+ main_desktop._promote_staged_desktop_app(desktop_dir, staging)+ assert not swapped, "the live app must not be swapped when signing was refused"+ assert not staging.exists(), "the refused staging is discarded"+ out = capsys.readouterr().out+ assert "not promoting" in out++@pytest.mark.platforms("macos")def test_relaunchable_fixup_legacy_adhoc_failure_never_touches_keychain(tmp_path, monkeypatch):"""A failed fallback re-sign must preserve the keychain item (no deletion).