testsAndMisc/linux_configuration/tests/test_extracted_repos.sh
Krzysztof kuhy Rudnicki 1ea94e142c lan blocker: gateway mode, WARP drop with a Mon/Fri 09:00-15:30 window
Gateway mode routes LAN devices through the PC: forced DNS, DoH/DoT
dropped. The work laptop still bypassed it through Cloudflare WARP, so
the WARP ingress is dropped too. warp_window.sh opens it for the LAN
only Mon/Fri 09:00-15:30 (nft set with a timeout to 15:30), asked for
over a forced-command key by warp_home.sh, which keeps WARP off at home
otherwise because WARP fails closed. Also: dnsmasq upstreams, AAAA
filtering, DoH canary, and extracted_repo_dir resolving ~/src first
(the nightly blocklist refresh had failed since 2026-09-11).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019C8pdLR4MePsLocE1pWz7F
2026-10-25 09:52:40 +01:00

53 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Regression tests for lib/extracted_repos.sh.
#
# The 2026-09-11 home tidy moved every extracted repo from ~/<name> to
# ~/src/<name>, but extracted_repo_dir kept building ~/<name>. Every caller
# broke silently; dns-blocklist-refresh.service failed nightly for six weeks
# with "Feed generator not found: /home/kuhy/hosts-blocker/...".
set -euo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
REPO_DIR=$(cd -- "$SCRIPT_DIR/.." && pwd)
fail() {
printf 'FAIL: %s\n' "$1" >&2
exit 1
}
TMP_DIR=$(mktemp -d)
cleanup() { rm -rf "$TMP_DIR"; }
trap cleanup EXIT
# Resolve <name> against a fake home, in a clean shell, with no override set.
resolve() {
EXTRACTED_REPOS_HOME="$TMP_DIR" bash -c '
unset HOSTS_BLOCKER_DIR SCREEN_LOCKER_DIR
source "$1/lib/extracted_repos.sh"
extracted_repo_dir "$2"
' _ "$REPO_DIR" "$1"
}
# 1. Repo checked out under ~/src (the current layout) -> ~/src/<name>.
mkdir -p "$TMP_DIR/src/hosts-blocker"
got=$(resolve hosts-blocker)
[[ $got == "$TMP_DIR/src/hosts-blocker" ]] || fail "src layout: got '$got'"
# 2. Only the legacy ~/<name> checkout exists -> keep finding it.
mkdir -p "$TMP_DIR/screen-locker"
got=$(resolve screen-locker)
[[ $got == "$TMP_DIR/screen-locker" ]] || fail "legacy layout: got '$got'"
# 3. Neither exists -> ~/src/<name>, which is also where a clone lands.
got=$(resolve wake-alarm)
[[ $got == "$TMP_DIR/src/wake-alarm" ]] || fail "missing repo: got '$got'"
# 4. The per-repo override still wins over both layouts.
got=$(EXTRACTED_REPOS_HOME="$TMP_DIR" HOSTS_BLOCKER_DIR=/opt/hb bash -c '
source "$1/lib/extracted_repos.sh"; extracted_repo_dir hosts-blocker
' _ "$REPO_DIR")
[[ $got == "/opt/hb" ]] || fail "override: got '$got'"
printf 'PASS: test_extracted_repos.sh\n'