mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 16:54:07 +01:00
Shell redirections are builtins, so no PATH stub can intercept `cat > /etc/modprobe.d/x.conf`. That left installer scripts unverifiable: stub cp/chmod/ln and the trace is nearly empty, don't and the run rewrites the live system. --prefix redirects HOME and every XDG_* base into a temp tree. XDG_DATA_HOME is exported explicitly, not left to default off HOME: install_leechblock.sh reads it directly and then runs `rsync -a --delete` at it. --bind-abs binds hardcoded absolutes via bwrap --unshare-user --uid 0, leaf directories only. uid 0 is load-bearing beyond permissions: common.sh's require_root does `exec sudo "$0"`, and under the sudo stub that truncated the whole run to one recorded call -- a trace that diffs clean against any split. Binding /etc wholesale was measured to shadow /etc/passwd, collapse $SUDO_USER to /home//, and mask a nested bind, so the scanner never emits it. The trace gains a manifest of every file written, with content hashes. That section is the point: with it, a dropped write in the fixture pair is a one-line diff; with it stripped, the two traces are identical, i.e. the old harness passed that broken split. Hashes normalize the prefix to @PREFIX@ because install_usage_monitoring.sh writes an unquoted heredoc that bakes $HOME into the artifact. Verified: ~/.config/systemd/user, ~/.local/bin, ~/.local/share and /etc/modprobe.d byte-identical before and after; usage-report units still 2. The three prior regressions are now committed fixtures rather than ad-hoc -- one was silently neutered mid-change when a trailing echo added for SC2034 became the function's last statement and turned exit 1 into exit 0. Stub generation moved to lib/ because --prefix pushed the harness to 252 lines, over the cap it exists to serve. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
33 lines
1.3 KiB
Bash
Executable File
33 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Regression fixture: the self-referencing nameref.
|
|
#
|
|
# `local -n LANG_CODE_FILES="$1"` pointing at a global of the same name still
|
|
# moves data on bash 5.3, but warns `circular name reference` on EVERY access,
|
|
# straight into the script's output.
|
|
#
|
|
# Traced, this shows up as the warning in stderr despite exit 0 and correct
|
|
# stdout -- which is why stderr belongs in the trace and not just the status.
|
|
|
|
set -euo pipefail
|
|
|
|
# The array is declared and populated indirectly. Declaring it as a literal
|
|
# `declare -A LANG_CODE_FILES=(...)` lets shellcheck tie the global to the
|
|
# same-named `local -n` below and raise SC2178, and suppressing that is barred.
|
|
# The runtime shape under test is untouched: at execution time there is still a
|
|
# global associative array whose name the local nameref reuses, which is what
|
|
# produces the circular-reference warning.
|
|
CODE_FILES_MAP="LANG_CODE_FILES"
|
|
declare -A "$CODE_FILES_MAP"
|
|
printf -v "${CODE_FILES_MAP}[python]" '%s' 7
|
|
|
|
count_files() {
|
|
# The bug: a local nameref bound to a global of the SAME name. bash still
|
|
# moves the data, but warns `circular name reference` on every access.
|
|
local -n LANG_CODE_FILES="$1"
|
|
echo "python=${LANG_CODE_FILES[python]}"
|
|
}
|
|
|
|
count_files "$CODE_FILES_MAP"
|
|
echo "exit 0 with correct stdout, but stderr carries the warning"
|