Skip to content

bug: Fix lead percentage when the losing final score is zero #188

Description

@O2sa

When comparing two users and the lower-scoring user has a finalScore of 0, the winner banner can show Leads by 0% even though the score difference is positive. The issue comes from percentage calculations that avoid division by zero by returning 0, which makes the UI look like there is no lead.

Context

  • app/api/compare/route.ts sets percentageDifference to 0 when overallLoser.finalScore is 0.
  • components/result-dashboard.tsx recomputes winnerDiffPct and also falls back to 0 when loserUser.finalScore is 0.
  • The language-focused winner path has the same pattern for languageWinner.percentageDifference.

Tasks

  • Define the expected display behavior when the loser score is 0 and the winner score is greater than 0 (for example, show N/A, +{points} points, or another explicit non-percentage label).
  • Update the compare API winner payload so zero-baseline comparisons do not report a misleading 0% lead.
  • Update the winner banner in components/result-dashboard.tsx to render the zero-baseline state correctly.
  • Apply the same behavior to language-focused winner comparisons.
  • Add tests for cases where one user has a positive final score and the other has 0.

Tip

🚀 Want to contribute?
Comment assign me to be automatically assigned to this issue via our GitHub Actions bot. Happy coding! ✨

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions