Context
PR #156 added 3 tests to defend against #155's silent failure (proxy binary missing → DNS mode looks enabled but port 53 has no listener):
test_pid_file_content_format — asserts the script contains expected echo "$PROXY_PID ..." line
test_enable_script_contains_safety_layers — asserts the script has [ ! -x ] / kill -0 / log dump / PROXY_PID / networksetup ordering
test_enable_script_loudly_fails_when_proxy_missing — runs a 6-line [ ! -x ] snippet through /bin/sh
Problem: the first two rebuild the script with their own format! macro call instead of invoking the production enable_dns_mode script generator. The shell test executes only a synthetic snippet, not the real PROXY_PID / kill -0 / log-dump path.
Net effect: reverting enable_dns_mode to the old set -e + cmd & echo "\$! ..." buggy form would keep all 3 tests passing. The tests guard against script-shape regression, not against silent failure on production paths.
Repro
git checkout fix/dns-mode-silent-failure-155 -- src-tauri/crates/mhost-dns/src/platform.rs
# revert just the script body inside enable_dns_mode to the old `echo "$! {proxy}"` form
cargo test --package mhost-dns --lib test_enable_script_contains_safety_layers test_pid_file_content_format test_enable_script_loudly_fails_when_proxy_missing
# All 3 pass against the buggy version
Fix
Extract production builders and have all tests consume them:
// in platform.rs
pub(crate) fn build_enable_script(
proxy_path: &Path, dns_port: u16, pid_file: &Path, log_path: &Path, interface: &str,
) -> String { /* the actual script body */ }
pub(crate) fn validate_proxy_binary(path: &Path) -> Result<(), PlatformError> { /* pre-check */ }
Test refactor:
- Structural tests consume
build_enable_script(...) directly — assert against the production string.
- Execution test writes the production script to a temp file, swaps in fake
mhost-dns-proxy (long-running script that just sleeps) and fake networksetup (writes args to a log file, exits 0 or non-zero per flag), runs /bin/sh on it with MHOST_RUNTIME_DIR=/tmp/path with space and interface="Thunderbolt Ethernet", asserts:
- Cover:
- Path containing spaces (PID file / log / runtime_dir)
- Interface containing spaces
- Delayed proxy startup (kill -0 retry loop with timeout)
- Proxy bind failure (early exit before bind)
networksetup failure post-proxy-startup (transactional cleanup)
Linked
Context
PR #156 added 3 tests to defend against #155's silent failure (proxy binary missing → DNS mode looks enabled but port 53 has no listener):
test_pid_file_content_format— asserts the script contains expectedecho "$PROXY_PID ..."linetest_enable_script_contains_safety_layers— asserts the script has[ ! -x ]/kill -0/ log dump /PROXY_PID/networksetuporderingtest_enable_script_loudly_fails_when_proxy_missing— runs a 6-line[ ! -x ]snippet through/bin/shProblem: the first two rebuild the script with their own
format!macro call instead of invoking the productionenable_dns_modescript generator. The shell test executes only a synthetic snippet, not the realPROXY_PID/kill -0/ log-dump path.Net effect: reverting
enable_dns_modeto the oldset -e + cmd & echo "\$! ..."buggy form would keep all 3 tests passing. The tests guard against script-shape regression, not against silent failure on production paths.Repro
Fix
Extract production builders and have all tests consume them:
Test refactor:
build_enable_script(...)directly — assert against the production string.mhost-dns-proxy(long-running script that just sleeps) and fakenetworksetup(writes args to a log file, exits 0 or non-zero per flag), runs/bin/shon it withMHOST_RUNTIME_DIR=/tmp/path with spaceandinterface="Thunderbolt Ethernet", asserts:networksetupfailure post-proxy-startup (transactional cleanup)Linked