Files
dotfiles-public/.tests/fakebin/_curl
T
bcherb2 4043787a58 fix: close the four known installer bugs (DU-H1, DU-H2, BUG-1, BUG-2)
- DU-H1: flags are parsed wherever they sit, so `install --unattended`
  and `--unattended install` are the same run; any unknown flag, word,
  or subcommand exits 2 to stderr before a package manager is touched.
- DU-H2: every download lands in one private mktemp -d (mode 700)
  workdir per run, is checked non-empty before sudo tar sees it, and an
  EXIT/INT/TERM trap cleans up. No fixed /tmp paths remain.
- BUG-1: ^t is now toggle-shown — it ticks only the rows the active
  filter is showing, and @needs expansion stops at the first invasive
  row, so an invasive package can never be ticked off-screen.
- BUG-2: ^t journals what it added, so a second ^t over the same shown
  set unticks exactly that set; the bind no longer clears the query.
- lab: the type verb polls fzf's reported query to a deadline instead
  of a fixed sleep; marks_settled retries within its deadline.

Suite 256/0 host, 214/0 docker (ubuntu:24.04), mutations 24/24 killed
(six new mutants re-introduce each bug and all die), lab 6/6 green.
2026-08-22 13:25:21 -04:00

105 lines
4.5 KiB
Plaintext

# Sourced by _fake when it is invoked as `curl`. Stands in for every remote the
# installer talks to, and for nothing else: a URL this file does not recognise
# is a failed download, not a silent success, so a typo'd host or a moved path
# shows up as the failure it would really be.
#
# Knobs, all set by the caller:
# FAKE_BOOT_BLOB file whose contents the bootstrap endpoint returns on 200
# FAKE_BOOT_PW the password that gets a 200; anything else gets a 401
# FAKE_BOOT_CODE force a code (404, 000, 500 ...) whatever the password
# FAKE_BWS_SUMS match (default) | mismatch | absent
# FAKE_FAIL=curl:deb | curl:chezmoi | curl:fzf fail just that one download
_fb=$(dirname "$0") # the fakebin directory
url=; out=; prev=; readcfg=0
for a in "$@"; do
case $prev in -o) out=$a ;; -K) [ "$a" = - ] && readcfg=1 ;; esac
case $a in http://*|https://*|get.chezmoi.io|*.io|*.sh) [ -z "$url" ] && url=$a ;; esac
prev=$a
done
cfg=
[ "$readcfg" = 1 ] && cfg=$(cat) # always drain: the writer is a pipe
# Where a download lands is itself under test (DU-H2: the tarballs used to go to
# /tmp/nvim.tgz and be unpacked by `sudo tar`). The directory is private to the
# run and removed before it exits, so its mode can only be observed from in
# here. Recorded beside the argv line _fake has already written.
[ -n "$out" ] && printf 'curl-outdir %s %s\n' "$(dirname "$out")" \
"$(stat -c %a "$(dirname "$out")" 2>/dev/null || echo unknown)" \
>> "${DOTUP_TEST_LOG:?DOTUP_TEST_LOG unset}"
emit() { if [ -n "$out" ]; then cat > "$out"; else cat; fi; }
# A tiny installer script, printed the way get.chezmoi.io and astral.sh print
# theirs. It installs the FAKE of the same name, so whatever it drops behaves
# like every other fake in this directory.
installer() { # $1 tool, $2 default dir
printf '%s\n' \
"b=$2" \
'while [ $# -gt 0 ]; do case $1 in -b) b=$2; shift 2 ;; *) shift ;; esac; done' \
"mkdir -p \"\$b\" && ln -sf $_fb/_fake \"\$b/$1\" && echo \"installed $1 to \$b\""
}
case $url in
*get.chezmoi.io*)
[ "$mode" = chezmoi ] && exit 22
installer chezmoi "\$HOME/.local/bin"; exit 0 ;;
*astral.sh/uv/install.sh*)
installer uv "\$HOME/.local/bin"; exit 0 ;;
*go.dev/VERSION*)
echo go1.99.0; exit 0 ;;
*api.github.com*)
echo ' "browser_download_url": "https://example.invalid/fake_amd64.deb"'; exit 0 ;;
# ------------------------------------------------------------------- fzf ----
# Only the real release path answers. The tarball is built here from the
# version in the URL, so `dotup preflight` reporting "0.74.2" is evidence that
# the pinned version travelled through the URL and into the binary -- not that
# a fixture happened to say so.
https://github.com/junegunn/fzf/releases/download/*)
[ "$mode" = fzf ] && exit 22
f=${url##*/} # fzf-0.74.2-linux_amd64.tar.gz
v=${f#fzf-}; v=${v%%-*}
d=$(mktemp -d); printf '#!/bin/sh\ncase ${1:-} in --version) echo "%s (fake)" ;; esac\nexit 0\n' "$v" > "$d/fzf"
chmod 755 "$d/fzf"; tar -czf - -C "$d" fzf; rm -rf "$d"; exit 0 ;;
# ------------------------------------------------------------------- bws ----
*/sdk-sm/releases/download/*bws-sha256-checksums-*)
case ${FAKE_BWS_SUMS:-match} in
absent) exit 22 ;;
mismatch) s=0000000000000000000000000000000000000000000000000000000000000000 ;;
*) s=$(printf 'PK-fake-bws-zip\n' | sha256sum | cut -d' ' -f1) ;;
esac
v=${url##*bws-sha256-checksums-}; v=${v%.txt}
for t in x86_64-unknown-linux-musl aarch64-unknown-linux-musl macos-universal; do
printf '%s bws-%s-%s.zip\n' "$s" "$t" "$v"
done | emit
exit 0 ;;
*/sdk-sm/releases/download/*.zip)
printf 'PK-fake-bws-zip\n' | emit; exit 0 ;;
# -------------------------------------------------------------- bootstrap ---
*/bootstrap.env)
pw=$(printf '%s\n' "$cfg" | sed -n 's/^user = "[^:]*:\(.*\)"$/\1/p' | head -1)
code=${FAKE_BOOT_CODE:-}
if [ -z "$code" ]; then
if [ "$pw" = "${FAKE_BOOT_PW:-}" ]; then code=200; else code=401; fi
fi
if [ "$code" = 200 ]; then cat "${FAKE_BOOT_BLOB:?FAKE_BOOT_BLOB unset}"; fi
printf '\n%s' "$code"
[ "$code" = 000 ] && exit 7
exit 0 ;;
esac
# --------------------------------------------------------------- anything ---
# A download to a file still has to produce the file; a download of something
# this stand-in has never heard of is a failure, which is the honest answer.
case $url in
*.deb|*.tar.gz|*.tgz)
[ "$mode" = deb ] && exit 22
[ -n "$out" ] && { : > "$out"; exit 0; }
exit 0 ;;
esac
[ -n "$out" ] && { : > "$out"; exit 0; }
exit 22