From 9b01a4172b80d33f99df87064fb655235d80e8b2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 11:05:59 -0800 Subject: [PATCH 1/3] ci: run the real-filer integration tests; report invariants-ledger anchors The chunkstore_integration tests (real weed master, volume and filer) ran nowhere in CI. They now run in the process-level job against the pinned weed it already downloads: always on pushes to main and train PRs, and on any other PR that touches core/frontend/chunkstore/ or core/storage/. Only the integration tests run (-run '^TestIntegration' in chunkstore, the layout sync crash cases in durable); the default suite already covers the rest. The spec-trace job also prints every code and test anchor of docs/design/invariants.md that does not exist at the PR's commit. It reads git objects only and never fails the check yet: it becomes gating once the known imprecise anchors are corrected. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/.github/scripts/ledger_check.py | 106 ++++++++++++++++++ .../.github/workflows/spec-trace.yml | 10 ++ seaweed-block/.github/workflows/test.yml | 23 ++++ 3 files changed, 139 insertions(+) create mode 100644 seaweed-block/.github/scripts/ledger_check.py diff --git a/seaweed-block/.github/scripts/ledger_check.py b/seaweed-block/.github/scripts/ledger_check.py new file mode 100644 index 0000000000..128c6923ff --- /dev/null +++ b/seaweed-block/.github/scripts/ledger_check.py @@ -0,0 +1,106 @@ +"""Check that every code and test anchor of the invariants ledger exists at a git ref. + +usage: python -I ledger_check.py [] + +A ledger row is a table line whose first cell holds `INV-...`. In its cells, a +backticked token that ends in .go is a FILE; a backticked identifier (or +Type.Method) is a SYMBOL of the nearest file named before it in the same cell, +or, in the test cell, of any file named in that cell. A file must exist at the +ref; a symbol must occur in its file as a whole word (for a test: `func Name(`). +A symbol with no file in its cell is looked up in the whole tree. A file may +be a glob (`volume_lock*.go`). A lower-case token with an underscore (a build +tag, a JSON key, a reason string) is not a Go symbol and is not checked. +Prints one line per missing anchor and a summary. It reads; it changes nothing. +""" +import re +import subprocess +import sys + + +def git(repo, *args): + return subprocess.run(["git", "-C", repo] + list(args), capture_output=True, text=True, + encoding="utf-8", errors="replace").stdout + + +def main(): + repo, ref = sys.argv[1], sys.argv[2] + ledger = sys.argv[3] if len(sys.argv) > 3 else "docs/design/invariants.md" + text = git(repo, "show", "%s:%s" % (ref, ledger)) + files = set(git(repo, "ls-tree", "-r", "--name-only", ref).split("\n")) + cache = {} + + def body(path): + if path not in cache: + cache[path] = git(repo, "show", "%s:%s" % (ref, path)) + return cache[path] + + def resolve(tok): + """A file token may be a full path or a bare file name.""" + if tok in files: + return [tok] + if "*" in tok: + rx = re.compile("^(.*/)?" + "[^/]*".join(re.escape(x) for x in tok.split("*")) + "$") + return [f for f in files if rx.match(f)] + if "/" not in tok: + return [f for f in files if f.endswith("/" + tok)] + return [f for f in files if f.endswith("/" + tok) or f.endswith(tok)] + + ident = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?(\(\))?$") + go_all = None + rows = missing = anchors = 0 + for n, line in enumerate(text.split("\n"), 1): + if not line.startswith("|"): + continue + cells = [c.strip() for c in line.strip().strip("|").split("|")] + m = re.match(r"`(INV-[A-Z0-9-]+)`", cells[0]) if cells else None + if not m or len(cells) < 6: + continue + rows += 1 + inv, status = m.group(1), cells[-1] + if "ARCHIVED" in status: + continue + for ci, kind in ((3, "code"), (4, "test")): + toks = re.findall(r"`([^`]+)`", cells[ci]) + cell_files = [] + for t in toks: + if t.endswith(".go"): + cell_files.append(t) + cur = None + for t in toks: + if t.endswith(".go"): + cur = t + anchors += 1 + if not resolve(t): + missing += 1 + print("%s (line %d, %s, %s): file %s does not exist" % (inv, n, kind, status, t)) + continue + if not ident.match(t): + continue + sym = t.rstrip("()").split(".")[-1] + if sym in ("nil", "true", "false") or sym.isupper() or len(sym) < 3: + continue + if "_" in sym and sym == sym.lower(): + # a build tag, a JSON key or a reason string: not a Go symbol + continue + scope = [cur] if (cur and kind == "code") else cell_files + paths = [p for f in scope for p in resolve(f)] + anchors += 1 + if kind == "test" and sym.startswith(("Test", "Fuzz", "Benchmark")): + pat = re.compile(r"func %s\(" % re.escape(sym)) + else: + pat = re.compile(r"\b%s\b" % re.escape(sym)) + if paths: + ok = any(pat.search(body(p)) for p in paths) + else: + if go_all is None: + go_all = git(repo, "grep", "-h", "-E", r"^(func|type|var|const|\s+[A-Za-z_]+\s)", ref, "--", "*.go") + ok = bool(pat.search(go_all)) + if not ok: + missing += 1 + where = ", ".join(scope) if scope else "the tree" + print("%s (line %d, %s, %s): %s not found in %s" % (inv, n, kind, status, t, where)) + print("%d rows, %d anchors, %d missing at %s" % (rows, anchors, missing, ref)) + + +if __name__ == "__main__": + main() diff --git a/seaweed-block/.github/workflows/spec-trace.yml b/seaweed-block/.github/workflows/spec-trace.yml index 077d5f7ef6..ad47abbf46 100644 --- a/seaweed-block/.github/workflows/spec-trace.yml +++ b/seaweed-block/.github/workflows/spec-trace.yml @@ -68,3 +68,13 @@ jobs: bash .github/scripts/public-text-check-test.sh printf '%s' "$TITLE" >title.txt bash .github/scripts/public-text-check.sh "$mb" "$HEAD" title.txt body.txt + + - name: Invariants ledger anchors (report only) + # Every code and test anchor of docs/design/invariants.md must exist at + # the PR's commit (git objects only; nothing from the PR is run). It + # reports and does not fail the check while the known imprecise + # anchors are being corrected; then this step becomes gating. + continue-on-error: true + env: + HEAD: ${{ github.event.pull_request.head.sha }} + run: python3 -I .github/scripts/ledger_check.py . "$HEAD" || true diff --git a/seaweed-block/.github/workflows/test.yml b/seaweed-block/.github/workflows/test.yml index d0d4b62893..52840ebf9f 100644 --- a/seaweed-block/.github/workflows/test.yml +++ b/seaweed-block/.github/workflows/test.yml @@ -157,6 +157,29 @@ jobs: tar -xzf "$tgz" -C "$bin" weed echo "CHUNKSTORE_WEED=$bin/weed" >>"$GITHUB_ENV" + - name: Real-filer integration tests + if: matrix.suite == 'process' && steps.scope.outputs.docs_only != '1' + # The chunkstore_integration tests run against the pinned weed above + # (master, volume and filer as real processes): the conditional HEAD + # writes, cut uploads and object deletes of the chunk store, and the + # layout sync crash cases of the durable provider. They fail, never + # skip, without the binary. Pushes to main and train PRs always run + # them; another PR runs them when it touches core/frontend/chunkstore/ + # or core/storage/. + env: + EVENT: ${{ github.event_name }} + HEAD_REF: ${{ github.head_ref }} + run: | + set -euo pipefail + if [ "$EVENT" != push ] && [[ "$HEAD_REF" != train/* ]]; then + if ! git diff --name-only HEAD^1 HEAD | grep -qE '^core/(frontend/chunkstore|storage)/'; then + echo "skipped: the PR touches neither core/frontend/chunkstore/ nor core/storage/" + exit 0 + fi + fi + go test -count=1 -timeout 20m -tags chunkstore_integration -run '^TestIntegration' ./core/frontend/chunkstore/ + go test -count=1 -timeout 20m -tags chunkstore_integration -run '^TestQD1LayoutSync' ./core/frontend/durable/ + - name: Build the binaries and the test binary once if: matrix.suite == 'process' && steps.scope.outputs.docs_only != '1' run: | From 2eb42694487d49a9ff8973f0a9de7d21a55d9394 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 11:14:41 -0800 Subject: [PATCH 2/3] ci: decide the integration-test scope in a tested script The path check piped git diff into grep -q under pipefail: on a match grep exits early, git diff can die of SIGPIPE, and the pipeline's failure read as "no match", so the tests were skipped exactly when they were needed. chunkstore-scope.sh writes the NUL-delimited list to a file and reads it to its end, as docs-only-scope.sh does; an error of the check runs the tests. Its self-test covers a match listed after 20000 other files, a deletion, a look-alike prefix and an unknown revision. Each filtered go test must PASS at least one test, so a filter that matches nothing fails instead of passing. Co-Authored-By: Claude Opus 5.5 --- .../.github/scripts/chunkstore-scope-test.sh | 50 +++++++++++++++++++ .../.github/scripts/chunkstore-scope.sh | 32 ++++++++++++ .../.github/scripts/docs-only-scope-test.sh | 2 +- seaweed-block/.github/workflows/test.yml | 22 ++++++-- 4 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 seaweed-block/.github/scripts/chunkstore-scope-test.sh create mode 100644 seaweed-block/.github/scripts/chunkstore-scope.sh diff --git a/seaweed-block/.github/scripts/chunkstore-scope-test.sh b/seaweed-block/.github/scripts/chunkstore-scope-test.sh new file mode 100644 index 0000000000..9d0744a86e --- /dev/null +++ b/seaweed-block/.github/scripts/chunkstore-scope-test.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# Tests chunkstore-scope.sh against real commits. Any failure exits nonzero. +set -euo pipefail +here=$(cd "$(dirname "$0")" && pwd) +scope="$here/chunkstore-scope.sh" +fail=0 +check() { # name want got + if [ "$2" = "$3" ]; then echo "ok $1"; else echo "FAIL $1: want [$2], got [$3]"; fail=1; fi +} +repo=$(mktemp -d) +trap 'rm -rf "$repo"' EXIT +cd "$repo" +git init -q +git config user.email t@example.invalid +git config user.name t +git config core.autocrlf false +mkdir -p core/frontend/chunkstore core/storage core/other docs +echo c >core/frontend/chunkstore/c.go +echo s >core/storage/s.go +echo o >core/other/o.go +echo d >docs/d.md +git add -A +git commit -qm base +base=$(git rev-parse HEAD) +case_of() { # name want: commit the current tree, classify against base, reset + git add -A + git commit -qm "$1" --allow-empty + check "$1" "$2" "$(bash "$scope" "$base" HEAD)" + git reset -q --hard "$base" +} +echo c2 >core/frontend/chunkstore/c.go +case_of "a chunkstore file" "run 1 core/frontend/chunkstore/c.go" +echo s2 >core/storage/s.go; echo o2 >core/other/o.go +case_of "storage and another package" "run 2 core/storage/s.go" +echo o2 >core/other/o.go; echo d2 >docs/d.md +case_of "neither path" "skip 2" +case_of "no file changed" "skip 0" +mkdir -p core/storage-old; echo x >core/storage-old/x.go +case_of "a storage-like prefix" "skip 1" +git rm -q core/storage/s.go +case_of "a storage deletion" "run 1 core/storage/s.go" +for i in $(seq 1 20000); do printf 'x\n' >"docs/f$i.md"; done +echo late >core/storage/zz_late.go +case_of "20000 other files and one storage file, listed last" "run 20001 core/storage/zz_late.go" +if out=$(bash "$scope" "$base" no-such-revision 2>/dev/null); then + check "an unknown revision is an error" "nonzero exit" "exit 0: $out" +else + check "an unknown revision is an error" "nonzero exit" "nonzero exit" +fi +exit "$fail" diff --git a/seaweed-block/.github/scripts/chunkstore-scope.sh b/seaweed-block/.github/scripts/chunkstore-scope.sh new file mode 100644 index 0000000000..47d44a3963 --- /dev/null +++ b/seaweed-block/.github/scripts/chunkstore-scope.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# chunkstore-scope.sh BASE HEAD: decides whether a pull request runs the +# real-filer integration tests. It prints one line: +# "run N FIRST" at least one of the N changed files is under +# core/frontend/chunkstore/ or core/storage/ (FIRST is one) +# "skip N" none of the N changed files is +# and exits 0. Any error (git fails, the list cannot be read) exits nonzero, +# and the caller then runs the tests: an error never selects skip. +# +# The NUL-delimited list is written to a file first and read to its end, so +# no pipe can stop early and leave a writer's error looking like an answer. +set -euo pipefail +[ "$#" -eq 2 ] || { echo "usage: chunkstore-scope.sh BASE HEAD" >&2; exit 2; } +list=$(mktemp) +trap 'rm -f "$list"' EXIT +if ! git diff --name-only --no-renames -z "$1" "$2" >"$list"; then + echo "chunkstore-scope: git diff $1 $2 failed" >&2 + exit 2 +fi +n=0 +hit="" +while IFS= read -r -d '' f; do + n=$((n + 1)) + case $f in + core/frontend/chunkstore/* | core/storage/*) [ -n "$hit" ] || hit=$f ;; + esac +done <"$list" +if [ -n "$hit" ]; then + echo "run $n $hit" +else + echo "skip $n" +fi diff --git a/seaweed-block/.github/scripts/docs-only-scope-test.sh b/seaweed-block/.github/scripts/docs-only-scope-test.sh index 519ab5ac34..18079f05c9 100644 --- a/seaweed-block/.github/scripts/docs-only-scope-test.sh +++ b/seaweed-block/.github/scripts/docs-only-scope-test.sh @@ -54,6 +54,6 @@ fi # every process step it can skip names its output. step=$(grep -n -A3 'name: Docs-only pull request' "$workflow" | grep "if:" || true) check "scope step condition" "1" "$(printf '%s' "$step" | grep -c "matrix.suite == 'process' && github.event_name == 'pull_request'" || true)" -check "process steps gated" "4" "$(grep -c "if: matrix.suite == 'process' && steps.scope.outputs.docs_only != '1'" "$workflow" || true)" +check "process steps gated" "5" "$(grep -c "if: matrix.suite == 'process' && steps.scope.outputs.docs_only != '1'" "$workflow" || true)" check "no ungated process step" "0" "$(grep -c "if: matrix.suite == 'process'$" "$workflow" || true)" exit "$fail" diff --git a/seaweed-block/.github/workflows/test.yml b/seaweed-block/.github/workflows/test.yml index 52840ebf9f..14ac2e422b 100644 --- a/seaweed-block/.github/workflows/test.yml +++ b/seaweed-block/.github/workflows/test.yml @@ -130,6 +130,7 @@ jobs: # hangs; this proves it before it judges the real run. run: | python3 -I .github/scripts/required-tests-check-test.py + bash .github/scripts/chunkstore-scope-test.sh bash .github/scripts/run-named-tests-test.sh python3 -I .github/scripts/shard-named-tests-test.py @@ -169,16 +170,27 @@ jobs: env: EVENT: ${{ github.event_name }} HEAD_REF: ${{ github.head_ref }} + # .github/scripts/chunkstore-scope.sh decides; an error of that check + # runs the tests. Each filtered run must PASS at least one test, so a + # filter that matches nothing fails instead of passing empty. run: | set -euo pipefail if [ "$EVENT" != push ] && [[ "$HEAD_REF" != train/* ]]; then - if ! git diff --name-only HEAD^1 HEAD | grep -qE '^core/(frontend/chunkstore|storage)/'; then - echo "skipped: the PR touches neither core/frontend/chunkstore/ nor core/storage/" - exit 0 + if out=$(bash .github/scripts/chunkstore-scope.sh HEAD^1 HEAD); then + case $out in + "skip "*) echo "skipped: the PR touches neither core/frontend/chunkstore/ nor core/storage/ ($out)"; exit 0 ;; + *) echo "real-filer integration tests run: $out" ;; + esac + else + echo "real-filer integration tests run: the scope check failed" fi fi - go test -count=1 -timeout 20m -tags chunkstore_integration -run '^TestIntegration' ./core/frontend/chunkstore/ - go test -count=1 -timeout 20m -tags chunkstore_integration -run '^TestQD1LayoutSync' ./core/frontend/durable/ + for spec in "./core/frontend/chunkstore/ ^TestIntegration" "./core/frontend/durable/ ^TestQD1LayoutSync"; do + pkg=${spec%% *}; filter=${spec#* } + log="$RUNNER_TEMP/integration-$(basename "$pkg").log" + go test -count=1 -v -timeout 20m -tags chunkstore_integration -run "$filter" "$pkg" 2>&1 | tee "$log" + grep -q '^--- PASS: ' "$log" || { echo "no test of $pkg matched $filter"; exit 1; } + done - name: Build the binaries and the test binary once if: matrix.suite == 'process' && steps.scope.outputs.docs_only != '1' From 166bba1252a54f62c0fd7275c487ef954239da95 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 29 Nov 2026 18:45:26 -0800 Subject: [PATCH 3/3] ci: run the integration tests for provider-only changes; harden the ledger check The scope gate selected the real-filer suites only for chunk-store and storage changes, but its second suite tests the durable provider: a PR that changed only core/frontend/durable/ skipped it. The ledger anchor check is the hardened script: a git failure or a ledger with no rows is an error (exit 2), not a pass, and a path matches whole components only. Co-Authored-By: Claude Opus 5.5 --- .../.github/scripts/chunkstore-scope-test.sh | 5 ++++- .../.github/scripts/chunkstore-scope.sh | 5 +++-- seaweed-block/.github/scripts/ledger_check.py | 20 ++++++++++++++++--- seaweed-block/.github/workflows/test.yml | 4 ++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/seaweed-block/.github/scripts/chunkstore-scope-test.sh b/seaweed-block/.github/scripts/chunkstore-scope-test.sh index 9d0744a86e..b1d5a1c3ad 100644 --- a/seaweed-block/.github/scripts/chunkstore-scope-test.sh +++ b/seaweed-block/.github/scripts/chunkstore-scope-test.sh @@ -14,8 +14,9 @@ git init -q git config user.email t@example.invalid git config user.name t git config core.autocrlf false -mkdir -p core/frontend/chunkstore core/storage core/other docs +mkdir -p core/frontend/chunkstore core/frontend/durable core/storage core/other docs echo c >core/frontend/chunkstore/c.go +echo p >core/frontend/durable/p.go echo s >core/storage/s.go echo o >core/other/o.go echo d >docs/d.md @@ -30,6 +31,8 @@ case_of() { # name want: commit the current tree, classify against base, reset } echo c2 >core/frontend/chunkstore/c.go case_of "a chunkstore file" "run 1 core/frontend/chunkstore/c.go" +echo p2 >core/frontend/durable/p.go +case_of "a durable provider file only" "run 1 core/frontend/durable/p.go" echo s2 >core/storage/s.go; echo o2 >core/other/o.go case_of "storage and another package" "run 2 core/storage/s.go" echo o2 >core/other/o.go; echo d2 >docs/d.md diff --git a/seaweed-block/.github/scripts/chunkstore-scope.sh b/seaweed-block/.github/scripts/chunkstore-scope.sh index 47d44a3963..5b1364ab7d 100644 --- a/seaweed-block/.github/scripts/chunkstore-scope.sh +++ b/seaweed-block/.github/scripts/chunkstore-scope.sh @@ -2,7 +2,8 @@ # chunkstore-scope.sh BASE HEAD: decides whether a pull request runs the # real-filer integration tests. It prints one line: # "run N FIRST" at least one of the N changed files is under -# core/frontend/chunkstore/ or core/storage/ (FIRST is one) +# core/frontend/chunkstore/, core/storage/ or +# core/frontend/durable/ (FIRST is one) # "skip N" none of the N changed files is # and exits 0. Any error (git fails, the list cannot be read) exits nonzero, # and the caller then runs the tests: an error never selects skip. @@ -22,7 +23,7 @@ hit="" while IFS= read -r -d '' f; do n=$((n + 1)) case $f in - core/frontend/chunkstore/* | core/storage/*) [ -n "$hit" ] || hit=$f ;; + core/frontend/chunkstore/* | core/storage/* | core/frontend/durable/*) [ -n "$hit" ] || hit=$f ;; esac done <"$list" if [ -n "$hit" ]; then diff --git a/seaweed-block/.github/scripts/ledger_check.py b/seaweed-block/.github/scripts/ledger_check.py index 128c6923ff..afb31ae2e1 100644 --- a/seaweed-block/.github/scripts/ledger_check.py +++ b/seaweed-block/.github/scripts/ledger_check.py @@ -11,6 +11,8 @@ A symbol with no file in its cell is looked up in the whole tree. A file may be a glob (`volume_lock*.go`). A lower-case token with an underscore (a build tag, a JSON key, a reason string) is not a Go symbol and is not checked. Prints one line per missing anchor and a summary. It reads; it changes nothing. +Exit: 0 when every anchor exists; 1 when one is missing; 2 when git fails or no +row or anchor was found (an error is never read as a pass). """ import re import subprocess @@ -18,8 +20,15 @@ import sys def git(repo, *args): - return subprocess.run(["git", "-C", repo] + list(args), capture_output=True, text=True, - encoding="utf-8", errors="replace").stdout + """git's output. A git failure ends the check with exit 2: an error must + never read as "no anchors". `git grep` finding nothing (exit 1) is not one.""" + r = subprocess.run(["git", "-C", repo] + list(args), capture_output=True, text=True, + encoding="utf-8", errors="replace") + if r.returncode != 0 and not (args and args[0] == "grep" and r.returncode == 1): + print("ledger_check: git %s failed (exit %d): %s" % (" ".join(args[:2]), r.returncode, r.stderr.strip()[:300]), + file=sys.stderr) + sys.exit(2) + return r.stdout def main(): @@ -43,7 +52,8 @@ def main(): return [f for f in files if rx.match(f)] if "/" not in tok: return [f for f in files if f.endswith("/" + tok)] - return [f for f in files if f.endswith("/" + tok) or f.endswith(tok)] + # a path with a directory matches whole path components only + return [f for f in files if f.endswith("/" + tok)] ident = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?(\(\))?$") go_all = None @@ -100,6 +110,10 @@ def main(): where = ", ".join(scope) if scope else "the tree" print("%s (line %d, %s, %s): %s not found in %s" % (inv, n, kind, status, t, where)) print("%d rows, %d anchors, %d missing at %s" % (rows, anchors, missing, ref)) + if rows == 0 or anchors == 0: + print("ledger_check: no ledger rows or anchors found: refusing to pass", file=sys.stderr) + sys.exit(2) + sys.exit(1 if missing else 0) if __name__ == "__main__": diff --git a/seaweed-block/.github/workflows/test.yml b/seaweed-block/.github/workflows/test.yml index 14ac2e422b..c139ab0134 100644 --- a/seaweed-block/.github/workflows/test.yml +++ b/seaweed-block/.github/workflows/test.yml @@ -165,8 +165,8 @@ jobs: # writes, cut uploads and object deletes of the chunk store, and the # layout sync crash cases of the durable provider. They fail, never # skip, without the binary. Pushes to main and train PRs always run - # them; another PR runs them when it touches core/frontend/chunkstore/ - # or core/storage/. + # them; another PR runs them when it touches core/frontend/chunkstore/, + # core/storage/ or core/frontend/durable/. env: EVENT: ${{ github.event_name }} HEAD_REF: ${{ github.head_ref }}