From 3425e87dbfdd449fb4fcb8e115f8f4639fc404b0 Mon Sep 17 00:00:00 2001 From: Andrew Pimenov Date: Sun, 9 Aug 2026 03:43:57 +0300 Subject: [PATCH] interpret: label a non-responding hop instead of printing None a hop with no icmp reply has ip=None; the sustained-loss finding formatted it straight into the report text as the literal string '(None)'. seen live in a --quick smoke test report. --- src/netcheck/interpret.py | 2 +- tests/test_interpret.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/netcheck/interpret.py b/src/netcheck/interpret.py index 54efdc8..53daa2b 100644 --- a/src/netcheck/interpret.py +++ b/src/netcheck/interpret.py @@ -125,7 +125,7 @@ def path_findings(trace: TraceResult) -> list[Finding]: id="path.loss_jump", severity="crit" if hop.loss_pct >= 50.0 else "warn", title="Sustained loss starts mid-path", - detail=f"Loss appears at hop {hop.ttl} ({hop.ip}) at {hop.loss_pct}% and persists downstream.", + detail=f"Loss appears at hop {hop.ttl} ({hop.ip or 'no reply'}) at {hop.loss_pct}% and persists downstream.", metric="loss_pct", value=hop.loss_pct, threshold=20.0, diff --git a/tests/test_interpret.py b/tests/test_interpret.py index 73f540e..516d913 100644 --- a/tests/test_interpret.py +++ b/tests/test_interpret.py @@ -118,6 +118,24 @@ def test_path_findings_highlight_the_first_sustained_loss_jump(): assert "198.51.100.7" in loss.detail +def test_path_findings_label_a_non_responding_hop_instead_of_printing_none(): + trace = TraceResult( + target="1.1.1.1", + resolved_ip="1.1.1.1", + backend="mtr_json", + hops=[ + TraceHop(ttl=1, ip="192.168.1.1", loss_pct=0.0, avg_ms=1.0), + TraceHop(ttl=2, ip=None, loss_pct=100.0, avg_ms=None), + TraceHop(ttl=3, ip="1.1.1.1", loss_pct=100.0, avg_ms=None), + ], + completed=True, + ) + findings = path_findings(trace) + loss = [f for f in findings if f.id == "path.loss_jump"][0] + assert "None" not in loss.detail + assert "no reply" in loss.detail + + def test_path_findings_ignore_a_single_hop_that_rate_limits_icmp(): trace = TraceResult( target="1.1.1.1",