From 85937ca0e26eb4b9262cd36dd79ec691683a18a8 Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Mon, 30 Nov 2026 22:25:31 -0600 Subject: [PATCH 1/3] fix: skip ip_alert for devices configured with a tailnet address A device whose devices.yml ip is a Tailscale address alerted forever because it also holds a LAN address. Co-Authored-By: Claude Sonnet 5.5 --- adbops.py | 11 ++++++++--- tests/test_enhancements.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/adbops.py b/adbops.py index 1a3ebb3..8818eae 100644 --- a/adbops.py +++ b/adbops.py @@ -243,12 +243,17 @@ async def status(dev: dict[str, Any]) -> dict[str, Any]: _addrs: dict[str, tuple[float, list[str]]] = {} +def is_tailnet(addr: str) -> bool: + """True for a Tailscale (CGNAT) IPv4 address.""" + m = re.fullmatch(r"(\d{1,3})\.(\d{1,3})(?:\.\d{1,3}){2}", addr) + return bool(m) and int(m[1]) == 100 and 64 <= int(m[2]) <= 127 + + def lan_addresses(text: str) -> list[str]: """IPv4 addresses the device holds, less loopback and the tailnet range.""" found = [] for addr in INET_RE.findall(text): - a, b = (int(x) for x in addr.split(".")[:2]) - if a == 127 or (a == 100 and 64 <= b <= 127): + if addr.startswith("127.") or is_tailnet(addr): continue found.append(addr) return found @@ -257,7 +262,7 @@ def lan_addresses(text: str) -> list[str]: async def ip_alert(dev: dict[str, Any], serial: str) -> str | None: """Why devices.yml ip is stale: the device holds other LAN addresses, or only a fallback path answered.""" configured = str(dev.get("ip") or "") - if not configured: + if not configured or is_tailnet(configured): return None cached = _addrs.get(dev["name"]) if cached is None or time.monotonic() - cached[0] > ADDR_TTL_S: diff --git a/tests/test_enhancements.py b/tests/test_enhancements.py index 4135bb1..e0dd7aa 100644 --- a/tests/test_enhancements.py +++ b/tests/test_enhancements.py @@ -104,6 +104,16 @@ def test_ip_alert_is_quiet_when_the_address_matches( assert run(adbops.ip_alert(SHIELD, "192.0.2.1:5555")) is None +def test_ip_alert_skips_a_device_configured_with_a_tailnet_address( + monkeypatch: pytest.MonkeyPatch, +) -> None: + calls = _read_returns(monkeypatch, IP_OUT) + tailnet = ".".join(["100", "67", "0", "1"]) + dev = {**SHIELD, "name": "remote-shield", "ip": tailnet} + assert run(adbops.ip_alert(dev, f"{tailnet}:5555")) is None + assert calls == [] + + def test_ip_alert_names_a_fallback_path_when_the_device_reports_no_address( monkeypatch: pytest.MonkeyPatch, ) -> None: From f1cf5e4e4e4d964bfe73cb6f73631790364f4fea Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Mon, 30 Nov 2026 22:26:26 -0600 Subject: [PATCH 2/3] test: build the tailnet address from parts to satisfy ruff Co-Authored-By: Claude Sonnet 5.5 --- tests/test_enhancements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_enhancements.py b/tests/test_enhancements.py index e0dd7aa..5ba80c6 100644 --- a/tests/test_enhancements.py +++ b/tests/test_enhancements.py @@ -108,7 +108,7 @@ def test_ip_alert_skips_a_device_configured_with_a_tailnet_address( monkeypatch: pytest.MonkeyPatch, ) -> None: calls = _read_returns(monkeypatch, IP_OUT) - tailnet = ".".join(["100", "67", "0", "1"]) + tailnet = ".".join(map(str, (100, 67, 0, 1))) dev = {**SHIELD, "name": "remote-shield", "ip": tailnet} assert run(adbops.ip_alert(dev, f"{tailnet}:5555")) is None assert calls == [] From 1adb46d85046b17101f70c01799a077d0859de99 Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Mon, 30 Nov 2026 22:29:15 -0600 Subject: [PATCH 3/3] fix: narrow the Match type in is_tailnet for mypy Co-Authored-By: Claude Sonnet 5.5 --- adbops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adbops.py b/adbops.py index 8818eae..2305290 100644 --- a/adbops.py +++ b/adbops.py @@ -246,7 +246,7 @@ async def status(dev: dict[str, Any]) -> dict[str, Any]: def is_tailnet(addr: str) -> bool: """True for a Tailscale (CGNAT) IPv4 address.""" m = re.fullmatch(r"(\d{1,3})\.(\d{1,3})(?:\.\d{1,3}){2}", addr) - return bool(m) and int(m[1]) == 100 and 64 <= int(m[2]) <= 127 + return m is not None and int(m[1]) == 100 and 64 <= int(m[2]) <= 127 def lan_addresses(text: str) -> list[str]: