html: clamp JS-recomputed footer percentage to mirror display_covered - #2259
Open
MsfPablo wants to merge 1 commit into
Open
html: clamp JS-recomputed footer percentage to mirror display_covered#2259MsfPablo wants to merge 1 commit into
MsfPablo wants to merge 1 commit into
Conversation
The HTML index's <tfoot> Total percentage is recomputed in coverage_html.js with toFixed(), which can round to 0 or 100 even when actual coverage is not exactly 0 or 100. The <h1> heading on the same page is server-rendered via coverage.results.display_covered, which documents the invariant that "0" is only returned when the value is truly zero, and "100" is only returned when the value is truly 100. Mirror display_covered's clamp in JS so the footer can never disagree with the heading. Fixes coveragepy#2256.
Member
|
#2257 is already working on this. |
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.
Fixes #2256.
The HTML index's
<tfoot>Total percentage is recomputed incoverage_html.jswithtoFixed(), which can round to0or100%even when actual coverage is not exactly 0 or 100. The
<h1>headingon the same page is server-rendered via
coverage.results.display_covered,which documents the invariant that "0" is only returned when the value
is truly zero, and "100" is only returned when the value is truly 100.
Rounding can never result in either "0" or "100".
Since the JS handler also runs on page load (it dispatches an
inputevent unconditionally to reapply stored filters; see the comment at
the bottom of the same function), the footer is overwritten on every
page view, so the bug shows up even without typing anything into the
filter.
This patch mirrors
display_covered's clamp in JS:pc > 0andpc < 1/10**places, nudge up to1/10**places.pc < 100andpc > 100 - 1/10**places, nudge down to100 - 1/10**places.This keeps the JS-recomputed footer from disagreeing with the
server-rendered heading or the text-mode report.
Disclosed: this contribution was prepared with the help of Claude
(a large language model). The human in the loop reviewed the diff and
verified the change matches the invariant documented in
coverage/results.py::display_covered.