mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 20:22:03 +03:00
exporter: surface a skipped module's warning as its placeholder reason
unavailable() only ever read module.errors for the placeholder detail
text, so a deliberately skipped section (speed in --quick or target
mode, which reports its reason as a warning, not an error) always
fell through to the generic 'no data was collected for this section'
line even though the real reason ('speedtest skipped in target mode')
was sitting right there in the json. spec says a skipped speedtest
must say why, not just that it's missing.
This commit is contained in:
parent
44b1c4a39d
commit
5e4aa8b101
2 changed files with 14 additions and 0 deletions
|
|
@ -208,6 +208,8 @@ def unavailable(report: dict[str, Any], section: str) -> str | None:
|
||||||
if module.get("status") in ("ok", "partial") and module.get("data") is not None:
|
if module.get("status") in ("ok", "partial") and module.get("data") is not None:
|
||||||
return None
|
return None
|
||||||
detail = "; ".join(f"{e.get('source')}: {e.get('message')}" for e in module.get("errors") or [])
|
detail = "; ".join(f"{e.get('source')}: {e.get('message')}" for e in module.get("errors") or [])
|
||||||
|
if not detail:
|
||||||
|
detail = "; ".join(module.get("warnings") or [])
|
||||||
if not detail:
|
if not detail:
|
||||||
detail = "no data was collected for this section"
|
detail = "no data was collected for this section"
|
||||||
return f"_Not available — {module.get('status', 'skipped')}: {detail}._"
|
return f"_Not available — {module.get('status', 'skipped')}: {detail}._"
|
||||||
|
|
|
||||||
|
|
@ -570,6 +570,18 @@ def test_unavailable_explains_a_skipped_module_without_inventing_an_error():
|
||||||
assert "skipped" in note
|
assert "skipped" in note
|
||||||
|
|
||||||
|
|
||||||
|
def test_unavailable_surfaces_the_skip_reason_from_warnings():
|
||||||
|
report = build_report(
|
||||||
|
meta(),
|
||||||
|
{"speed": ModuleResult(name="speed", status="skipped", warnings=["speedtest skipped in target mode"])},
|
||||||
|
[],
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
note = unavailable(report, "speed")
|
||||||
|
assert note is not None
|
||||||
|
assert "speedtest skipped in target mode" in note
|
||||||
|
|
||||||
|
|
||||||
def test_an_all_modules_failed_run_still_renders_every_section():
|
def test_an_all_modules_failed_run_still_renders_every_section():
|
||||||
text = render_markdown(dead_report())
|
text = render_markdown(dead_report())
|
||||||
headings = [line for line in text.splitlines() if line.startswith("## ")]
|
headings = [line for line in text.splitlines() if line.startswith("## ")]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue