From 48d034b2fd11862728e0692165c62b50989c5f6c Mon Sep 17 00:00:00 2001 From: Lawrence Chen Date: Tue, 17 Mar 2026 15:06:12 -0700 Subject: [PATCH 1/5] Add regression coverage for app lookup open targets --- Sources/AppDelegate.swift | 4 +- cmuxTests/CmuxWebViewKeyEquivalentTests.swift | 40 +++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index 26b1d4d4c6ac..772afcdb5d9e 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -417,11 +417,13 @@ enum TerminalDirectoryOpenTarget: String, CaseIterable { let homeDirectoryPath: String let fileExistsAtPath: (String) -> Bool let isExecutableFileAtPath: (String) -> Bool + let applicationPathForName: (String) -> String? static let live = DetectionEnvironment( homeDirectoryPath: FileManager.default.homeDirectoryForCurrentUser.path, fileExistsAtPath: { FileManager.default.fileExists(atPath: $0) }, - isExecutableFileAtPath: { FileManager.default.isExecutableFile(atPath: $0) } + isExecutableFileAtPath: { FileManager.default.isExecutableFile(atPath: $0) }, + applicationPathForName: { NSWorkspace.shared.fullPath(forApplication: $0) } ) } diff --git a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift index 5ec9aae7e43a..2af4d5cd37b0 100644 --- a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift +++ b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift @@ -7667,12 +7667,14 @@ final class FinderServicePathResolverTests: XCTestCase { final class TerminalDirectoryOpenTargetAvailabilityTests: XCTestCase { private func environment( existingPaths: Set, - homeDirectoryPath: String = "/Users/tester" + homeDirectoryPath: String = "/Users/tester", + applicationPathsByName: [String: String] = [:] ) -> TerminalDirectoryOpenTarget.DetectionEnvironment { TerminalDirectoryOpenTarget.DetectionEnvironment( homeDirectoryPath: homeDirectoryPath, fileExistsAtPath: { existingPaths.contains($0) }, - isExecutableFileAtPath: { existingPaths.contains($0) } + isExecutableFileAtPath: { existingPaths.contains($0) }, + applicationPathForName: { applicationPathsByName[$0] } ) } @@ -7711,9 +7713,10 @@ final class TerminalDirectoryOpenTargetAvailabilityTests: XCTestCase { XCTAssertFalse(availableTargets.contains(.vscode)) } - func testVSCodeRequiresCodeTunnelExecutable() { + func testVSCodeInlineRequiresCodeTunnelExecutable() { let env = environment(existingPaths: ["/Applications/Visual Studio Code.app"]) - XCTAssertFalse(TerminalDirectoryOpenTarget.vscode.isAvailable(in: env)) + XCTAssertTrue(TerminalDirectoryOpenTarget.vscode.isAvailable(in: env)) + XCTAssertFalse(TerminalDirectoryOpenTarget.vscodeInline.isAvailable(in: env)) } func testITerm2DetectsLegacyBundleName() { @@ -7726,6 +7729,35 @@ final class TerminalDirectoryOpenTargetAvailabilityTests: XCTestCase { XCTAssertTrue(TerminalDirectoryOpenTarget.tower.isAvailable(in: env)) } + func testAvailableTargetsFallbackToApplicationLookupForVSCodeAliasOutsideApplications() { + let vscodePath = "/Volumes/Tools/Code.app" + let env = environment( + existingPaths: [ + vscodePath, + "\(vscodePath)/Contents/Resources/app/bin/code-tunnel", + ], + applicationPathsByName: [ + "Code": vscodePath, + ] + ) + + let availableTargets = TerminalDirectoryOpenTarget.availableTargets(in: env) + XCTAssertTrue(availableTargets.contains(.vscode)) + XCTAssertTrue(availableTargets.contains(.vscodeInline)) + } + + func testTowerDetectedViaApplicationLookupOutsideApplications() { + let towerPath = "/Volumes/Setapp/Tower.app" + let env = environment( + existingPaths: [towerPath], + applicationPathsByName: [ + "Tower": towerPath, + ] + ) + + XCTAssertTrue(TerminalDirectoryOpenTarget.tower.isAvailable(in: env)) + } + func testCommandPaletteShortcutsExcludeGenericIDEEntry() { let targets = TerminalDirectoryOpenTarget.commandPaletteShortcutTargets XCTAssertFalse(targets.contains(where: { $0.commandPaletteTitle == "Open Current Directory in IDE" })) From 2863ed845316acf92d4d67cdfcf73c18442ebb60 Mon Sep 17 00:00:00 2001 From: Lawrence Chen Date: Tue, 17 Mar 2026 15:09:58 -0700 Subject: [PATCH 2/5] Fix command palette open target availability --- Sources/AppDelegate.swift | 21 +++++++++++++++++++-- Sources/ContentView.swift | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index 772afcdb5d9e..13514a426e20 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -435,8 +435,6 @@ enum TerminalDirectoryOpenTarget: String, CaseIterable { Set(commandPaletteShortcutTargets.filter { $0.isAvailable(in: environment) }) } - static let cachedLiveAvailableTargets: Set = availableTargets(in: .live) - var commandPaletteCommandId: String { "palette.terminalOpenDirectory.\(rawValue)" } @@ -526,6 +524,17 @@ enum TerminalDirectoryOpenTarget: String, CaseIterable { for path in expandedCandidatePaths(in: environment) where environment.fileExistsAtPath(path) { return path } + + // Fall back to LaunchServices so apps outside the standard bundle paths + // still appear in the command palette. + for applicationName in applicationSearchNames { + guard let resolvedPath = environment.applicationPathForName(applicationName), + environment.fileExistsAtPath(resolvedPath) else { + continue + } + return resolvedPath + } + return nil } @@ -545,6 +554,14 @@ enum TerminalDirectoryOpenTarget: String, CaseIterable { return uniquePreservingOrder(expanded) } + private var applicationSearchNames: [String] { + uniquePreservingOrder( + applicationBundlePathCandidates.map { + URL(fileURLWithPath: $0).deletingPathExtension().lastPathComponent + } + ) + } + private var applicationBundlePathCandidates: [String] { switch self { case .androidStudio: diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 38e908f508c6..fdbdf0eb038c 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -4803,7 +4803,7 @@ struct ContentView: View { snapshot.setBool(CommandPaletteContextKeys.panelHasUnread, hasUnread) if panelIsTerminal { - let availableTargets = TerminalDirectoryOpenTarget.cachedLiveAvailableTargets + let availableTargets = TerminalDirectoryOpenTarget.availableTargets() for target in TerminalDirectoryOpenTarget.commandPaletteShortcutTargets { snapshot.setBool( CommandPaletteContextKeys.terminalOpenTargetAvailable(target), From f3704266304ee391946276b9bce95b08b407357a Mon Sep 17 00:00:00 2001 From: Lawrence Chen Date: Tue, 17 Mar 2026 15:24:39 -0700 Subject: [PATCH 3/5] Show all open-in commands in the palette --- Sources/ContentView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index fdbdf0eb038c..15a34bb18a67 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -5372,7 +5372,6 @@ struct ContentView: View { keywords: target.commandPaletteKeywords, when: { context in context.bool(CommandPaletteContextKeys.panelIsTerminal) - && context.bool(CommandPaletteContextKeys.terminalOpenTargetAvailable(target)) } ) ) From f4cc7c88ca2deea35963587b2495d5c27373c4af Mon Sep 17 00:00:00 2001 From: Lawrence Chen Date: Tue, 17 Mar 2026 16:18:55 -0700 Subject: [PATCH 4/5] Add failing command palette blink regression test --- cmuxUITests/SidebarHelpMenuUITests.swift | 104 +++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/cmuxUITests/SidebarHelpMenuUITests.swift b/cmuxUITests/SidebarHelpMenuUITests.swift index b27cee628925..dfd0e3b0d450 100644 --- a/cmuxUITests/SidebarHelpMenuUITests.swift +++ b/cmuxUITests/SidebarHelpMenuUITests.swift @@ -299,6 +299,7 @@ final class CommandPaletteAllSurfacesUITests: XCTestCase { private var socketPath = "" private let hiddenSurfaceToken = "cmux-command-palette-hidden-surface" private let visibleSurfaceToken = "cmux-command-palette-visible-surface" + private let noMatchWorkspaceQuery = "cmux-command-palette-no-match" override func setUp() { super.setUp() @@ -475,6 +476,69 @@ final class CommandPaletteAllSurfacesUITests: XCTestCase { ) } + func testSwitcherEmptyStateDoesNotBlinkWhileRefiningNoMatchQuery() throws { + let app = XCUIApplication() + app.launchArguments += ["-AppleLanguages", "(en)", "-AppleLocale", "en_US"] + app.launchEnvironment["CMUX_UI_TEST_MODE"] = "1" + app.launchEnvironment["CMUX_SOCKET_PATH"] = socketPath + launchAndActivate(app) + + XCTAssertTrue( + sidebarHelpPollUntil(timeout: 8.0) { + app.windows.count >= 1 + }, + "Expected the main window to be visible" + ) + XCTAssertTrue(waitForSocketPong(timeout: 12.0), "Expected control socket at \(socketPath)") + + let mainWindowId = try XCTUnwrap( + socketCommand("current_window")?.trimmingCharacters(in: .whitespacesAndNewlines) + ) + try seedWorkspaceSwitcherCorpus(workspaceCount: 96) + + let searchField = app.textFields["CommandPaletteSearchField"] + app.typeKey("p", modifierFlags: [.command]) + XCTAssertTrue(searchField.waitForExistence(timeout: 5.0), "Expected command palette search field") + searchField.click() + + try debugTypeText(String(repeating: "z", count: 8)) + + let emptyLabel = app.staticTexts["No workspaces match your search."].firstMatch + XCTAssertTrue( + sidebarHelpPollUntil(timeout: 5.0) { + guard emptyLabel.exists else { return false } + guard let snapshot = commandPaletteSnapshot(windowId: mainWindowId) else { return false } + return (snapshot["query"] as? String) == String(repeating: "z", count: 8) + && self.commandPaletteResultRows(from: snapshot).isEmpty + }, + "Expected the switcher to reach a visible no-results state before refining the query" + ) + + try debugTypeText("z") + + let emptyLabelDisappearedWhileRefining = sidebarHelpPollUntil(timeout: 0.5, pollInterval: 0.01) { + !emptyLabel.exists + } + XCTAssertFalse( + emptyLabelDisappearedWhileRefining, + "Expected refining an already-empty switcher query to keep the empty-state label visible" + ) + + let refinedSnapshot = try XCTUnwrap( + waitForCommandPaletteSnapshot( + windowId: mainWindowId, + query: String(repeating: "z", count: 9), + timeout: 5.0 + ) { snapshot in + self.commandPaletteResultRows(from: snapshot).isEmpty + } + ) + XCTAssertTrue( + commandPaletteResultRows(from: refinedSnapshot).isEmpty, + "Expected the refined no-match query to stay empty. snapshot=\(refinedSnapshot)" + ) + } + private func launchAndActivate(_ app: XCUIApplication) { app.launch() XCTAssertTrue( @@ -592,6 +656,46 @@ final class CommandPaletteAllSurfacesUITests: XCTestCase { return UUID(uuidString: value) != nil ? value : nil } + private func debugTypeText(_ text: String) throws { + let response = try XCTUnwrap( + socketJSON( + method: "debug.type", + params: ["text": text] + ), + "Expected a response from debug.type" + ) + XCTAssertEqual(response["ok"] as? Bool, true, "Expected debug.type to succeed. response=\(response)") + } + + private func seedWorkspaceSwitcherCorpus(workspaceCount: Int) throws { + guard workspaceCount > 1 else { return } + + for index in 1.. String? { ControlSocketClient(path: socketPath, responseTimeout: 2.0).sendLine(command) } From b65c794cfb958e3a06361b1f9e5f62102d0f0471 Mon Sep 17 00:00:00 2001 From: Lawrence Chen Date: Tue, 17 Mar 2026 16:29:35 -0700 Subject: [PATCH 5/5] Keep command palette empty state stable while typing --- Sources/ContentView.swift | 43 ++++++++++++++- .../CommandPaletteSearchEngineTests.swift | 53 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 15a34bb18a67..c68ea94ed924 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -1404,6 +1404,7 @@ struct ContentView: View { @State private var commandPaletteResolvedSearchRequestID: UInt64 = 0 @State private var commandPaletteResolvedSearchScope: CommandPaletteListScope? @State private var commandPaletteResolvedSearchFingerprint: Int? + @State private var commandPaletteResolvedMatchingQuery = "" @State private var isCommandPaletteSearchPending = false @State private var commandPalettePendingActivation: CommandPalettePendingActivation? @State private var commandPaletteResultsRevision: UInt64 = 0 @@ -3257,7 +3258,7 @@ struct ContentView: View { // stale switcher rows cannot linger above command-mode results. VStack(spacing: 0) { if visibleResults.isEmpty { - if commandPaletteHasCurrentResolvedResults { + if commandPaletteShouldShowEmptyState { Text(commandPaletteEmptyStateText) .font(.system(size: 13, weight: .regular)) .foregroundStyle(.secondary) @@ -4106,6 +4107,27 @@ struct ContentView: View { !hasVisibleResultsForScope } + static func commandPaletteShouldPreserveEmptyStateWhileSearchPending( + isSearchPending: Bool, + visibleResultsScopeMatches: Bool, + resolvedSearchScopeMatches: Bool, + resolvedSearchFingerprintMatches: Bool, + resolvedResultsAreEmpty: Bool, + currentMatchingQuery: String, + resolvedMatchingQuery: String + ) -> Bool { + guard isSearchPending, + visibleResultsScopeMatches, + resolvedSearchScopeMatches, + resolvedSearchFingerprintMatches, + resolvedResultsAreEmpty else { + return false + } + + return currentMatchingQuery == resolvedMatchingQuery + || currentMatchingQuery.hasPrefix(resolvedMatchingQuery) + } + private func scheduleCommandPaletteResultsRefresh( query: String? = nil, forceSearchCorpusRefresh: Bool = false @@ -4152,6 +4174,7 @@ struct ContentView: View { commandPaletteResolvedSearchRequestID = requestID commandPaletteResolvedSearchScope = scope commandPaletteResolvedSearchFingerprint = fingerprint + commandPaletteResolvedMatchingQuery = matchingQuery isCommandPaletteSearchPending = false setCommandPaletteVisibleResults( cachedCommandPaletteResults, @@ -4210,6 +4233,7 @@ struct ContentView: View { commandPaletteResolvedSearchRequestID = requestID commandPaletteResolvedSearchScope = scope commandPaletteResolvedSearchFingerprint = fingerprint + commandPaletteResolvedMatchingQuery = matchingQuery isCommandPaletteSearchPending = false setCommandPaletteVisibleResults( cachedCommandPaletteResults, @@ -6096,6 +6120,23 @@ struct ContentView: View { !isCommandPaletteSearchPending && commandPaletteResolvedSearchRequestID == commandPaletteSearchRequestID } + private var commandPaletteShouldShowEmptyState: Bool { + guard commandPaletteVisibleResults.isEmpty else { return false } + if commandPaletteHasCurrentResolvedResults { + return true + } + + return Self.commandPaletteShouldPreserveEmptyStateWhileSearchPending( + isSearchPending: isCommandPaletteSearchPending, + visibleResultsScopeMatches: commandPaletteVisibleResultsScope == commandPaletteListScope, + resolvedSearchScopeMatches: commandPaletteResolvedSearchScope == commandPaletteListScope, + resolvedSearchFingerprintMatches: commandPaletteResolvedSearchFingerprint == commandPaletteVisibleResultsFingerprint, + resolvedResultsAreEmpty: cachedCommandPaletteResults.isEmpty, + currentMatchingQuery: commandPaletteQueryForMatching, + resolvedMatchingQuery: commandPaletteResolvedMatchingQuery + ) + } + private func runCommandPaletteResolvedActivation(_ activation: CommandPaletteResolvedActivation) { switch activation { case .command(let commandID): diff --git a/cmuxTests/CommandPaletteSearchEngineTests.swift b/cmuxTests/CommandPaletteSearchEngineTests.swift index 6976ad1db265..51cd41824d26 100644 --- a/cmuxTests/CommandPaletteSearchEngineTests.swift +++ b/cmuxTests/CommandPaletteSearchEngineTests.swift @@ -434,6 +434,59 @@ final class CommandPaletteSearchEngineTests: XCTestCase { ) } + func testPendingEmptyStateIsPreservedWhenRefiningAResolvedNoMatchQuery() { + XCTAssertTrue( + ContentView.commandPaletteShouldPreserveEmptyStateWhileSearchPending( + isSearchPending: true, + visibleResultsScopeMatches: true, + resolvedSearchScopeMatches: true, + resolvedSearchFingerprintMatches: true, + resolvedResultsAreEmpty: true, + currentMatchingQuery: "zzzzzzzzz", + resolvedMatchingQuery: "zzzzzzzz" + ) + ) + } + + func testPendingEmptyStateIsNotPreservedWhenQueryDoesNotRefineResolvedNoMatch() { + XCTAssertFalse( + ContentView.commandPaletteShouldPreserveEmptyStateWhileSearchPending( + isSearchPending: true, + visibleResultsScopeMatches: true, + resolvedSearchScopeMatches: true, + resolvedSearchFingerprintMatches: true, + resolvedResultsAreEmpty: true, + currentMatchingQuery: "zzzza", + resolvedMatchingQuery: "zzzzb" + ) + ) + } + + func testPendingEmptyStateIsNotPreservedWhenResolvedResultsMayBeStale() { + XCTAssertFalse( + ContentView.commandPaletteShouldPreserveEmptyStateWhileSearchPending( + isSearchPending: true, + visibleResultsScopeMatches: true, + resolvedSearchScopeMatches: true, + resolvedSearchFingerprintMatches: false, + resolvedResultsAreEmpty: true, + currentMatchingQuery: "zzzzzzzzz", + resolvedMatchingQuery: "zzzzzzzz" + ) + ) + XCTAssertFalse( + ContentView.commandPaletteShouldPreserveEmptyStateWhileSearchPending( + isSearchPending: true, + visibleResultsScopeMatches: true, + resolvedSearchScopeMatches: true, + resolvedSearchFingerprintMatches: true, + resolvedResultsAreEmpty: false, + currentMatchingQuery: "zzzzzzzzz", + resolvedMatchingQuery: "zzzzzzzz" + ) + ) + } + func testVisibleResultsResetWhenQueryChangesCommandPaletteScope() { XCTAssertTrue( ContentView.commandPaletteShouldResetVisibleResultsForQueryTransition(