test(cmux-next): suites that build AppServices make the shared application first (DiffRemoteWiringTests trap)
Base crash fix: on feat-cmux-next the CmuxNext suite run traps in DiffRemoteWiringTests.unresolvedRemoteChatDoesNotFallBackToLocalGitLink, then hangs 180 s until the watchdog:
CmuxNextApp/AppServices.swift:85: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
Cause. The fleet runs each suite in its own process. DiffRemoteWiringTests (added in #26113) builds AppServices and never makes NSApplication.shared, so NSApp (implicitly unwrapped) is nil. ServerUpdatePresenter's notices observer calls sync(), which reads windows.active, which calls keyWindowSource { NSApp.keyWindow }, and that traps. The hung process's stack shows exactly that path. The suite traps the same way before #25861 and #27166 (at 9c6b4a24), so neither of those caused it.
Fix (test only). CmuxNextApp reads NSApp directly in about 168 places, and the app always has it. Making keyWindowSource nil-safe only moved the trap to NotificationCenterService+ProgramStatusSeen.swift:57 (NSApp.isActive). So the fix is the test setup, as 381 test files already do: _ = NSApplication.shared before AppKit work. Of the 185 test files that build AppServices, six had no NSApplication setup at all: DiffRemoteWiring, TerminalFontZoomRelaunch, DebugSettingsHangWatch, ClosedWorkspaceTerminal, BrowserToolbarPressTarget and HomeLinkPreview. Each now makes it in its suite's init(), which runs before every test. The other 179 already make the shared app. No product code changes.
Proof (fleet Mac, Xcode 26.6, package-test-lane.sh suite Packages/macOS/CmuxNext with those six suites):
| tree | result | step |
|---|---|---|
| base 15c62f68 | DiffRemoteWiringTests traps at AppServices.swift:85; the other 5 pass | 6fdf79f74bd6457ae10a10cf |
| first attempt 48385637 (nil-safe keyWindowSource) | traps at ProgramStatusSeen.swift:57 | c4e7c1eb7bad0529d911a7fd |
| this head d7fcb14c | all 6 suites pass | 5751860bbf6711e6cdf89daa |
| 9c6b4a24 (before #25861/#27166) | traps at AppServices.swift:84 | 48fee378c8c8ef4c2ebd691e |
Agent session: agent session
š¤ Generated with Claude Code