Skip to content

Fix TOTP form submit and front-end coverage#447

Merged
davideluque merged 5 commits intomainfrom
fix/totp-branch-coverage
Mar 16, 2026
Merged

Fix TOTP form submit and front-end coverage#447
davideluque merged 5 commits intomainfrom
fix/totp-branch-coverage

Conversation

@davideluque
Copy link
Contributor

Summary

  • Fix missing 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 properly
  • Fix handleKeyDown to use form.requestSubmit() instead of directly calling verifyTotp() (which now requires a FormEvent parameter)
  • Add browser test for invalid OTP submission, covering the error branch and raising inertia/pages/session/totp.tsx branch coverage from 33% to above the 50% threshold

Test plan

  • All 61 tests pass locally
  • TypeScript compiles cleanly
  • Prettier formatting passes on changed files
  • CI passes on this branch

🤖 Generated with Claude Code

davideluque and others added 2 commits March 16, 2026 13:58
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>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • TOTP Form Submission: Resolved an issue where the TOTP login form's native GET submission raced with the Inertia POST, preventing error states from rendering correctly by adding e.preventDefault().
  • Keyboard Event Handling: Modified the handleKeyDown function to use form.requestSubmit() instead of directly calling verifyTotp(), aligning with the updated verifyTotp signature.
  • Front-end Test Coverage: Introduced a new browser test to cover invalid OTP submission scenarios, significantly increasing the branch coverage for inertia/pages/session/totp.tsx.

🧠 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
  • inertia/pages/session/totp.tsx
    • Imported FormEvent type from 'react'.
    • Modified the verifyTotp function to accept a FormEvent parameter and call e.preventDefault() to prevent default form submission.
    • Updated the handleKeyDown function to trigger form submission using e.currentTarget.form?.requestSubmit() instead of directly calling verifyTotp.
  • tests/browser/auth.spec.ts
    • Added a new browser test case named 'sign in with totp shows error for invalid otp' to verify that an error message is displayed when an invalid OTP is submitted.
Activity
  • The author, davideluque, created this pull request to fix a TOTP form submission issue and improve front-end test coverage.
  • The author has provided a detailed summary and test plan in the PR description.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

davideluque and others added 2 commits March 16, 2026 14:26
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>
@davideluque
Copy link
Contributor Author

Ready for review

@davideluque
Copy link
Contributor Author

@copilot please re-review this PR

@davideluque
Copy link
Contributor Author

/gemini review

Copy link

Copilot AI commented Mar 16, 2026

@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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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>
@davideluque
Copy link
Contributor Author

Ready for review

All CI checks are green. Changes since last review:

@davideluque davideluque merged commit c2ac49c into main Mar 16, 2026
8 checks passed
@davideluque davideluque deleted the fix/totp-branch-coverage branch March 16, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants