test: add unit tests for keyboard key parsing - #2512
Merged
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Adds dedicated unit tests for parseKey in src/utils/keyboard.ts, which validates and parses the key input for the press_key tool. Moves the existing inline parseKey assertions out of tests/tools/input.test.ts into the new tests/utils/keyboard.test.ts and expands coverage: modifier ordering, literal plus handling, case sensitivity, whitespace handling, duplicate keys, error message shapes, and empty input.
ZayanKhan-12
force-pushed
the
chore/tests-keyboard
branch
from
August 8, 2026 21:46
a4145c4 to
66e981f
Compare
OrKoN
approved these changes
Aug 10, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
src/utils/keyboard.ts(parseKey) validates and parses the user-suppliedkeyargument for thepress_keytool, so it is a small but agent-facing input-validation path. Its only coverage so far was a handful of inline assertions insidetests/tools/input.test.ts. This PR gives the module a dedicated unit test file undertests/utils/(alongsidefiles.test.tsandurl.test.ts), moves the existing inline assertions there, and expands coverage.Coverage
Enter,Escape,F5,5,Numpad5,KeyA,a,A,' ',\r,\n) and lone modifiers (Shift,Control,Meta)Control+Shift+P→['P', 'Control', 'Shift'],Alt+Control+DeletevsControl+Alt+Delete)+,Shift++,Control+Shift++)Shift+→['Shift'],++→['+'])Shift+avsShift+A;shift+aandENTERthrow)Shift + a,Enterthrow)<key> is invalid. Valid keys are: ...message shape (includingNotAKey+Enterand+a)Key could not be parsed.Shift+Shift,Control+a+Control,a+a)No
src/changes; the tests assert current behavior. One observation (not changed here): a trailing+after a valid key is silently dropped (Shift+parses as justShift), which may or may not be intended.Testing
npm run build— cleannode scripts/test.js tests/utils/keyboard.test.ts tests/tools/input.test.ts— all pass (exit 0)npm run test:no-build— only failures were the knownTimeout uninstalling extensionflakes inconsole/extensions/pages; re-rannode scripts/test.js tests/tools/console.test.ts tests/tools/extensions.test.ts tests/tools/pages.test.tsin isolation — all pass (exit 0)npm run check-format— eslint and prettier clean🤖 Generated with Claude Code