Files
cc-ci/tests/unit/test_card.py
autonomic-bot d733e2c4ca
Some checks failed
continuous-integration/drone/push Build is failing
feat(card): badge differentiates expected vs unexpected skip
The level badge gains a third segment derived from level_cap_intent:
- amber 'gap?'   when the climb was capped by an UNDECLARED gap-sensitive N/A
                 (backup_restore / functional) — a likely-missing test (unexpected skip)
- muted 'expected' when capped by a DECLARED intentional N/A (reviewed, nothing to fix)
- nothing extra for a clean cap, a full climb, or a real failure.

Font-safe text labels (no emoji) so the SVG renders headless/anywhere. Badge
never inflates — it only annotates the cap the level already reflects.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 02:26:44 +00:00

104 lines
3.6 KiB
Python

"""Unit tests for the pure card/badge renderers (harness.card), Phase 3 U2 (R3/R6).
Covers the deterministic HTML + SVG string builders (the PNG step needs Playwright + is exercised in
the U2 live demo). The cardinal check: the card REPORTS the data verbatim — level/marks come straight
from the dict, never recomputed. Run cold: cc-ci-run -m pytest tests/unit/test_card.py -q
"""
from __future__ import annotations
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
from harness import card as C # noqa: E402
def _data(level=4, cap="L5 integration (SSO/OIDC + cross-app) N/A"):
return {
"recipe": "uptime-kuma",
"version": "1.23.0",
"level": level,
"level_cap_reason": cap,
"flags": {"clean_teardown": True, "no_secret_leak": True},
"screenshot": "screenshot.png",
"stages": [
{
"name": "install",
"status": "pass",
"tests": [{"name": "test_serving", "status": "pass", "ms": 168}],
},
{
"name": "custom",
"status": "fail",
"tests": [
{"name": "test_health", "status": "pass", "ms": 17},
{"name": "test_broken", "status": "fail", "ms": 5},
],
},
],
}
def test_level_color_ramp():
assert C.level_color(0) != C.level_color(6)
assert C.level_color(6) == "#3fb950"
assert C.level_color(99) == "#8b949e" # unknown → grey
def test_badge_svg_wellformed():
svg = C.level_badge_svg(4)
assert svg.startswith("<svg") and svg.endswith("</svg>")
assert "level 4" in svg
assert C.level_color(4) in svg
# plain cap (no intent) → two-box badge, no third segment
assert "expected" not in svg and "gap?" not in svg
def test_badge_svg_differentiates_expected_vs_unexpected_skip():
# declared intentional N/A capped the climb → muted "expected" third segment
exp = C.level_badge_svg(2, "L3 backup/restore N/A", "intentional · no persistent data")
assert "level 2" in exp and "expected" in exp and C.EXPECT_COLOR in exp
assert "gap?" not in exp
# undeclared gap-sensitive N/A → amber "gap?" third segment (an UNEXPECTED skip)
gap = C.level_badge_svg(2, "L3 backup/restore N/A", "undeclared N/A — possible coverage gap")
assert "level 2" in gap and "gap?" in gap and C.GAP_COLOR in gap
assert "expected" not in gap
def test_card_html_reports_level_verbatim():
html = C.render_card_html(_data(level=2, cap="L3 backup/restore (data integrity) N/A"))
assert "uptime-kuma" in html
assert "1.23.0" in html
# the level shown is exactly what was passed (no recompute)
assert ">2<" in html
assert "L3 backup/restore" in html
assert C.level_color(2) in html
def test_card_html_shows_stage_and_test_marks():
html = C.render_card_html(_data())
assert "install" in html and "custom" in html
assert "test_serving" in html and "test_broken" in html
assert C.STATUS_MARK["pass"] in html and C.STATUS_MARK["fail"] in html
def test_card_html_flags_rendered():
html = C.render_card_html(_data())
assert "clean teardown" in html and "no secret leak" in html
def test_card_html_no_screenshot_placeholder():
d = _data()
d["screenshot"] = None
html = C.render_card_html(d)
assert "no screenshot" in html
def test_card_html_escapes_recipe_name():
d = _data()
d["recipe"] = "<script>x</script>"
html = C.render_card_html(d)
assert "<script>x" not in html
assert "&lt;script&gt;" in html