Files
dotfiles/tests/rebuild-update-steps.sh
T

65 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Behavior check: rebuild.sh updates every installed component that is not
# declarative, and never relies on a bare `npm`.
#
# The check is static, so it runs without changing the machine:
# - the script parses as bash;
# - every npm global is updated through /opt/homebrew/bin/npm;
# - no bare npm invocation survives;
# - each component (Homebrew, npm globals, no-mistakes, Hermes, flake inputs,
# agent skills, Pi extensions) has a named step that warns instead of
# killing the rebuild;
# - the frozen security-audit skill is excluded from the skills update.
set -euo pipefail
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
REBUILD="$ROOT/rebuild.sh"
[ -f "$REBUILD" ] || { echo "FAIL: missing $REBUILD" >&2; exit 1; }
fail() {
echo "FAIL: $1" >&2
exit 1
}
bash -n "$REBUILD" || fail "rebuild.sh does not parse"
echo "PASS: rebuild.sh parses"
grep -qF 'NPM=/opt/homebrew/bin/npm' "$REBUILD" \
|| fail "rebuild.sh does not set NPM to Homebrew's npm"
echo "PASS: npm globals use /opt/homebrew/bin/npm"
# A bare `npm install|uninstall|view|ls|root` would resolve Nix's npm under the
# activation PATH. Every call must go through $NPM.
if grep -nE '(^|[^/[:alnum:]_-])npm[[:space:]]+(install|uninstall|view|ls|root)' "$REBUILD"; then
fail "rebuild.sh calls bare npm; use \$NPM instead"
fi
echo "PASS: no bare npm invocation"
for pkg in '@steipete/bird' acpx backpass chrome-devtools-axi defuddle forgejo-axi \
gh-axi lavish-axi quota-axi tasks-axi; do
grep -qF "$pkg" "$REBUILD" || fail "rebuild.sh does not update npm global $pkg"
done
echo "PASS: every npm global has an update entry"
for step in 'Updating Homebrew formulae and casks' 'Updating npm global tools' \
'Updating no-mistakes' 'Updating Hermes Agent' 'Updating flake inputs' \
'Updating agent skills' 'Updating pi extensions'; do
grep -qF "==> $step..." "$REBUILD" || fail "rebuild.sh has no step: $step"
done
echo "PASS: every update step is present"
# Each update step reports a warning and returns instead of aborting the whole
# rebuild when its tool or network is missing.
[ "$(grep -cF '==> WARNING:' "$REBUILD")" -ge 7 ] \
|| fail "rebuild.sh is missing warning fallbacks"
grep -qF 'hermes update --yes' "$REBUILD" \
|| fail "rebuild.sh does not use the supported hermes updater"
grep -qF 'skills@latest update -g -y' "$REBUILD" \
|| fail "rebuild.sh does not use the supported Skills CLI updater"
grep -qF 'name != "security-audit"' "$REBUILD" \
|| fail "rebuild.sh does not exclude the frozen security-audit skill"
echo "PASS: update steps warn and skip instead of failing"
echo "PASS: rebuild update steps"