Repository navigation
Fix notification unread persistence when workspaces regain focus #971
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6658,6 +6658,8 @@ final class NotificationDockBadgeTests: XCTestCase { | |
| } | ||
|
|
||
| override func tearDown() { | ||
| AppFocusState.overrideIsFocused = nil | ||
| AppDelegate.shared = nil | ||
| TerminalNotificationStore.shared.resetNotificationSettingsPromptHooksForTesting() | ||
| TerminalNotificationStore.shared.replaceNotificationsForTesting([]) | ||
| super.tearDown() | ||
|
|
@@ -7161,6 +7163,155 @@ final class NotificationDockBadgeTests: XCTestCase { | |
| XCTAssertEqual(store.latestNotification(forTabId: tabB)?.id, notificationBUnread.id) | ||
| } | ||
|
|
||
| func testFocusedTabNotificationIsStoredWhenNativeDeliveryIsSuppressed() { | ||
| let store = TerminalNotificationStore.shared | ||
| store.replaceNotificationsForTesting([]) | ||
|
|
||
| let appDelegate = AppDelegate() | ||
| let tabManager = TabManager() | ||
| appDelegate.tabManager = tabManager | ||
| AppDelegate.shared = appDelegate | ||
| AppFocusState.overrideIsFocused = true | ||
|
|
||
| guard let tabId = tabManager.selectedTabId else { | ||
| XCTFail("Expected selected tab for notification test") | ||
| return | ||
| } | ||
|
|
||
| store.addNotification( | ||
| tabId: tabId, | ||
| surfaceId: nil, | ||
| title: "Needs input", | ||
| subtitle: "", | ||
| body: "agent requires user action" | ||
| ) | ||
|
|
||
| XCTAssertEqual(store.unreadCount(forTabId: tabId), 1) | ||
| guard let latest = store.latestNotification(forTabId: tabId) else { | ||
| XCTFail("Expected notification to be stored for focused tab") | ||
| return | ||
| } | ||
| XCTAssertEqual(latest.tabId, tabId) | ||
| XCTAssertEqual(latest.title, "Needs input") | ||
| XCTAssertEqual(latest.body, "agent requires user action") | ||
| XCTAssertFalse(latest.isRead) | ||
| } | ||
|
|
||
| func testApplicationDidBecomeActiveDoesNotMarkFocusedNotificationRead() { | ||
| let store = TerminalNotificationStore.shared | ||
| let appDelegate = AppDelegate() | ||
| let tabManager = TabManager() | ||
| appDelegate.tabManager = tabManager | ||
| appDelegate.notificationStore = store | ||
| AppDelegate.shared = appDelegate | ||
| AppFocusState.overrideIsFocused = true | ||
|
|
||
| guard let tabId = tabManager.selectedTabId, | ||
| let surfaceId = tabManager.focusedSurfaceId(for: tabId) else { | ||
| XCTFail("Expected selected tab and focused surface for activation test") | ||
| return | ||
| } | ||
|
|
||
| let notification = TerminalNotification( | ||
| id: UUID(), | ||
| tabId: tabId, | ||
| surfaceId: surfaceId, | ||
| title: "Unread", | ||
| subtitle: "", | ||
| body: "should persist across app activation", | ||
| createdAt: Date(), | ||
| isRead: false | ||
| ) | ||
| store.replaceNotificationsForTesting([notification]) | ||
|
|
||
| appDelegate.applicationDidBecomeActive( | ||
| Notification(name: NSApplication.didBecomeActiveNotification) | ||
| ) | ||
|
|
||
| XCTAssertTrue(store.hasUnreadNotification(forTabId: tabId, surfaceId: surfaceId)) | ||
| XCTAssertFalse(store.notifications[0].isRead) | ||
| } | ||
|
|
||
| func testSelectingWorkspaceDoesNotMarkFocusedNotificationRead() { | ||
| let store = TerminalNotificationStore.shared | ||
| let appDelegate = AppDelegate() | ||
| let tabManager = TabManager() | ||
| appDelegate.tabManager = tabManager | ||
| appDelegate.notificationStore = store | ||
| AppDelegate.shared = appDelegate | ||
| AppFocusState.overrideIsFocused = true | ||
|
|
||
| guard let originalTabId = tabManager.selectedTabId, | ||
| let originalSurfaceId = tabManager.focusedSurfaceId(for: originalTabId) else { | ||
| XCTFail("Expected selected tab and focused surface for workspace selection test") | ||
| return | ||
| } | ||
| guard let originalWorkspace = tabManager.tabs.first(where: { $0.id == originalTabId }) else { | ||
| XCTFail("Expected original workspace for workspace selection test") | ||
| return | ||
| } | ||
|
|
||
| let notification = TerminalNotification( | ||
| id: UUID(), | ||
| tabId: originalTabId, | ||
| surfaceId: originalSurfaceId, | ||
| title: "Unread", | ||
| subtitle: "", | ||
| body: "should persist across workspace selection", | ||
| createdAt: Date(), | ||
| isRead: false | ||
| ) | ||
| store.replaceNotificationsForTesting([notification]) | ||
|
|
||
| _ = tabManager.addWorkspace(select: true) | ||
| tabManager.selectWorkspace(originalWorkspace) | ||
|
|
||
| let drained = expectation(description: "workspace selection side effects drained") | ||
| DispatchQueue.main.async { drained.fulfill() } | ||
| wait(for: [drained], timeout: 1.0) | ||
|
|
||
| XCTAssertEqual(tabManager.selectedTabId, originalTabId) | ||
| XCTAssertTrue(store.hasUnreadNotification(forTabId: originalTabId, surfaceId: originalSurfaceId)) | ||
| XCTAssertFalse(store.notifications[0].isRead) | ||
| } | ||
|
|
||
| func testNotificationFocusNavigationDoesNotMarkNotificationRead() { | ||
| let store = TerminalNotificationStore.shared | ||
| let appDelegate = AppDelegate() | ||
| let tabManager = TabManager() | ||
| appDelegate.tabManager = tabManager | ||
| appDelegate.notificationStore = store | ||
| AppDelegate.shared = appDelegate | ||
| AppFocusState.overrideIsFocused = true | ||
|
|
||
| guard let tabId = tabManager.selectedTabId, | ||
| let surfaceId = tabManager.focusedSurfaceId(for: tabId) else { | ||
| XCTFail("Expected selected tab and focused surface for notification focus test") | ||
| return | ||
| } | ||
|
|
||
| let notification = TerminalNotification( | ||
| id: UUID(), | ||
| tabId: tabId, | ||
| surfaceId: surfaceId, | ||
| title: "Unread", | ||
| subtitle: "", | ||
| body: "should persist after notification focus", | ||
| createdAt: Date(), | ||
| isRead: false | ||
| ) | ||
| store.replaceNotificationsForTesting([notification]) | ||
|
|
||
| tabManager.focusTabFromNotification(tabId, surfaceId: surfaceId) | ||
|
|
||
| let drained = expectation(description: "notification focus drained") | ||
| DispatchQueue.main.async { drained.fulfill() } | ||
|
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 async drain can finish before notification-focus delayed side effects run, so the test may assert too early and miss regressions. Prompt for AI agents |
||
| wait(for: [drained], timeout: 1.0) | ||
|
|
||
| XCTAssertTrue(store.hasUnreadNotification(forTabId: tabId, surfaceId: surfaceId)) | ||
| XCTAssertFalse(store.notifications[0].isRead) | ||
| } | ||
|
|
||
| func testNotificationIndexesUpdateAfterReadAndClearMutations() { | ||
| let tab = UUID() | ||
| let surfaceUnread = UUID() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.