pkg-cache selfcheck: re-check nginx started by something else while stopped; fix test fake is-active

The marker branch left a manually/otherwise restarted nginx running unchecked
while the disks were still bad. Now a running nginx with our marker present is
judged like normal operation (stopped again if unhealthy). The test systemctl
fake always returned 0 for is-active, hiding the admin-stopped branch; fixed,
and the tests now pin PKGCACHE_SERVICES and cover the empty-list case.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-29 07:30:52 -08:00
1 parent 8107b29e14
commit bd685f72fb
2 files changed
+18 -1

No files matched your search

+11 -1
View File
@@ -32,13 +32,14 @@ EOS
cat >"$T/bin/systemctl" <<'EOS'
#!/bin/sh
echo "$*" >>"$CALLS"
case "$1" in is-active) [ -e "$ACTIVE" ];; start) touch "$ACTIVE";; stop) rm -f "$ACTIVE";; esac
case "$1" in is-active) [ -e "$ACTIVE" ]; exit $?;; start) touch "$ACTIVE";; stop) rm -f "$ACTIVE";; esac
exit 0
EOS
printf '#!/bin/sh\nexit 0\n' >"$T/bin/logger"; chmod +x "$T/bin/"*
export PATH="$T/bin:$PATH" CALLS="$T/calls" ACTIVE="$T/active"
export PKGCACHE_STATE_DIR="$T/state" PKGCACHE_CHECK_PATHS="$T/disk1 $T/disk2"
export PKGCACHE_PROBE_URL=http://probe PKGCACHE_ORIGIN_URL=http://origin
export PKGCACHE_SERVICES="nginx docker-registry" # explicit: never rely on the script default in a test
export PKGCACHE_NGINX_TEST=true FAKE_RO=none FAKE_PROBE=ok FAKE_ORIGIN=ok
run() { "$S" >"$T/out" 2>&1; }
reset() { rm -rf "$T/state" "$T/calls"; touch "$T/calls" "$ACTIVE"; }
@@ -67,6 +68,15 @@ run; run; PKGCACHE_NGINX_TEST=false run && bad "nginx -t fail exit" || { [ ! -e
reset; FAKE_PROBE=empty run || true; run; run; FAKE_PROBE=empty run && bad "restart-fail exit" || { [ ! -e "$ACTIVE" ] && [ -e "$T/state/stopped" ] && ok "restart with failing fetch: stopped again" || bad "restart-fail"; }
# never start something an admin stopped
reset; rm -f "$ACTIVE"; run && ! grep -q '^start' "$CALLS" && ok "admin-stopped nginx is left alone" || bad "admin stop"
# empty services list must mean "manage nothing", never the real defaults
reset; PKGCACHE_SERVICES="" FAKE_PROBE=empty run || true
! grep -q '^stop' "$CALLS" && ok "empty PKGCACHE_SERVICES: nothing stopped" || bad "empty services list stopped something"
# something else restarts nginx while our marker exists: re-checked, stopped again if still bad
reset; FAKE_PROBE=empty run || true; touch "$ACTIVE"
FAKE_RO="$T/disk1" run || true
[ ! -e "$ACTIVE" ] && ok "nginx restarted by someone else while unhealthy: stopped again" || bad "fight: left running"
reset; FAKE_PROBE=empty run || true; touch "$ACTIVE"
run && [ -e "$ACTIVE" ] && [ ! -e "$T/state/stopped" ] && ok "nginx restarted by someone else and healthy: left running, marker cleared" || bad "fight: healthy case"
# REAL read-only bind mount
mkdir -p "$T/real" "$T/robind"
if sudo -n mount --bind "$T/real" "$T/robind" 2>/dev/null && sudo -n mount -o remount,bind,ro "$T/robind"; then