monitoring: fix progress bar when estimate is short

Rebalance PROGRESS_TOTAL if done exceeds it (never print 224/205);
raise e2e estimate for ATM ladder INFO volume; final line snaps N/N.
This commit is contained in:
Hernâni Marques 2026-07-17 18:55:08 +02:00
parent 4cf923b271
commit d08442a904
No known key found for this signature in database
2 changed files with 40 additions and 8 deletions

View file

@ -493,6 +493,10 @@ set_progress_total() {
# PROGRESS_TOTAL=0 → no percent, only "done=N".
# Does not reset GLOBAL_N / PROGRESS_DONE if already mid-run (state file).
local n="${1:-0}"
# Never shrink below already completed work (re-estimate mid-run safe)
if [ "${PROGRESS_DONE:-0}" -gt 0 ] && [ "$n" -gt 0 ] && [ "$n" -lt "$PROGRESS_DONE" ]; then
n=$PROGRESS_DONE
fi
PROGRESS_TOTAL="$n"
if [ "${PROGRESS_DONE:-0}" -eq 0 ]; then
PROGRESS_LAST_SHOWN=0
@ -504,11 +508,30 @@ add_progress_total() {
PROGRESS_TOTAL=$((PROGRESS_TOTAL + n))
_mon_state_save
}
# When estimate was short, grow total so we never print done>total (e.g. 224/205).
# Keeps ~10% headroom so the bar is not stuck at 100% while checks continue.
_progress_rebalance() {
[ "${PROGRESS_TOTAL:-0}" -gt 0 ] || return 0
[ "${PROGRESS_DONE:-0}" -gt 0 ] || return 0
if [ "$PROGRESS_DONE" -gt "$PROGRESS_TOTAL" ]; then
local head=$((PROGRESS_DONE / 10))
[ "$head" -lt 12 ] && head=12
PROGRESS_TOTAL=$((PROGRESS_DONE + head))
fi
}
_progress_bar_line() {
local done="$1" total="$2" width=24 pct=0 filled empty i bar
# Defensive: never display done > total
if [ "$total" -gt 0 ] && [ "$done" -gt "$total" ]; then
total=$done
fi
if [ "$total" -gt 0 ]; then
pct=$((done * 100 / total))
[ "$pct" -gt 100 ] && pct=100
# While still running past an estimate, keep bar at most 99% until final rebalance
if [ "$done" -lt "$total" ] && [ "$pct" -ge 100 ]; then
pct=99
fi
filled=$((pct * width / 100))
[ "$filled" -gt "$width" ] && filled=$width
empty=$((width - filled))
@ -536,6 +559,7 @@ _progress_maybe_show() {
local force="${1:-0}"
[ "${PROGRESS_OFF:-0}" = "1" ] && return 0
[ "$PROGRESS_DONE" -le 0 ] && [ "$force" != "1" ] && return 0
_progress_rebalance
if [ "$force" = "1" ] || \
[ $((PROGRESS_DONE - PROGRESS_LAST_SHOWN)) -ge "$PROGRESS_SHOW_EVERY" ] || \
{ [ "$PROGRESS_TOTAL" -gt 0 ] && [ "$PROGRESS_DONE" -ge "$PROGRESS_TOTAL" ]; }; then
@ -561,6 +585,7 @@ _take_tid() {
LAST_TID=$(printf '%s-%02d' "$TEST_AREA" "$TEST_N")
fi
PROGRESS_DONE=$((PROGRESS_DONE + 1))
_progress_rebalance
_mon_state_save
_progress_maybe_show 0
}
@ -683,6 +708,11 @@ summary() {
echo ""
# final progress line (no _take_tid — plain printf)
if [ "${PROGRESS_OFF:-0}" != "1" ] && [ "$PROGRESS_DONE" -gt 0 ]; then
# Snap total to actual so last line is exact N/N 100%
if [ "$PROGRESS_TOTAL" -gt 0 ] && [ "$PROGRESS_DONE" -ne "$PROGRESS_TOTAL" ]; then
PROGRESS_TOTAL=$PROGRESS_DONE
_mon_state_save
fi
_progress_bar_line "$PROGRESS_DONE" "$PROGRESS_TOTAL"
fi
if [ "$GLOBAL_N" -gt 0 ]; then

View file

@ -221,18 +221,20 @@ if [ "${#PHASES[@]}" -eq 0 ]; then
PHASES=(urls)
fi
# Rough expected check counts for progress % (override: PROGRESS_TOTAL=N)
# Rough expected check counts for progress % (override: PROGRESS_TOTAL=N).
# Prefer slightly high — lib.sh rebalances if still short (never shows done>total).
if [ "${PROGRESS_TOTAL:-0}" = "0" ] || [ -z "${PROGRESS_TOTAL:-}" ]; then
_pt=0
for p in "${PHASES[@]}"; do
case "$p" in
urls) _pt=$((_pt + 70)) ;;
inside) _pt=$((_pt + 25)) ;;
versions) _pt=$((_pt + 20)) ;;
sanity) _pt=$((_pt + 30)) ;;
server) _pt=$((_pt + 15)) ;;
e2e) _pt=$((_pt + 90)) ;;
ladder|goa-ladder) _pt=$((_pt + 80)) ;;
urls) _pt=$((_pt + 85)) ;; # +qr group
inside) _pt=$((_pt + 30)) ;;
versions) _pt=$((_pt + 25)) ;;
sanity) _pt=$((_pt + 35)) ;;
server) _pt=$((_pt + 20)) ;;
# e2e: ATM ladder emits many INFO lines (coins before/after each note)
e2e) _pt=$((_pt + 240)) ;;
ladder|goa-ladder) _pt=$((_pt + 120)) ;;
esac
done
set_progress_total "$_pt"