Skip to content

feat(web): add development collision detection for hotkeys - #334

Merged
imshashank merged 1 commit into
Noveum:mainfrom
SinghAstra:feat/332-duplicate-hotkeys
Aug 19, 2026
Merged

imshashank merged 1 commit into
Noveum:mainfrom
SinghAstra:feat/332-duplicate-hotkeys

Conversation

@SinghAstra

@SinghAstra SinghAstra commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Adds a development-mode warning check inside HotkeyRegistry.register() to detect and flag silent hotkey tie collisions, along with a dedicated unit test suite.

Why

When two advertised shortcuts tie on all three tiebreakers (steps, shift specificity, and priority), the registry silently resolves them based on registration order. This caused issues like #331 where the theme toggle shadowed the due-date menu shortcut. This check ensures developers are loudly warned in non-production environments if a tie occurs.

Closes #332

How you know it works

Added a new unit test file at apps/web/tests/lib/keyboard/registry.test.ts.

Ran bun test apps/web/tests/lib/keyboard/registry.test.ts to verify that:

  1. Identical priorities triggering a duplicate binding correctly fire a console.warn.
  2. Differing priorities (global vs surface) pass cleanly without warnings.

Screenshots

Not applicable.

Checklist

  • bun run verify is green, all four checks
  • Tests added or updated, and they fail without the change
  • No comments added to code, and no em-dash characters anywhere
  • No any, no non-null assertions
  • External input is parsed with a Zod schema from @orbit/shared
  • Authorization is enforced on the server through packages/shared/src/policy, not only in the UI
  • Docs updated if behaviour, configuration or setup changed
  • bun run db:release and bun run db:check-drift passed against the target database before this ships

Anything reviewers should know

Implemented option 2 from the issue description: a non-production console.warn inside HotkeyRegistry.register() when advertised hotkeys tie on all tiebreakers, allowing existing integration/E2E test runs to surface collisions.

Greptile Summary

The PR adds development-only warnings when advertised hotkeys tie on binding structure, Shift specificity, and priority, plus focused registry tests.

  • Detects collisions across identical and differently positioned Shift modifiers.
  • Avoids warnings where priority resolves the conflict.
  • Restores test-level console stubs through exception-safe cleanup.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/web/src/lib/keyboard/registry.ts Adds collision detection whose comparison now matches the registry's runtime matching and tie-break semantics.
apps/web/tests/lib/keyboard/registry.test.ts Covers duplicate, priority-separated, and multi-step Shift collisions while restoring console.warn in finally blocks.

Reviews (3): Last reviewed commit: "feat(web): add development collision det..." | Re-trigger Greptile

@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

@SinghAstra is attempting to deploy a commit to the MagicAPI Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@SinghAstra, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

Limit details: You’ve used all 1 included review currently available under your plan.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 630d70f7-048a-4e87-b16a-090281a1dd05

📥 Commits

Reviewing files that changed from the base of the PR and between a447d5a and ac0b21f.

📒 Files selected for processing (2)
  • apps/web/src/lib/keyboard/registry.ts
  • apps/web/tests/lib/keyboard/registry.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added tests Test coverage and test infrastructure area: web The Next.js app and its UI labels Aug 18, 2026
Comment thread apps/web/src/lib/keyboard/registry.ts Resolved
@SinghAstra
SinghAstra force-pushed the feat/332-duplicate-hotkeys branch from ccda13a to a22b17d Compare August 18, 2026 16:37
Resolves Noveum#332. Adds a strict collision check to HotkeyRegistry.register that warns in non-production environments when two advertised hotkeys tie on all tiebreakers (steps, shift specificity, and priority). Includes unit tests to verify identical priorities warn while differing priorities safely resolve.

@imshashank imshashank left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right shape and it would have caught #331: two advertised entries, same key, same priority, warned about instead of silently resolved. Test file is in the correct mirrored path, the process.env.NODE_ENV guard keeps it out of production bundles, and skipping the self-comparison by id means a re-register does not warn at itself. 47 tests in apps/web/tests/lib/keyboard/ pass locally.

I want to flag the part I got wrong while reviewing, because it is the most interesting thing in the PR.

I had written you a comment arguing that stepsCollide was buggy: that ignoring shift per step and comparing the totals at the end was too loose, that shift+a b and a shift+b can never both match one keystroke sequence, and that your third test was therefore asserting a false positive. I was about to send it. Then I checked stepMatches before posting:

return step.shift ? actual.shift : true;

A step without shift matches a shifted press. So pressing Shift+A then Shift+B matches both bindings. I proved it rather than reasoning about it a second time:

shift+a b matches Shift+A,Shift+B : true
a shift+b matches Shift+A,Shift+B : true

Both match, both have two steps, both have shift specificity 1, so beats() ties and selectMatch silently picks whichever registered first. That is exactly the class of bug this PR exists to catch, and comparing shift totals rather than per step flags is what catches it. Your version is correct and my correction would have introduced a false negative that quietly stopped detecting real collisions.

Worth a line in the PR description or the issue, because the next person to read stepsCollide will have the same objection I did, and the reason it is written that way is not obvious from the function alone.

Two small things, neither blocking:

  • The test imports '../../../src/lib/keyboard/registry.ts'. Everything else under apps/web uses the @/ alias and AGENTS.md asks for it. @/lib/keyboard/registry.ts also survives the file moving.
  • The rest of the suite uses describe with it, this file uses bare test.

Happy to take those in a follow up rather than another round here. Approving.

@imshashank
imshashank merged commit aa3e922 into Noveum:main Aug 19, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: web The Next.js app and its UI tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two shortcuts on the same key silently resolve instead of failing

2 participants