Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/305.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix inverted SparklineData direction semantics for lower-is-better metrics in _make_report_with_sparklines test helper.
39 changes: 38 additions & 1 deletion tests/test_report_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
Expand Down Expand Up @@ -4509,6 +4509,43 @@ def test_degraded_gracefully_without_sparklines(self, tmp_path: Path) -> None:
# No SVG polyline (sparklines not provided)
assert "<polyline" not in content

def test_rework_cycles_lower_is_better_direction_is_up(self) -> 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)
Expand Down
Loading