reset; run && ! stopped && ok "healthy: nothing stopped"|| bad "healthy"
[ -z "$(ls -A "$T/disk1")"]&& ok "test file removed"|| bad "test file left behind"
reset;FAKE_RO="$T/disk2" run && bad "ro disk exit"||{ stopped && grep -q '^stop docker-registry'"$CALLS"&& ok "ro mount: nginx+registry stopped"|| bad "ro mount not stopped";}
reset; chmod 555"$T/disk1";if["$(id -u)" !=0];then run && bad "unwritable exit"||{ stopped && ok "write failure: stopped"|| bad "write failure not stopped";};fi; chmod 755"$T/disk1"
reset;FAKE_PROBE=empty run && bad "empty reply exit"||{ stopped && ok "empty reply (curl 52), origin up: stopped"|| bad "empty reply not stopped";}
reset;FAKE_PROBE=http500 run && bad "500 exit"||{ stopped && ok "HTTP 500, origin up: stopped"|| bad "500 not stopped";}
reset;FAKE_PROBE=empty FAKE_ORIGIN=down run && ! stopped && ok "origin down too: warn only, not stopped"|| bad "upstream outage must not stop"
# recovery: needs 3 consecutive good runs, only if WE stopped it
reset;FAKE_PROBE=empty run ||true
exportFAKE_PROBE=ok
run; stopped && ok "recovery 1/3: still stopped"|| bad "recovery 1"
FAKE_RO="$T/disk1" run || true; run; stopped && ok "failure resets the streak (1/3 again)"|| bad "streak reset"
run; stopped && ok "recovery 2/3: still stopped"|| bad "recovery 2"
run &&[ -e "$ACTIVE"]&&[ ! -e "$T/state/stopped"]&& grep -q '^start nginx'"$CALLS"&& ok "3rd healthy run: services started, marker cleared"|| bad "recovery 3"
# nginx -t failure blocks the restart
reset;FAKE_PROBE=empty run || true;exportFAKE_PROBE=ok
run; run;PKGCACHE_NGINX_TEST=false run && bad "nginx -t fail exit"||{[ ! -e "$ACTIVE"]&& ok "bad nginx config: stays stopped"|| bad "started despite bad config";}
# restart whose fetch check fails is stopped again
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"
if sudo -n mount --bind "$T/real""$T/robind" 2>/dev/null && sudo -n mount -o remount,bind,ro "$T/robind";then
rm "$T/bin/findmnt"; reset;PKGCACHE_CHECK_PATHS="$T/robind" run && bad "real ro exit"||{ stopped && ok "REAL read-only bind mount: stopped"|| bad "real ro";}
sudo -n umount "$T/robind"
elseecho"skip - cannot bind-mount here, skipping the real ro bind mount case";fi