diff --git a/seaweed-block/.github/scripts/spec-trace-check-test.sh b/seaweed-block/.github/scripts/spec-trace-check-test.sh index f9ee44dd5c..2995c03b83 100644 --- a/seaweed-block/.github/scripts/spec-trace-check-test.sh +++ b/seaweed-block/.github/scripts/spec-trace-check-test.sh @@ -32,8 +32,9 @@ expect 0 "CHANGE kind" "${ok/IMPL M5.Quiesce>Copy/CHANGE M5}" expect 0 "core change with Simplest" "$ok $simplest" M core/storage/gc.go expect 0 "core test only needs no Simplest" "$ok" M core/storage/gc_test.go -expect 0 "core file deleted needs no Simplest" "$ok" D core/storage/old.go expect 0 "CRLF body" "$(printf '%s\n' "$ok" | sed 's/$/\r/')" +expect 0 "CHANGE of two machines" "${ok/IMPL M5.Quiesce>Copy/CHANGE M4, M6}" +expect 0 "list markers and bold keys" "$(printf '%s\n' "$ok" | sed "s/^Feature:/- **Feature:**/; s/^Model:/* Model:/")" expect 0 "Model NONE with a reason" "${ok/Model: docs\/spec\/MaintenanceOwner.tla, exhausted/Model: NONE: CI wiring only, no state}" expect 1 "empty body" "" @@ -42,10 +43,35 @@ expect 1 "short NONE" "${ok/Model: docs\/spec\/MaintenanceOwner.tla, exhausted/M expect 1 "no kind" "${ok/IMPL M5.Quiesce>Copy/B,D,E}" expect 1 "IMPL without transition" "${ok/IMPL M5.Quiesce>Copy/IMPL M5}" expect 1 "NONE is not a kind" "${ok/IMPL M5.Quiesce>Copy \/ INV-MAINT-ONE-OWNER/NONE: tooling only, no machine}" +expect 1 "core file deleted without Simplest" "$ok" D core/storage/old.go +expect 1 "two kinds" "${ok/IMPL M5.Quiesce>Copy/IMPL M5.Quiesce>Copy FIX INV-MAINT-ONE-OWNER}" +expect 1 "kind token with a trailing junk" "${ok/IMPL M5.Quiesce>Copy/FIX INV-GC-SKEW-001x}" +expect 1 "transition with a stray character" "${ok/IMPL M5.Quiesce>Copy/IMPL M5.Quiesce>Copy;x}" +expect 1 "key inside another word" "${ok/Feature: O-SNAP-2/Not-Feature: O-SNAP-2}" +expect 1 "placeholder left in Feature" "${ok/Feature: O-SNAP-2/Feature: }" +expect 1 "placeholder left in Red-first" "$(printf '%s\n' "$ok" | sed "s/^Red-first:.*/Red-first: /")" +expect 1 "placeholder left in Simplest" "$ok +Simplest: " M core/storage/gc.go expect 1 "unfilled template" "$(cat "$here/../pull_request_template.md")" expect 1 "core change without Simplest" "$ok" M core/storage/gc.go expect 1 "cmd change, short Simplest" "$ok Simplest: small" A cmd/sw-block/new.go +# expect_raw WANT_EXIT NAME BYTES: a change list given as printf format. +expect_raw() { + local want=$1 name=$2 got=0 + printf "%s" "$ok" >"$tmp/body" + printf "$3" | bash "$check" "$tmp/body" >/dev/null 2>&1 || got=$? + if [[ $got != "$want" ]]; then + echo "FAIL $name: exit $got, want $want" + fail=1 + fi +} +expect_raw 2 "record cut off before its NUL" "M\0core/storage/gc.go" +expect_raw 2 "status without a path" "M\0" +expect_raw 2 "status cut off before its NUL" "M\0docs/a.md\0M" +expect_raw 2 "unknown status" "R100\0core/a.go\0" +expect_raw 0 "well-formed docs change" "M\0docs/a.md\0" + [[ $fail == 0 ]] && echo "spec-trace self-test: ok" exit $fail diff --git a/seaweed-block/.github/scripts/spec-trace-check.sh b/seaweed-block/.github/scripts/spec-trace-check.sh index e19c72b965..38c83a8185 100644 --- a/seaweed-block/.github/scripts/spec-trace-check.sh +++ b/seaweed-block/.github/scripts/spec-trace-check.sh @@ -4,28 +4,32 @@ # Checks the spec trace in a PR description. changes are NUL-separated # STATUS, PATH pairs (post-merge-review-changed.sh). # -# - Feature:, Machine/INV:, Model: and Red-first: are each present and -# non-empty; "NONE:" needs a reason of at least 10 characters. -# - Machine/INV: starts with the PR's kind: "IMPL .", +# - Feature:, Machine/INV:, Model: and Red-first: each start a line (after +# optional indentation, a list marker or bold) and carry a value that is not +# a template placeholder; "NONE:" needs a reason of at least 10 characters. +# - Machine/INV: starts with exactly one PR kind: "IMPL .", # "FIX " or "CHANGE ". NONE is not a kind. -# - Simplest: is present (20+ characters) when the PR changes non-test Go -# under core/ or cmd/. +# - Simplest: (20+ characters) is present when the PR adds, modifies or +# deletes non-test Go under core/ or cmd/. # # Prints every problem and exits 1 if there is one; exits 0 if none, 2 on a -# usage error. +# usage error or a malformed change list. set -euo pipefail body_file=${1:?usage: spec-trace-check.sh BODY_FILE < changes} [[ -f $body_file ]] || { echo "spec-trace: body file $body_file missing" >&2; exit 2; } body=$(tr -d '\r' <"$body_file") -# value KEY: the text after the first KEY in the body, leading space trimmed. +# value KEY: the text after KEY on the first line that starts with KEY, +# trimmed. A key inside another word ("Not-Feature:") does not count. value() { local line - line=$(printf '%s\n' "$body" | grep -m1 -F -- "$1" || true) + line=$(printf '%s\n' "$body" | grep -m1 -E "^[[:space:]]*([-*][[:space:]]+)?(\*\*)?$1" || true) [[ -n $line ]] || return 0 line=${line#*"$1"} - printf '%s' "${line#"${line%%[![:space:]]*}"}" + line=${line#\*\*} + line=${line#"${line%%[![:space:]]*}"} + printf '%s' "${line%"${line##*[![:space:]]}"}" } bad=0 @@ -35,6 +39,8 @@ for key in Feature: Machine/INV: Model: Red-first:; do v=$(value "$key") if [[ -z $v ]]; then problem "missing or empty $key" + elif [[ $v == '<'* ]]; then + problem "$key still holds the template placeholder" elif [[ $v == NONE:* ]]; then r=${v#NONE:} r=${r#"${r%%[![:space:]]*}"} @@ -42,22 +48,34 @@ for key in Feature: Machine/INV: Model: Red-first:; do fi done -kind_re='^(IMPL [A-Za-z0-9_]+[.][^[:space:]]+|FIX INV-[A-Z0-9-]+|CHANGE [A-Za-z0-9_]+)' +# One kind token, ending at the line end, a space, a comma or a slash. +end='($|[[:space:],/])' +kind_re="^(IMPL [A-Za-z0-9_]+[.][A-Za-z0-9_>.-]+|FIX INV-[A-Z0-9]+(-[A-Z0-9]+)*|CHANGE [A-Za-z0-9_]+)$end" mi=$(value Machine/INV:) -if [[ -n $mi && ! $mi =~ $kind_re ]]; then - problem "Machine/INV: must start with IMPL ., FIX or CHANGE " +if [[ -n $mi && $mi != '<'* ]]; then + if [[ ! $mi =~ $kind_re ]]; then + problem "Machine/INV: must start with IMPL ., FIX or CHANGE " + elif [[ ${mi#"${BASH_REMATCH[0]}"} =~ (^|[^A-Za-z0-9_])(IMPL|FIX|CHANGE)([^A-Za-z0-9_]|$) ]]; then + problem "Machine/INV: names more than one kind; a PR is exactly one of IMPL, FIX or CHANGE" + fi fi core=0 -while IFS= read -r -d '' status && IFS= read -r -d '' path; do - [[ $status == D ]] && continue +while IFS= read -r -d '' status; do + [[ $status == [ADMT] ]] || { echo "spec-trace: malformed change list: status ${status@Q}" >&2; exit 2; } + IFS= read -r -d '' path || { echo "spec-trace: malformed change list: status $status without a path" >&2; exit 2; } + [[ -n $path ]] || { echo "spec-trace: malformed change list: empty path" >&2; exit 2; } if [[ $path == core/*.go || $path == cmd/*.go ]] && [[ $path != *_test.go ]]; then core=1 fi done +# A record cut off before its NUL is malformed, not skipped. +[[ -z ${status-} ]] || { echo "spec-trace: malformed change list: unterminated record" >&2; exit 2; } if ((core)); then s=$(value Simplest:) - ((${#s} >= 20)) || problem "Simplest: (20+ characters) is required when non-test Go under core/ or cmd/ changes" + if ((${#s} < 20)) || [[ $s == '<'* ]]; then + problem "Simplest: (20+ characters) is required when non-test Go under core/ or cmd/ changes" + fi fi exit $bad