fix: prevent self-referential DNS backup on re-install #40
Reference in New Issue
Block a user
Delete Branch "fix/stale-dns-backup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
numa installpreviously captured current system DNS servers verbatim into the backup file. If numa was already installed, current DNS was127.0.0.1, so the "backup" recorded127.0.0.1as the "original" — making a subsequentnuma uninstalla no-op self-reference.Reproduced during v0.10.0 brew dogfood: after
sudo numa uninstall(which removed the backup) thensudo /opt/homebrew/bin/numa install(which re-captured, but system DNS was still 127.0.0.1 from a prior install that hadn't been cleanly reverted),sudo numa uninstallprinted:Fix
All three platforms, same pattern:
Tests
Three new unit tests cover the predicates:
macos_backup_real_upstream_detection—HashMapwith empty, all-loopback, and mixed entrieswindows_backup_filters_loopback— filter logic onWindowsInterfaceDns(added in a follow-up commit, reviewed for parity with the macOS test)resolv_conf_real_upstream_detection— real upstream, self-referential, numa marker, systemd stub (127.0.0.53), and mixed contentAll 130 existing + new tests pass locally and on CI.
Test plan
sudo numa installa second time reportsExisting DNS backup preservedand leaves the backup file untouched. Verified manually on macOS with a fabricated{"Wi-Fi": ["1.1.1.1", "8.8.8.8"]}backup (the dogfood machine had been numa-managed long enough that no useful pre-numa backup existed naturally — the predicate path that fires the preserve branch needs ≥1 non-loopback upstream in the existing file).sudo numa installcaptures real upstreams (or empty = DHCP) rather than 127.0.0.1. Verified manually on macOS — the resulting backup contained{"Wi-Fi": [], ...}(filtered loopback → empty → restore-to-DHCP), not the buggy{"Wi-Fi": ["127.0.0.1"]}that v0.10.0 produced.