Files
dotfiles-public/.tests/lab/scenarios/00-smoke.sh
T
bcherb2 a001406a33 test: container lab for the two-tier apply
A disposable ubuntu container, a fake private tier and a fake bootstrap
endpoint, so the whole documented path — chezmoi init --apply, dotup pick,
dotup private, cmp apply, dotsecrets — can run end to end without touching a
real machine or a real credential. The fake tier mirrors the real one's
structure (seven secrets and one alias) because dotsecrets is copied verbatim
and the "8 exports, not 7" assertion depends on that cardinality; its ids are
sequential and obviously synthetic.

check-verbatim.sh keeps the fake tier's copies of shipped files honest, and
snapshot.sh records file modes so a 644 where a 600 belongs is a diff.
2026-08-21 22:34:53 -04:00

63 lines
3.0 KiB
Bash

#!/bin/bash
# Does the lab itself work? Clone the public tier from the local server exactly
# as the README's first command does, and prove the code that arrived is the
# working tree rather than whatever was last pushed.
set -u
fail() { echo "FAIL: $*"; exit 1; }
ok() { echo " ok $*"; }
echo "-- environment as handed to a real user --"
echo " user=$(id -un) uid=$(id -u) shell=$SHELL home=$HOME"
echo " PATH=$PATH"
case ":$PATH:" in *":$HOME/.local/bin:"*)
fail "~/.local/bin is already on PATH -- the box is not fresh, and the
'command not found' bug cannot reproduce here" ;;
esac
ok "~/.local/bin is NOT on PATH yet (matches a real fresh login)"
command -v git >/dev/null && fail "git pre-installed -- image is too generous"
ok "git absent, as on a stock image"
echo "-- the documented first command --"
# ISSUE-1 regression guard: NOTHING is installed by hand here. git is absent,
# and the documented command has to cope with that on its own. If this scenario
# ever needs an `apt-get install git` again, the front door has re-broken.
sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply "$PUB_URL" >/tmp/init.log 2>&1 \
|| { tail -20 /tmp/init.log; fail "chezmoi init --apply"; }
ok "public tier applied — from a box with no git, unaided"
grep -q 'installing git' /tmp/init.log \
|| fail "git was installed, but not by run_before_00-require-git.sh —
something else is satisfying the prerequisite and the fix is untested"
ok "run_before_00-require-git.sh is what supplied git"
command -v git >/dev/null || fail "git still missing after the apply"
n=$(ls -d "$HOME/.oh-my-zsh" "$HOME/.tmux" 2>/dev/null | wc -l)
[ "$n" -eq 2 ] || fail "the git-repo externals did not clone ($n/2 present)"
ok "the six git-repo externals cloned"
[ -x "$HOME/.local/bin/dotup" ] || fail "no executable at ~/.local/bin/dotup"
ok "dotup landed at ~/.local/bin/dotup"
# The whole point of the lab: prove we are running uncommitted code. The
# snapshot commit message is the marker, and it cannot exist on any real remote.
src=$(~/bin/chezmoi source-path 2>/dev/null || chezmoi source-path 2>/dev/null || echo "$HOME/.local/share/chezmoi")
msg=$(git -C "$src" log -1 --format=%s 2>/dev/null || echo none)
case $msg in
"working-tree snapshot of dotfiles-public") ok "serving the WORKING TREE, not a pushed commit" ;;
*) fail "expected the working-tree snapshot commit, got: $msg" ;;
esac
echo "-- and the bug, reproduced --"
if command -v dotup >/dev/null 2>&1; then
fail "bare 'dotup' resolved in this shell -- expected 'command not found'"
fi
ok "bare 'dotup' is command-not-found in the shell that ran the install"
if bash -lc 'command -v dotup' >/dev/null 2>&1; then
ok "a NEW login shell does resolve it (~/.profile picks up ~/.local/bin)"
grep -q 'Next: ~/.local/bin/dotup' /tmp/init.log \
|| fail "the install never told the user what to run next, so the only
way to find out is to type 'dotup' and be told it does not exist"
ok "the install printed the absolute path to run next, and why"
else
fail "even a new login shell cannot find dotup"
fi
echo "SMOKE PASS"