diff --git a/Sources/Workspace.swift b/Sources/Workspace.swift index 25a7173d..a14cbf69 100644 --- a/Sources/Workspace.swift +++ b/Sources/Workspace.swift @@ -1388,7 +1388,8 @@ final class Workspace: Identifiable, ObservableObject { return preferredProfileID } if let sourcePanelId, - let sourceBrowserPanel = browserPanel(for: sourcePanelId) { + let sourceBrowserPanel = browserPanel(for: sourcePanelId), + BrowserProfileStore.shared.profileDefinition(id: sourceBrowserPanel.profileID) != nil { return sourceBrowserPanel.profileID } if let preferredBrowserProfileID, diff --git a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift index 67f8cadf..6ce551a0 100644 --- a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift +++ b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift @@ -65,6 +65,15 @@ private func drainMainQueue() { XCTWaiter().wait(for: [expectation], timeout: 1.0) } +@MainActor +private func makeTemporaryBrowserProfile(named prefix: String) throws -> BrowserProfileDefinition { + try XCTUnwrap( + BrowserProfileStore.shared.createProfile( + named: "\(prefix)-\(UUID().uuidString)" + ) + ) +} + final class SplitShortcutTransientFocusGuardTests: XCTestCase { func testSuppressesWhenFirstResponderFallsBackAndHostedViewIsTiny() { XCTAssertTrue( @@ -6277,18 +6286,10 @@ final class WorkspaceBrowserProfileSelectionTests: XCTestCase { } } - private func makeProfile(named prefix: String) throws -> BrowserProfileDefinition { - try XCTUnwrap( - BrowserProfileStore.shared.createProfile( - named: "\(prefix)-\(UUID().uuidString)" - ) - ) - } - func testNewBrowserSurfacePrefersSelectedBrowserProfileInTargetPane() throws { let workspace = Workspace() - let profileA = try makeProfile(named: "Alpha") - let profileB = try makeProfile(named: "Beta") + let profileA = try makeTemporaryBrowserProfile(named: "Alpha") + let profileB = try makeTemporaryBrowserProfile(named: "Beta") let paneId = try XCTUnwrap(workspace.bonsplitController.focusedPaneId) let browserA = try XCTUnwrap( workspace.newBrowserSurface( @@ -6332,8 +6333,8 @@ final class WorkspaceBrowserProfileSelectionTests: XCTestCase { func testNewBrowserSurfaceFailureDoesNotMutatePreferredProfile() throws { let workspace = Workspace() - let preferredProfile = try makeProfile(named: "Preferred") - let unexpectedProfile = try makeProfile(named: "Unexpected") + let preferredProfile = try makeTemporaryBrowserProfile(named: "Preferred") + let unexpectedProfile = try makeTemporaryBrowserProfile(named: "Unexpected") let paneId = try XCTUnwrap(workspace.bonsplitController.focusedPaneId) _ = try XCTUnwrap( @@ -6363,8 +6364,8 @@ final class WorkspaceBrowserProfileSelectionTests: XCTestCase { func testNewBrowserSplitFailureDoesNotMutatePreferredProfile() throws { let workspace = Workspace() - let preferredProfile = try makeProfile(named: "Preferred") - let unexpectedProfile = try makeProfile(named: "Unexpected") + let preferredProfile = try makeTemporaryBrowserProfile(named: "Preferred") + let unexpectedProfile = try makeTemporaryBrowserProfile(named: "Unexpected") let paneId = try XCTUnwrap(workspace.bonsplitController.focusedPaneId) let browser = try XCTUnwrap( @@ -6453,16 +6454,8 @@ final class TabManagerWorkspaceConfigInheritanceSourceTests: XCTestCase { @MainActor final class BrowserPanelProfileIsolationTests: XCTestCase { - private func makeProfile(named prefix: String) throws -> BrowserProfileDefinition { - try XCTUnwrap( - BrowserProfileStore.shared.createProfile( - named: "\(prefix)-\(UUID().uuidString)" - ) - ) - } - func testStaleDidFinishDoesNotRecordVisitIntoSwitchedProfileHistory() throws { - let alternateProfile = try makeProfile(named: "Switched") + let alternateProfile = try makeTemporaryBrowserProfile(named: "Switched") let defaultStore = BrowserHistoryStore.shared let alternateStore = BrowserProfileStore.shared.historyStore(for: alternateProfile.id) defaultStore.clearHistory() diff --git a/cmuxTests/GhosttyConfigTests.swift b/cmuxTests/GhosttyConfigTests.swift index 9ac2a8f7..4ceb61d1 100644 --- a/cmuxTests/GhosttyConfigTests.swift +++ b/cmuxTests/GhosttyConfigTests.swift @@ -2029,7 +2029,10 @@ final class BrowserInstallDetectorTests: XCTestCase { private func createFile(at url: URL, contents: Data) throws { try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true) guard FileManager.default.createFile(atPath: url.path, contents: contents) else { - throw CocoaError(.fileWriteUnknown) + throw CocoaError( + .fileWriteUnknown, + userInfo: [NSFilePathErrorKey: url.path] + ) } } } diff --git a/cmuxUITests/BrowserImportProfilesUITests.swift b/cmuxUITests/BrowserImportProfilesUITests.swift index cc28d425..feb55471 100644 --- a/cmuxUITests/BrowserImportProfilesUITests.swift +++ b/cmuxUITests/BrowserImportProfilesUITests.swift @@ -98,6 +98,22 @@ final class BrowserImportProfilesUITests: XCTestCase { XCTAssertEqual(capture["scope"] as? String, "everything") } + func testWaitForCapturedSelectionReadsCaptureWrittenAtTimeoutBoundary() throws { + let payload: [String: Any] = [ + "mode": "boundary-write", + "entries": [] + ] + let payloadData = try JSONSerialization.data(withJSONObject: payload) + let captureURL = URL(fileURLWithPath: capturePath) + + DispatchQueue.main.asyncAfter(deadline: .now() + 0.19) { + try? payloadData.write(to: captureURL) + } + + let capture = try XCTUnwrap(waitForCapturedSelection(timeout: 0.2)) + XCTAssertEqual(capture["mode"] as? String, "boundary-write") + } + private func launchApp() -> XCUIApplication { let app = XCUIApplication() app.launchEnvironment["CMUX_UI_TEST_MODE"] = "1" @@ -138,6 +154,10 @@ final class BrowserImportProfilesUITests: XCTestCase { } RunLoop.current.run(until: Date().addingTimeInterval(0.05)) } + if let data = try? Data(contentsOf: url), + let object = try? JSONSerialization.jsonObject(with: data) as? [String: Any] { + return object + } return nil }