fix: reconcile final control panel coverage UX

This commit is contained in:
gti
2026-09-22 23:04:53 -03:00
parent 283749e860
commit ce606b04cc
12 changed files with 312 additions and 12 deletions
@@ -100,6 +100,70 @@ def test_dashboard_reconciles_five_health_states_and_counts_distinct_safe_produc
assert summary["online"] == 1 and summary["safe_blocked"] == 2
def test_snapshot_coverage_exposes_unclassified_residual_and_overcount():
session_factory = setup_db()
with session_factory() as session:
tenant, agent, installation, snapshot = _installation(session, 1, coverage=80, blocked=1)
snapshot.total_products = 100
snapshot.fiscally_complete = 96
snapshot.safe_blocked = 1
snapshot.failed_products = 1
session.commit()
item = list_installations(session, page_size=5)["items"][0]
assert item["unclassified_products"] == 2
assert item["coverage_overcount_products"] == 0
assert item["coverage_invariant_pass"] is True
assert item["total_products"] == item["fiscally_complete"] + item["safe_blocked"] + item["failed_products"] + item["unclassified_products"]
snapshot.fiscally_complete = 99
session.commit()
inconsistent = list_installations(session, page_size=5)["items"][0]
assert inconsistent["unclassified_products"] == 0
assert inconsistent["coverage_overcount_products"] == 1
assert inconsistent["coverage_invariant_pass"] is False
def test_dashboard_coverage_totals_reconcile_and_keep_registry_metric_separate():
session_factory = setup_db()
with session_factory() as session:
tenant, _, installation, snapshot = _installation(session, 1, coverage=96, blocked=1)
snapshot.total_products = 100
snapshot.fiscally_complete = 96
snapshot.safe_blocked = 1
snapshot.failed_products = 1
_blocker(session, tenant, product="P-OPEN", field="CFOP", index=91, installation_id=installation.id)
session.commit()
summary = dashboard_summary(session, now=NOW)
assert summary["total_products"] == 100
assert summary["fiscally_complete"] == 96
assert summary["safe_blocked"] == 1
assert summary["failed_products"] == 1
assert summary["unclassified_products"] == 2
assert summary["coverage_overcount_products"] == 0
assert summary["coverage_invariant_pass"] is True
assert summary["safe_blocked_products"] == 1
assert summary["total_products"] == summary["fiscally_complete"] + summary["safe_blocked"] + summary["failed_products"] + summary["unclassified_products"]
def test_dashboard_marks_inconsistent_snapshot_partition_instead_of_clamping():
session_factory = setup_db()
with session_factory() as session:
_, _, _, snapshot = _installation(session, 1, coverage=100, blocked=2)
snapshot.total_products = 10
snapshot.fiscally_complete = 9
snapshot.safe_blocked = 2
snapshot.failed_products = 0
session.commit()
summary = dashboard_summary(session, now=NOW)
assert summary["coverage_overcount_products"] == 1
assert summary["coverage_invariant_pass"] is False
def test_attention_items_are_ranked_and_capped_at_ten():
session_factory = setup_db()
with session_factory() as session: