herdr hook files are herdr-managed, so none is committed. The installer ends by running `herdr integration install <agent>` for each of claude, codex, pi and omp that is present, skipping any herdr already reports current and saying nothing when herdr is absent. Seal and fake learn herdr; tests and two mutations cover install, idempotence, failure and absence (G-AG-5).
1565 lines
92 KiB
Bash
Executable File
1565 lines
92 KiB
Bash
Executable File
#!/bin/sh
|
|
# dotup test suite.
|
|
#
|
|
# Everything here is pty-free and runs unchanged in a container: the toggle
|
|
# rule is pure state-file logic, the match-confinement test uses
|
|
# `fzf --filter`, which is non-interactive, and the installer is driven against
|
|
# a directory of fake package managers that record what they were asked to do
|
|
# and install nothing. The one test that genuinely needs a terminal is fenced
|
|
# off at the bottom and skips cleanly without one.
|
|
#
|
|
# sh .tests/test.sh on the host
|
|
# sh .tests/test.sh --docker in a clean ubuntu:24.04 container
|
|
#
|
|
# NOTHING IN THIS FILE INSTALLS A PACKAGE. If you add a case that could, it
|
|
# belongs in a container and behind an explicit opt-in, not here.
|
|
|
|
set -eu
|
|
cd "$(dirname "$0")"
|
|
|
|
if [ "${1:-}" = "--docker" ]; then
|
|
# curl and script are here so the pty test runs too: the container has
|
|
# apt's fzf 0.44.1, not whatever the dev box has, and the cursor-on-reload
|
|
# behaviour is the one property that must hold on the older release.
|
|
exec docker run --rm -v "$(cd .. && pwd):/w:ro" "${DOTUP_TEST_IMAGE:-ubuntu:24.04}" sh -c '
|
|
apt-get update -qq
|
|
apt-get install -y -qq fzf curl ca-certificates xz-utils >/dev/null 2>&1
|
|
cp -r /w /work && cd /work/.tests && rm -rf state fzfver
|
|
echo " distro fzf: $(fzf --version 2>/dev/null || echo none)"
|
|
sh ../dot_local/bin/executable_dotup preflight # exactly what a real run does first
|
|
exec sh test.sh'
|
|
fi
|
|
|
|
ROOT=$(CDPATH= cd -- .. && pwd)
|
|
D=$ROOT/dot_local/bin/executable_dotup
|
|
M=$ROOT/dot_local/share/dotup/packages.tsv
|
|
export DOTUP_STATE=$PWD/state
|
|
export DOTUP_MANIFEST=$M
|
|
|
|
pass=0; fail=0
|
|
ok() { pass=$((pass+1)); printf ' \033[32mok\033[0m %s\n' "$1"; }
|
|
no() { fail=$((fail+1)); printf ' \033[31mFAIL\033[0m %s\n' "$1"; }
|
|
is() { # is <desc> <expected> <actual>
|
|
if [ "$2" = "$3" ]; then ok "$1"; else no "$1 — want [$2] got [$3]"; fi
|
|
}
|
|
has() { # has <desc> <needle> <haystack>
|
|
case $3 in *"$2"*) ok "$1" ;; *) no "$1 — [$2] not in output" ;; esac
|
|
}
|
|
hasnt(){ # hasnt <desc> <needle> <haystack>
|
|
case $3 in *"$2"*) no "$1 — [$2] IS in output" ;; *) ok "$1" ;; esac
|
|
}
|
|
# Normalise before parsing: "[x]" is one awk field but "[ ]" is two, so column
|
|
# positions shift with tick state. Collapse the box to a single token first.
|
|
rows() { sh $D render | sed 's/\x1b\[[0-9;]*m//g; s/\[[x~ ]\]/BOX/'; }
|
|
grp() { rows | awk -v g="$1" '$1!="BOX" && $3==g {print $4}'; }
|
|
# Every selected key matching a flag. Trailing ":" keeps a failed grep on the
|
|
# last item from tripping set -e via the loop's exit status.
|
|
picked(){ awk -F'\t' -v f="$1" '!/^#/ && !/^@/ && NF>=3 && $3==f {print $1"/"$2}' "$M" \
|
|
| while read -r k; do grep -qxF "$k" state/selected && echo "$k"; done; :; }
|
|
missed(){ awk -F'\t' -v f="$1" '!/^#/ && !/^@/ && NF>=3 && $3==f {print $1"/"$2}' "$M" \
|
|
| while read -r k; do grep -qxF "$k" state/selected || echo "$k"; done; :; }
|
|
reset() { rm -rf state; sh $D preset defaults; }
|
|
|
|
# ---------------------------------------------------------------- the seal ---
|
|
# The old harness put .tests/fakebin at the FRONT of $PATH. That fails OPEN: a
|
|
# package manager with no fake fell through to the real one, and an audit of
|
|
# this suite ran the host's actual `brew`. Everything below runs under a SEALED
|
|
# PATH instead (see seal.sh) with `env -i`, so the run inherits nothing at all
|
|
# and a tool nobody thought to fake is command-not-found rather than the
|
|
# machine's own copy.
|
|
SEAL=${TMPDIR:-/tmp}/dotup-seal.$$
|
|
SEALSUDO=${TMPDIR:-/tmp}/dotup-seal-sudo.$$
|
|
sh ./seal.sh "$SEAL" >/dev/null
|
|
sh ./seal.sh "$SEALSUDO" --with sudo >/dev/null
|
|
BOXN=0; SB=; LOG=; BOXENV=; BOXPATH=$SEAL; PW=
|
|
# agents/specify-cli was the manifest's only uv row, and it is gone: broken on
|
|
# dev and unused. The uv CHANNEL stays -- it is a channel, not a package -- so
|
|
# its tests run against the real manifest plus one fixture row, inserted beside
|
|
# the agents it would belong with so the group stays one contiguous run.
|
|
UVM=${TMPDIR:-/tmp}/dotup-uvm.$$
|
|
awk -F'\t' '{ print }
|
|
$1=="agents" && $2=="herdr" {
|
|
print "@needs\tagents/uv-fixture\tcore/uv"
|
|
print "agents\tuv-fixture\tsafe\t-uv\t-uv\tfixture for the uv channel" }' "$M" > "$UVM"
|
|
cleanup_boxes() { rm -rf "$SEAL" "$SEALSUDO" "$UVM" ${TMPDIR:-/tmp}/dotup-box."$$".* \
|
|
${TMPDIR:-/tmp}/dotup-sealtest."$$" ; }
|
|
trap cleanup_boxes EXIT INT TERM
|
|
|
|
# A fresh $HOME per case, because find_tool probes ~/.local/bin, ~/bin and
|
|
# ~/.npm-global/bin: a run against the developer's real $HOME is a run against
|
|
# whatever the developer happens to have installed.
|
|
newbox() {
|
|
BOXN=$((BOXN+1)); SB=${TMPDIR:-/tmp}/dotup-box.$$.$BOXN
|
|
rm -rf "$SB"; mkdir -p "$SB/.config/dotfiles" "$SB/tmp" "$SB/.local/bin"
|
|
: > "$SB/.config/dotfiles/expanded"; : > "$SB/.config/dotfiles/selected"
|
|
LOG=$SB/calls.log; : > "$LOG"; BOXENV=; BOXPATH=$SEAL
|
|
}
|
|
# $BOXENV is deliberately unquoted: it is a list of NAME=VALUE words to add.
|
|
box() { env -i HOME="$SB" PATH="$BOXPATH" TERM=dumb LANG=C TMPDIR="$SB/tmp" \
|
|
DOTUP_STATE="$SB/.config/dotfiles" DOTUP_MANIFEST="$M" \
|
|
DOTUP_TEST_LOG="$LOG" $BOXENV "$BOXPATH/sh" $D "$@"; }
|
|
boxrc() { c=0; box "$@" >/dev/null 2>&1 || c=$?; echo "$c"; }
|
|
pick() { printf '%s\n' "$@" > "$SB/.config/dotfiles/selected"; }
|
|
# A seal with a hole in it, for the cases whose whole point is that a tool is
|
|
# NOT there. Refuses if the host would satisfy the lookup anyway through one of
|
|
# find_tool's four absolute probes -- an absence that is not real would make the
|
|
# assertion pass for the wrong reason.
|
|
holed() {
|
|
sh ./seal.sh "$SB/seal" --without "$@" >/dev/null
|
|
BOXPATH=$SB/seal
|
|
for h in "$@"; do
|
|
grep -q "^$h " "$SB/seal/.shadowed" 2>/dev/null && return 1
|
|
done
|
|
return 0
|
|
}
|
|
# Everything a run wrote, colour stripped.
|
|
plain() { sed 's/\x1b\[[0-9;]*m//g'; }
|
|
|
|
printf '\n\033[1mtoggle rule\033[0m\n'
|
|
reset
|
|
is "package off -> group goes partial" "2/3" \
|
|
"$(sh $D toggle p:media/sox >/dev/null; grp media)"
|
|
is "group partial -> all on" "3/3" \
|
|
"$(sh $D toggle g:media >/dev/null; grp media)"
|
|
is "group full -> all off" "0/3" \
|
|
"$(sh $D toggle g:media >/dev/null; grp media)"
|
|
is "group empty -> all on" "3/3" \
|
|
"$(sh $D toggle g:media >/dev/null; grp media)"
|
|
is "bulk, mixed set -> all on" "3/3" \
|
|
"$(sh $D toggle p:gpu/cuda-toolkit >/dev/null
|
|
sh $D toggle p:gpu/nvidia-driver p:gpu/cuda-toolkit p:gpu/container-toolkit >/dev/null
|
|
grp gpu)"
|
|
is "bulk, all on -> all off" "0/3" \
|
|
"$(sh $D toggle p:gpu/nvidia-driver p:gpu/cuda-toolkit p:gpu/container-toolkit >/dev/null
|
|
grp gpu)"
|
|
|
|
printf '\n\033[1mdependencies — @needs auto-ticks, both directions\033[0m\n'
|
|
on() { grep -qxF "$1" state/selected && echo on || echo off; }
|
|
reset; sh $D toggle p:networking/xrdp >/dev/null
|
|
is "ticking xrdp pulls in the desktop group" "2/2" "$(grp desktop)"
|
|
sh $D toggle g:desktop >/dev/null
|
|
is "unticking desktop drops xrdp" "off" "$(on networking/xrdp)"
|
|
is "unticking desktop drops xorgxrdp" "off" "$(on networking/xorgxrdp)"
|
|
reset; sh $D toggle p:gpu/container-toolkit >/dev/null
|
|
is "container-toolkit pulls in docker" "3/3" "$(grp docker)"
|
|
reset; sh $D toggle p:core/node >/dev/null
|
|
is "dropping node drops codex" "off" "$(on agents/codex)"
|
|
is "dropping node drops mermaid-cli" "off" "$(on core/mermaid-cli)"
|
|
is "…and transitively drops neovim" "off" "$(on core/neovim)"
|
|
is "but leaves unrelated packages be" "on" "$(on core/ripgrep)"
|
|
# The directives must not leak into package parsing.
|
|
is "@needs lines are not packages" "" \
|
|
"$(rows | awk '$1!="BOX" && $3 ~ /@/ {print $3}')"
|
|
is "group count unchanged by directives" "11" \
|
|
"$(awk -F'\t' '!/^[#@]/ && NF>=3 {print $1}' "$M" | uniq | grep -c .)"
|
|
# @spec is the second directive kind and must be as invisible as the first.
|
|
is "@spec lines are not packages" "0" \
|
|
"$(sh $D render | cut -f2 | grep -c 'spec' || true)"
|
|
rm -rf state; DOTUP_MANIFEST=$UVM sh $D preset defaults
|
|
is "control: a uv tool is in the defaults" "on" "$(on agents/uv-fixture)"
|
|
DOTUP_MANIFEST=$UVM sh $D toggle p:core/uv >/dev/null
|
|
is "dropping uv drops the uv tools" "off" "$(on agents/uv-fixture)"
|
|
reset
|
|
# The brew-only rows. Without core/brew they have no source on a Linux box, so
|
|
# the closure has to carry it: the precedent lazygit, omp and herdr set.
|
|
for k in agents/beads core/tea core/bun; do
|
|
reset; sh $D toggle p:core/brew >/dev/null
|
|
is "dropping brew drops $k" "off" "$(on $k)"
|
|
done
|
|
# go-tools is `go install`; without a go there is nothing to run it.
|
|
reset; sh $D toggle p:core/go >/dev/null
|
|
is "dropping go drops go-tools" "off" "$(on core/go-tools)"
|
|
# bws-secrets promised seven API keys and installed nothing to fetch them with.
|
|
# The binary ships as a .zip and 24.04 minimal has no unzip, so the dependency
|
|
# is real rather than decorative.
|
|
reset; sh $D toggle p:private/bws-secrets >/dev/null
|
|
is "ticking bws-secrets pulls in unzip" "on" "$(on core/unzip)"
|
|
# bws must NOT be a manifest package. selected_packages drops every private row
|
|
# ("private is never a package" is what makes --unattended safe), and a safe row
|
|
# would put a Bitwarden binary on every throwaway public VM via the defaults
|
|
# preset. So the private tier installs it itself, next to the token.
|
|
is "bws-secrets stays a non-package" "-" \
|
|
"$(awk -F'\t' '$1=="private" && $2=="bws-secrets" {print $4}' "$M")"
|
|
is "no manifest row installs bws" "0" \
|
|
"$(awk -F'\t' '!/^[#@]/ && NF>=3 && $2=="bws" {c++} END{print c+0}' "$M")"
|
|
|
|
printf '\n\033[1m^t — the bulk toggle over the shown rows\033[0m\n'
|
|
# ^t is `toggle-shown`, not `toggle`, and these are the two bugs that made it a
|
|
# separate command. Pure state-file logic, so it is checked here rather than in
|
|
# the lab: the picker only ever hands it the keys of the matched rows.
|
|
#
|
|
# BUG-1: the walk widened past the filter. Typing `nvidia` shows exactly three
|
|
# gpu rows; gpu/container-toolkit @needs docker, and all three docker rows are
|
|
# invasive — "the docker group is root-equivalent". One keystroke ticked them
|
|
# off screen.
|
|
reset; cp state/selected state/before
|
|
sh $D toggle-shown p:gpu/nvidia-driver p:gpu/cuda-toolkit p:gpu/container-toolkit >/dev/null
|
|
is "^t over 'nvidia' ticks exactly the three rows on screen" \
|
|
"gpu/container-toolkit
|
|
gpu/cuda-toolkit
|
|
gpu/nvidia-driver" \
|
|
"$(grep -vxF -f state/before state/selected | sort || true)"
|
|
is "…and the invasive group it @needs stays off" "0/3" "$(grp docker)"
|
|
# BUG-2: and the same keystroke twice is a no-op. The reverse @needs closure
|
|
# cannot do this — nothing needs the gpu rows — so the journal is what undoes it.
|
|
sh $D toggle-shown p:gpu/nvidia-driver p:gpu/cuda-toolkit p:gpu/container-toolkit >/dev/null
|
|
sort -u state/before > state/before.s; sort -u state/selected > state/after.s
|
|
is "^t ^t returns the selection exactly as it was" "" \
|
|
"$(diff state/before.s state/after.s 2>&1 || :)"
|
|
# The guard is on `invasive`, not on "anything off screen": a safe dependency is
|
|
# still pulled in, and the undo still gives it back.
|
|
reset; sh $D preset none >/dev/null; cp state/selected state/before
|
|
sh $D toggle-shown p:agents/codex >/dev/null
|
|
is "^t still pulls in a SAFE @needs" "on" "$(on core/node)"
|
|
sh $D toggle-shown p:agents/codex >/dev/null
|
|
sort -u state/before > state/before.s; sort -u state/selected > state/after.s
|
|
is "…and ^t ^t hands that back too, node included" "" \
|
|
"$(diff state/before.s state/after.s 2>&1 || :)"
|
|
# One row, both commands, so the difference is not hidden behind a bulk case.
|
|
reset; sh $D preset none >/dev/null; sh $D toggle-shown p:gpu/container-toolkit >/dev/null
|
|
is "^t never auto-ticks an invasive dependency" "0/3" "$(grp docker)"
|
|
is "…but does tick the visible row it was handed" "on" "$(on gpu/container-toolkit)"
|
|
reset; sh $D preset none >/dev/null; sh $D toggle p:gpu/container-toolkit >/dev/null
|
|
is "space on that row is unchanged — you asked for that one" "3/3" "$(grp docker)"
|
|
# With no journal to undo, ^t is cmd_toggle's plain all-on/all-off rule.
|
|
reset; sh $D toggle-shown g:media >/dev/null
|
|
is "^t on an already-full group turns it off" "0/3" "$(grp media)"
|
|
reset; sh $D toggle-shown p:core/node >/dev/null
|
|
is "…and that all-off still drops what needed it" "off" "$(on agents/codex)"
|
|
is "the picker binds ^t to toggle-shown, never the plain toggle" "1" \
|
|
"$(grep -c 'ctrl-t:select-all+execute-silent($SELF toggle-shown ' $D)"
|
|
# clear-query used to hang off that bind. It has to be gone, not merely
|
|
# unused: it drops the filter, so the second ^t is over the whole manifest and
|
|
# the undo becomes "tick everything".
|
|
is "…and does not drop the query out from under the undo" "0" \
|
|
"$(grep -c -- '+clear-query' $D || true)"
|
|
|
|
printf '\n\033[1mcredentials never reach a log\033[0m\n'
|
|
# `run` echoes its whole argv to stderr. The private init's argv ends in
|
|
# https://user:TOKEN@host, so it must not go through `run`.
|
|
is "private init does not use run()" "0" \
|
|
"$(grep -c 'run chezmoi init' $D)"
|
|
# Two, not one: the dry-run branch traces it too, and a dry run that printed a
|
|
# live token would be the worse leak of the pair.
|
|
is "both traced URLs are redacted" "2" \
|
|
"$(grep -c 'redact_url "\$p_clean"' $D)"
|
|
# Not printing the token was never enough. p_repo is the URL as the endpoint
|
|
# hands it over, credential inline; putting THAT on chezmoi's command line
|
|
# publishes it to /proc/<pid>/cmdline, which every account on the box can read
|
|
# for as long as the clone runs, and then into the clone's .git/config, which
|
|
# keeps it. Only the split-out p_clean may reach an argv.
|
|
# Exercise the real implementation lifted straight out of dotup. A copy of the
|
|
# sed expression here would keep passing after someone edited the original.
|
|
split() { p_repo=$1; eval "$(sed -n '/p_cred=\$(printf/p;/p_clean=\$(printf/p' $D)"
|
|
printf '%s %s\n' "${p_cred:-<none>}" "$p_clean"; }
|
|
is "split lifts the credential out of the URL" \
|
|
"https://ben:deadbeefcafe@git.example.com https://git.example.com/x.git" \
|
|
"$(split 'https://ben:deadbeefcafe@git.example.com/x.git')"
|
|
# A port must survive into the credential line: git matches the store entry on
|
|
# host AND port, so dropping :3000 would silently stop authenticating.
|
|
is "…keeping the port" \
|
|
"http://u:p@example.com:3000 http://example.com:3000/a/b.git" \
|
|
"$(split 'http://u:p@example.com:3000/a/b.git')"
|
|
# No userinfo means nothing to store and nothing to strip — ssh remotes and
|
|
# unauthenticated https must pass through byte-identical.
|
|
is "…and leaves a credential-free remote untouched" \
|
|
"<none> https://git.example.com/x.git" \
|
|
"$(split 'https://git.example.com/x.git')"
|
|
is "…including scp-style ssh" \
|
|
"<none> git@git.example.com:ben/x.git" \
|
|
"$(split 'git@git.example.com:ben/x.git')"
|
|
# The bootstrap URL a human pastes comes from Bitwarden, where the rotation
|
|
# scripts put the FULL file URL. dotup appends /bootstrap.env itself, so without
|
|
# normalisation that becomes .../bootstrap.env/bootstrap.env -- a 404 that
|
|
# curl --fail turns into "endpoint refused the credentials", blaming the
|
|
# password for a URL shape. Both forms must land on the same request.
|
|
# Indentation-agnostic on purpose: these two lines moved from function body to
|
|
# inside the retry loop, and an anchor of `^\t` silently stopped matching, so
|
|
# the eval became a no-op and the assertions failed as if dotup were broken.
|
|
# Bind to the statement, not to where it happens to sit.
|
|
norm() { P_URL=$1; eval "$(sed -n 's/^[[:space:]]*\(P_URL=\${P_URL%[^}]*}\)$/\1/p' $D)"
|
|
printf '%s\n' "${P_URL%/}/bootstrap.env"; }
|
|
is "a directory URL resolves to the blob" "https://h/r/bootstrap.env" \
|
|
"$(norm 'https://h/r/')"
|
|
is "...without a trailing slash too" "https://h/r/bootstrap.env" \
|
|
"$(norm 'https://h/r')"
|
|
is "...and the full file URL, which is what Bitwarden holds" "https://h/r/bootstrap.env" \
|
|
"$(norm 'https://h/r/bootstrap.env')"
|
|
is "...even with a trailing slash on the file URL" "https://h/r/bootstrap.env" \
|
|
"$(norm 'https://h/r/bootstrap.env/')"
|
|
rd() { eval "$(sed -n '/^redact_url()/p' $D)"; redact_url "$1"; }
|
|
is "redact_url strips userinfo" "https://<redacted>@git.example.com/x.git" \
|
|
"$(rd 'https://ben:deadbeefcafe@git.example.com/x.git')"
|
|
is "...and leaves a credential-free URL alone" "https://git.example.com/x.git" \
|
|
"$(rd 'https://git.example.com/x.git')"
|
|
# Two tiers, two configs. Sharing one meant the public installer silently ate
|
|
# the private tier's seven promptStringOnce answers.
|
|
|
|
printf '\n\033[1mchezmoi is not assumed to be on PATH\033[0m\n'
|
|
# dotup ARRIVES via chezmoi, so "it must be here already" is the natural
|
|
# assumption and it is wrong: get.chezmoi.io installs to ./bin relative to the
|
|
# CWD when -b is not given, which is what the README one-liner does. From
|
|
# /workspace that is /workspace/bin, on no PATH anywhere. The private tier died
|
|
# with `chezmoi: not found` AFTER writing the bws token.
|
|
is "nothing calls chezmoi by bare name" "0" \
|
|
"$(grep -cE '^[[:space:]]*chezmoi (init|apply|update)' $D)"
|
|
# Resolution happens before the prompt: discovering it afterwards means the
|
|
# password is spent and the token is already on disk.
|
|
is "chezmoi is resolved before the password is asked for" "yes" \
|
|
"$(awk '/ensure_chezmoi \|\|/{e=NR} /head_ "private tier"/{h=NR} END{print (e && h && e<h) ? "yes" : "no"}' $D)"
|
|
|
|
printf '\n\033[1ma wrong password is not a reinstall\033[0m\n'
|
|
# The endpoint credentials are asked for at the very END of a run, after every
|
|
# package is installed. Any non-200 used to be fatal, so one mistyped character
|
|
# meant repeating the whole install to get back to the prompt.
|
|
# The subcommand existed but was absent from --help, so there was no way to
|
|
# discover the recovery path.
|
|
is "dotup private is documented" "1" \
|
|
"$(sh $D --help 2>&1 | grep -c 'ONLY the private tier')"
|
|
|
|
printf '\n\033[1mrisk model — the invariants that matter\033[0m\n'
|
|
reset
|
|
# Positive controls FIRST. `picked` and `missed` both end in `; :` so a failed
|
|
# grep cannot trip `set -e` -- which also means a broken helper returns nothing
|
|
# and is indistinguishable from a clean result. These three invariants are the
|
|
# whole safety story, and all three "passed" by producing no output. Prove the
|
|
# helpers can still speak before trusting their silence.
|
|
is "control: picked can see a safe row" "core/ripgrep" \
|
|
"$(picked safe | grep -x 'core/ripgrep' || echo MISSING)"
|
|
is "control: missed can see an unticked row" "gpu/nvidia-driver" \
|
|
"$(missed invasive | grep -x 'gpu/nvidia-driver' || echo MISSING)"
|
|
is "defaults tick nothing invasive" "" "$(picked invasive)"
|
|
is "defaults tick nothing private" "" "$(picked private)"
|
|
is "defaults tick every safe package" "" "$(missed safe)"
|
|
|
|
# A group must never render a flag milder than something inside it.
|
|
bad=$(rows | awk '$1!="BOX" && $2=="BOX" {print $3, $5}' \
|
|
| while read -r g f; do
|
|
worst=$(awk -F'\t' -v g="$g" '!/^#/ && !/^@/ && NF>=3 && $1==g {
|
|
s=($3=="invasive")?3:($3=="private")?2:($3=="gui")?1:0
|
|
if (s>m) m=s } END{ print (m==3)?"invasive":(m==2)?"private":(m==1)?"gui":"safe" }' "$M")
|
|
[ "$f" = "$worst" ] || echo "$g shows $f, worst child is $worst"
|
|
done; :)
|
|
is "no group looks safer than its contents" "" "$bad"
|
|
|
|
printf '\n\033[1mmatch confinement — regression for the ^t bug\033[0m\n'
|
|
if command -v fzf >/dev/null; then
|
|
sh $D expand-all >/dev/null # every package row visible
|
|
grep -q gpu/nvidia-driver <<-EOF || sh $D expand-all >/dev/null
|
|
$(sh $D render | cut -f2)
|
|
EOF
|
|
rows=$(sh $D render | sed 's/\x1b\[[0-9;]*m//g')
|
|
hit=$(printf '%s\n' "$rows" | fzf --exact --filter=nvidia --no-sort | cut -f2 | sort)
|
|
is "--exact: 'nvidia' hits only gpu packages" \
|
|
"p:gpu/container-toolkit
|
|
p:gpu/cuda-toolkit
|
|
p:gpu/nvidia-driver" "$hit"
|
|
# The bug: without --exact this also matches docker, networking and desktop,
|
|
# and ^t silently switched all three on.
|
|
loose=$(printf '%s\n' "$rows" | fzf --filter=nvidia --no-sort | cut -f2 \
|
|
| grep -cv '^p:gpu/' || true)
|
|
if [ "$loose" -gt 0 ]; then
|
|
ok "fuzzy would over-match $loose non-gpu rows (why --exact is required)"
|
|
else
|
|
no "fuzzy no longer over-matches — re-check whether --exact is still load-bearing"
|
|
fi
|
|
is "the fzf invocation carries --exact" "1" \
|
|
"$(grep -c '\--ansi --exact' $D)"
|
|
|
|
# Every action the picker binds must exist on THIS fzf. Ubuntu 24.04 ships
|
|
# 0.44.1; a dev box may be 28 releases ahead. fzf validates binds at
|
|
# startup, and empty stdin makes it exit without needing a terminal.
|
|
badbind=$(sed -n 's/.*--bind "\([^"]*\)".*/\1/p; s/.*--bind '"'"'\([^'"'"']*\)'"'"'.*/\1/p' $D \
|
|
| sed "s|\$SELF|$D|g" \
|
|
| while read -r b; do
|
|
out=$(fzf --bind "$b" </dev/null 2>&1 || true)
|
|
case $out in *nvalid*|*nknown*|*nsupported*) echo "$b" ;; esac
|
|
done; :)
|
|
is "every binding parses on fzf $(fzf --version | cut -d' ' -f1)" "" "$badbind"
|
|
else
|
|
printf ' \033[33mskip\033[0m fzf not installed\n'
|
|
fi
|
|
|
|
printf '\n\033[1mpreflight — the picker brings its own fzf\033[0m\n'
|
|
vc() { sh $D vercmp "$1" "$2" && echo ge || echo lt; }
|
|
is "0.44.1 clears the floor" "ge" "$(vc 0.44.1 0.44.0)"
|
|
is "0.29 (jammy) does not" "lt" "$(vc 0.29 0.44.0)"
|
|
is "0.38 (bookworm) does not" "lt" "$(vc 0.38.0 0.44.0)"
|
|
is "compare is numeric, not lexical" "ge" "$(vc 0.100.0 0.44.0)"
|
|
is "0.9.5 is not above 0.44.0" "lt" "$(vc 0.9.5 0.44.0)"
|
|
is "preflight resolves a fzf above the floor" "ge" \
|
|
"$(vc "$(sh $D fzf-path | xargs -r -I{} sh -c '{} --version' | awk '{print $1}')" 0.44.0)"
|
|
# The picker must call its resolved binary, never whatever PATH happens to hold.
|
|
is "picker invokes the resolved binary" "1" \
|
|
"$(grep -c 'cmd_render | "\$FZF"' $D)"
|
|
is "picker never calls bare fzf" "0" \
|
|
"$(grep -c 'render | fzf ' $D)"
|
|
# The whole point of the cache: PATH and ~/.local/bin are left alone.
|
|
is "preflight writes nothing to ~/.local/bin" "absent" \
|
|
"$(sh $D preflight >/dev/null 2>&1; [ -e "$HOME/.local/bin/fzf" ] && echo present || echo absent)"
|
|
is "preflight does not export PATH" "0" \
|
|
"$(grep -c 'PATH=.*export PATH' $D)"
|
|
# fzf is still offered as a normal package — for your shell, not for the picker.
|
|
is "manifest still offers fzf to you" "core/fzf" \
|
|
"$(awk -F'\t' '!/^#/ && !/^@/ && NF>=3 && $2=="fzf" {print $1"/"$2}' "$M")"
|
|
|
|
printf '\n\033[1mplatform resolution\033[0m\n'
|
|
is "brew-only pkg resolves on linux (omp)" "" \
|
|
"$(sh $D expand g:agents >/dev/null
|
|
sh $D render | sed 's/\x1b\[[0-9;]*m//g' | grep 'omp' | grep -o 'unavailable' || true)"
|
|
|
|
# One place decides what installs a package; everything downstream reads it.
|
|
rs() { sh $D resolve "$1" | tr '\t' ' '; }
|
|
is "plain apt name resolves to apt" "apt sox" "$(rs media/sox)"
|
|
is "no apt package falls through to brew" "brew lazygit" "$(rs core/lazygit)"
|
|
is "tap-only pkg falls through to brew" "brew can1357/tap/omp" "$(rs agents/omp)"
|
|
is "special channel carries its @spec" "npm @openai/codex" "$(rs agents/codex)"
|
|
is "…and the scoped mermaid name" "npm @mermaid-js/mermaid-cli" "$(rs core/mermaid-cli)"
|
|
# %a and %v are expanded at install time from `dpkg --print-architecture` and
|
|
# /etc/os-release. The literal `_amd64.deb` that used to be here matched no
|
|
# asset ghostty-ubuntu has ever published -- they are named
|
|
# ghostty_1.3.1-0.ppa2_amd64_24.04.deb -- so apps/ghostty could never install.
|
|
is "deb channel carries a source" "deb gh:mkasberg/ghostty-ubuntu:_%a_%v.deb" "$(rs apps/ghostty)"
|
|
is "snap channel renames to the binary" "snap bw" "$(rs core/bitwarden-cli)"
|
|
is "tarball is dispatched, not named" "tarball neovim" "$(rs core/neovim)"
|
|
# The docker group. `docker-ce`, `docker-buildx-plugin` and
|
|
# `docker-compose-plugin` exist only in Docker's OWN apt repository, which
|
|
# nothing here configures — so as apt names they had no installation candidate,
|
|
# fell through to the brew column, and a system daemon went looking at Homebrew.
|
|
# They are a script row on both platforms now and never a formula.
|
|
is "docker is a script row, not an apt name" "script docker-ce" "$(rs docker/docker-ce)"
|
|
is "…the buildx plugin with it" "script docker-buildx" "$(rs docker/docker-buildx)"
|
|
is "…and compose, which is the plugin" "script docker-compose" "$(rs docker/docker-compose)"
|
|
# Guest tools for when this box is the VM, not the host. Ubuntu main, so these
|
|
# stay plain apt rows — the docker/nvidia vendor-repo trap does not apply.
|
|
is "the qemu guest agent is an apt row" "apt qemu-guest-agent" "$(rs virt/guest-agent)"
|
|
is "…and the spice agent beside it" "apt spice-vdagent" "$(rs virt/spice-vdagent)"
|
|
is "an unknown key says so" "missing" "$(rs nope/nope | tr -d ' ')"
|
|
# The rows a new laptop was missing (audit C, G-pkg-1..9; audit B, G-AG-9).
|
|
is "claude code is a script row" "script claude" "$(rs agents/claude)"
|
|
is "beads comes from brew, apt has none" "brew beads" "$(rs agents/beads)"
|
|
is "jq is a plain apt row" "apt jq" "$(rs core/jq)"
|
|
is "shellcheck is a plain apt row" "apt shellcheck" "$(rs core/shellcheck)"
|
|
is "clang-format is a plain apt row" "apt clang-format" "$(rs core/clang-format)"
|
|
is "gitleaks is a plain apt row" "apt gitleaks" "$(rs core/gitleaks)"
|
|
is "tea falls through to brew" "brew tea" "$(rs core/tea)"
|
|
is "bun falls through to its tap" "brew oven-sh/bun/bun" "$(rs core/bun)"
|
|
is "go tools have a channel of their own" "go go-tools" "$(rs core/go-tools)"
|
|
is "rust is a script row" "script rust" "$(rs core/rust)"
|
|
is "incus is an apt row" "apt incus" "$(rs virt/incus)"
|
|
is "claude desktop configures its own repo" "script claude-desktop" "$(rs apps/claude-desktop)"
|
|
is "signal is a flathub app id" "flatpak org.signal.Signal" "$(rs apps/signal)"
|
|
# fonts-powerline is the Powerline glyphs alone, not a Nerd Font: the prompt and
|
|
# nvim's icons drew as tofu on every fresh Linux box.
|
|
is "a Nerd Font is the release, not fonts-powerline" "tarball hack-nerd-font" "$(rs fonts/hack-nerd-font)"
|
|
is "…both of them" "tarball iosevka-nerd-font" "$(rs fonts/iosevka-nerd-font)"
|
|
is "no row names fonts-powerline any more" "" \
|
|
"$(awk -F'\t' '!/^[#@]/ && NF>=3 && ($4=="fonts-powerline" || $5=="fonts-powerline")' "$M")"
|
|
# specify-cli was broken on dev and unused; DECISIONS dropped it.
|
|
is "specify-cli is gone" "missing" "$(rs agents/specify-cli | tr -d ' ')"
|
|
is "…with its directives" "" \
|
|
"$(grep 'specify' "$M" || true)"
|
|
# Two plugins dev runs that the spec did not list.
|
|
has "the pi plugin spec carries pi-lens" " pi-lens" "$(rs agents/pi-plugins)"
|
|
has "…and pi-mcp-adapter" " pi-mcp-adapter" "$(rs agents/pi-plugins)"
|
|
# The flag is the safety story: incus is a daemon whose group is root-equivalent,
|
|
# the two apps are gui. None of them is ticked on a headless box.
|
|
fl() { awk -F'\t' -v k="$1" '!/^[#@]/ && NF>=3 && $1"/"$2==k {print $3}' "$M"; }
|
|
is "incus is invasive" "invasive" "$(fl virt/incus)"
|
|
is "claude desktop is gui" "gui" "$(fl apps/claude-desktop)"
|
|
is "signal is gui" "gui" "$(fl apps/signal)"
|
|
reset
|
|
is "…so the headless defaults tick none of them" "off off off" \
|
|
"$(on virt/incus) $(on apps/claude-desktop) $(on apps/signal)"
|
|
# The macOS half of the manifest is exercised nowhere else. Resolution is pure
|
|
# data, so a fake `uname` is enough to check it — and it caught a real bug: the
|
|
# apt/brew fallback used to run both ways, so a Linux-only package resolved to
|
|
# `apt install davfs2` on a machine that has never had apt.
|
|
DARWIN=$PWD/fakeuname
|
|
drs() { PATH="$DARWIN:$PATH" sh $D resolve "$1" | tr '\t' ' '; }
|
|
is "darwin: tap-only pkg is a brew tap" "brew can1357/tap/omp" "$(drs agents/omp)"
|
|
is "darwin: zsh is built in" "builtin zsh" "$(drs core/zsh)"
|
|
is "darwin: no apt package is not a reason to try apt" "unavailable" \
|
|
"$(drs networking/davfs2 | tr -d ' ')"
|
|
# Docker Desktop's own CLI installer, off the .dmg. There is no brew cask in
|
|
# this story on either platform.
|
|
is "darwin: docker is a script row too" "script docker-ce" "$(drs docker/docker-ce)"
|
|
is "darwin: claude code is the same script" "script claude" "$(drs agents/claude)"
|
|
is "darwin: go tools are the same channel" "go go-tools" "$(drs core/go-tools)"
|
|
is "darwin: rust is the same script" "script rust" "$(drs core/rust)"
|
|
is "darwin: fonts stay brew casks" "brew font-hack-nerd-font" "$(drs fonts/hack-nerd-font)"
|
|
is "darwin: claude desktop is the cask" "brew claude" "$(drs apps/claude-desktop)"
|
|
is "darwin: signal is the cask" "brew signal" "$(drs apps/signal)"
|
|
is "darwin: bun is the tap" "brew oven-sh/bun/bun" "$(drs core/bun)"
|
|
is "darwin: incus has no source" "unavailable" "$(drs virt/incus | tr -d ' ')"
|
|
# G-boot-1: core/brew was `builtin` here, and builtin runs AFTER the brew stage,
|
|
# so a fresh Mac failed every brew row "brew missing" and only then installed
|
|
# Homebrew. A script row runs before brew, on both platforms.
|
|
is "darwin: homebrew itself is a script row" "script brew" "$(drs core/brew)"
|
|
|
|
# Nothing in the default set may be unresolvable — that is a manifest bug, and
|
|
# it is silent until someone runs the installer on a fresh machine.
|
|
reset
|
|
# This one passed if `dotup plan` crashed: no output, no unresolved lines, green.
|
|
is "control: plan produces a table at all" "yes" \
|
|
"$(sh $D plan 2>/dev/null | grep -q 'packages' && echo yes || echo no)"
|
|
is "every default package resolves" "" \
|
|
"$(sh $D plan 2>/dev/null | sed -n '/no source on this platform/,$p' | grep -v 'no source' || true)"
|
|
|
|
printf '\n\033[1mthe installer — driven against a SEALED set of fakes\033[0m\n'
|
|
# Sealed, not prepended. This section keeps `sudo` in the seal because two of
|
|
# its assertions are about what is and is not run through it; the failure
|
|
# injection sections further down deliberately leave sudo out, so that apt-get
|
|
# is invoked directly and can be made to fail.
|
|
newbox; BOXPATH=$SEALSUDO
|
|
box preset defaults >/dev/null
|
|
: > "$LOG"
|
|
out=$(box --unattended --print 2>&1 || true)
|
|
# "Calls nothing at all" stopped being the right bar when resolution began
|
|
# asking the machine what it is: `dpkg --print-architecture` and `apt-cache
|
|
# policy` are questions. What a dry run must never do is CHANGE anything.
|
|
# "a dry run never invents a failure" lives in .tests/lab/scenarios/, NOT here,
|
|
# and the reason is worth recording. The bug was core/brew probing `have brew`
|
|
# after an install step that --print had only printed; the check then reported
|
|
# "brew still not found after installing it" for a run that installed nothing.
|
|
# It cannot be reproduced on a developer box: `find_tool` probes
|
|
# /home/linuxbrew/.linuxbrew/bin by ABSOLUTE path, this host has brew there, so
|
|
# `have brew` succeeds and the failure never happens. No $PATH can seal an
|
|
# absolute probe -- seal.sh says so in its .shadowed list. An assertion written
|
|
# here would have passed forever without ever being able to fail.
|
|
is "--print installs nothing" "" \
|
|
"$(grep -E ' (install|remove|upgrade) ' "$LOG" || true)"
|
|
is "…and does not so much as refresh a package list" "" \
|
|
"$(grep -E 'apt-get update' "$LOG" || true)"
|
|
has "--print still shows the apt batch" "apt-get install -y" "$out"
|
|
has "--print shows the npm batch" "npm install -g" "$out"
|
|
hasnt "--print never reaches the private stage" "Bootstrap URL:" "$out"
|
|
|
|
# Now the real engine, over a subset chosen to exercise every non-destructive
|
|
# channel. Deliberately not the whole default set: the tarball and script
|
|
# handlers write outside $HOME, and a test suite has no business doing that.
|
|
newbox; BOXPATH=$SEALSUDO
|
|
BOXENV="DOTUP_MANIFEST=$UVM"
|
|
pick agents/omp agents/uv-fixture apps/obsidian core/bitwarden-cli \
|
|
core/gh core/lazygit core/mermaid-cli core/ripgrep gpu/container-toolkit
|
|
box install >/dev/null 2>&1 || true
|
|
log=$(cat "$LOG")
|
|
has "apt batches its packages in one call" "apt-get install -y ripgrep" "$log"
|
|
has "brew gets the tap-only package" "brew install can1357/tap/omp" "$log"
|
|
has "brew gets the apt-less package" "brew install lazygit" "$log"
|
|
has "npm gets the scoped spec" "@mermaid-js/mermaid-cli" "$log"
|
|
has "uv installs the tool, not the package" "uv tool install uv-fixture" "$log"
|
|
has "snap gets the renamed binary" "snap install bw" "$log"
|
|
has "flatpak gets the app id" "flatpak install" "$log"
|
|
has "…with the real obsidian app id" "md.obsidian.Obsidian" "$log"
|
|
# The one that matters on Linux: apt not knowing a name is not a dead end.
|
|
# `apt-cache show` is not an existence test -- it exits 0 for a name that has
|
|
# no installation candidate. The probe asks for the candidate now, so the
|
|
# assertion follows it.
|
|
has "apt probes before it batches" "apt-cache policy gh" "$log"
|
|
# nvidia-container-toolkit is here for one reason: it is in the apt cache but
|
|
# has no installation candidate -- it ships from NVIDIA's own repository -- and
|
|
# `apt-cache show` exits 0 for exactly that shape. Under the old probe it stayed
|
|
# in the batch and apt refused all of them at once: one unavailable name taking
|
|
# thirty installable ones down with it. (docker-ce was this test's example until
|
|
# the docker rows moved to get.docker.com and stopped reaching apt at all.)
|
|
has "…and rejects a name with no candidate" "apt-cache policy nvidia-container-toolkit" "$log"
|
|
hasnt "…leaving it out of the apt batch" "apt-get install -y nvidia-container-toolkit" "$log"
|
|
# Asserted as the WHOLE line, not as a prefix. `has "apt-get install -y ripgrep"`
|
|
# passed for any batch that merely began with ripgrep, so a rejected name
|
|
# reappearing after it -- the exact regression this section exists to catch --
|
|
# would have gone unseen, and the assertion was pinned to sort order rather than
|
|
# to content. The brew prerequisite call is excluded by name because it is a
|
|
# second, deliberate apt line rather than a batch that split apart.
|
|
# The two leading words are stripped rather than asserted: $SUDO is empty for a
|
|
# run that is already root (the suite's own container is), so pinning them would
|
|
# make this pass on a laptop and fail in CI for a reason that is not the batch.
|
|
is "…while the rest of the batch survives, and only it" \
|
|
"apt-get install -y ripgrep" \
|
|
"$(grep 'apt-get install' "$LOG" | grep -v 'build-essential procps curl file git$' \
|
|
| sed 's/^sudo //; s/^DEBIAN_FRONTEND=noninteractive //')"
|
|
has "an apt name apt rejects moves to brew" "brew install gh" "$log"
|
|
hasnt "…and is not left in the apt batch" "apt-get install -y gh" "$log"
|
|
# npm cannot run before node, uv cannot run before uv. The pipeline is fixed
|
|
# rather than sorted, so assert the order it actually produces.
|
|
is "apt runs before npm" "yes" \
|
|
"$(a=$(grep -n 'apt-get install' "$LOG" | head -1 | cut -d: -f1)
|
|
b=$(grep -n 'npm install' "$LOG" | head -1 | cut -d: -f1)
|
|
[ -n "$a" ] && [ -n "$b" ] && [ "$a" -lt "$b" ] && echo yes || echo no)"
|
|
# Nothing runs as root that does not have to.
|
|
hasnt "brew is never run through sudo" "sudo brew" "$log"
|
|
|
|
printf '\n\033[1mdocker comes from Docker — never brew, never compose v1\033[0m\n'
|
|
# The group named docker-ce, docker-buildx-plugin and docker-compose-plugin as
|
|
# apt packages. All three live in download.docker.com/linux/<distro>, which
|
|
# nothing here configures, so on a fresh box apt had no candidate for any of
|
|
# them, install_apt's unknown-name path fired, and the brew column was consulted
|
|
# for a system daemon. Docker's convenience script is the vendor's supported
|
|
# route and lays down the engine and BOTH plugins in one pass.
|
|
newbox; BOXPATH=$SEALSUDO
|
|
pick docker/docker-ce docker/docker-buildx docker/docker-compose
|
|
out=$(box install --print 2>&1 | plain || true)
|
|
has "the group resolves to the official script" "get.docker.com" "$out"
|
|
is "…run once for three rows, not three times" "1" \
|
|
"$(printf '%s\n' "$out" | grep -c 'get.docker.com' || true)"
|
|
has "…and the rows it covers say so rather than going quiet" \
|
|
"docker/docker-compose: covered by the docker group's single install" "$out"
|
|
hasnt "no docker row reaches apt at all" "apt-get install -y docker" "$out"
|
|
# The line-by-line form of "never via brew": not one line of a full docker
|
|
# selection may name both.
|
|
is "no line of the docker plan pairs brew with docker" "" \
|
|
"$(printf '%s\n' "$out" | grep -i brew | grep -i docker || true)"
|
|
# v1 is a different program from the plugin, deprecated, and reachable from pip,
|
|
# apt and brew under the same hyphenated name. What lands is `docker compose`.
|
|
is "the deprecated standalone docker-compose is never fetched" "" \
|
|
"$(printf '%s\n' "$out" | grep -E 'install[^|]*docker-compose' || true)"
|
|
is "…nor named in either package-manager column" "" \
|
|
"$(awk -F'\t' '!/^[#@]/ && NF>=3 && ($4 ~ /docker-compose/ || $5 ~ /docker-compose/) {print}' "$M")"
|
|
|
|
# The real engine, against the seal. Two things about the setup are load-bearing.
|
|
#
|
|
# holed docker find_tool probes /usr/local/bin and /opt/homebrew/bin by
|
|
# ABSOLUTE path, which no PATH can seal. On a machine with
|
|
# Docker Desktop installed, the first run below would take the
|
|
# "already present" branch and every assertion here would pass
|
|
# or fail for a reason that has nothing to do with the code.
|
|
# `holed` refuses instead of pretending.
|
|
# no sudo SUDO='' means the vendor script is run directly, so the
|
|
# stand-in installer actually executes and drops a `docker`
|
|
# where find_tool will find it -- which is what makes the
|
|
# idempotence assertion below about something.
|
|
newbox
|
|
if holed docker; then
|
|
pick docker/docker-ce docker/docker-buildx docker/docker-compose
|
|
box install >/dev/null 2>&1 || true
|
|
has "the real run fetches the vendor script" "curl -fsSL https://get.docker.com" "$(cat "$LOG")"
|
|
is "…exactly once" "1" "$(grep -c 'get.docker.com' "$LOG" || true)"
|
|
is "…and never invokes brew for it" "" "$(grep -i brew "$LOG" || true)"
|
|
is "…nor a package manager for a docker name" "" \
|
|
"$(grep -E '^(apt-get|apt-cache|snap|flatpak|npm) .*docker' "$LOG" || true)"
|
|
# Idempotence. The script's stand-in installed to ~/.local/bin, one of
|
|
# find_tool's probes, so the second run sees it the way a real one would -- and
|
|
# what it asks is `docker buildx version` and `docker compose version`, not the
|
|
# mere existence of a `docker`: docker.io, podman-docker and a hand-dropped
|
|
# binary all satisfy that while shipping neither plugin, which would have made
|
|
# the two plugin rows silently do nothing.
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "a second run leaves an installed docker alone" "already present — leaving it" "$out"
|
|
is "…and downloads nothing the second time" "1" "$(grep -c 'get.docker.com' "$LOG" || true)"
|
|
else
|
|
printf ' \033[33mskip\033[0m docker sits at an absolute path find_tool probes\n'
|
|
fi
|
|
|
|
# The failure path, and it is the one the pipe form could not reach: with no
|
|
# pipefail a failed download exited 0, note_fail was unreachable, and whatever
|
|
# fragment arrived had already run as root. Downloading to a file and checking
|
|
# it arrived is what makes any of this observable.
|
|
newbox
|
|
if holed docker; then
|
|
BOXENV='FAKE_FAIL=curl:docker'
|
|
pick docker/docker-ce docker/docker-buildx docker/docker-compose
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "a failed download is reported, not swallowed" \
|
|
"the Docker install script download failed or arrived empty" "$out"
|
|
has "…against the key you can type at the picker" "docker/docker-ce" "$out"
|
|
is "…and the file that never arrived is never run" "" \
|
|
"$(printf '%s\n' "$out" | grep " sh '" || true)"
|
|
has "…and the other two rows say they were not attempted" \
|
|
"not attempted — the docker install failed" "$out"
|
|
is "…rather than claiming the install covered them" "" \
|
|
"$(printf '%s\n' "$out" | grep 'covered by the docker' || true)"
|
|
is "…having tried the download once, not once per row" "1" \
|
|
"$(grep -c 'get.docker.com' "$LOG" || true)"
|
|
is "…and the run exits non-zero" "1" "$(boxrc install)"
|
|
else
|
|
printf ' \033[33mskip\033[0m docker sits at an absolute path find_tool probes\n'
|
|
fi
|
|
|
|
printf '\n\033[1mvendor scripts are downloaded, checked, then run — never piped\033[0m\n'
|
|
# Claude Code and rustup, the docker shape: fetched into this run's private
|
|
# directory, `[ -s ]` before anything runs it, then run from the file. Neither
|
|
# runs as root -- both are per-user installs.
|
|
for spec in "agents/claude claude https://claude.ai/install.sh bash claude-install.sh" \
|
|
"core/rust rustup https://sh.rustup.rs sh rustup-init.sh"; do
|
|
set -- $spec; k=$1; bin=$2; url=$3; shl=$4; file=$5
|
|
newbox
|
|
if holed "$bin"; then
|
|
pick "$k"
|
|
dry=$(box --print install 2>&1 | plain || true)
|
|
dl=$(printf '%s\n' "$dry" | sed -n "s|.*curl .*$url -o '\([^']*$file\)'.*|\1|p" | head -1)
|
|
has "$k: downloads to this run's own directory" "$SB/tmp/dotup." "$dl"
|
|
has "…checks it arrived non-empty" "[ -s '$dl' ]" "$dry"
|
|
has "…and runs that file" "$shl '$dl'" "$dry"
|
|
is "…never piping the download into a shell" "" \
|
|
"$(grep -nE "curl[^|]*${url#https://}[^|]*\|" $D || true)"
|
|
box install >/dev/null 2>&1 || true
|
|
is "$k: the real run fetches it once" "1" "$(grep -c "curl.*$url" "$LOG" || true)"
|
|
is "…and never through sudo" "" \
|
|
"$(grep -nE "SUDO[^\"]*$file|$file[^\"]*SUDO" $D || true)"
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "…and a second run leaves it alone" "already present" "$out"
|
|
is "…downloading nothing the second time" "1" "$(grep -c "curl.*$url" "$LOG" || true)"
|
|
newbox; holed "$bin" || :
|
|
BOXENV="FAKE_FAIL=curl:$bin"; pick "$k"
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "$k: a failed download is reported against the key" "$k: " "$out"
|
|
is "…and nothing is run in its place" "" \
|
|
"$(printf '%s\n' "$out" | grep "$shl '" || true)"
|
|
is "…and the run exits non-zero" "1" "$(boxrc install)"
|
|
else
|
|
printf ' \033[33mskip\033[0m %s sits at an absolute path find_tool probes\n' "$bin"
|
|
fi
|
|
done
|
|
set --
|
|
has "rustup leaves the shell files to chezmoi" "-y --no-modify-path" \
|
|
"$(grep 'rustup-init.sh.*-y' $D)"
|
|
|
|
printf '\n\033[1mNerd Fonts are the release, per user, not fonts-powerline\033[0m\n'
|
|
newbox; BOXPATH=$SEALSUDO; pick fonts/hack-nerd-font fonts/iosevka-nerd-font
|
|
box install >/dev/null 2>&1 || true
|
|
is "both fonts land in the user's font directory" "2" \
|
|
"$(find "$SB/.local/share/fonts/NerdFonts" -name '*NerdFont-Regular.ttf' 2>/dev/null | wc -l | tr -d ' ')"
|
|
has "…from the Nerd Fonts release" "ryanoasis/nerd-fonts/releases/latest/download/Hack.tar.xz" "$(cat "$LOG")"
|
|
hasnt "…with no root and no package manager" "apt-get" "$(cat "$LOG")"
|
|
hasnt "…not even sudo" "sudo" "$(cat "$LOG")"
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "a second run leaves an installed font alone" "Nerd Font already in" "$out"
|
|
is "…and downloads nothing" "2" "$(grep -c 'nerd-fonts/releases' "$LOG" || true)"
|
|
reset; sh $D toggle p:core/xz >/dev/null
|
|
is "dropping xz drops the font rows" "off off" "$(on fonts/hack-nerd-font) $(on fonts/iosevka-nerd-font)"
|
|
newbox; BOXENV='FAKE_FAIL=curl:font'; pick fonts/hack-nerd-font
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "a failed font download is named" "fonts/hack-nerd-font: font download failed" "$out"
|
|
is "…and the run exits non-zero" "1" "$(boxrc install)"
|
|
|
|
printf '\n\033[1mgo tools install after go, into GOPATH/bin\033[0m\n'
|
|
# The order is the whole point of the channel: `go install` before core/go's
|
|
# tarball has unpacked would be "go: not found" on every fresh box.
|
|
newbox; pick core/go core/go-tools
|
|
dry=$(box --print install 2>&1 | plain || true)
|
|
is "the go tarball is unpacked before any go install" "yes" \
|
|
"$(a=$(printf '%s\n' "$dry" | grep -n 'go.tgz.*-C /usr/local' | head -1 | cut -d: -f1)
|
|
b=$(printf '%s\n' "$dry" | grep -n ' install golang.org/x/tools/gopls@latest' | head -1 | cut -d: -f1)
|
|
[ -n "$a" ] && [ -n "$b" ] && [ "$a" -lt "$b" ] && echo yes || echo "no [$a/$b]")"
|
|
for gm in golang.org/x/tools/gopls golang.org/x/tools/cmd/goimports \
|
|
github.com/golangci/golangci-lint/v2/cmd/golangci-lint honnef.co/go/tools/cmd/staticcheck; do
|
|
has "…and installs ${gm##*/}" "install $gm@latest" "$dry"
|
|
done
|
|
newbox; sh ./seal.sh "$SB/seal" --with go >/dev/null; BOXPATH=$SB/seal
|
|
pick core/go-tools
|
|
box install >/dev/null 2>&1 || true
|
|
is "a real run installs all four" "4" "$(grep -c '^go install .*@latest' "$LOG" || true)"
|
|
is "…into ~/go/bin" "4" "$(ls "$SB/go/bin" 2>/dev/null | wc -l | tr -d ' ')"
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "a second run leaves them alone" "gopls already present" "$out"
|
|
is "…building nothing the second time" "4" "$(grep -c '^go install .*@latest' "$LOG" || true)"
|
|
newbox; sh ./seal.sh "$SB/seal" --with go >/dev/null; BOXPATH=$SB/seal
|
|
BOXENV='FAKE_FAIL=go:install'; pick core/go-tools
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "a failed go install is named" "core/go-tools: go install staticcheck failed" "$out"
|
|
is "…and the run exits non-zero" "1" "$(boxrc install)"
|
|
newbox
|
|
if holed go; then
|
|
pick core/go-tools
|
|
has "with no go at all it says so" "go missing — core/go did not install" "$(box install 2>&1 | plain || true)"
|
|
else
|
|
printf ' \033[33mskip\033[0m go sits at an absolute path find_tool probes\n'
|
|
fi
|
|
|
|
printf '\n\033[1ma fresh Mac installs Homebrew before the brew stage\033[0m\n'
|
|
# The seal's own uname swapped for the fake Mac one: the whole of the run, not
|
|
# just resolution, believes it is on Darwin. A dry run, because what matters is
|
|
# the ORDER of the commands, and --print shows exactly what a real run executes.
|
|
newbox; sh ./seal.sh "$SB/seal" --with sudo >/dev/null
|
|
ln -sf "$DARWIN/uname" "$SB/seal/uname"; BOXPATH=$SB/seal
|
|
pick core/brew agents/herdr
|
|
dry=$(box --print install 2>&1 | plain || true)
|
|
is "darwin: the Homebrew installer runs before any brew install" "yes" \
|
|
"$(a=$(printf '%s\n' "$dry" | grep -n 'Homebrew/install/HEAD/install.sh' | head -1 | cut -d: -f1)
|
|
b=$(printf '%s\n' "$dry" | grep -n 'brew install herdr' | head -1 | cut -d: -f1)
|
|
[ -n "$a" ] && [ -n "$b" ] && [ "$a" -lt "$b" ] && echo yes || echo "no [$a/$b]")"
|
|
is "darwin: …after asking for sudo, which NONINTERACTIVE cannot" "yes" \
|
|
"$(a=$(printf '%s\n' "$dry" | grep -n '+ sudo -v$' | head -1 | cut -d: -f1)
|
|
b=$(printf '%s\n' "$dry" | grep -n 'Homebrew/install/HEAD/install.sh' | head -1 | cut -d: -f1)
|
|
[ -n "$a" ] && [ -n "$b" ] && [ "$a" -lt "$b" ] && echo yes || echo "no [$a/$b]")"
|
|
hasnt "darwin: no apt prerequisites on a machine with no apt" "apt-get" "$dry"
|
|
|
|
printf '\n\033[1mherdr installs its own agent integrations\033[0m\n'
|
|
# G-AG-5: herdr's hook files say "managed by herdr", so none is committed and
|
|
# herdr writes them. One per agent that is actually present, none for one
|
|
# herdr already reports current, and silence on a box with no herdr at all.
|
|
newbox; sh ./seal.sh "$SB/seal" --with herdr claude codex >/dev/null; BOXPATH=$SB/seal
|
|
BOXENV='FAKE_HERDR_CURRENT=codex'; pick core/ripgrep
|
|
out=$(box install 2>&1 | plain || true)
|
|
is "herdr installs the claude integration" "1" \
|
|
"$(grep -c '^herdr integration install claude$' "$LOG" || true)"
|
|
is "…but not one herdr reports current" "0" \
|
|
"$(grep -c '^herdr integration install codex' "$LOG" || true)"
|
|
is "…nor one for an agent that is not here" "0" \
|
|
"$(grep -cE '^herdr integration install (pi|omp)' "$LOG" || true)"
|
|
: > "$LOG"; BOXENV='FAKE_HERDR_CURRENT=claude codex'
|
|
out=$(box install 2>&1 | plain || true)
|
|
is "a second run installs nothing" "0" \
|
|
"$(grep -c '^herdr integration install' "$LOG" || true)"
|
|
hasnt "…and prints no herdr section" "herdr integrations" "$out"
|
|
BOXENV='FAKE_FAIL=herdr:install'
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "a failed integration is named" "herdr integration install claude failed" "$out"
|
|
newbox; sh ./seal.sh "$SB/seal" --with claude codex >/dev/null; BOXPATH=$SB/seal
|
|
if grep -q '^herdr ' "$SB/seal/.shadowed" 2>/dev/null; then
|
|
printf ' \033[33mskip\033[0m herdr sits at an absolute path find_tool probes\n'
|
|
else
|
|
pick core/ripgrep
|
|
out=$(box install 2>&1 | plain || true)
|
|
hasnt "with no herdr the step says nothing" "herdr" "$out"
|
|
fi
|
|
|
|
printf '\n\033[1mclaude desktop trusts only Anthropic'"'"'s key\033[0m\n'
|
|
# A vendor apt repository is a key apt will trust for root-installed packages,
|
|
# so the key is checked against the published fingerprint before it is placed.
|
|
# The happy path is read off the dry run, which prints exactly what a real run
|
|
# executes: the suite's own container runs as root, where $SUDO is empty and a
|
|
# real run would write /usr/share/keyrings for real. The refusal paths below run
|
|
# for real, because each stops before anything is written.
|
|
newbox; BOXPATH=$SEALSUDO; pick apps/claude-desktop
|
|
dry=$(box --print install 2>&1 | plain || true)
|
|
has "it fetches the signing key" "curl -fsSL https://downloads.claude.ai/claude-desktop/key.asc" "$dry"
|
|
has "…checks it against the published fingerprint" "31DDDE24DDFAB679F42D7BD2BAA929FF1A7ECACE" "$dry"
|
|
has "…places it where the source line says" "/usr/share/keyrings/claude-desktop-archive-keyring.asc" "$dry"
|
|
has "…adds the repository" "/etc/apt/sources.list.d/claude-desktop.list" "$dry"
|
|
is "…refreshes apt after adding it" "yes" \
|
|
"$(a=$(printf '%s\n' "$dry" | grep -n 'sources.list.d/claude-desktop.list$' | head -1 | cut -d: -f1)
|
|
b=$(printf '%s\n' "$dry" | grep -n 'apt-get update' | tail -1 | cut -d: -f1)
|
|
[ -n "$a" ] && [ -n "$b" ] && [ "$a" -lt "$b" ] && echo yes || echo "no [$a/$b]")"
|
|
has "…then installs the package" "apt-get install -y claude-desktop" "$dry"
|
|
newbox; BOXPATH=$SEALSUDO; BOXENV='FAKE_GPG_FPR=0000000000000000000000000000000000000000'
|
|
pick apps/claude-desktop
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "a key with the wrong fingerprint is refused" "fingerprint is not Anthropic's" "$out"
|
|
has "…after gpg read the key it downloaded" "gpg --show-keys --with-colons $SB/tmp/dotup." "$(cat "$LOG")"
|
|
hasnt "…and never placed" "claude-desktop-archive-keyring" "$(cat "$LOG")"
|
|
hasnt "…nor the repository added" "sources.list.d" "$(cat "$LOG")"
|
|
is "…and the run exits non-zero" "1" "$(boxrc install)"
|
|
newbox
|
|
if holed gpg; then
|
|
BOXPATH=$SB/seal; pick apps/claude-desktop
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "with no gpg the key is not trusted on faith" "gpg is needed" "$out"
|
|
is "…and nothing is downloaded" "" "$(grep 'claude-desktop/key.asc' "$LOG" || true)"
|
|
else
|
|
printf ' \033[33mskip\033[0m gpg sits at an absolute path find_tool probes\n'
|
|
fi
|
|
|
|
printf '\n\033[1munattended — the boundary holds because of what is missing\033[0m\n'
|
|
# A stale state file is the adversary here: it ticks the two things an
|
|
# unattended run must never act on, and the run has to refuse both anyway.
|
|
newbox; BOXPATH=$SEALSUDO
|
|
pick core/ripgrep docker/docker-ce networking/openssh-server \
|
|
private/bws-secrets private/private-repo
|
|
out=$(box --unattended --print 2>&1 || true)
|
|
hasnt "unattended never installs a private row" "bws-secrets" "$out"
|
|
hasnt "unattended never prompts for a password" "Password:" "$out"
|
|
hasnt "unattended refuses a stale invasive tick" "docker-ce" "$out"
|
|
hasnt "…including a listening ssh port" "openssh-server" "$out"
|
|
has "…but still installs the safe defaults" "ripgrep" "$out"
|
|
# Determinism: the same command twice, on the same machine, means the same
|
|
# thing. A state file left by an interactive run must not change it.
|
|
# Normalised on the one thing that is MEANT to differ between two runs: every
|
|
# run gets its own mktemp'd download directory now (DU-H2), and the printed
|
|
# commands name it. What must not differ is the selection, which is what this
|
|
# assertion has always been about.
|
|
strip_wd() { sed 's|/dotup\.[^/]*/|/dotup.XXXXXX/|g'; }
|
|
a=$(box --unattended --print 2>/dev/null | strip_wd || true)
|
|
box preset none >/dev/null
|
|
b=$(box --unattended --print 2>/dev/null | strip_wd || true)
|
|
is "unattended is computed, not inherited" "same" \
|
|
"$([ "$a" = "$b" ] && echo same || echo different)"
|
|
# `set -e` would kill the subshell at the failing command, so the status is
|
|
# captured through a || branch rather than read from $? afterwards.
|
|
rc() { c=0; "$@" >/dev/null 2>&1 || c=$?; echo "$c"; }
|
|
is "unattended exits clean when nothing fails" "0" "$(boxrc --unattended --print)"
|
|
is "an unknown flag is refused" "2" "$(rc sh $D --nonsense)"
|
|
# The negative test in PLAN.md phase 3 runs `zsh -ic exit` after an unattended
|
|
# run. That only passes if zsh is in the unattended set.
|
|
has "unattended installs the shell it configures" "zsh" \
|
|
"$(box --unattended --print 2>&1 | grep 'apt-get install' || true)"
|
|
|
|
printf '\n\033[1mruns where it has to run\033[0m\n'
|
|
# A machine with no sudo and no root is a real case -- a locked-down work box, a
|
|
# rootless container. `A || { B && C; }` is one || list, so when `command -v
|
|
# sudo` failed the whole list failed and `set -e` killed dotup at load, before
|
|
# it printed anything. A minimal PATH is the only way to see that.
|
|
# Not under state/ -- reset() removes that whole directory, and a PATH that
|
|
# vanishes mid-test looks exactly like the bug being tested for.
|
|
MIN=${TMPDIR:-/tmp}/dotup-minbin.$$
|
|
rm -rf "$MIN"; mkdir -p "$MIN"
|
|
# Resolved by looking, not by `command -v`: an interactive shell can report an
|
|
# alias or a bare name for these, and a symlink to a bare name is a loop.
|
|
# mktemp and chmod earn their place the same way the rest do: dotup gives every
|
|
# run its own private download directory (DU-H2), and it makes it here.
|
|
for t in awk grep sed sort cut tr id uname mkdir cp mv rm cat head sh dirname basename mktemp chmod; do
|
|
for bd in /usr/bin /bin /usr/local/bin; do
|
|
[ -x "$bd/$t" ] && { ln -sf "$bd/$t" "$MIN/$t"; break; }
|
|
done
|
|
done
|
|
reset >/dev/null 2>&1
|
|
is "runs as a non-root user with no sudo on PATH" "0" \
|
|
"$(c=0; env -i HOME="$HOME" PATH="$MIN" DOTUP_STATE="$DOTUP_STATE" DOTUP_MANIFEST="$M" \
|
|
"$MIN/sh" $D --unattended --print >/dev/null 2>&1 || c=$?
|
|
echo "$c")"
|
|
# Two apt calls, and the distinction is the point: the manifest's packages go
|
|
# in ONE batch, and core/brew's prerequisites are a separate, named call. This
|
|
# used to assert "exactly 1" and would now read 2 with no way to tell a
|
|
# regression (the batch split apart) from the intended second call.
|
|
minprint=$(env -i HOME="$HOME" PATH="$MIN" DOTUP_STATE="$DOTUP_STATE" DOTUP_MANIFEST="$M" \
|
|
"$MIN/sh" $D --unattended --print 2>/dev/null)
|
|
# Discriminate on the exact prerequisite list, not on `build-essential` --
|
|
# that is itself a manifest package, so it appears in BOTH lines and a
|
|
# `grep -v` for it excluded the very batch this is meant to count.
|
|
is "…and still resolves the default set in ONE apt batch" "1" \
|
|
"$(printf '%s\n' "$minprint" | grep 'apt-get install -y ' \
|
|
| grep -vc 'build-essential procps curl file git$')"
|
|
is "…with brew's prerequisites as their own call" "1" \
|
|
"$(printf '%s\n' "$minprint" | grep -c 'build-essential procps curl file git$')"
|
|
unset minprint
|
|
rm -rf "$MIN"
|
|
# `sudo` must not be glued onto anything that is not a system package manager or
|
|
# a file operation under a system prefix. Two vendor installers do have to run as
|
|
# root, and WHICH FILE each of them runs is the entire question -- so they are
|
|
# pinned below by name rather than allowlisted by shape.
|
|
#
|
|
# The old pattern stopped at `[a-z-]+`, which could not see an invocation
|
|
# beginning with a quote or a slash AT ALL: the macOS installer path was
|
|
# invisible to it, and so was any future one written that way. `[^ ]+` sees
|
|
# every one, and every one has to appear on this list.
|
|
sudoers() { grep -oE '\$\{SUDO:\+\$SUDO \}[^ ]+' $D | sed "s/.*}//; s/'//g" | sort -u; }
|
|
is "every root invocation is one of the ones we meant" "" \
|
|
"$(sudoers | grep -vxF -e apt-get -e rm -e mkdir -e tar -e ln -e sh -e install \
|
|
-e DEBIAN_FRONTEND=noninteractive -e '$SNAP' \
|
|
-e '$WORKDIR/mnt/Docker.app/Contents/MacOS/install' || true)"
|
|
# `sh` is on that list for exactly one caller, and it must stay exactly one.
|
|
is "…exactly one root shell in the whole script" "1" \
|
|
"$(grep -cE '\$\{SUDO:\+\$SUDO \}sh ' $D || true)"
|
|
is "…and it runs this run's own copy of the vendor script" "1" \
|
|
"$(grep -cE '\$\{SUDO:\+\$SUDO \}sh .\$WORKDIR/get-docker\.sh.' $D || true)"
|
|
is "…which was downloaded to that file first" "1" \
|
|
"$(grep -cF 'curl -fsSL https://get.docker.com -o ' $D || true)"
|
|
# POSIX sh has no pipefail: a download fed straight to a root shell reports the
|
|
# SHELL's status, so a truncated body gets executed AND called a success.
|
|
# Nothing in this script may have that shape.
|
|
# `install` is on the list for the Claude Desktop repository and nothing else:
|
|
# the signing key and the source line, each from this run's own directory.
|
|
is "…root \`install\` writes only the two Claude Desktop apt files" "2" \
|
|
"$(grep -cE '\$\{SUDO:\+\$SUDO \}install -m 644 .\$WORKDIR/claude-desktop\.(asc. /usr/share/keyrings/claude-desktop-archive-keyring\.asc|list. /etc/apt/sources\.list\.d/claude-desktop\.list)' $D || true)"
|
|
is "…and no other root install exists" "2" \
|
|
"$(grep -cE '\$\{SUDO:\+\$SUDO \}install ' $D || true)"
|
|
is "nothing is ever piped into a root shell" "" \
|
|
"$(grep -nE 'curl[^|]*\|[^|]*\$\{SUDO' $D || true)"
|
|
# The macOS root invocation, named. It runs out of this run's own 700 directory
|
|
# rather than /Volumes/Docker -- a fixed path anyone able to mount an image can
|
|
# occupy, and which hdiutil silently sidesteps to "/Volumes/Docker 1" while
|
|
# still exiting 0.
|
|
is "…and Docker Desktop's installer runs from this run's mount" "1" \
|
|
"$(grep -cE '\$\{SUDO:\+\$SUDO \}.\$WORKDIR/mnt/Docker\.app/Contents/MacOS/install.' $D || true)"
|
|
is "…which was mounted read-only at a path this run chose" "1" \
|
|
"$(grep -cE 'hdiutil attach .*-readonly .*-mountpoint .\$WORKDIR/mnt.' $D || true)"
|
|
|
|
printf '\n\033[1mthe seal itself — a missing fake is an error, not the host tool\033[0m\n'
|
|
SB1=${TMPDIR:-/tmp}/dotup-sealtest.$$; rm -rf "$SB1"; mkdir -p "$SB1"
|
|
# The reason every section below can be believed. Under the old harness the
|
|
# fakes were PREPENDED to $PATH, so a package manager nobody had faked fell
|
|
# through to the real one; an audit of this suite invoked the developer's own
|
|
# `brew`. `env -i` plus a PATH that is only the seal makes that impossible.
|
|
is "the seal supplies the package managers" "$SEAL/brew" \
|
|
"$(env -i PATH="$SEAL" "$SEAL/sh" -c 'command -v brew')"
|
|
is "…and a tool nobody faked is simply absent" "" \
|
|
"$(env -i PATH="$SEAL" "$SEAL/sh" -c 'command -v wget || true')"
|
|
is "…so nothing in a sealed run can reach the host's own copy" "" \
|
|
"$(env -i PATH="$SEAL" "$SEAL/sh" -c 'command -v brew npm curl unzip' | grep -v "^$SEAL/" || true)"
|
|
# find_tool ALSO probes four absolute directories, which no PATH can seal. The
|
|
# seal ships a fake for every name that would be shadowed there -- `command -v`
|
|
# is consulted first, so the fake wins -- and records the rest, because a case
|
|
# whose point is that a tool is absent must not quietly pass on a box where it
|
|
# is not. seal.sh refuses to build a hole it cannot honour.
|
|
if [ -s "$SEAL/.shadowed" ]; then
|
|
printf ' \033[33mnote\033[0m this host also carries %sat find_tool'"'"'s absolute probes\n' \
|
|
"$(cut -f1 "$SEAL/.shadowed" | sort -u | tr '\n' ' ')"
|
|
fi
|
|
# A new `have foo` with no fake would silently reopen the hole. seal.sh refuses
|
|
# to build such a seal at all, so the failure lands on the harness rather than
|
|
# on an assertion that quietly starts measuring the host.
|
|
is "an unfaked probe refuses to build a seal" "1" \
|
|
"$(sed 's|^have() {.*|&\n\thave nosuchtool|' $D > "$SB1/doctored"
|
|
c=0; DOTUP_SEAL_TARGET=$SB1/doctored sh ./seal.sh "$SB1/seal" >/dev/null 2>&1 || c=$?
|
|
echo "$c")"
|
|
is "…naming the tool it has never heard of" "1" \
|
|
"$(DOTUP_SEAL_TARGET=$SB1/doctored sh ./seal.sh "$SB1/seal" 2>&1 >/dev/null \
|
|
| grep -c nosuchtool || true)"
|
|
|
|
printf '\n\033[1mprivate is never a package\033[0m\n'
|
|
# The invariant that makes --unattended safe. selected_packages drops every row
|
|
# flagged private, so a ticked private row cannot become an install command --
|
|
# and the plan, which is what the installer reads, is where that has to show.
|
|
newbox
|
|
pick core/ripgrep private/bws-secrets private/private-repo
|
|
plan=$(box plan 2>&1 | plain)
|
|
hasnt "no private row reaches the plan" "private/" "$plan"
|
|
has "…while the ordinary row does" "core/ripgrep" "$plan"
|
|
out=$(box install 2>&1 | plain || true)
|
|
hasnt "…nor the installer's own accounting" "private/" "$out"
|
|
has "…and the ordinary one still installs" "apt-get install -y ripgrep" "$(cat "$LOG")"
|
|
# A private row is not merely unresolvable -- it is not offered at all. Ticking
|
|
# only private rows must produce an empty plan rather than two failures.
|
|
newbox; pick private/bws-secrets private/private-repo
|
|
is "a private-only selection plans nothing" "0 packages" \
|
|
"$(box plan 2>&1 | plain | grep -o '[0-9]* packages' | head -1)"
|
|
|
|
printf '\n\033[1munattended refuses invasive rows a stale state file still ticks\033[0m\n'
|
|
# `dotup --unattended` recomputes the selection first, which HIDES this filter:
|
|
# cmd_install never sees a stale tick because cmd_run overwrote it a moment
|
|
# earlier. `dotup --unattended install` is the same installer with the state
|
|
# file left alone -- which is what a cron job re-running a saved selection is.
|
|
newbox; pick core/ripgrep docker/docker-ce networking/openssh-server
|
|
out=$(box --unattended install 2>&1 | plain || true)
|
|
log=$(cat "$LOG")
|
|
has "it names what it refused" "refusing invasive packages" "$out"
|
|
hasnt "the daemon never reaches a package manager" "get.docker.com" "$log"
|
|
hasnt "…nor does the listening ssh port" "openssh-server" "$log"
|
|
has "…and the safe package still installs" "ripgrep" "$log"
|
|
# Conditional on the flag, or it is a broken installer rather than a boundary.
|
|
newbox; pick core/ripgrep docker/docker-ce
|
|
box install >/dev/null 2>&1 || true
|
|
has "with a human present the same tick does install" "get.docker.com" "$(cat "$LOG")"
|
|
|
|
printf '\n\033[1mflags are read wherever they sit — DU-H1\033[0m\n'
|
|
# The production incident. The old parser stopped at the first bare word and
|
|
# left everything behind it in "$@", where nothing ever looked at it again --
|
|
# so `dotup install --unattended`, which is how half the people who type this
|
|
# type it, ran a FULL ATTENDED install and put every ticked invasive package on
|
|
# the machine. Silence is the worst possible answer to a flag: the operator has
|
|
# no way to tell the run they asked for from the run they got.
|
|
#
|
|
# These are the same assertions the flags-first section above makes, with the
|
|
# words the other way round. Both orders are one command line.
|
|
newbox; BOXPATH=$SEALSUDO
|
|
pick core/ripgrep docker/docker-ce networking/openssh-server
|
|
out=$(box install --unattended 2>&1 | plain || true)
|
|
log=$(cat "$LOG")
|
|
has "install --unattended refuses invasive too" "refusing invasive packages" "$out"
|
|
hasnt "…so the daemon never reaches a package manager" "get.docker.com" "$log"
|
|
hasnt "…nor does the listening ssh port" "openssh-server" "$log"
|
|
has "…and the safe package still installs" "ripgrep" "$log"
|
|
# A box where no selection has EVER existed: `install --unattended` must mean
|
|
# the defaults, not a silent empty plan. (Found live 2026-08-23: a fresh VM ran
|
|
# it, printed "done", and installed nothing at all.) An EXISTING empty file is
|
|
# the opposite case -- someone chose none -- and stays honoured.
|
|
newbox; BOXPATH=$SEALSUDO; rm -f "$SB/.config/dotfiles/selected"
|
|
out=$(box install --unattended 2>&1 | plain || true)
|
|
log=$(cat "$LOG")
|
|
has "no state file ever -> unattended install seeds the defaults" "ripgrep" "$log"
|
|
hasnt "…and the seeded defaults never include an invasive row" "get.docker.com" "$log"
|
|
newbox; BOXPATH=$SEALSUDO; : > "$SB/.config/dotfiles/picked"
|
|
out=$(box install --unattended 2>&1 | plain || true)
|
|
is "an accepted chose-none is a decision — nothing installs" "" "$(grep -E ' (install|remove|upgrade) ' "$LOG" || true)"
|
|
|
|
# --print is the flag whose absence is most expensive to discover afterwards.
|
|
newbox; BOXPATH=$SEALSUDO; pick core/ripgrep
|
|
out=$(box install --print 2>&1 | plain || true)
|
|
is "install --print installs nothing" "" \
|
|
"$(grep -E ' (install|remove|upgrade) ' "$LOG" || true)"
|
|
has "…while still printing what it would" "apt-get install -y" "$out"
|
|
# A flag on each side is one command line, not two halves of one.
|
|
newbox; BOXPATH=$SEALSUDO; pick core/ripgrep docker/docker-ce
|
|
out=$(box --print install --unattended 2>&1 | plain || true)
|
|
has "flags on both sides are all parsed" "refusing invasive packages" "$out"
|
|
is "…and the run still changed nothing" "" \
|
|
"$(grep -E ' (install|remove|upgrade) ' "$LOG" || true)"
|
|
# The other half of DU-H1, and the half that keeps the fix honest: a flag or a
|
|
# word this script does not recognise must STOP the run. A typo that installs
|
|
# the wrong set of packages is worse than one that installs nothing.
|
|
newbox; BOXPATH=$SEALSUDO; pick core/ripgrep
|
|
is "an unknown flag after the subcommand is refused" "2" "$(boxrc install --nonsense)"
|
|
is "…an unknown word after it too" "2" "$(boxrc install extra)"
|
|
is "…and an unknown subcommand" "2" "$(boxrc instal)"
|
|
is "…and a short flag nobody defined" "2" "$(boxrc install -Q)"
|
|
is "a refused command line installs nothing at all" "" "$(cat "$LOG")"
|
|
has "…and names the argument it did not understand" "unknown flag: --nonsense" \
|
|
"$(box install --nonsense 2>&1 | plain || true)"
|
|
has "…or the command, when that is what was wrong" "unknown command: instal" \
|
|
"$(box instal 2>&1 | plain || true)"
|
|
# Operands must survive the same parser: these are how the fzf bindings call
|
|
# back into dotup, and a picker whose every tick errored would be worse still.
|
|
is "a subcommand's own operands still reach it" "not selected" \
|
|
"$(box explain p:media/sox 2>&1 | plain | sed -n 's/^state *//p')"
|
|
is "…several of them, in order" "0" \
|
|
"$(boxrc toggle p:media/sox p:media/ffmpeg)"
|
|
|
|
printf '\n\033[1ma package that fails is reported, and the run says so\033[0m\n'
|
|
# Reachable only because the fakes can be made to fail. Every assertion here
|
|
# survived deleting the code it is about, for want of a way to make brew lose.
|
|
newbox; BOXENV=FAKE_FAIL=brew
|
|
pick core/lazygit agents/omp core/ripgrep
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "the failure is named by its manifest key" "core/lazygit" "$out"
|
|
has "…and by the second one too" "agents/omp" "$out"
|
|
has "…with what went wrong" "brew install failed" "$out"
|
|
has "…under a heading you can find" "did not install" "$out"
|
|
has "…and a count at the end" "package(s) did not install" "$out"
|
|
is "the run exits non-zero" "1" "$(boxrc install)"
|
|
has "…and the packages that CAN install still do" "apt-get install -y ripgrep" "$(cat "$LOG")"
|
|
newbox; pick core/ripgrep
|
|
is "a run with nothing failing exits 0" "0" "$(boxrc install)"
|
|
|
|
printf '\n\033[1mone unknown name does not sink the batch\033[0m\n'
|
|
# Real apt refuses the WHOLE batch when one name is unusable. The fake fails in
|
|
# exactly that shape -- any call carrying more than one package -- so the only
|
|
# way through is the one-at-a-time retry, and the only way to see the retry is
|
|
# to make the batch lose.
|
|
newbox; BOXENV=FAKE_FAIL=apt-get:batch
|
|
pick core/ripgrep core/btop core/htop
|
|
out=$(box install 2>&1 | plain || true)
|
|
is "the batch is attempted first" "1" \
|
|
"$(grep -cx 'apt-get install -y btop htop ripgrep' "$LOG" || true)"
|
|
is "…then btop on its own" "1" "$(grep -cx 'apt-get install -y btop' "$LOG" || true)"
|
|
is "…and htop" "1" "$(grep -cx 'apt-get install -y htop' "$LOG" || true)"
|
|
is "…and ripgrep" "1" "$(grep -cx 'apt-get install -y ripgrep' "$LOG" || true)"
|
|
has "it says why it is retrying" "retrying one at a time" "$out"
|
|
hasnt "…and nothing is left failed" "did not install" "$out"
|
|
is "…so the run still exits 0" "0" "$(boxrc install)"
|
|
|
|
newbox; BOXENV=FAKE_FAIL=npm:batch
|
|
pick agents/codex agents/pi core/mermaid-cli
|
|
out=$(box install 2>&1 | plain || true)
|
|
is "npm batches first" "1" \
|
|
"$(grep -c 'npm install -g @earendil-works/pi-coding-agent @mermaid-js/mermaid-cli @openai/codex' "$LOG" || true)"
|
|
is "…then @openai/codex on its own" "1" "$(grep -cx 'npm install -g @openai/codex' "$LOG" || true)"
|
|
is "…and the scoped mermaid name" "1" "$(grep -cx 'npm install -g @mermaid-js/mermaid-cli' "$LOG" || true)"
|
|
hasnt "…and nothing is left failed" "did not install" "$out"
|
|
|
|
printf '\n\033[1ma tool installed a moment ago is still found\033[0m\n'
|
|
# uv lands in ~/.local/bin, which is on no PATH this process has -- dotup will
|
|
# not rewrite PATH for its own convenience, so find_tool looks in the places
|
|
# the run just wrote to instead. Stop looking there and every uv tool is
|
|
# reported missing on a machine where uv was installed sixty seconds earlier.
|
|
newbox
|
|
if holed uv; then
|
|
ln -s "$BOXPATH/_fake" "$SB/.local/bin/uv"
|
|
BOXENV="DOTUP_MANIFEST=$UVM"
|
|
pick agents/uv-fixture
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "uv is found in ~/.local/bin, off PATH" "uv tool install uv-fixture" "$(cat "$LOG")"
|
|
hasnt "…so nothing claims uv is missing" "uv missing" "$out"
|
|
is "…and the run exits clean" "0" "$(boxrc install)"
|
|
else
|
|
printf ' \033[33mskip\033[0m this host carries uv at one of find_tool'"'"'s absolute probes\n'
|
|
fi
|
|
# ~/bin is the other one, and it is not decorative: get.chezmoi.io installs
|
|
# there when -b is not given, which is what the README one-liner does.
|
|
newbox
|
|
if holed snap; then
|
|
mkdir -p "$SB/bin"; ln -s "$BOXPATH/_fake" "$SB/bin/snap"
|
|
pick core/bitwarden-cli
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "…and in ~/bin, where get.chezmoi.io puts things" "snap install bw" "$(cat "$LOG")"
|
|
hasnt "…so nothing claims snapd is absent" "snapd is not present" "$out"
|
|
else
|
|
printf ' \033[33mskip\033[0m this host carries snap at one of find_tool'"'"'s absolute probes\n'
|
|
fi
|
|
|
|
printf '\n\033[1mthe deb channel installs what it downloads\033[0m\n'
|
|
newbox; pick apps/chrome
|
|
out=$(box install 2>&1 | plain || true)
|
|
has "the vendor .deb is fetched" \
|
|
"curl -fsSL https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" "$(cat "$LOG")"
|
|
is "…and then handed to the package manager" "1" \
|
|
"$(grep -c 'apt-get install -y .*\.deb' "$LOG" || true)"
|
|
hasnt "…and nothing is left failed" "did not install" "$out"
|
|
# A download that fails must not be followed by an install of a file that is
|
|
# not there -- and must be reported.
|
|
newbox; BOXENV=FAKE_FAIL=curl:deb; pick apps/chrome
|
|
out=$(box install 2>&1 | plain || true)
|
|
is "a failed download installs nothing" "0" \
|
|
"$(grep -c 'apt-get install -y .*\.deb' "$LOG" || true)"
|
|
has "…and is reported against the package" "apps/chrome" "$out"
|
|
|
|
printf '\n\033[1mthe neovim tarball lands where the symlink points\033[0m\n'
|
|
# Four commands name the same directory: the rm, the mkdir, tar's -C, and the
|
|
# symlink's target. A typo in any one of them installs nothing and leaves a
|
|
# dangling /usr/local/bin/nvim -- silently, because tar succeeded. Read the
|
|
# four back out of dotup's own dry run and make them agree, rather than
|
|
# trusting four separate spellings to stay in step.
|
|
newbox; pick core/neovim
|
|
dry=$(box --print install 2>&1 | plain || true)
|
|
xt=$(printf '%s\n' "$dry" | sed -n 's/.*tar -xzf [^ ]* -C \([^ ]*\) --strip-components=1.*/\1/p' | head -1)
|
|
xl=$(printf '%s\n' "$dry" | sed -n 's|.*ln -sf \(.*\)/bin/nvim /usr/local/bin/nvim.*|\1|p' | head -1)
|
|
xr=$(printf '%s\n' "$dry" | sed -n 's/.*rm -rf \([^ ]*\) && .*mkdir -p \([^ ]*\) &&.*/\1 \2/p' | head -1)
|
|
is "the tarball is extracted where the symlink points" "$xt" "$xl"
|
|
is "…into the directory that was cleared and recreated" "$xt $xt" "$xr"
|
|
is "…and that directory is /opt/nvim" "/opt/nvim" "$xt"
|
|
|
|
printf '\n\033[1mdownloads land in a private directory, never a fixed /tmp path — DU-H2\033[0m\n'
|
|
# The tarball handlers wrote /tmp/nvim.tgz, /tmp/node.tgz and /tmp/go.tgz and
|
|
# then unpacked them with `sudo tar`. Any account on the box could pre-create
|
|
# those names as symlinks, or swap the file in the window between the download
|
|
# and the extract, and have tar write their content anywhere, as root.
|
|
#
|
|
# Static half first, because it covers handlers no test drives -- go and node
|
|
# both write outside $HOME and have no business running here at all.
|
|
is "no download is written to a fixed /tmp path" "" \
|
|
"$(grep -nE -- "-o +'?/tmp/|-o +'?.\{TMPDIR:-/tmp\}/" $D || true)"
|
|
is "…and nothing is extracted from one" "" \
|
|
"$(grep -nE -- "tar [^|]*-x[a-z]*f +'?/tmp/" $D || true)"
|
|
is "the working directory comes from mktemp -d" "1" \
|
|
"$(grep -c 'mktemp -d "\${TMPDIR:-/tmp}/dotup\.' $D)"
|
|
is "…and its mode is stated rather than assumed" "1" \
|
|
"$(grep -c 'chmod 700 "\$WORKDIR"' $D)"
|
|
is "…and a trap removes it however the run ends" "1" \
|
|
"$(grep -c '^trap dotup_cleanup EXIT INT TERM' $D)"
|
|
# cmd_private REPLACES that trap with one of its own. If it does not do the
|
|
# cleanup too, every run that reaches the private tier leaks its directory.
|
|
is "…including the trap the private tier installs" "1" \
|
|
"$(grep -c "dotup_cleanup. EXIT INT TERM" $D)"
|
|
|
|
# Behavioural half. The directory is gone by the time the run exits, so the
|
|
# fake curl records it and its mode from the inside (see fakebin/_curl).
|
|
newbox; BOXPATH=$SEALSUDO; pick apps/chrome
|
|
box install >/dev/null 2>&1 || true
|
|
wdline=$(grep '^curl-outdir ' "$LOG" | head -1 || true)
|
|
is "control: the run recorded where it downloaded to" "yes" \
|
|
"$([ -n "$wdline" ] && echo yes || echo no)"
|
|
is "the deb lands in a directory made for this run" "yes" \
|
|
"$(case ${wdline:-} in *" $SB/tmp/dotup."*) echo yes ;; *) echo "no [$wdline]" ;; esac)"
|
|
is "…which nobody else can read into" "700" \
|
|
"$(printf '%s\n' "$wdline" | awk '{print $3}')"
|
|
is "…and which does not outlive the run" "" \
|
|
"$(ls "$SB/tmp" 2>/dev/null || true)"
|
|
# Predictability was the whole bug, so two runs must not agree on the name.
|
|
# Same box, so the only thing that can differ is what mktemp chose.
|
|
one=$(printf '%s\n' "$wdline" | awk '{print $2}')
|
|
: > "$LOG"
|
|
box install >/dev/null 2>&1 || true
|
|
two=$(grep '^curl-outdir ' "$LOG" | head -1 | awk '{print $2}' || true)
|
|
is "control: the second run named one as well" "yes" \
|
|
"$([ -n "$two" ] && echo yes || echo no)"
|
|
is "no two runs choose the same directory" "different" \
|
|
"$([ "$one" = "$two" ] && echo same || echo different)"
|
|
|
|
# The neovim handler, read back out of dotup's own dry run: what it downloads
|
|
# and what it hands to `sudo tar` must be the same file, and that file must not
|
|
# be under a name anyone could have written down in advance.
|
|
newbox; pick core/neovim
|
|
dry=$(box --print install 2>&1 | plain || true)
|
|
dl=$(printf '%s\n' "$dry" | sed -n "s/.*-o '\([^']*nvim\.tgz\)'.*/\1/p" | head -1)
|
|
ex=$(printf '%s\n' "$dry" | sed -n "s/.*tar -xzf '\([^']*\)' -C .*/\1/p" | head -1)
|
|
is "control: the dry run names a download path" "yes" \
|
|
"$([ -n "$dl" ] && echo yes || echo no)"
|
|
is "the tarball is extracted from the file just downloaded" "$dl" "$ex"
|
|
is "…out of this run's own directory, not /tmp/nvim.tgz" "yes" \
|
|
"$(case $dl in "$SB/tmp/dotup."*/nvim.tgz) echo yes ;; *) echo "no [$dl]" ;; esac)"
|
|
# Nothing may reach `sudo tar` that was not checked to be there and non-empty:
|
|
# a truncated proxy error page is a zero-byte file, and tar's complaint about
|
|
# one is not a sentence anyone can act on.
|
|
has "…and only if it arrived non-empty" "[ -s '$dl' ]" "$dry"
|
|
|
|
printf '\n\033[1mthe picker fetches its own fzf, from the real release URL\033[0m\n'
|
|
# The stand-in for GitHub answers ONE path -- the release download URL -- and
|
|
# builds the tarball from the version named in it. So a preflight that reports
|
|
# a version is evidence the pin travelled through the URL into the binary; a
|
|
# wrong host or a wrong path shape is a failed fetch, exactly as it would be.
|
|
newbox
|
|
out=$(box preflight 2>&1 | plain || true)
|
|
is "the fetch goes to the fzf release download URL" "1" \
|
|
"$(grep -c 'curl -sfL https://github.com/junegunn/fzf/releases/download/' "$LOG" || true)"
|
|
has "preflight resolves the fzf it just cached" "using $SB/.cache/dotup/fzf" "$out"
|
|
is "the binary that landed is the version the URL asked for" \
|
|
"$(grep -o 'fzf-[0-9][0-9.]*-linux_' "$LOG" | head -1 | sed 's/^fzf-//; s/-linux_$//')" \
|
|
"$(printf '%s\n' "$out" | sed -n 's/.*fzf (\([0-9][0-9.]*\),.*/\1/p' | head -1)"
|
|
is "…and it clears the verified floor" "1" \
|
|
"$(printf '%s\n' "$out" | grep -c 'floor 0.44.0' || true)"
|
|
is "nothing was written to ~/.local/bin" "absent" \
|
|
"$([ -e "$SB/.local/bin/fzf" ] && echo present || echo absent)"
|
|
|
|
printf '\n\033[1mthe picker actually runs — every binding reaches fzf\033[0m\n'
|
|
# DU-C1. Comments were inserted BETWEEN the continued lines of the fzf
|
|
# invocation. The `\`-newline is stripped first, so the comment's own newline
|
|
# terminated the command: fzf ran with two binds, the lines below it ran as a
|
|
# command named `--bind`, and `dotup pick` returned 1 having drawn a picker
|
|
# where nothing but the cursor worked. Every other test here greps the SOURCE
|
|
# for bind strings, so all of them still passed. This one runs cmd_pick.
|
|
#
|
|
# Static half first: it needs nothing, and it catches the whole class anywhere
|
|
# in the file rather than only at the one site that was broken.
|
|
stray=$(awk '/\\$/ { cont=1; next }
|
|
cont && /^[[:space:]]*#/ { printf "%d: %s\n", NR, $0 }
|
|
{ cont=0 }' $D)
|
|
is "no comment interrupts a line continuation" "" "$stray"
|
|
|
|
if command -v python3 >/dev/null; then
|
|
# A real pty, because cmd_pick's first act is to open /dev/tty; a fake fzf,
|
|
# because the assertion is about the argv it was handed. FAKE_FZF_ARGV
|
|
# writes that argv one argument per line, so a bind that lost its
|
|
# continuation cannot be mistaken for one that survived.
|
|
newbox
|
|
BOXPATH=$SB/seal; sh ./seal.sh "$BOXPATH" --with fzf >/dev/null
|
|
ARGV=$SB/fzf.argv; : > "$SB/nothing.expect"
|
|
prc=0
|
|
python3 ./ptydrive.py --timeout 30 --script "$SB/nothing.expect" -- \
|
|
/usr/bin/env -i HOME="$SB" PATH="$BOXPATH" TERM=dumb LANG=C \
|
|
TMPDIR="$SB/tmp" DOTUP_STATE="$SB/.config/dotfiles" \
|
|
DOTUP_MANIFEST="$M" DOTUP_TEST_LOG="$LOG" FAKE_FZF_ARGV="$ARGV" \
|
|
"$BOXPATH/sh" $D pick >/dev/null 2>&1 || prc=$?
|
|
is "dotup pick exits 0" "0" "$prc"
|
|
is "…having actually invoked fzf once" "1" \
|
|
"$(grep -c '^fzf --ansi' "$LOG" || true)"
|
|
# Counted against the source, not against a literal 7: a binding added
|
|
# later must reach fzf too, and a test that hard-codes the count would not
|
|
# notice that it did not.
|
|
is "…with every --bind the source writes" \
|
|
"$(grep -c -- '--bind ' $D)" "$(grep -cx -- '--bind' "$ARGV" || true)"
|
|
nobind=$(for k in space tab ctrl-t ctrl-a ctrl-x ctrl-o enter; do
|
|
grep -q "^$k:" "$ARGV" || echo "$k"
|
|
done; :)
|
|
is "…and all seven keys among them" "" "$nobind"
|
|
# The other half of what DU-C1 cost: the marker is written after fzf
|
|
# accepts, so with the command truncated it never was, and the defaults
|
|
# re-seeded over the user's selection on every subsequent run.
|
|
is "…and the completed-pick marker is written" "present" \
|
|
"$([ -f "$SB/.config/dotfiles/picked" ] && echo present || echo absent)"
|
|
else
|
|
printf ' \033[33mskip\033[0m needs python3 to open a pty\n'
|
|
fi
|
|
|
|
printf '\n\033[1m[y/N] means what it says — asked on the terminal\033[0m\n'
|
|
# ISSUE-9. confirm() asked `[ -t 0 ]`, so `dotup < /dev/null` in a terminal
|
|
# drew the picker on /dev/tty, accepted, and installed without ever asking.
|
|
# The pty is the terminal; stdin is /dev/null, as in the report.
|
|
if command -v python3 >/dev/null; then
|
|
ttyrun() { # ttyrun <script> -- dotup's default run on a pty, stdin /dev/null
|
|
python3 ./ptydrive.py --timeout 30 --script "$1" -- \
|
|
/usr/bin/env -i HOME="$SB" PATH="$BOXPATH" TERM=dumb LANG=C \
|
|
TMPDIR="$SB/tmp" DOTUP_STATE="$SB/.config/dotfiles" \
|
|
DOTUP_MANIFEST="$M" DOTUP_TEST_LOG="$LOG" \
|
|
"$BOXPATH/sh" -c 'exec "$0" "$@" </dev/null' "$BOXPATH/sh" $D 2>&1 \
|
|
| tr -d '\r' | plain
|
|
}
|
|
newbox; sh ./seal.sh "$SB/seal" --with fzf >/dev/null; BOXPATH=$SB/seal
|
|
pick core/ripgrep
|
|
printf 'expect install\\? \\[y/N\\]\nsend n\nexpect nothing installed\n' > "$SB/no.expect"
|
|
out=$(ttyrun "$SB/no.expect" || true)
|
|
has "stdin /dev/null with a terminal still asks [y/N]" "install? [y/N]" "$out"
|
|
is "…and n installs nothing" "0" \
|
|
"$(grep -c 'apt-get install' "$LOG" || true)"
|
|
newbox; sh ./seal.sh "$SB/seal" --with fzf >/dev/null; BOXPATH=$SB/seal
|
|
pick core/ripgrep
|
|
printf 'expect install\\? \\[y/N\\]\nsend y\n' > "$SB/yes.expect"
|
|
out=$(ttyrun "$SB/yes.expect" || true)
|
|
is "…and y, typed on the terminal, installs" "1" \
|
|
"$(grep -c 'apt-get install.* ripgrep' "$LOG" || true)"
|
|
else
|
|
printf ' \033[33mskip\033[0m needs python3 to open a pty\n'
|
|
fi
|
|
|
|
printf '\n\033[1mthe private tier — the three guards, exercised\033[0m\n'
|
|
# Each of these is one line of dotup, and each of them survived being INVERTED:
|
|
# the suite only ever checked that the words were in the file. What matters is
|
|
# which of the three fires, because they say three different things and only one
|
|
# of them is true at a time.
|
|
newbox; pick private/private-repo private/bws-secrets
|
|
out=$(box --unattended private </dev/null 2>&1 | plain || true)
|
|
has "--unattended: nobody is here to type it" "nobody is here to type" "$out"
|
|
hasnt "…so it never reaches a prompt" "Bootstrap URL" "$out"
|
|
hasnt "…and does not blame the terminal instead" "no terminal" "$out"
|
|
out=$(box private </dev/null 2>&1 | plain || true)
|
|
has "no tty: it says THAT instead" "no terminal" "$out"
|
|
hasnt "…and still never prompts" "Bootstrap URL" "$out"
|
|
hasnt "…and does not blame a flag nobody passed" "nobody is here to type" "$out"
|
|
out=$(box --print private </dev/null 2>&1 | plain || true)
|
|
has "--print describes the step" "prompt for URL, username, password" "$out"
|
|
hasnt "…and asks nothing" "Bootstrap URL:" "$out"
|
|
newbox; pick core/ripgrep
|
|
is "with no private row ticked there is no tier at all" "" \
|
|
"$(box private </dev/null 2>&1 | plain || true)"
|
|
|
|
printf '\n\033[1mthe private tier — driven through a real terminal\033[0m\n'
|
|
if command -v python3 >/dev/null 2>&1; then
|
|
# Everything below runs the SHIPPING cmd_private on a pty, against the
|
|
# sealed fakes: a stand-in endpoint that checks the password it was given,
|
|
# a stand-in GitHub that serves a bws zip and a checksum file, and a
|
|
# stand-in chezmoi that produces a source tree at the caller's umask. The
|
|
# assertions are then made against the filesystem -- modes, contents -- and
|
|
# against what the run actually said, not against what the source contains.
|
|
privrun() {
|
|
sc=$1; shift
|
|
(umask 022; python3 ./ptydrive.py --timeout 40 --script "$sc" -- \
|
|
env -i HOME="$SB" PATH="$BOXPATH" TERM=dumb LANG=C TMPDIR="$SB/tmp" \
|
|
DOTUP_STATE="$SB/.config/dotfiles" DOTUP_MANIFEST="$M" \
|
|
DOTUP_TEST_LOG="$LOG" FAKE_BOOT_PW="$PW" \
|
|
FAKE_BOOT_BLOB="$SB/blob.env" "$@" \
|
|
"$BOXPATH/sh" $D private) 2>&1 | tr -d '\r' | plain
|
|
}
|
|
mode_of() { stat -c %a "$1" 2>/dev/null || echo missing; }
|
|
|
|
# ---- a wrong password costs one password, not one reinstall -------------
|
|
# These credentials are asked for at the very END of a run. Before the retry
|
|
# loop existed, one mistyped character meant repeating the entire install to
|
|
# get back to this prompt. So the first attempt here is wrong on purpose.
|
|
newbox; pick private/private-repo private/bws-secrets
|
|
PW=pw-ok-$$
|
|
printf 'PRIVATE_REPO_URL=http://git:tok-%s@example.test/dotfiles-private.git\nBWS_ACCESS_TOKEN=bwstok-%s\n' \
|
|
"$$" "$$" > "$SB/blob.env"
|
|
cat > "$SB/steps" <<STEPS
|
|
expect Bootstrap URL:
|
|
send http://example.test/boot
|
|
expect Username:
|
|
send ben
|
|
expect Password:
|
|
send WRONG-ON-PURPOSE
|
|
expect wrong username or password
|
|
expect Bootstrap URL \[
|
|
send
|
|
expect Username \[
|
|
send
|
|
expect Password:
|
|
send $PW
|
|
STEPS
|
|
sed -i 's/^\t//' "$SB/steps"
|
|
out=$(privrun "$SB/steps")
|
|
has "a wrong password names the password" "wrong username or password" "$out"
|
|
has "…and says how to get out" "type q at the URL prompt" "$out"
|
|
has "…then asks again, keeping the URL" "Bootstrap URL [http://example.test/boot]" "$out"
|
|
has "…and the username" "Username [ben]" "$out"
|
|
is "…so the endpoint is asked exactly twice" "2" \
|
|
"$(grep -c 'bootstrap.env' "$LOG" || true)"
|
|
hasnt "the password is never echoed back" "WRONG-ON-PURPOSE" "$out"
|
|
|
|
# ---- what the second attempt actually produced --------------------------
|
|
is "the bws token is written 600" "600" "$(mode_of "$SB/.config/bitwarden/bws-token")"
|
|
is "…holding what the endpoint sent" "bwstok-$$" \
|
|
"$(cat "$SB/.config/bitwarden/bws-token" 2>/dev/null || true)"
|
|
is "the private source is unreadable to anyone else" "700" \
|
|
"$(mode_of "$SB/.local/share/dotfiles-private")"
|
|
is "the credential file is 600" "600" \
|
|
"$(mode_of "$SB/.config/dotfiles/private-credentials")"
|
|
is "…and holds the token the URL carried" "http://git:tok-$$@example.test" \
|
|
"$(cat "$SB/.config/dotfiles/private-credentials" 2>/dev/null || true)"
|
|
hasnt "no credential-bearing URL reaches the transcript" "tok-$$@" "$out"
|
|
is "…nor any command line the run built" "0" \
|
|
"$(grep -c '://[^ /]*:[^ /]*@' "$LOG" || true)"
|
|
has "chezmoi is called by its resolved path" \
|
|
"chezmoi init --apply --source $SB/.local/share/dotfiles-private" "$(cat "$LOG")"
|
|
has "…against the private tier's OWN config file" \
|
|
"-c $SB/.config/chezmoi/private.toml" "$(cat "$LOG")"
|
|
is "…which is never the config the public tier rewrites" "0" \
|
|
"$(grep -c 'chezmoi/chezmoi.toml' "$LOG" || true)"
|
|
is "a later update can still authenticate" "1" \
|
|
"$(grep -c "git -C $SB/.local/share/dotfiles-private config credential.helper" "$LOG" || true)"
|
|
has "bws is verified against the published checksum" "bws checksum verified" "$out"
|
|
is "…and installed, executable" "755" "$(mode_of "$SB/.local/bin/bws")"
|
|
is "…only after a token exists to use it" "yes" \
|
|
"$(printf '%s\n' "$out" | awk '/bws token written/{t=NR} /fetching bws/{f=NR}
|
|
END{print (t && f && t < f) ? "yes" : "no"}')"
|
|
|
|
# ---- the checksum is a decision, not a decoration -----------------------
|
|
# A binary about to hold the key to every other credential. Inverting this
|
|
# one comparison installs exactly the file the check exists to reject, and
|
|
# says "verified" while doing it.
|
|
privbox() { # privbox <selected>... -- fresh box, blob, password, prompts
|
|
newbox; pick "$@"
|
|
PW=pw-$$-$BOXN
|
|
printf 'PRIVATE_REPO_URL=http://git:tok@example.test/x.git\nBWS_ACCESS_TOKEN=bt-%s\n' \
|
|
"$BOXN" > "$SB/blob.env"
|
|
{ printf 'expect Bootstrap URL:\nsend http://example.test/boot\n'
|
|
printf 'expect Username:\nsend ben\n'
|
|
printf 'expect Password:\nsend %s\n' "$PW"; } > "$SB/steps"
|
|
}
|
|
privbox private/bws-secrets
|
|
out=$(privrun "$SB/steps" FAKE_BWS_SUMS=mismatch)
|
|
has "a checksum mismatch refuses to install" "checksum mismatch" "$out"
|
|
is "…and nothing lands in ~/.local/bin" "absent" \
|
|
"$([ -e "$SB/.local/bin/bws" ] && echo present || echo absent)"
|
|
hasnt "…and it does not claim to have verified anything" "checksum verified" "$out"
|
|
privbox private/bws-secrets
|
|
out=$(privrun "$SB/steps" FAKE_BWS_SUMS=absent)
|
|
has "no checksum file says so out loud" "checksums unavailable" "$out"
|
|
is "…and installs anyway, as it says" "755" "$(mode_of "$SB/.local/bin/bws")"
|
|
|
|
# ---- three failures, three different next moves -------------------------
|
|
# One message for 401, 404 and an unreachable host is how a URL-shape bug
|
|
# spends an evening looking like a password problem.
|
|
qsteps() { printf 'expect Bootstrap URL \[\nsend q\n' >> "$SB/steps"; }
|
|
privbox private/bws-secrets; qsteps
|
|
has "a 404 names the route" "no bootstrap.env is there" \
|
|
"$(privrun "$SB/steps" FAKE_BOOT_CODE=404)"
|
|
privbox private/bws-secrets; qsteps
|
|
has "an unreachable host says so" "could not reach that address" \
|
|
"$(privrun "$SB/steps" FAKE_BOOT_CODE=000)"
|
|
privbox private/bws-secrets; qsteps
|
|
has "anything else reports its code" "answered HTTP 500" \
|
|
"$(privrun "$SB/steps" FAKE_BOOT_CODE=500)"
|
|
# An error page must never be parsed as the credential blob.
|
|
privbox private/bws-secrets; qsteps
|
|
out=$(privrun "$SB/steps" FAKE_BOOT_CODE=404)
|
|
is "a non-200 body is never read as a token" "absent" \
|
|
"$([ -e "$SB/.config/bitwarden/bws-token" ] && echo present || echo absent)"
|
|
has "…and q leaves a public-only machine" "public-only machine" "$out"
|
|
|
|
# ---- it asks again, but not forever -------------------------------------
|
|
privbox private/bws-secrets
|
|
{ printf 'expect Bootstrap URL:\nsend http://example.test/boot\n'
|
|
printf 'expect Username:\nsend ben\n'
|
|
printf 'expect Password:\nsend bad1\n'
|
|
i=2
|
|
while [ "$i" -le 5 ]; do
|
|
printf 'expect wrong username or password\n'
|
|
printf 'expect Bootstrap URL \[\nsend\nexpect Username \[\nsend\n'
|
|
printf 'expect Password:\nsend bad%s\n' "$i"
|
|
i=$((i + 1))
|
|
done
|
|
printf 'expect five failed attempts\n'; } > "$SB/steps"
|
|
out=$(privrun "$SB/steps")
|
|
has "five wrong passwords stop the loop" "five failed attempts" "$out"
|
|
has "…pointing at the cheap way back in" "dotup private" "$out"
|
|
is "…having asked the endpoint five times, not four or six" "5" \
|
|
"$(grep -c 'bootstrap.env' "$LOG" || true)"
|
|
|
|
# ---- q at the first prompt is a supported answer ------------------------
|
|
privbox private/private-repo private/bws-secrets
|
|
printf 'expect Bootstrap URL:\nsend q\n' > "$SB/steps"
|
|
out=$(privrun "$SB/steps")
|
|
has "q at the first prompt is public-only" "public-only machine" "$out"
|
|
is "…and writes nothing at all" "0" \
|
|
"$(grep -c 'bootstrap.env' "$LOG" || true)"
|
|
is "…no token" "absent" "$([ -e "$SB/.config/bitwarden/bws-token" ] && echo present || echo absent)"
|
|
is "…and no clone" "absent" "$([ -e "$SB/.local/share/dotfiles-private" ] && echo present || echo absent)"
|
|
else
|
|
printf ' \033[33mskip\033[0m needs python3 to open a pty\n'
|
|
fi
|
|
|
|
printf '\n\033[1mbootstrap.sh — the first command, wrapped\033[0m\n'
|
|
B=$ROOT/bootstrap.sh
|
|
if sh -n "$B" 2>/dev/null; then ok "bootstrap.sh parses"; else no "bootstrap.sh has a syntax error"; fi
|
|
# The tier names no real host, with one carved-out exception: this file may
|
|
# name ITS OWN clone URL (fetching it proves you know the host already). It
|
|
# must never name the endpoint, the VPS, or the private repo.
|
|
if grep -qEi 'xeta|15\.204|dotfiles-private' "$B"; then no "bootstrap.sh names a host beyond its own repo"; else ok "bootstrap.sh names nothing beyond its own repo"; fi
|
|
if grep -q 'DEFAULT_URL="https://[^"]*/dotfiles-public.git"' "$B"; then ok "…and defaults to its own clone URL"; else no "…and defaults to its own clone URL — default missing or malformed"; fi
|
|
# An explicit empty URL is an error, not a fall-through to the default: the
|
|
# caller said "this one" and named nothing.
|
|
rc=0; out=$(DOTFILES_URL= sh "$B" "" </dev/null 2>&1) || rc=$?
|
|
is "an explicit empty URL is refused, not defaulted" 2 "$rc"
|
|
has "…and says how to call it" "usage:" "$out"
|
|
|
|
printf '\n\033[1minteractive loop (needs a pty)\033[0m\n'
|
|
if command -v fzf >/dev/null && command -v curl >/dev/null && command -v script >/dev/null; then
|
|
out=$(sh ./listen-test.sh 2>/dev/null | tr -d '\r' || true)
|
|
case $out in
|
|
*CURSOR_HELD*) ok "cursor survives toggle+reload" ;;
|
|
*) no "cursor position lost across reload — rapid ticking breaks" ;;
|
|
esac
|
|
else
|
|
printf ' \033[33mskip\033[0m needs fzf, curl and script\n'
|
|
fi
|
|
|
|
printf '\n%d passed, %d failed\n\n' "$pass" "$fail"
|
|
[ "$fail" -eq 0 ]
|