Skip to content

[HYPER-545] suggest corrections for mistyped email domains - #231

Open
aspiers wants to merge 1 commit into
mainfrom
adam/hyper-545-email-typo-guard
Open

[HYPER-545] suggest corrections for mistyped email domains#231
aspiers wants to merge 1 commit into
mainfrom
adam/hyper-545-email-typo-guard

Conversation

@aspiers

@aspiers aspiers commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Prevent obvious email-domain typos from silently sending sign-in codes to unreachable addresses. Before either the OAuth login form or account-settings login sends a code, ePDS now offers a conservative, non-blocking correction for near-misses of Gmail, Hotmail, Outlook, Yahoo, and iCloud.

Changes

  • add a one-edit domain matcher with adjacent-transposition support for cases such as gmial.com
  • share one dependency-free client-side guard across both email entry points, reacting immediately to input changes
  • show only “Did you mean ?” with a single “Yes, fix it” action and a subtle dismiss icon; disable Continue until the user accepts, dismisses, or edits
  • preserve custom theming through semantic --email-typo-* CSS variables
  • add unit coverage for observed and representative provider typos
  • add behavioral E2E scenarios proving the prompt appears before Continue is pressed, neither submits nor repeats the typo, accepting only updates the field, and dismissing preserves the original address
  • add an end-user changeset

Testing

  • pnpm format:check
  • pnpm lint
  • pnpm typecheck
  • pnpm build
  • pnpm test — 1,084 tests pass
  • pnpm test:coverage — thresholds pass; the new helper has 100% statement/branch/function/line coverage
  • full Cucumber definition dry-run — 61 scenarios / 391 steps defined
  • local browser verification of the compact prompt, correction acceptance, dismiss behavior, input values, and Continue state
  • deployed Railway E2E — 74 scenarios / 506 steps pass on current SHA fe3b15c in run 30666552929

Before and after

The screenshots are embedded in this PR description only; no screenshot binaries are committed to the repository.

Before

Submitting the plain email form immediately attempted to send a code, even for an obvious provider-domain typo.

Before: email form without a typo decision

After

The prompt appears immediately when the typed domain matches, shows only the corrected address, offers one compact Yes, fix it mini button, and provides a subtle × to dismiss it and keep the original input. Either action hides the prompt and re-enables Continue without submitting.

After: compact email correction suggestion with a mini fix button and dismiss icon

Notes

  • Linear: HYPER-545
  • Matching is intentionally limited to one insertion, deletion, substitution, or adjacent transposition from the five configured common domains. Less-certain guesses are ignored.

Summary by CodeRabbit

  • New Features

    • Added email-domain typo detection for account and OAuth sign-in flows.
    • Users can review suggested corrections, accept them, or dismiss them to keep the original address.
    • Sign-in code requests are blocked until a detected typo is resolved.
  • Bug Fixes

    • Prevented one-time codes from being sent to mistyped email addresses.
    • Added support for common provider-domain misspellings, including transposed characters.

@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fe3b15c

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
epds-demo Ready Ready Preview Jul 31, 2026 9:26pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds common email-domain typo detection with accessible correction prompts. Integrates the guard into OAuth and account login pages. Adds unit and end-to-end coverage for accepting, dismissing, and blocking typo corrections before OTP requests.

Changes

Email Typo Guard

Layer / File(s) Summary
Detection and browser prompt
packages/auth-service/src/lib/email-typo-guard.ts, packages/auth-service/src/__tests__/email-typo-guard.test.ts
Adds edit-distance matching for common provider domains, suggestion generation, accessible prompt markup, CSS, and client-side accept, dismiss, reset, and submission handling.
Login page integration
packages/auth-service/src/routes/account-login.ts, packages/auth-service/src/routes/login-page.ts
Adds the typo-guard markup, styles, and script to the account and OAuth login forms.
End-to-end flow validation
features/email-typo-guard.feature, e2e/step-definitions/email-typo-guard.steps.ts, e2e/support/world.ts, .changeset/suggest-mistyped-email-domains.md
Adds scenarios and request assertions for blocked, accepted, and dismissed corrections across both login flows. Documents the release change.
Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant LoginForm
  participant EmailTypoGuard
  participant AuthService
  participant OTPForm
  User->>LoginForm: enter mistyped email
  LoginForm->>EmailTypoGuard: submit email
  EmailTypoGuard->>LoginForm: show correction and block submission
  User->>EmailTypoGuard: accept or dismiss suggestion
  EmailTypoGuard->>LoginForm: update or retain email
  LoginForm->>AuthService: request OTP
  AuthService->>OTPForm: display code form
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: suggesting corrections for mistyped email domains.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch adam/hyper-545-email-typo-guard

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.

@railway-app

railway-app Bot commented Jul 31, 2026

Copy link
Copy Markdown

🚅 Deployed to the ePDS-pr-231 environment in ePDS

Service Status Web Updated (UTC)
@certified-app/auth-service ✅ Success (View Logs) Web Jul 31, 2026 at 9:27 pm
@certified-app/pds-core ✅ Success (View Logs) Web Jul 31, 2026 at 9:14 pm
@certified-app/demo ✅ Success (View Logs) Web Jul 31, 2026 at 9:14 pm
@certified-app/demo untrusted ✅ Success (View Logs) Web Jul 31, 2026 at 9:14 pm

@coveralls-official

coveralls-official Bot commented Jul 31, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 30666552997

Coverage increased (+0.4%) to 57.672%

Details

  • Coverage increased (+0.4%) from the base build.
  • Patch coverage: 29 of 29 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3098
Covered Lines: 1782
Line Coverage: 57.52%
Relevant Branches: 1927
Covered Branches: 1116
Branch Coverage: 57.91%
Branches in Coverage %: Yes
Coverage Strength: 9.45 hits per line

💛 - Coveralls

@aspiers
aspiers force-pushed the adam/hyper-545-email-typo-guard branch from 4311a18 to 71c1472 Compare July 31, 2026 19:35
@railway-app
railway-app Bot temporarily deployed to ePDS / ePDS-pr-231 July 31, 2026 19:35 Destroyed
@aspiers
aspiers force-pushed the adam/hyper-545-email-typo-guard branch from 71c1472 to 4e6f846 Compare July 31, 2026 20:17
@railway-app
railway-app Bot temporarily deployed to ePDS / ePDS-pr-231 July 31, 2026 20:17 Destroyed
@aspiers
aspiers force-pushed the adam/hyper-545-email-typo-guard branch from 4e6f846 to d7b593b Compare July 31, 2026 20:53
@railway-app
railway-app Bot temporarily deployed to ePDS / ePDS-pr-231 July 31, 2026 20:53 Destroyed
@aspiers aspiers changed the title feat(auth): suggest corrections for mistyped email domains [HYPER-545] suggest corrections for mistyped email domains Jul 31, 2026
@aspiers
aspiers marked this pull request as ready for review July 31, 2026 20:57
Copilot AI review requested due to automatic review settings July 31, 2026 20:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/auth-service/src/lib/email-typo-guard.ts (1)

104-236: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reduce drift risk between the TS algorithm and its embedded JS duplicate.

suggestEmailAddress (lines 57-74) and the embedded script's editDistance/suggest (lines 127-177) implement the identical algorithm twice. suggestEmailAddress is unit-tested, but browsers only ever run the string-embedded copy. A future edit to one without the other changes production behavior while the test suite still passes.

Consider deriving the embedded script from the tested function, or add a regression test that evaluates the embedded script (for example via Node's vm module) against the same fixtures as email-typo-guard.test.ts to guarantee parity.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/auth-service/src/lib/email-typo-guard.ts` around lines 104 - 236,
Eliminate algorithm drift between the tested suggestEmailAddress implementation
and the embedded editDistance/suggest functions in renderEmailTypoGuardScript.
Either generate the browser script from the shared tested implementation or add
a regression test that evaluates the embedded script and compares it with the
existing email-typo fixtures, ensuring both paths remain behaviorally identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/auth-service/src/lib/email-typo-guard.ts`:
- Around line 104-236: Eliminate algorithm drift between the tested
suggestEmailAddress implementation and the embedded editDistance/suggest
functions in renderEmailTypoGuardScript. Either generate the browser script from
the shared tested implementation or add a regression test that evaluates the
embedded script and compares it with the existing email-typo fixtures, ensuring
both paths remain behaviorally identical.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 07c92fa6-bcb8-4145-aa89-db6fda7ccf61

📥 Commits

Reviewing files that changed from the base of the PR and between a6cf09d and d7b593b.

📒 Files selected for processing (8)
  • .changeset/suggest-mistyped-email-domains.md
  • e2e/step-definitions/email-typo-guard.steps.ts
  • e2e/support/world.ts
  • features/email-typo-guard.feature
  • packages/auth-service/src/__tests__/email-typo-guard.test.ts
  • packages/auth-service/src/lib/email-typo-guard.ts
  • packages/auth-service/src/routes/account-login.ts
  • packages/auth-service/src/routes/login-page.ts

@aspiers
aspiers force-pushed the adam/hyper-545-email-typo-guard branch from d7b593b to 2a9a77f Compare July 31, 2026 21:12
Copilot AI review requested due to automatic review settings July 31, 2026 21:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Without this change, addresses such as gmial.com and hotmal.com proceed directly to code delivery and leave users unable to receive their sign-in code.

Add a conservative one-edit domain check for common providers. Both email entry points now pause before sending, offer the corrected address, and still allow the original address explicitly. Behavioral tests cover corrected and original sends.

Refs HYPER-545.

Co-authored-by: OpenAI Codex <noreply@openai.com>
@aspiers
aspiers force-pushed the adam/hyper-545-email-typo-guard branch from 2a9a77f to fe3b15c Compare July 31, 2026 21:26
Copilot AI review requested due to automatic review settings July 31, 2026 21:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

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