diff --git a/seaweed-block/.github/scripts/post-merge-review-check-test.sh b/seaweed-block/.github/scripts/post-merge-review-check-test.sh index 6699a12f56..7cf3d0c8b5 100644 --- a/seaweed-block/.github/scripts/post-merge-review-check-test.sh +++ b/seaweed-block/.github/scripts/post-merge-review-check-test.sh @@ -86,9 +86,19 @@ expect_changes 1 "test type changed" T cmd/foo/guard_test.go expect_changes 1 "test moved (delete plus add)" D cmd/foo/guard_test.go A cmd/foo/renamed_test.go # A malformed change list or a missing or empty allow list fails closed. -got=0 -printf 'M\0' | bash "$check" "$allow" >/dev/null 2>&1 || got=$? -[[ $got == 2 ]] || { echo "FAIL change list without a path: exit $got, want 2"; fail=1; } +malformed() { # malformed NAME PRINTF-FORMAT + local got=0 + printf "$2" | bash "$check" "$allow" >/dev/null 2>&1 || got=$? + [[ $got == 2 ]] || { echo "FAIL malformed list, $1: exit $got, want 2"; fail=1; } +} +malformed "status without a path" 'M\0' +malformed "bare unterminated status" 'M' +malformed "trailing partial status after a valid pair" 'M\0docs/x.md\0D' +malformed "unterminated path" 'M\0docs/x.md' +malformed "unknown status" 'BOGUS\0docs/x.md\0' +malformed "rename status (renames are off)" 'R100\0docs/x.md\0' +malformed "empty status" '\0docs/x.md\0' +malformed "empty path" 'M\0\0' empty=$(mktemp) for bad in "$empty" "/nonexistent/post-merge-review-allow.txt"; do got=0 diff --git a/seaweed-block/.github/scripts/post-merge-review-check.sh b/seaweed-block/.github/scripts/post-merge-review-check.sh index e9b4b6f3e8..5875b0b928 100644 --- a/seaweed-block/.github/scripts/post-merge-review-check.sh +++ b/seaweed-block/.github/scripts/post-merge-review-check.sh @@ -34,11 +34,20 @@ fi denied=0 checked=0 -while IFS= read -r -d '' status; do - if ! IFS= read -r -d '' path || [[ -z $status || -z $path ]]; then - echo "post-merge-review: malformed change list (status ${status@Q})" >&2 - exit 2 +malformed() { + echo "post-merge-review: malformed change list: $1" >&2 + exit 2 +} +while :; do + # Every field ends in NUL: a field cut off at the end is malformed, not + # skipped, and only the statuses git diff --no-renames writes are known. + if ! IFS= read -r -d '' status; then + [[ -z $status ]] || malformed "unterminated status ${status@Q}" + break fi + [[ $status == [ADMT] ]] || malformed "unknown status ${status@Q}" + IFS= read -r -d '' path || malformed "status $status without a terminated path" + [[ -n $path ]] || malformed "status $status with an empty path" checked=$((checked + 1)) why="not on the allow list" for p in "${allow[@]}"; do