From 1e75dc27d1e6c0387dc7ab81a2a36f8b73e49b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20=22decko=22=20de=20Brito?= Date: Tue, 26 May 2026 16:43:54 -0300 Subject: [PATCH 1/2] test(report): fix inverted SparklineData direction semantics for lower-is-better metrics in _make_report_with_sparklines (#305) The _make_report_with_sparklines helper in TestSparklineSvgRendering had rework_cycles SparklineData with direction='down', but since rework_cycles is a lower-is-better metric and values [1.5, 1.2, 0.9] are decreasing (improvement), the semantic direction field must be 'up' (green/improving). Two fixes: 1. Change direction='down' to direction='up' in the rework_cycles fixture so it correctly reflects the polarity-aware improvement semantics. 2. Fix the test_rework_cycles_delta_badge_no_red_css_class assertion to check for the HTML element class attribute pattern ('class="delta-badge delta-down"') rather than the bare string 'delta-down', which also appears in the CSS definition (.delta-badge.delta-down { ... }) and would always fail. --- tests/test_report_html.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) 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) From aec6af3745b70ed4e25e32d6bf494430fc52d4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20=22decko=22=20de=20Brito?= Date: Tue, 26 May 2026 16:53:51 -0300 Subject: [PATCH 2/2] chore: add towncrier fragment for #305 --- changes/305.fix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/305.fix 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.