From 5b22f50be34dcdd8f5a7526994ac174516d8f0e4 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 21 Sep 2026 10:50:25 +0200 Subject: [PATCH 1/2] Stub route discovery in network QR tests --- test/shell.d/network-qr-test.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/shell.d/network-qr-test.sh b/test/shell.d/network-qr-test.sh index 7c64ef28..071950a9 100644 --- a/test/shell.d/network-qr-test.sh +++ b/test/shell.d/network-qr-test.sh @@ -8,6 +8,12 @@ tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT mkdir -p "$tmp/bin" +# Loopback is never wireless, so exercise the connected-Wi-Fi fallback. +cat >"$tmp/bin/ip" <<'EOF' +#!/bin/bash +printf '1.1.1.1 dev lo\n' +EOF + cat >"$tmp/bin/nmcli" <<'EOF' #!/bin/bash if [[ $* == *"DEVICE,TYPE,STATE"* ]]; then @@ -28,13 +34,13 @@ payload=$("$QR_PAYLOAD_FILE" printf '## \n ## \n ##\n' EOF -chmod +x "$tmp/bin/nmcli" "$tmp/bin/qrencode" +chmod +x "$tmp/bin/ip" "$tmp/bin/nmcli" "$tmp/bin/qrencode" run_success_case() { local description=$1 fields=$2 expected_payload=$3 shift 3 local output meta matrix payload arg with_meta=false - local expected_matrix expected_security expected_ssid expected_iface="*" + local expected_matrix expected_security expected_ssid expected_iface="wlan0" for arg in "$@"; do [[ $arg == "--meta" ]] && with_meta=true || expected_iface=$arg @@ -49,9 +55,8 @@ run_success_case() { meta=$(head -n1 <<<"$output") matrix=$(tail -n +2 <<<"$output") - # The meta line leads with the shared interface, security, and SSID. With - # no interface argument the helper detects one from the live host, so that - # field is only pinned when the case pinned it. + # The metadata reports the requested interface, or the connected Wi-Fi + # interface supplied by the nmcli stub when no interface was requested. expected_security=${expected_payload#WIFI:T:} expected_security=${expected_security%%;*} expected_ssid=$(head -n1 <<<"$fields") From 5c2be2e6532a509a0db8ccb6a874f99b5b26c6ed Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 21 Sep 2026 10:54:38 +0200 Subject: [PATCH 2/2] Fix Wi-Fi QR fallback after failed route lookup --- bin/omarchy-network-qr | 4 +++- test/shell.d/network-qr-test.sh | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/omarchy-network-qr b/bin/omarchy-network-qr index 9502c25c..fb1c6696 100755 --- a/bin/omarchy-network-qr +++ b/bin/omarchy-network-qr @@ -22,7 +22,9 @@ if [[ -z $interface ]]; then # menu's visibility gate describe. Fall back to the first connected Wi-Fi # device. nmcli localizes state names, so pin the locale, and the prefix # match accepts states like "connected (externally)". - route_device=$(ip route get 1.1.1.1 2>/dev/null | awk '{ for (i = 1; i <= NF; i++) if ($i == "dev") { print $(i + 1); exit } }') + if ! route_device=$(ip route get 1.1.1.1 2>/dev/null | awk '{ for (i = 1; i <= NF; i++) if ($i == "dev") { print $(i + 1); exit } }'); then + route_device="" + fi if [[ -n $route_device && -d /sys/class/net/$route_device/wireless ]]; then interface=$route_device else diff --git a/test/shell.d/network-qr-test.sh b/test/shell.d/network-qr-test.sh index 071950a9..7e54ad43 100644 --- a/test/shell.d/network-qr-test.sh +++ b/test/shell.d/network-qr-test.sh @@ -7,10 +7,12 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT mkdir -p "$tmp/bin" +export QR_ROUTE_EXIT=0 # Loopback is never wireless, so exercise the connected-Wi-Fi fallback. cat >"$tmp/bin/ip" <<'EOF' #!/bin/bash +[[ $QR_ROUTE_EXIT == "0" ]] || exit "$QR_ROUTE_EXIT" printf '1.1.1.1 dev lo\n' EOF @@ -93,6 +95,12 @@ run_success_case \ 'WIFI:T:WPA;S:Cafe Detected;P:secret;;' \ --meta +QR_ROUTE_EXIT=2 run_success_case \ + "network QR helper detects Wi-Fi when route lookup fails" \ + $'Cafe No Route\nwpa-psk\nsecret\nno\n' \ + 'WIFI:T:WPA;S:Cafe No Route;P:secret;;' \ + --meta + run_success_case \ "network QR helper supports open networks" \ $'Cafe Open\nnone\n\nno\n' \