diff --git a/cmuxTests/BrowserConfigTests.swift b/cmuxTests/BrowserConfigTests.swift index f0bf1742555a..80d5b5c200b9 100644 --- a/cmuxTests/BrowserConfigTests.swift +++ b/cmuxTests/BrowserConfigTests.swift @@ -312,6 +312,12 @@ final class CmuxWebViewKeyEquivalentTests: XCTestCase { super.delegate = newValue } } + + /// macOS 27's NSTextView initializer reads its own `delegate`. Only + /// reads after construction belong to the code under test. + func resetDelegateReadCount() { + delegateReadCount = 0 + } } private final class FieldEditorProbeTextView: NSTextView { @@ -329,6 +335,12 @@ final class CmuxWebViewKeyEquivalentTests: XCTestCase { } } + /// macOS 27's NSTextView initializer reads its own `delegate`. Only + /// reads after construction belong to the code under test. + func resetDelegateReadCount() { + delegateReadCount = 0 + } + override var isFieldEditor: Bool { get { true } set {} @@ -991,6 +1003,7 @@ final class CmuxWebViewKeyEquivalentTests: XCTestCase { window.contentView = container let textView = DelegateProbeTextView(frame: NSRect(x: 0, y: 0, width: 100, height: 40)) + textView.resetDelegateReadCount() container.addSubview(textView) window.makeKeyAndOrderFront(nil) @@ -1028,6 +1041,7 @@ final class CmuxWebViewKeyEquivalentTests: XCTestCase { webView.addSubview(descendant) let fieldEditor = FieldEditorProbeTextView(frame: NSRect(x: 0, y: 0, width: 100, height: 20)) + fieldEditor.resetDelegateReadCount() window.makeKeyAndOrderFront(nil) defer { diff --git a/cmuxTests/ShortcutAndCommandPaletteTests.swift b/cmuxTests/ShortcutAndCommandPaletteTests.swift index 8b36c1a963e3..95fc9d47a903 100644 --- a/cmuxTests/ShortcutAndCommandPaletteTests.swift +++ b/cmuxTests/ShortcutAndCommandPaletteTests.swift @@ -719,6 +719,12 @@ final class CommandPaletteFocusStealerClassificationTests: XCTestCase { super.delegate = newValue } } + + /// macOS 27's NSTextView initializer reads its own `delegate`. Only + /// reads after construction belong to the code under test. + func resetDelegateReadCount() { + delegateReadCount = 0 + } } func testTreatsGhosttySurfaceViewAsFocusStealer() { @@ -748,6 +754,7 @@ final class CommandPaletteFocusStealerClassificationTests: XCTestCase { func testDoesNotReadTextViewDelegateForFocusStealerClassification() { let textView = DelegateTrackingTextView(frame: NSRect(x: 0, y: 0, width: 120, height: 24)) + textView.resetDelegateReadCount() XCTAssertFalse(textView.isCommandPaletteFocusStealingTerminalOrBrowser) XCTAssertEqual( diff --git a/cmuxTests/TerminalAndGhosttyTests.swift b/cmuxTests/TerminalAndGhosttyTests.swift index 35707e40954e..b59a88628b74 100644 --- a/cmuxTests/TerminalAndGhosttyTests.swift +++ b/cmuxTests/TerminalAndGhosttyTests.swift @@ -2984,6 +2984,12 @@ final class GhosttyResponderResolutionTests: XCTestCase { super.delegate = newValue } } + + /// macOS 27's NSTextView initializer reads its own `delegate`. Only + /// reads after construction belong to the code under test. + func resetDelegateReadCount() { + delegateReadCount = 0 + } } func testResolvesGhosttyViewFromDescendantResponder() { @@ -3044,6 +3050,7 @@ final class GhosttyResponderResolutionTests: XCTestCase { func testDoesNotReadTextViewDelegateForGhosttyResponderResolution() { let textView = DelegateTrackingTextView(frame: NSRect(x: 0, y: 0, width: 40, height: 40)) + textView.resetDelegateReadCount() XCTAssertNil(textView.cmuxStrictOwningGhosttyView()) XCTAssertEqual(