From 30219b0ea8b9257c8c65fece189f96a224950cc3 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 12:36:32 -0800 Subject: [PATCH] ci: post-merge-review: deny test gates, test deletes and every old protected path; status server out Co-Authored-By: Claude Opus 5.5 --- .../.github/post-merge-review-allow.txt | 23 +++++- .../scripts/post-merge-review-changed.sh | 8 +- .../scripts/post-merge-review-check-test.sh | 73 ++++++++++++++++--- .../scripts/post-merge-review-check.sh | 28 ++++--- 4 files changed, 102 insertions(+), 30 deletions(-) diff --git a/seaweed-block/.github/post-merge-review-allow.txt b/seaweed-block/.github/post-merge-review-allow.txt index f19ce36e25..7aa3a5325a 100644 --- a/seaweed-block/.github/post-merge-review-allow.txt +++ b/seaweed-block/.github/post-merge-review-allow.txt @@ -18,16 +18,14 @@ docs/* *.md -# Test harness and tests (a test file in a denied directory stays denied). -internal/testops/* -cmd/sw-testops/* +# Tests: added or modified, never deleted or moved (the check enforces +# that); a test file in a denied directory stays denied. *_test.go # Status, metrics and observation files, by name. core/host/master/observation_service.go core/host/master/observation_snapshot.go core/host/volume/memory_status.go -core/host/volume/status_server.go core/ops/observation.go core/ops/observation_bundle.go core/ops/observation_dashboard.go @@ -42,6 +40,12 @@ core/ops/volume_status_summary.go # The check itself and CI. !.github/* +# The test gates: the testops engine, its CLI and the gate definitions +# (their docs stay allowed). +!internal/testops/*.go +!internal/testops/*.json +!cmd/sw-testops/* + # Data path and replication. !core/storage/* !core/frontend/* @@ -60,6 +64,17 @@ core/ops/volume_status_summary.go # Wire and persisted formats. !*.proto !*.pb.go +!core/host/master/journal_isolation* +!core/lifecycle/store* +!cmd/sparrow/persist* + +# GC and delete paths. +!cmd/sw-block/chunk_gc* +!cmd/sw-block/chunk_volume_delete* +!core/lifecycle/deletion_reservations* +!core/ops/delete_safety_contract* +!*/gc[_.]* +!*_gc[_.]* # Lease, epoch, claim, admission, GC, delete or format code (tests included) # wherever it lives, by file name. diff --git a/seaweed-block/.github/scripts/post-merge-review-changed.sh b/seaweed-block/.github/scripts/post-merge-review-changed.sh index 4b11c9c2a3..1e23f0d63b 100644 --- a/seaweed-block/.github/scripts/post-merge-review-changed.sh +++ b/seaweed-block/.github/scripts/post-merge-review-changed.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash # Usage: post-merge-review-changed.sh BASE HEAD # -# Writes the paths a PR changes (BASE...HEAD), NUL-separated and unquoted, so -# any byte in a name reaches the check as itself. --no-renames lists both -# names of a moved file. +# Writes what a PR changes (BASE...HEAD) as NUL-separated STATUS, PATH pairs, +# unquoted, so any byte in a name reaches the check as itself. --no-renames +# reports a move as a delete of the old name and an add of the new one. set -euo pipefail base=${1:?usage: post-merge-review-changed.sh BASE HEAD} head=${2:?usage: post-merge-review-changed.sh BASE HEAD} -exec git diff -z --name-only --no-renames "$base...$head" +exec git diff -z --name-status --no-renames "$base...$head" 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 4923e1efb9..6699a12f56 100644 --- a/seaweed-block/.github/scripts/post-merge-review-check-test.sh +++ b/seaweed-block/.github/scripts/post-merge-review-check-test.sh @@ -10,25 +10,34 @@ allow=$here/../post-merge-review-allow.txt workflow=$here/../workflows/post-merge-review.yml fail=0 -expect() { # expect WANT_EXIT NAME PATH... +expect_changes() { # expect_changes WANT_EXIT NAME [STATUS PATH]... local want=$1 name=$2 shift 2 local got=0 - printf '%s\0' "$@" | bash "$check" "$allow" >/dev/null || got=$? + if (($#)); then printf '%s\0' "$@"; fi | bash "$check" "$allow" >/dev/null || got=$? if [[ $got != "$want" ]]; then echo "FAIL $name: exit $got, want $want" fail=1 fi } +expect() { # expect WANT_EXIT NAME PATH... : each path modified + local want=$1 name=$2 p + shift 2 + local args=() + for p in "$@"; do args+=(M "$p"); done + expect_changes "$want" "$name" ${args[@]+"${args[@]}"} +} # Allowed. expect 0 "docs" docs/README.md README.md cmd/sw-block/NOTES.md -expect 0 "harness" internal/testops/run.go cmd/sw-testops/main.go +expect 0 "testops docs" internal/testops/registry-overview.md expect 0 "test outside denied dirs" core/ops/cleanup_projection_test.go cmd/blockmaster/topology_test.go -expect 0 "named status files" core/host/master/observation_service.go core/host/volume/status_server.go +expect 0 "named status files" core/host/master/observation_service.go core/host/volume/memory_status.go expect 0 "release is not lease" cmd/sw-block/release_test.go expect 0 "names with a space, tab or newline" "docs/a b.md" $'docs/a\tb.md' $'docs/a\nb.md' -expect 0 "no paths" "" +expect 0 "no paths" +expect_changes 0 "test added" A cmd/foo/new_test.go +expect_changes 0 "doc deleted" D docs/old.md # Denied by default: not on the allow list. expect 1 "new file anywhere" core/newpkg/decide.go @@ -36,6 +45,7 @@ expect 1 "decision code by name" core/host/master/product_loop.go core/lifecycle expect 1 "go.mod" go.mod expect 1 "go.sum" go.sum expect 1 "status-like but not named" core/ops/operator_status_controller.go +expect 1 "status server: registers a mutating endpoint" core/host/volume/status_server.go # Denied explicitly, even where an allow line matches. expect 1 "storage" core/storage/walstore.go @@ -55,19 +65,42 @@ expect 1 "PR template under .github" .github/pull_request_template.md expect 1 "mixed: allowed plus denied" docs/README.md core/storage/walstore.go expect 1 "mixed: allowed plus unlisted" docs/README.md go.mod -# A missing or empty allow list fails closed. +# Persisted-format, GC and delete paths stay denied, tests included. +expect 1 "lifecycle store test" core/lifecycle/store_test.go +expect 1 "journal isolation test" core/host/master/journal_isolation_test.go +expect 1 "sparrow persist test" cmd/sparrow/persist_sidecar_test.go +expect 1 "chunk volume delete test" cmd/sw-block/chunk_volume_delete_test.go +expect 1 "deletion reservations test" core/lifecycle/deletion_reservations_test.go +expect 1 "delete safety contract test" core/ops/delete_safety_contract_test.go +expect 1 "gc doc" docs/spec/cfg/RED_gc_ageonly.cfg + +# The test gates: engine, CLI and gate definitions (and their tests). +expect 1 "testops engine" internal/testops/control.go +expect 1 "testops engine test" internal/testops/control_test.go +expect 1 "testops gate definition" internal/testops/registry/iscsi-p2-os-smoke.json +expect 1 "testops CLI" cmd/sw-testops/main.go + +# A test may be added or modified, never deleted or replaced. +expect_changes 1 "test deleted" D cmd/foo/guard_test.go +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; } empty=$(mktemp) for bad in "$empty" "/nonexistent/post-merge-review-allow.txt"; do got=0 - printf 'docs/README.md\0' | bash "$check" "$bad" >/dev/null 2>&1 || got=$? + printf 'M\0docs/README.md\0' | bash "$check" "$bad" >/dev/null 2>&1 || got=$? [[ $got == 2 ]] || { echo "FAIL allow list $bad: exit $got, want 2"; fail=1; } done rm -f "$empty" # Real Git: names that git quotes in its default output, a rename out of a -# denied directory, and a retarget onto a base that differs. +# denied directory, a retarget onto a base that differs, and test deletes. repo=$(mktemp -d) -trap 'rm -rf "$repo"' EXIT +trap 'rm -rf "$repo" "${changes:-}"' EXIT g() { git -C "$repo" -c user.name=t -c user.email=t@t -c core.quotePath=true -c core.protectNTFS=false "$@"; } blob= commit() { # commit PARENT PATH... : PARENT's tree plus PATHs (-PATH removes) @@ -84,9 +117,15 @@ commit() { # commit PARENT PATH... : PARENT's tree plus PATHs (-PATH removes) done g commit-tree "$(g write-tree)" -p "$parent" -m c } +changes=$(mktemp) expect_diff() { # expect_diff WANT_EXIT NAME BASE HEAD local got=0 - (cd "$repo" && bash "$changed" "$3" "$4") | bash "$check" "$allow" >/dev/null || got=$? + if ! (cd "$repo" && bash "$changed" "$3" "$4") >"$changes"; then + echo "FAIL $2: listing the changes failed" + fail=1 + return + fi + bash "$check" "$allow" <"$changes" >/dev/null || got=$? if [[ $got != "$1" ]]; then echo "FAIL $2: exit $got, want $1" fail=1 @@ -96,15 +135,18 @@ g init -q blob=$(printf x | g hash-object -w --stdin) g read-tree --empty root=$(g commit-tree "$(g write-tree)" -m root) -main=$(commit "$root" core/storage/old.go docs/x.md) +main=$(commit "$root" core/storage/old.go docs/x.md cmd/foo/guard_test.go) unicode=$(commit "$main" $'core/storage/\xc3\xa9_test.go') oddnames=$(commit "$main" $'docs/tab\there.md' $'docs/new\nline.md' $'docs/\xc3\xa9.md') moved=$(commit "$main" -core/storage/old.go docs/moved.md) parent=$(commit "$main" core/storage/parent.go) stacked=$(commit "$parent" docs/child.md) later=$(commit "$main" core/storage/later.go) +testadd=$(commit "$main" cmd/foo/extra_test.go) +testdel=$(commit "$main" -cmd/foo/guard_test.go) +testmove=$(commit "$main" -cmd/foo/guard_test.go cmd/foo/renamed_test.go) n=$( (cd "$repo" && bash "$changed" "$main" "$oddnames") | tr -cd '\000' | wc -c | tr -d ' ') -[[ $n == 3 ]] || { echo "FAIL fixture: $n odd names in the diff, want 3"; fail=1; } +[[ $n == 6 ]] || { echo "FAIL fixture: $n NULs for 3 odd names, want 6"; fail=1; } if ! (cd "$repo" && git diff --name-only "$main...$unicode") | grep -q '^"'; then echo "FAIL fixture: expected git to quote the unicode name in its default output" fail=1 @@ -115,6 +157,13 @@ expect_diff 1 "git: moved out of storage into docs" "$main" "$moved" expect_diff 0 "git: stacked PR against its parent" "$parent" "$stacked" expect_diff 1 "git: the same PR retargeted to main" "$main" "$stacked" expect_diff 0 "git: the base moved on with denied changes; the PR did not" "$later" "$oddnames" +expect_diff 0 "git: a test added" "$main" "$testadd" +expect_diff 1 "git: a test deleted" "$main" "$testdel" +expect_diff 1 "git: a test moved" "$main" "$testmove" +if (cd "$repo" && bash "$changed" 0000000000000000000000000000000000000001 "$main") >/dev/null 2>&1; then + echo "FAIL git: listing against an unknown base succeeded" + fail=1 +fi # The workflow reruns on every change that can change the verdict, including # a retarget (edited). diff --git a/seaweed-block/.github/scripts/post-merge-review-check.sh b/seaweed-block/.github/scripts/post-merge-review-check.sh index 36662418b3..e9b4b6f3e8 100644 --- a/seaweed-block/.github/scripts/post-merge-review-check.sh +++ b/seaweed-block/.github/scripts/post-merge-review-check.sh @@ -1,13 +1,15 @@ #!/usr/bin/env bash -# Usage: post-merge-review-check.sh ALLOW_FILE < changed-paths +# Usage: post-merge-review-check.sh ALLOW_FILE < changes # -# changed-paths are NUL-separated (post-merge-review-changed.sh). A path -# passes only if it matches an allow pattern and no "!" pattern. -# Prints every path that does not pass and exits 1 if there is one; exits 0 -# if all pass, 2 on a usage error or a missing or empty allow list. +# changes are NUL-separated STATUS, PATH pairs (post-merge-review-changed.sh). +# A path passes only if it matches an allow pattern and no "!" pattern, and +# a test file may be added or modified but not deleted (a move deletes its +# old name). Prints every change that does not pass and exits 1 if there is +# one; exits 0 if all pass, 2 on a usage error, a malformed change or a +# missing or empty allow list. set -euo pipefail -allow_file=${1:?usage: post-merge-review-check.sh ALLOW_FILE < changed-paths} +allow_file=${1:?usage: post-merge-review-check.sh ALLOW_FILE < changes} if [[ ! -f $allow_file ]]; then echo "post-merge-review: allow list $allow_file missing" >&2 exit 2 @@ -32,8 +34,11 @@ fi denied=0 checked=0 -while IFS= read -r -d '' path; do - [[ -n $path ]] || continue +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 + fi checked=$((checked + 1)) why="not on the allow list" for p in "${allow[@]}"; do @@ -49,9 +54,12 @@ while IFS= read -r -d '' path; do break fi done + # A labelled PR may not delete a test (or turn it into something else). + if [[ -z $why && $path == *_test.go && $status != [AM] ]]; then + why="test file status $status: only adding or modifying a test is allowed" + fi if [[ -n $why ]]; then - printf 'DENY %q (%s) -' "$path" "$why" + printf 'DENY %s %q (%s)\n' "$status" "$path" "$why" denied=1 fi done