diff --git a/changes/305.fix b/changes/305.fix new file mode 100644 index 0000000..acfcff6 --- /dev/null +++ b/changes/305.fix @@ -0,0 +1 @@ +Fix inverted SparklineData direction semantics for lower-is-better metrics in _make_report_with_sparklines test helper. diff --git a/tests/test_report_html.py b/tests/test_report_html.py index 1eef5b2..ae29ea8 100644 --- a/tests/test_report_html.py +++ b/tests/test_report_html.py @@ -4406,7 +4406,7 @@ def _make_report_with_sparklines(self) -> tuple: normalized=[1.0, 0.5, 0.0], delta=-0.3, pct_delta=30.0, - direction="down", + direction="up", value_direction="down", ), } @@ -4509,6 +4509,43 @@ def test_degraded_gracefully_without_sparklines(self, tmp_path: Path) -> None: # No SVG polyline (sparklines not provided) assert " None: + """rework_cycles values going down = improvement for a lower-is-better metric. + + When rework_cycles decreases (delta < 0), the semantic ``direction`` field must + be ``"up"`` (green / improving), NOT ``"down"`` (red / declining). + ``value_direction`` correctly tracks the raw numeric movement (down), while + ``direction`` reflects whether the change is an improvement. + """ + _, sparklines = self._make_report_with_sparklines() + rework_sd = sparklines["rework_cycles"] + assert rework_sd.direction == "up", ( + f"rework_cycles is lower-is-better; values=[1.5, 1.2, 0.9] (decreasing) " + f"is an improvement and must yield direction='up' (green), " + f"got direction={rework_sd.direction!r}" + ) + + def test_rework_cycles_delta_badge_no_red_css_class(self, tmp_path: Path) -> None: + """rework_cycles improvement must NOT render with delta-down CSS class (red). + + When rework_cycles decreases (lower-is-better improvement), the delta badge + must NOT use ``delta-down`` (red); it must use ``delta-up`` (green). + The fixture provides only two sparklines: first_pass_success_rate (direction='up') + and rework_cycles (direction must be 'up' after fix), so no delta-down should appear. + """ + from raki.report.html_report import write_html_report + + report, sparklines = self._make_report_with_sparklines() + output = tmp_path / "report.html" + write_html_report(report, output, sparklines=sparklines) + content = output.read_text() + # CSS always defines `.delta-badge.delta-down { ... }`, so we check for the + # HTML element attribute pattern instead of the bare string "delta-down". + assert 'class="delta-badge delta-down"' not in content, ( + "rework_cycles is lower-is-better and values improved (1.5→0.9); " + "the rendered delta badge must NOT use delta-down (red CSS class)" + ) + # --------------------------------------------------------------------------- # Task 4: Cross-check parametrized tests for CLI/HTML threshold parity (#300)