fix: add pipe2 init invariant check

This commit is contained in:
2026-07-13 17:38:12 +03:00
parent 829e1b87f5
commit bf8f012eff
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
project_root="$(git -C "$script_dir" rev-parse --show-toplevel)"
file_path="$project_root/local/sources/base/init/src/service.rs"
if [[ -t 1 ]]; then
c_reset=$'\033[0m'
c_red=$'\033[31m'
c_green=$'\033[32m'
c_yellow=$'\033[33m'
else
c_reset=''
c_red=''
c_green=''
c_yellow=''
fi
ok() { printf '%sOK%s: %s\n' "$c_green" "$c_reset" "$*"; }
warn() { printf '%sWARN%s: %s\n' "$c_yellow" "$c_reset" "$*"; }
fail() { printf '%sFAIL%s: %s\n' "$c_red" "$c_reset" "$*" >&2; }
usage() {
cat <<EOF
Usage: $(basename "$0") [--strict]
Static check for panic-on-pipe regressions in local/sources/base/init/src/service.rs.
Options:
--strict Also fail on any unwrap() or expect() inside local/sources/base/init/
-h, --help Show this help
EOF
}
strict=0
for arg in "$@"; do
case "$arg" in
--strict) strict=1 ;;
-h|--help) usage; exit 0 ;;
*) fail "unknown argument: $arg"; usage; exit 2 ;;
esac
done
if [[ ! -f "$file_path" ]]; then
fail "missing file: $file_path"
exit 1
fi
pipe_line=""
if pipe_line=$(grep -nE '\.unwrap_or_else.*panic.*pipe' "$file_path" | head -1); then
line_no="${pipe_line%%:*}"
fail "pipe panic still present at line $line_no: ${pipe_line#*:}"
exit 1
fi
panic_count=$(grep -o 'panic!' "$file_path" | wc -l | tr -d ' ')
expect_count=$(grep -o '\.expect(' "$file_path" | wc -l | tr -d ' ')
warn "panic! count: $panic_count"
warn ".expect( count: $expect_count"
if (( strict )); then
unwrap_count=$(grep -R -o '\.unwrap()' "$project_root/local/sources/base/init" | wc -l | tr -d ' ')
if (( unwrap_count > 0 || expect_count > 0 )); then
fail "strict mode failed: unwrap()/expect() found under init/"
exit 1
fi
fi
ok "no panic-on-pipe in init/service.rs"