2026-11-29 10:37:58 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# Check that the Nix source wires the Brave-only bird wrapper into the shell.
|
|
|
|
|
#
|
|
|
|
|
# The Bird merge added home.file entries for the wrapper and the Brave config,
|
|
|
|
|
# but no PATH entry. A rebuild installs the wrapper at ~/.pi/agent/bin/bird and
|
|
|
|
|
# leaves `bird` resolving to Homebrew's npm shim. This check evaluates the real
|
|
|
|
|
# home-manager config, then runs the generated zshrc in a fresh zsh with a fake
|
|
|
|
|
# Homebrew bird ahead of the wrapper. It passes only when the wrapper wins.
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
|
|
|
|
|
TMP=$(mktemp -d "${TMPDIR:-/tmp}/bird-path.XXXXXX")
|
|
|
|
|
trap 'rm -rf "$TMP"' EXIT
|
|
|
|
|
|
|
|
|
|
fail() { printf 'FAIL: %s\n' "$1" >&2; exit 1; }
|
|
|
|
|
pass() { printf 'PASS: %s\n' "$1"; }
|
|
|
|
|
|
|
|
|
|
command -v nix >/dev/null 2>&1 \
|
|
|
|
|
|| { echo "bird-path: nix is required to evaluate the configuration" >&2; exit 2; }
|
|
|
|
|
command -v jq >/dev/null 2>&1 \
|
|
|
|
|
|| { echo "bird-path: jq is required to read the session path" >&2; exit 2; }
|
|
|
|
|
command -v zsh >/dev/null 2>&1 \
|
|
|
|
|
|| { echo "bird-path: zsh is required to run the generated zshrc" >&2; exit 2; }
|
|
|
|
|
|
|
|
|
|
CONFIG='(builtins.getFlake (toString '"$ROOT"')).darwinConfigurations."lt-mbp".config.home-manager.users.laptran'
|
|
|
|
|
|
|
|
|
|
wrapper_source=$(nix eval --raw --impure --expr "$CONFIG.home.file.\".pi/agent/bin/bird\".source")
|
|
|
|
|
wrapper_target=$(readlink "$wrapper_source" 2>/dev/null || printf '%s' "$wrapper_source")
|
|
|
|
|
case "$wrapper_target" in
|
|
|
|
|
*"home/.pi/agent/bin/bird") pass "source declares the Brave-only bird wrapper" ;;
|
|
|
|
|
*) fail "wrapper home.file source points to $wrapper_target" ;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
nix eval --json --impure --expr "$CONFIG.home.sessionPath" > "$TMP/session-path.json"
|
|
|
|
|
first_path=$(jq -r '.[0] // ""' "$TMP/session-path.json")
|
|
|
|
|
case "$first_path" in
|
|
|
|
|
*"/.pi/agent/bin") pass "session PATH puts the wrapper directory first" ;;
|
|
|
|
|
*) fail "first session PATH entry is '$first_path', not the bird wrapper directory" ;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
nix eval --raw --impure --expr "$CONFIG.home.file.\"./.zshrc\".text" > "$TMP/zshrc"
|
|
|
|
|
mkdir -p "$TMP/home/.pi/agent/bin" "$TMP/homebrew/bin"
|
|
|
|
|
printf '#!/bin/sh\nprintf wrapper\n' > "$TMP/home/.pi/agent/bin/bird"
|
|
|
|
|
printf '#!/bin/sh\nprintf homebrew\n' > "$TMP/homebrew/bin/bird"
|
|
|
|
|
chmod +x "$TMP/home/.pi/agent/bin/bird" "$TMP/homebrew/bin/bird"
|
|
|
|
|
|
2026-11-29 13:22:54 -05:00
|
|
|
# shellcheck disable=SC2016 # the snippet expands inside the fresh zsh
|
2026-11-29 10:37:58 -05:00
|
|
|
resolved=$(HOME="$TMP/home" ZSHRC="$TMP/zshrc" \
|
|
|
|
|
PATH="$TMP/homebrew/bin:/usr/bin:/bin" \
|
|
|
|
|
timeout 60 zsh -f -i -c '
|
|
|
|
|
source "$ZSHRC" >/dev/null 2>&1 || exit 4
|
|
|
|
|
command -v bird
|
|
|
|
|
' 2>"$TMP/stderr") || {
|
|
|
|
|
echo "bird-path: failed to run generated zshrc" >&2
|
|
|
|
|
cat "$TMP/stderr" >&2
|
|
|
|
|
exit 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ "$resolved" = "$TMP/home/.pi/agent/bin/bird" ] \
|
|
|
|
|
|| fail "generated zshrc resolves bird to $resolved instead of the wrapper"
|
|
|
|
|
|
|
|
|
|
pass "generated zshrc resolves bird to the wrapper ahead of Homebrew"
|