ci: post-merge-review: fail closed on a malformed change record

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-20 12:45:03 -08:00
1 parent 30219b0ea8
commit d8ffd2e629
2 files changed
+26 -7

No files matched your search

@@ -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
+13 -4
View File
@@ -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