fix: direct-IP fallback when printer_mac unset; force utf-8 in bridge subprocess
Final-review hardening: - discover_printer falls back to direct IP reachability when printer_mac is empty (restores legacy behavior; avoids permanent unreachable on misconfig). Keeps the MAC check when a MAC IS set so we never print to a wrong DHCP tenant. - bridge subprocess decodes child stdout as utf-8 explicitly, so a LANG=C systemd locale can't UnicodeDecodeError on the success checkmark and mis-report error. - add tests for both no-MAC fallback paths (5 passed). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -498,6 +498,13 @@ def discover_printer():
|
||||
seeds.append(CACHE_FILE.read_text().strip())
|
||||
if PRINTER_IP:
|
||||
seeds.append(PRINTER_IP)
|
||||
if not PRINTER_MAC:
|
||||
# No MAC configured: fall back to direct IP reachability (legacy behavior).
|
||||
for ip in seeds:
|
||||
if ip and _port_open(ip, PRINTER_PORT):
|
||||
_cache_ip(ip)
|
||||
return ip
|
||||
raise RuntimeError("printer-not-found (no printer_mac configured)")
|
||||
for ip in seeds:
|
||||
if ip and _mac_of(ip) == PRINTER_MAC and _port_open(ip, PRINTER_PORT):
|
||||
_cache_ip(ip)
|
||||
|
||||
Reference in New Issue
Block a user