extract NDT7 consent check into a helper function

This commit is contained in:
Andrew Pimenov 2026-08-09 16:07:44 +03:00
parent d2ab0caafd
commit fc37ff369d
3 changed files with 19 additions and 11 deletions

View file

@ -493,6 +493,23 @@ async def diagnose(settings: Settings, options: Options) -> tuple[dict, list[Pat
return report, paths return report, paths
def _check_ndt7_consent(settings: Settings) -> bool:
consent_marker = Path(settings.output.cache_dir) / "ndt7_consent"
if consent_marker.exists():
return True
console.print(f"[yellow]{NDT7_CONSENT_NOTICE}[/yellow]")
if not sys.stdin.isatty():
return True
if typer.confirm("Continue with NDT7?", default=False):
consent_marker.parent.mkdir(parents=True, exist_ok=True)
consent_marker.write_text("consented\n", encoding="utf-8")
return True
return False
@app.command() @app.command()
def run( def run(
full: bool = typer.Option(False, "--full", help="Full run: speedtest and full MTR cycles."), full: bool = typer.Option(False, "--full", help="Full run: speedtest and full MTR cycles."),
@ -569,15 +586,7 @@ def run(
finally: finally:
probe.close() probe.close()
if ndt7: if ndt7:
consent_marker = Path(settings.output.cache_dir) / "ndt7_consent" options.ndt7 = _check_ndt7_consent(settings)
if not consent_marker.exists():
console.print(f"[yellow]{NDT7_CONSENT_NOTICE}[/yellow]")
if sys.stdin.isatty():
if typer.confirm("Continue with NDT7?", default=False):
consent_marker.parent.mkdir(parents=True, exist_ok=True)
consent_marker.write_text("consented\n", encoding="utf-8")
else:
options.ndt7 = False
if tcp_trace: if tcp_trace:
console.print( console.print(
"[yellow]--tcp-trace needs Npcap (Windows) or root (Unix) and the `tcptrace` extra; " "[yellow]--tcp-trace needs Npcap (Windows) or root (Unix) and the `tcptrace` extra; "

View file

@ -1,7 +1,6 @@
from __future__ import annotations from __future__ import annotations
import httpx import httpx
import pytest
from netsleuth.bgp import ( from netsleuth.bgp import (
classify_stability, classify_stability,

View file

@ -98,7 +98,7 @@ def test_bufferbloat_delta_needs_both_a_baseline_and_samples():
assert bufferbloat_delta(12.0, []) is None assert bufferbloat_delta(12.0, []) is None
from netsleuth.models import SpeedResult, TierAttempt from netsleuth.models import SpeedResult
from netsleuth.speed import NDT7_CONSENT_NOTICE, run_speed_cascade from netsleuth.speed import NDT7_CONSENT_NOTICE, run_speed_cascade