From b356d59fd9775b4a39f5b83b389c772b3713d6aa Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 3 Nov 2026 03:43:14 +0000 Subject: [PATCH] test(updater): UpdateInstallCheckTests fakes the frontmost app, as its sibling suites do theRelaunchRecordsTheInstallAndTheNextLaunchJudgesIt and anInstallThatEndsWithTheAppRunningLeavesNoRecord call updaterWillRelaunchApplication(), which reads UpdaterService.frontmost. Its default is AppKit's answer (UpdateFrontmostApp.current()), which reads NSApp.isActive. The package-test lane runs each suite in its own process, and this suite makes no NSApplication, so NSApp is nil and the read traps (UpdateRelaunchFocus.swift:99, 'Unexpectedly found nil'): the whole suite crashes. It passed only when an earlier suite in the same process had made NSApplication.shared. The seam is there for tests ('AppKit in the app, a fake in tests'); UpdateRelaunchFocusTests and UpdateRelaunchHandoffTests set it. The helper now sets it too. No product change: the app always has NSApp. Culprit: 622900473e8 (#31178) added the suite without the fake. Red: fleet job 2bf90b6c18ca136f3fb6c15d at feat 11dfe910c93. --- .../Tests/CmuxNextAppTests/UpdateInstallCheckTests.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Packages/macOS/CmuxNext/Tests/CmuxNextAppTests/UpdateInstallCheckTests.swift b/Packages/macOS/CmuxNext/Tests/CmuxNextAppTests/UpdateInstallCheckTests.swift index 30b3b4c39039..1695ae9b6503 100644 --- a/Packages/macOS/CmuxNext/Tests/CmuxNextAppTests/UpdateInstallCheckTests.swift +++ b/Packages/macOS/CmuxNext/Tests/CmuxNextAppTests/UpdateInstallCheckTests.swift @@ -17,8 +17,13 @@ import Testing let identity = UpdateBuildIdentity(bundleIdentifier: "com.cmuxterm.app.debug.install-check", shortVersion: "1.0.0", build: build, minimumSystemVersion: nil, infoFeedURL: "https://files-next.cmux.com/nightly-next/appcast-arm64.xml", hasPublicKey: false) - return UpdaterService(identity: identity, policy: ManagedUpdatePolicy { false }, defaults: defaults, - enableSparkle: false, recordsUpdates: false, now: { time }) + let updater = UpdaterService(identity: identity, policy: ManagedUpdatePolicy { false }, defaults: defaults, + enableSparkle: false, recordsUpdates: false, now: { time }) + // The relaunch reads the frontmost app (``UpdaterService/frontmost``); AppKit's answer needs + // an NSApplication, which a test process that made none lacks (`NSApp` is nil and the read + // traps). This app is frontmost, as when a person clicks Restart to Update. + updater.frontmost = { UpdateFrontmostApp(isThisApp: true, pid: 1, bundleID: "com.cmuxterm.app.debug.install-check") } + return updater } @Test func aLaunchOnTheOldBuildIsAFailedInstall() {