Repository navigation
Arch improv 01 software update - #2449
amilcarlucas wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
What changed in this PR
Refactors the software update flow to decouple core update logic from the Tkinter GUI by injecting a presenter, while also consolidating installer download/verification logic and aligning progress reporting.
Changes:
- Injects an
UpdatePresenterintoUpdateManager/check_for_software_updates()to remove GUI imports from the core update module. - Introduces a pure
select_install_plan()decision step and plan dataclasses to simplify platform-specific install selection. - Extracts
_download_and_verify_installer()to share URL gating, download, checksum verification, and file validation; updates progress semantics and adapts tests/docs accordingly.
| File | Description |
|---|---|
| tests/unit_frontend_tkinter_software_update.py | Adds unit coverage for the new Tkinter presenter wrapper present_update_dialog(). |
| tests/unit_data_model_software_updates.py | Updates tests for injected presenter and new install planning behavior. |
| tests/unit_backend_internet.py | Updates pip installer return type expectations and adds unit tests for _download_and_verify_installer(). |
| tests/bdd_software_update.py | Adjusts BDD tests to new presenter and bool-returning pip install flow. |
| tests/acceptance_software_update.py | Updates acceptance tests to pass presenter into check_for_software_updates(). |
| ardupilot_methodic_configurator/frontend_tkinter_software_update.py | Adds present_update_dialog() adapter and moves standalone dev entry point here. |
| ardupilot_methodic_configurator/data_model_software_updates.py | Introduces UpdatePresenter, install plans, select_install_plan(), and presenter injection. |
| ardupilot_methodic_configurator/backend_internet.py | Adds _download_and_verify_installer(), standardizes progress to 0–100, and makes pip installer return bool. |
| ardupilot_methodic_configurator/__main__.py | Wires the app to pass present_update_dialog into check_for_software_updates(). |
| ARCHITECTURE_1_software_update.md | Updates architecture notes for presenter injection, shared download/verify stage, and progress semantics. |
| ARCHITECTURE.md | Updates standalone update-check entry point reference. |
| .github/skills/improve-codebase-architecture/SKILL.md | Adds skill documentation (repo meta). |
| .github/skills/improve-codebase-architecture/HTML-REPORT.md | Adds HTML report format documentation (repo meta). |
| .github/skills/grilling/SKILL.md | Adds skill documentation (repo meta). |
| .github/skills/domain-modeling/SKILL.md | Adds skill documentation (repo meta). |
| .github/skills/domain-modeling/GLOSSARY-FORMAT.md | Adds glossary format documentation (repo meta). |
| .github/skills/domain-modeling/ADR-FORMAT.md | Adds ADR format documentation (repo meta). |
| .github/skills/codebase-design/SKILL.md | Adds shared architecture vocabulary documentation (repo meta). |
| .github/skills/codebase-design/DESIGN-IT-TWICE.md | Adds “design it twice” process documentation (repo meta). |
| .github/skills/codebase-design/DEEPENING.md | Adds deepening/testing strategy documentation (repo meta). |
Review effort: Lite
| progress_callback: Callable[[float, str], None] | None, | ||
| expected_sha256: str | None, |
| def check_for_software_updates(presenter: UpdatePresenter) -> bool: | ||
| """Main update orchestration function.""" |
|
|
||
| if ret == 0 and progress_callback: | ||
| if progress_callback: | ||
| progress_callback(100.0, _("Download complete")) |
☂️ Code Coverage
Overall Coverage
New FilesNo new covered files... Modified FilesNo covered modified files...
|
Test Results 5 files 5 suites 1h 2m 51s ⏱️ For more details on these failures, see this check. Results for commit 7a528d7. ♻️ This comment has been updated with latest results. |
Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <[email protected]>
…ng the dialog The update data model imported the tkinter UpdateDialog directly, so the core update flow could not run or be tested without the GUI. UpdateManager and check_for_software_updates now take a presenter callable (version_info, download) -> bool. The Tkinter adapter present_update_dialog wraps UpdateDialog and is injected from the composition root in __main__.py. Tests use a presenter stub instead of patching the dialog. Co-authored-by: Copilot <[email protected]> Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <[email protected]>
Route the Windows installer and the macOS DMG path through one _download_and_verify_installer stage, so both use the same URL gate, checksum verification and file validation. Progress is now reported on a single 0-100 scale. Post-download steps hold at 100% and rely on the status label, so the progress bar no longer drops back after the download completes on Windows. download_and_install_pip_release now returns bool instead of an exit code. Co-authored-by: Copilot <[email protected]> Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <[email protected]>
Extract the platform-to-installer choice into select_install_plan(), a pure function that returns an InstallerPlan, a PipPlan, or None when a Windows release has no installer asset. _perform_download now executes the chosen plan instead of dispatching through a handler dict and two per-platform install methods. Behaviour is unchanged: Windows prefers .exe and falls back to the first asset, macOS uses .dmg and falls back to pip, and other platforms use pip. Co-authored-by: Copilot <[email protected]> Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <[email protected]>
select_install_plan no longer falls back to the first release asset when no .exe is present. Such a release now reports "No suitable assets found for Windows installation" instead of trying to run an arbitrary file. The allow_fallback option of _find_asset is removed as it had no other caller. Co-authored-by: Copilot <[email protected]> Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <[email protected]>
The standalone development entry point lived at the bottom of data_model_software_updates.py and lazily imported the frontend to show the dialog. Move it into frontend_tkinter_software_update.py so that running the frontend module starts the update check, and the data model no longer needs a local import of the UI or the logging setup it used only for that block. Update ARCHITECTURE.md to reference the new entry point. Co-authored-by: Copilot <[email protected]> Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <[email protected]>
UpdateManager._perform_download branched on the plan type (isinstance(plan, PipPlan)) and the installers were typed as Callable[..., bool], although Windows, macOS and pip are three adapters of one concept: "install this release". - Replace InstallerPlan and PipPlan with a single frozen InstallPlan holding the platform installer, its release asset and the macos_without_dmg flag. InstallPlan.run(release, progress_callback) is identical on every platform, so UpdateManager no longer branches on the platform. - Add the _install_on_windows, _install_on_macos and _install_with_pip adapters, all with the signature (asset, release, progress_callback). They resolve the backend functions when called, so patching download_and_install_on_* in tests keeps working. - Type the asset installers with an AssetInstaller Protocol instead of Callable[..., bool], and name ProgressCallback. - select_install_plan stays a pure decision with no I/O. No behaviour change: the Windows installer still terminates the old process with os._exit(0) after launching run_installer.bat. That exit is intentional and its timing is relied on by the batch file's ~1 s wait, so it is deliberately not moved here. Tests: update the select_install_plan expectations and add tests that run a Windows plan and a pip plan through the same InstallPlan.run(). ARCHITECTURE_1_software_update.md notes the uniform interface. Signed-off-by: Amilcar Lucas <[email protected]> Co-authored-by: Copilot <[email protected]>
…e_assets
The trust policy for update downloads was spread over backend_internet.py
and data_model_software_updates.py, and each platform installer had its
own adapter. Callers had to know the order of the checks (URL whitelist,
SHA256 lookup, download, checksum, file validation), and tests had to
patch each stage separately.
Add backend_release_assets.py, which owns "obtain a verified release
asset" behind a single interface:
download_verified_asset(release, asset, dest_path, download,
progress_callback=None, magic_bytes=None,
magic_error_msg="") -> bool
It runs, in order: the GitHub HTTPS URL whitelist, SHA256 discovery from
the release, the download, SHA256 verification and file validation (size
and optional magic bytes). Invalid files are deleted and the reason is
logged. A missing name or browser_download_url raises KeyError, which
UpdateManager._perform_download already handles.
The download itself is injected as a Downloader protocol. backend_internet
imports this module, so importing download_file_from_url back would be
circular. The installers pass a small _download_installer wrapper that
keeps the 60 s timeout and resolves download_file_from_url at call time.
The installers now take (asset, release, progress_callback) instead of
(download_url, file_name, progress_callback, expected_sha256).
data_model_software_updates.py loses _install_from_asset, the
AssetInstaller protocol and the _install_on_windows/_install_on_macos
adapters. select_install_plan builds InstallPlan objects that call the
backend installers directly. _install_with_pip remains as a one-line
adapter because pip has no asset.
Behaviour is preserved, with one deliberate exception:
- The checksum is still fail-open: a release without a published SHA256
logs a warning and the file is accepted.
- Checksum parsing, including the "first 64 hex characters" fallback, and
all translated msgids are moved unchanged, so no POT/PO updates.
- Windows os._exit(0) in _launch_installer_and_exit is untouched.
- The URL whitelist now runs before the SHA256 lookup, so a rejected URL
makes no network request. Previously the lookup ran first.
Tests:
- Add tests/unit_backend_release_assets.py. It crosses the new interface
with a fake downloader, real temp files and real hashing. The URL and
file validation cases move there from unit_backend_internet.py.
- Rename unit_backend_internet_checksum_parsing.py to
unit_backend_release_assets_checksum_parsing.py and patch httpx2_get
in the new module.
- Rewrite the installer, BDD, acceptance and data-model tests for the new
signatures. Installer tests patch download_verified_asset, and one
Windows progress test runs the real verification path.
Update ARCHITECTURE_1_software_update.md for the new module, the
installer signatures, the file structure and the dependencies.
Signed-off-by: Amilcar Lucas <[email protected]>
Co-authored-by: Copilot <[email protected]>
…sion UpdateManager was a shallow class: it held a single presenter attribute and its methods were only reachable through one call site. Replace it with module-level functions whose seams are the real decisions. - Add UpdateOffer (frozen dataclass: release + formatted version_info) and assess_release(), a pure decision with no I/O and no logging. It returns None when current >= latest and raises KeyError (no tag_name) or ValueError (unparsable version). - Add offer_update(release, current_version, presenter), which orchestrates one offer: assess, open the releases page, ask the presenter, and install on consent. - Rename UpdateManager._perform_download to install_release(). - Turn UpdateManager.add_argparse_arguments into the module function add_update_argparse_arguments() and update __main__.py. The releases page is deliberately opened BEFORE the user is asked for consent, whatever the answer, so the user can read the full release notes to decide whether to upgrade. This behaviour is unchanged, now documented in the offer_update docstring and in ARCHITECTURE_1_software_update.md, and pinned by tests (browser opens before the presenter, opens even when the user declines, and is not opened when already on the latest version). Error handling and all translatable msgids are preserved, so no POT/PO changes are required. Tests: migrate unit, BDD and acceptance tests off UpdateManager, add mock-free assess_release tests, and add browser-ordering tests. Signed-off-by: Amilcar Lucas <[email protected]> Co-authored-by: Copilot <[email protected]>
3372ede to
7a528d7
Compare


Description
Improve (depen) the software update sub-application architecture.
Checklist
git commit --signoff)Testing
Describe how you tested these changes: