Fix TOTP form submit and front-end coverage#447
Conversation
The TOTP login page (inertia/pages/session/totp.tsx) had 33% branch coverage, below the 50% per-file threshold, because only the happy path was tested. This adds a test that submits an invalid OTP, which exercises the error variant of the input and raises coverage to ~66%. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The TOTP login form (inertia/pages/session/totp.tsx) was missing e.preventDefault() in its submit handler, causing a native GET form submission to race with the Inertia POST. This also caused the front-end branch coverage to stay below the 50% threshold since the error state was never properly rendered. - Add preventDefault to verifyTotp form handler - Fix handleKeyDown to use form.requestSubmit() instead of calling verifyTotp directly (which no longer has a matching signature) - Add browser test for invalid OTP submission to cover the error branch Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the Two-Factor Authentication (TOTP) login form that caused incorrect error rendering due to a race condition between native form submission and Inertia's POST request. It also refines the keyboard event handling for the OTP input and enhances front-end test coverage by adding a new browser test for invalid OTP submissions, ensuring robust error feedback to users. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the identified issues with the TOTP form submission, preventing a race condition and ensuring proper error rendering. The changes to use e.preventDefault() in verifyTotp and form.requestSubmit() in handleKeyDown are correct and improve the form's reliability. Additionally, the new browser test significantly enhances front-end coverage for the invalid OTP scenario, which is a valuable improvement.
The CI coverage check still failed because Istanbul counts the handleKeyDown Enter branch separately. Changed the happy-path TOTP test to submit via Enter key press instead of button click, which exercises the if (e.key === 'Enter') branch and raises coverage from 33% to ~66%. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Enter key press triggered both handleKeyDown (which called requestSubmit()) and the native Enter-to-submit behavior, causing a double submission. Added preventDefault() in handleKeyDown to prevent the native behavior. Moved Enter key usage to the invalid OTP test to reliably cover the handleKeyDown branch on CI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Ready for review |
|
@copilot please re-review this PR |
|
/gemini review |
|
@davideluque I've opened a new pull request, #450, to work on those changes. Once the pull request is ready, I'll request review from you. |
There was a problem hiding this comment.
Code Review
This pull request successfully addresses a form submission bug on the TOTP page by preventing a race condition, and it also improves test coverage by adding a test for invalid OTP submissions. The code changes in inertia/pages/session/totp.tsx are correct and well-implemented. I've added one suggestion for the new test in tests/browser/auth.spec.ts to refactor some duplicated logic, which will improve the overall maintainability of the test suite. The changes are solid and improve the robustness of the authentication flow.
The handleKeyDown was bound both via the JSX onKeyDown prop and via the native addEventListener in useAutofillRef, causing Enter to trigger two requestSubmit() calls. Removed the JSX prop since the useAutofillRef listener already covers it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Ready for review All CI checks are green. Changes since last review:
|
Summary
e.preventDefault()in the TOTP login form's submit handler, which caused a native GET form submission to race with the Inertia POST — this prevented error states from rendering properlyhandleKeyDownto useform.requestSubmit()instead of directly callingverifyTotp()(which now requires aFormEventparameter)inertia/pages/session/totp.tsxbranch coverage from 33% to above the 50% thresholdTest plan
🤖 Generated with Claude Code