Refactor: extract Sparkle self-update into CmuxUpdater package (WIP)

Merged
AZ
6mo ago
+2097-1122

Wave 3 of the modular refactor: extract the Sparkle self-update domain out of the flat app target into a new CmuxUpdater package (a later CmuxUpdaterUI package will follow for the views).

Draft / not ready. This is a checkpoint so the shape is visible. So far it lands only the parts with no remaining app-target coupling; the package builds and tests green standalone but is not yet wired into the app, so it changes no runtime behavior.

This is a redesign, not a lift: the existing state model is ObservableObject/@Published and the controller drives it through Combine, both forbidden in packages. The extraction rebuilds state propagation on @Observable + the sanctioned concurrency primitives while preserving behavior exactly (critical user path).

Landed in this commit (swift build + swift test green):

  • Package.swift — Sparkle from 2.5.1 (resolves 2.9.2), Swift 6 mode.
  • UpdateTiming — display/timeout constants.
  • UpdateFeedResolver — redesigned from a namespace-enum into an injectable struct returning a named Resolution (+ 4 Swift Testing behavioral tests).
  • UpdateLogging — protocol seam so the package logs through the app's existing UpdateLogStore (which stays in the app target) instead of a .shared singleton.
  • UpdateState — the phase enum lifted into its own public file.
  • UpdateStateModel — ObservableObject → @MainActor @Observable. All state writes funnel through setState/setOverrideState, which emit on a stateChanges() AsyncStream<Void> (the @Observable-native replacement for $state.sink / CombineLatest). SwiftUI Color computeds are deferred to CmuxUpdaterUI.

Still to do before this leaves draft:

  • UpdateController — replace the three Combine observers (force-install, attempt-update, no-update auto-dismiss) with one long-lived @MainActor Task over stateChanges(); relocate the asyncAfter timing sites behind one-shot DispatchSource timers.
  • UpdateDriver (SPUUserDriver) + UpdateSettings + test support; invert the AppDelegate/TerminalController reach-ins behind seams.
  • CmuxUpdaterUI package (UpdatePill, UpdatePopoverView, UpdateBadge + the Color computeds + an UpdateActionsHost seam).
  • Wire both packages into cmux.xcodeproj (cmux + cmux-unit); AppDelegate becomes the composition root + one-line forwards; split FocusLogStore into the app target.
  • Build cmux + cmux-unit green; dogfood the update pill/popover.

🤖 Generated with Claude Code


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag @codesmith with what you need. Autofix is disabled.


Summary by cubic

Extracted Sparkle self-update into CmuxUpdater and CmuxUpdaterUI, fully wired into the app with an @MainActor controller/driver. Added UI tests and localized error copy; builds/tests are green locally and in CI with Sparkle 2.8.1.

  • Refactors

    • Integrated CmuxUpdater + CmuxUpdaterUI into cmux.xcodeproj; removed legacy Sources/Update/* and the Combine-based controller.
    • AppDelegate: owns UpdateLogStore; constructs UpdateController(log:); conforms to UpdateActionDelegate and UpdateActionsHost.
    • UI: ContentView uses UpdateStateModel; UpdatePill/UpdatePopoverView call into UpdateActionsHost and use UpdateAppearance(accent:); titlebar accessory now takes UpdateLogStore.
    • Seams/timing: UpdateLogging, UpdateClock/SystemUpdateClock, UpdateActionDelegate, UpdateSettings; bounded, cancellable delays for min-display, no-update auto-dismiss, and readiness.
    • UI tests: coverage for error and downloading/extracting/installing states via CMUX_UI_TEST_*.
    • Injected FileManager and host Bundle into UpdateController for testability; ensureSparkleInstallationCache keys by bundle id.
  • Bug Fixes

    • Matched CI under Sparkle 2.8.1 by adding @preconcurrency imports and pinning versions in both packages.
    • Reliable re-checks: restored a bounded 100 ms post-dismiss delay and now cancel the deferred re-check on all paths to prevent duplicate checks.
    • Safer errors: sanitized the fallback error message and added localized update.error.failed.message and update.error.notReady (en/ja); full details stay in the log and “Copy Details.”
    • Emitted a single state-change signal when resetting for a new check; fixed cmux-unit by using an instance UpdateFeedResolver and updated readiness docs.
    • Stabilized UI tests by using consistent waitForExistence assertions.

Summary by CodeRabbit

  • New Features

    • Public in-app update UI (pill, badge, popover) plus packaged updater modules and a host-driven update actions API.
  • Improvements

    • More testable, cancellable clock-driven timing for update checks and auto-dismiss behavior.
    • Richer error details now expose an explicit log path for diagnostics.
    • Deterministic feed resolution (stable/nightly/fallback) and clearer retry/dismiss/update flows.
  • Documentation

    • Developer timing/synchronization guidance clarified and tightened.