fix(hooks): use terminal-notifier for macOS notification click-to-focus#2166
fix(hooks): use terminal-notifier for macOS notification click-to-focus#21661noilimrev wants to merge 3 commits intocode-yeongyu:devfrom
Conversation
|
All contributors have signed the CLA. Thank you! ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
2 issues found across 3 files
Confidence score: 4/5
- This PR looks safe to merge; the issues are confined to tests and are moderate in severity rather than user-facing code.
src/hooks/session-notification.test.tsrisks test pollution becauseprocess.env.__CFBundleIdentifiercleanup isn’t guarded with try/finally, so a failing assertion could leak state into other tests.- There’s also some duplicated mock setup in
src/hooks/session-notification.test.ts, which is a maintainability concern but not a functional blocker. - Pay close attention to
src/hooks/session-notification.test.ts- ensure env var cleanup is robust and consider extracting shared mock setup.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/hooks/session-notification.test.ts">
<violation number="1" location="src/hooks/session-notification.test.ts:372">
P2: Duplicate mock setup code across three test cases. Extract the `notifyCalls` array and `mockCtx` object creation into a shared helper function (e.g., `createMockCtx()`) to improve test maintainability.</violation>
<violation number="2" location="src/hooks/session-notification.test.ts:384">
P2: Test pollution risk: Environment variable mutation without try-finally. This test modifies `process.env.__CFBundleIdentifier` but places cleanup at the end of the test body. If an assertion fails or error is thrown before cleanup runs, the modified environment variable will leak to subsequent tests. Consider using try-finally or moving cleanup to the existing afterEach hook.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
@cubic-dev-ai can u review again? |
@1noilimrev I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: Addresses macOS notification click-to-focus behavior with a safe fallback to osascript and comprehensive test coverage.
Summary
osascript display notificationwithterminal-notifier -activate $__CFBundleIdentifieras the primary macOS notification backendosascriptwhenterminal-notifieris not installedChanges
src/hooks/session-notification-utils.ts: AddedgetTerminalNotifierPathexport using the existingcreateCommandFinderfactory; added eager pre-resolution instartBackgroundCheckdarwin casesrc/hooks/session-notification-sender.ts: Modified darwin case insendSessionNotificationto tryterminal-notifierfirst with-activate $__CFBundleIdentifierfor deterministic click-to-focus, falling back toosascriptwhenterminal-notifieris not availablesrc/hooks/session-notification.test.ts: Added 3 new tests for darwin notification backend selection logicScreenshots
Testing
bun run typecheck bun run build bun test src/hooks/session-notification.test.tsExpected: typecheck exits 0, build exits 0, 14 tests pass (11 existing + 3 new)
Root cause:
osascript -e 'display notification...'attributes notification ownership to Script Editor (com.apple.ScriptEditor2). When clicked, macOS tries to activate Script Editor; when it isn't running, Finder activates as fallback.Fix:
terminal-notifier -activate $__CFBundleIdentifierdeterministically activates the terminal that launched OpenCode (e.g.,com.mitchellh.ghosttyfor Ghostty,com.googlecode.iterm2for iTerm2). The__CFBundleIdentifierenv var is set by macOS and identifies the running app, working correctly even inside tmux sessions.Related Issues
Summary by cubic
Fixes macOS notification clicks opening Finder instead of the terminal. Notifications now use terminal-notifier so clicks focus the terminal that launched OpenCode.
Written for commit fbe3b54. Summary will update on new commits.