-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix blank terminal pane when notification fires on another tab #1155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -749,6 +749,122 @@ final class WindowBackgroundSelectionGateTests: XCTestCase { | |
| } | ||
| } | ||
|
|
||
| // MARK: - Issue #914 regression tests | ||
|
|
||
| /// Validates that `shouldApplyWindowBackground` returning false does NOT | ||
| /// prevent surface background from being maintained. The fix moves | ||
| /// `applySurfaceBackground()` before the guard so it always runs. | ||
| /// | ||
| /// These tests verify the decision logic that was previously the sole | ||
| /// gate for surface background application. When the guard rejects, | ||
| /// the surface background must still be applied (tested via the code | ||
| /// change, not a mock — these tests document the rejection scenarios). | ||
| final class WindowBackgroundSurfaceBackgroundGuaranteeTests: XCTestCase { | ||
| func testShouldApplyRejectsWhenOwningSelectionDiffersButSurfaceMustStayVisible() { | ||
| let surfaceTabId = UUID() | ||
| let differentSelectedTab = UUID() | ||
|
|
||
| // This is the scenario that triggers #914: the owning manager's | ||
| // selectedTabId temporarily differs from the surface's tabId | ||
| // (e.g., during notification-triggered tab reorder). | ||
| let rejected = !GhosttyNSView.shouldApplyWindowBackground( | ||
| surfaceTabId: surfaceTabId, | ||
| owningManagerExists: true, | ||
| owningSelectedTabId: differentSelectedTab, | ||
| activeSelectedTabId: surfaceTabId | ||
| ) | ||
| XCTAssertTrue(rejected, "Guard should reject when owning selection differs — this is the #914 trigger condition") | ||
| } | ||
|
|
||
| func testShouldApplyRejectsWhenActiveSelectionDiffersWithNoOwningManager() { | ||
| let surfaceTabId = UUID() | ||
| let differentActiveTab = UUID() | ||
|
|
||
| let rejected = !GhosttyNSView.shouldApplyWindowBackground( | ||
| surfaceTabId: surfaceTabId, | ||
| owningManagerExists: false, | ||
| owningSelectedTabId: nil, | ||
| activeSelectedTabId: differentActiveTab | ||
| ) | ||
| XCTAssertTrue(rejected, "Guard should reject when active selection differs — surface background must still be maintained") | ||
| } | ||
| } | ||
|
|
||
| /// Validates that notification-driven tab reorder is deferred to avoid | ||
| /// cascading @Published changes in the same run loop frame (#914). | ||
| /// | ||
| /// Uses source-code inspection (same pattern as | ||
| /// `TabManagerNotificationOrderingSourceTests`) to assert that | ||
| /// `moveTabToTop` is wrapped in `DispatchQueue.main.async` inside | ||
| /// `addNotification`. This avoids singleton state pollution from | ||
| /// `TerminalNotificationStore.shared` and provides a meaningful | ||
| /// regression guard — unlike a runtime test, this will fail if the | ||
| /// async wrapper is removed. | ||
| final class NotificationTabReorderDeferralTests: XCTestCase { | ||
| func testMoveTabToTopIsDeferredInsideAddNotification() throws { | ||
| let projectRoot = findProjectRoot() | ||
| let storeURL = projectRoot.appendingPathComponent("Sources/TerminalNotificationStore.swift") | ||
| let source = try String(contentsOf: storeURL, encoding: .utf8) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This test asserts source-code strings instead of runtime behavior, violating the repository test policy and creating brittle regression coverage. Prompt for AI agents |
||
|
|
||
| // Locate the addNotification method body. | ||
| guard let methodStart = source.range(of: "func addNotification(tabId:") else { | ||
| XCTFail("Failed to locate addNotification(tabId:) in TerminalNotificationStore.swift") | ||
| return | ||
| } | ||
|
|
||
| // Find the next top-level `func` after addNotification to bound the search. | ||
| let searchRange = methodStart.upperBound..<source.endIndex | ||
| let methodEnd = source.range(of: "\n func ", range: searchRange)?.lowerBound ?? source.endIndex | ||
| let methodBody = String(source[methodStart.lowerBound..<methodEnd]) | ||
|
|
||
| // The critical invariant: moveTabToTop must be called inside | ||
| // DispatchQueue.main.async, NOT directly. A synchronous call | ||
| // causes two @Published mutations in the same run loop frame | ||
| // (tabs reorder + notifications update), triggering a cascading | ||
| // SwiftUI re-render that blanks the active pane (#914). | ||
| XCTAssertTrue( | ||
| methodBody.contains("DispatchQueue.main.async"), | ||
| """ | ||
| addNotification must defer moveTabToTop via DispatchQueue.main.async \ | ||
| to prevent cascading @Published changes that blank the active pane (#914). | ||
| """ | ||
| ) | ||
| XCTAssertTrue( | ||
| methodBody.contains("moveTabToTop"), | ||
| "addNotification must call moveTabToTop for auto-reorder behavior." | ||
| ) | ||
|
|
||
| // Verify moveTabToTop appears ONLY inside the async block, not outside it. | ||
| // Split on DispatchQueue.main.async and check that moveTabToTop doesn't | ||
| // appear in the portion before the async block within the reorder section. | ||
| if let reorderStart = methodBody.range(of: "WorkspaceAutoReorderSettings.isEnabled()") { | ||
| let reorderSection = String(methodBody[reorderStart.lowerBound..<methodBody.endIndex]) | ||
| if let asyncStart = reorderSection.range(of: "DispatchQueue.main.async") { | ||
| let beforeAsync = String(reorderSection[reorderSection.startIndex..<asyncStart.lowerBound]) | ||
| XCTAssertFalse( | ||
| beforeAsync.contains("moveTabToTop"), | ||
| """ | ||
| moveTabToTop must NOT be called synchronously before the \ | ||
| DispatchQueue.main.async block — it must be inside it (#914). | ||
| """ | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func findProjectRoot() -> URL { | ||
| var dir = URL(fileURLWithPath: #file).deletingLastPathComponent().deletingLastPathComponent() | ||
| for _ in 0..<10 { | ||
| let marker = dir.appendingPathComponent("GhosttyTabs.xcodeproj") | ||
| if FileManager.default.fileExists(atPath: marker.path) { | ||
| return dir | ||
| } | ||
| dir = dir.deletingLastPathComponent() | ||
| } | ||
| return URL(fileURLWithPath: FileManager.default.currentDirectoryPath) | ||
| } | ||
|
Comment on lines
+780
to
+826
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test does not verify the claimed deferral behavior. The test claims to validate that
The verbose comments (lines 797-806, 810-813, 822-828) describe the intent, but the actual test body doesn't enforce it. Per learnings, tests should verify observable runtime behavior through executable paths. Consider either:
Based on learnings: "Tests must verify observable runtime behavior through executable paths (unit/integration/e2e/CLI), not implementation shape". 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| final class NotificationBurstCoalescerTests: XCTestCase { | ||
| func testSignalsInSameBurstFlushOnce() { | ||
| let coalescer = NotificationBurstCoalescer(delay: 0.01) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.