Refine verified update notices and Windows installation lifecycle

This commit is contained in:
2026-11-26 19:09:17 -06:00
parent f9fa7c258d
commit 2e93b7587d
19 changed files with 744 additions and 81 deletions

View File

@@ -9,6 +9,7 @@ import unittest
from unittest.mock import patch
from urllib.error import URLError
from zipfile import ZipFile
import psutil
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
@@ -16,7 +17,8 @@ from arm.branding import APP_MODEL_ID
from arm.config import Settings
from arm.update_client import ReleaseClient, UpdateCancelled
from arm.update_release import MANIFEST, UpdateError, artifact_name, canonical, verify_manifest
from arm.update_worker import unpack_portable
from arm.update_state import Phase, notice, notify_once, result_for, transaction_from_ack
from arm.update_worker import unpack_portable, wait_parent
from arm.version import VERSION, version_key
COUNTERS = version_key(VERSION)
@@ -150,3 +152,49 @@ class UpdateTests(unittest.TestCase):
self.assertEqual(Settings.from_dict({"update_startup": True, "update_interval": 168}).update_interval, 168)
default = Settings.from_dict({"update_startup": "yes", "update_interval": 169})
self.assertEqual((default.update_startup, default.update_interval), (False, 0))
def test_notification_only_once_across_checks_and_restarts(self):
path = self.work / "notices.json"
self.assertFalse(notify_once(path, NEW, False))
self.assertFalse(path.exists())
self.assertTrue(notify_once(path, NEW, True))
self.assertFalse(notify_once(path, NEW, True))
self.assertEqual(notice(Phase.CHECKING, None), "")
self.assertEqual(notice(Phase.INSTALLING, NEW, True), "")
self.assertEqual(notice(Phase.AVAILABLE, NEW), f"Update Available: {NEW}")
self.assertEqual(notice(Phase.READY, NEW, True), f"Update Ready to Install: {NEW}")
def test_update_result_requires_successful_restart_receipt(self):
directory = self.work / "updates" / "transactions" / ("a" * 32)
directory.mkdir(parents=True)
(directory / "plan.json").write_text(json.dumps({"old": VERSION, "new": NEW}))
status = directory / "status.json"
status.write_text(json.dumps({"state": "complete", "message": "Legacy completion status"}))
ready = directory / "ready.json"
self.assertEqual(transaction_from_ack(self.work, str(ready)), directory)
self.assertIsNone(transaction_from_ack(self.work, str(status)))
self.assertIsNone(result_for(directory, NEW))
ready.write_text(json.dumps({"version": NEW, "pid": 10}))
self.assertEqual(result_for(directory, NEW), (Phase.SUCCESS, notice(Phase.SUCCESS, NEW)))
self.assertIsNone(result_for(directory, VERSION))
status.write_text(json.dumps({"state": "rolled_back", "message": "Restored prior application"}))
self.assertEqual(result_for(directory, VERSION), (Phase.RESTORED, "Restored prior application"))
self.assertIsNone(result_for(directory, NEW))
def test_shutdown_requires_acknowledgement_and_confirmed_process_exit(self):
target = self.work
plan = {"parent": 10, "created": 1, "old": VERSION}
with patch("arm.update_worker.psutil.Process", side_effect=psutil.NoSuchProcess(10)):
with self.assertRaisesRegex(UpdateError, "without confirming"):
wait_parent(plan, target, self.work)
(self.work / "closed.json").write_text(json.dumps({"pid": 10, "version": VERSION}))
wait_parent(plan, target, self.work)
with patch("arm.update_worker.psutil.Process") as process:
process.return_value.create_time.return_value = 1
process.return_value.exe.return_value = str(target / "AdaptiveResourceMonitor.exe")
with self.assertRaisesRegex(UpdateError, "shut down in time"):
wait_parent(plan, target, self.work, timeout=.05)
self.assertEqual(process.return_value.exe.call_count, 1)
(self.work / "abort").touch()
with self.assertRaisesRegex(UpdateError, "canceled"):
wait_parent(plan, target, self.work)

View File

@@ -428,6 +428,89 @@ def verify_branding(session, results, captures=None):
results["verified_about_and_tray_actions"] = True
def verify_update_notices(session, wait_for, results, captures):
from PySide6.QtCore import QPoint
from unittest.mock import patch
from arm.model import ALL, LOCAL
from arm.update_client import Check
from arm.update_release import verify_manifest
from arm.update_state import Phase
from test_updates import NEW, PACKAGE, Response, UpdateTests
def capture(widget, filename):
session.qt.processEvents()
if captures:
assert widget.grab().save(str(captures / filename))
menu = session.menus[LOCAL]
hover, expanded = session.popup, session.expanded
update = session.about_page.updates
assert not menu.update.isVisible() and hover.update_banner.isHidden()
initial_size = hover.popup_size()
notices = []
update.notify.connect(notices.append)
rejected = Check(NEW, None, ("Fixture signature rejected",))
with patch.object(update.client, "check", return_value=rejected):
update.check_now()
wait_for(lambda: update.job is None)
assert not menu.update.isVisible() and not notices
fixture = UpdateTests()
try:
fixture.setUp()
release = verify_manifest(fixture.sign(fixture.metadata()), fixture.public)
checked = Check(NEW, release, ())
with patch.object(update.client, "check", return_value=checked):
for _ in range(2):
update.check_now()
wait_for(lambda: update.job is None)
available = f"Update Available: {NEW}"
assert update.phase is Phase.AVAILABLE and notices == [available]
assert menu.actions()[1] is menu.update and menu.update.text() == available
session.hover.show(LOCAL)
assert hover.popup_size().height() > initial_size.height()
assert hover.update_banner.label.text() == available
capture(hover, "update-hover.png")
session.select_machine(ALL, LOCAL)
session.hover.pin(True, LOCAL)
assert hover.update_banner.isVisible() and hover.selected_machine == ALL
session.hover.pin(False)
session.select_machine(LOCAL, LOCAL)
hover.hide()
session.open_expanded()
assert expanded.update_banner.isVisible() and expanded.monitor_visible
capture(expanded, "update-expanded.png")
menu.popup(QPoint(20, 20))
capture(menu, "update-tray-menu.png")
menu.hide()
menu.update.trigger()
assert expanded.tabs.currentWidget() == session.about_page and expanded.update_banner.isVisible()
capture(expanded, "update-about.png")
with patch.object(update.client, "open", return_value=Response(PACKAGE)):
update.client.source["public_key"], original_key = fixture.public, update.client.source["public_key"]
try:
update.download_now()
wait_for(lambda: update.job is None)
assert update.phase is Phase.READY and update.downloaded.is_file()
update.defer_install()
assert menu.update.text() == f"Update Ready to Install: {NEW}"
assert update.restore()[1][1] == update.downloaded
finally:
update.client.source["public_key"] = original_key
update.downloaded.unlink()
update.downloaded = None
with patch.object(update.client, "check", return_value=rejected):
update.check_now()
wait_for(lambda: update.job is None)
assert not menu.update.isVisible() and expanded.update_banner.isHidden()
assert hover.popup_size() == initial_size
expanded.close()
finally:
fixture.doCleanups()
results["verified_shared_update_notices"] = "Verified, ready, rejected, deferred and duplicate notification states"
def evaluate_app(work, results, short=False, captures=None):
import psutil
from PySide6.QtCore import QEventLoop, QTimer
@@ -536,6 +619,7 @@ def evaluate_app(work, results, short=False, captures=None):
assert update.fields["Latest published"].text() == "No public releases"
assert "UTC" in update.fields["Last successful check"].text()
session.expanded.close()
verify_update_notices(session, wait_for, results, captures)
results["asynchronous_update_check_with_live_telemetry"] = True
modes = {}
for mode in ("Stacked", STATIC_TRAY_MODE, "Overlay", "Composite"):