Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This repository exists to be reviewable. Five rules keep it that way.
template that emits the notice into a generated file) and is left alone;
the three such files say so in a comment.

Before you ask for a merge, run `scripts/pre-pr-checks.sh`. It runs the six host-side checks described in
Before you ask for a merge, run `scripts/pre-pr-checks.sh`. It runs the host-side checks described in
[docs/pre-pr-checks.md](docs/pre-pr-checks.md) and prints one line each (`--base <ref>` for the registration check, `--list`
to see the commands); a check that cannot run says `skip` and why, and an unresolvable `--base` is a usage error rather than a
skip. None of them needs a device or a build, and each answers a question that a green CI tick and a careful read of your own
Expand Down
9 changes: 4 additions & 5 deletions docs/pre-pr-checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ Ten commands, all host-side, none needing a device or a build. Every one of them

Run them from the repository root on the branch you are about to hand over.

**`scripts/pre-pr-checks.sh` runs the first ten**, one line each (`--base <ref>` for the registration check, `--list` to see the
commands; a check that cannot run says `skip` and why, and an unresolvable `--base` is a usage error rather than a skip). The
eleventh is an **author's check**, true or false exactly once — when you add a page — so it is not in the runner, and the section
below says why. The table's order is the runner's order: cheapest and most common first, and the check that needs a revision
(`registration_loss_check --base`) last.
**`scripts/pre-pr-checks.sh` runs every command in the table below**, one line each (`--base <ref>` for the registration check, `--list` to see the
commands; a check that cannot run says `skip` and why, and an unresolvable `--base` is a usage error rather than a skip). One further check is an **author's check**, true or false exactly once — when you add a page — so it is not in the runner, and the section
below says why. The table's order is the runner's order: cheapest and most common first, and last the checks that need a revision (`--base`) or a fetched tree.

| command | red means |
|---|---|
Expand All @@ -38,6 +36,7 @@ below says why. The table's order is the runner's order: cheapest and most commo
| `python3 tools/ci/registration_loss_check.py --check --base origin/main` | your branch would drop rows `main` has |
| `python3 tools/ci/registry_loss_check.py --base origin/main` | a reviewed class, a `coverage` counter or a test's mention of a class that the base has is gone at the merge, not only at the endpoint (engine#2385, #2391) |
| `python3 tools/ci/branch_stale_check.py --base origin/main` | the merge with the base conflicts, or would not keep a base change the branch never touched; a branch that is only behind gets a note (the merge keeps the base's copy, but the branch's tests ran on the older one) (engine#2398, #2410) |
| `python3 tools/ci/guard_loss_check.py --check --base origin/main` | a guard-shaped line was deleted and its identifiers appear nowhere at head (a refusal or an assert silently removed) |
| `python3 tools/ci/hip_f16_audit.py --find .` | a HIP add-on kernel accumulates in f16, or the gpu-kernels tree is not at the pinned commit; `skip` (the audit did NOT run) when there is no tree: set `GPU_KERNELS_DIR` to a checkout at the pin |
| `git grep -l -F "$(basename <your new page>)" -- '*.md'` | nothing links to the page you just added — measured tonight: 45 docs, one with no inbound link, and it was the page whose whole subject is pre-merge checks |

Expand Down
4 changes: 4 additions & 0 deletions scripts/pre-pr-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ checks=(
"tools/ci/registration_loss_check.py --check --base $base"
"tools/ci/registry_loss_check.py --base $base"
"tools/ci/branch_stale_check.py --base $base"
# engine#2429: a refusing/asserting condition deleted in the diff with nothing replacing it. Calibrated on 15
# open PR heads (one spurious hit, fixed by the head-tree search) and on the real llama.cpp#371 diff; exit 2 when
# it cannot read the refs, so "cannot tell" is never a pass.
"tools/ci/guard_loss_check.py --check --base $base"
# engine#2416: the HIP add-on's f16 audit over $GPU_KERNELS_DIR (or third_party/gpu-kernels) at the pin; with no
# tree it exits 77 and is listed as `skip`, never `ok`
"tools/ci/hip_f16_audit.py --find ."
Expand Down
40 changes: 38 additions & 2 deletions tools/ci/guard_loss_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@

GUARD_KEYWORDS = ("refus", "assert", "GGML_ABORT", "!= 0", "== nullptr", "cannot", "must be", "is not set")
IDENT = re.compile(r"[A-Za-z_][A-Za-z_0-9]{3,}")
SKIP_DIRS = ("third_party/", "docs/", "registry/", "tests/data/")
# engine#2451: `tests/`, not only `tests/data/`. A test's `REQUIRE`/`CHECK` is a fixture, not the
# product's refusal - and the heuristic cannot see that style anyway (REQUIRE is not a guard keyword),
# so skipping tests/ loses nothing it could catch while removing the case that would redden a PR for
# rewriting an assertion on purpose (measured: 8 of 72 LOST hits over 55 fork commits were in tests/,
# every one a deliberate assertion rewrite; the engine, where the row runs, was 0 over 11 heads).
SKIP_DIRS = ("third_party/", "docs/", "registry/", "tests/")


def git(*args, cwd=None):
Expand Down Expand Up @@ -128,7 +133,11 @@ def check(root, base, head):
else:
lost.append((path, body, "not in this file and not anywhere at head: " + ", ".join(sorted(missing))))
else:
moved.append((path, body))
# every `moved` entry is a 3-tuple: the print loop unpacks a destination list. This path
# (guard rewritten in place, identifiers still present) appended 2-tuples and crashed the
# tool - and Python's traceback exits 1, which a runner reads as "guard LOST". Found by
# running the row below against a diff that rewrites a guard.
moved.append((path, body, []))
for path, body, why in lost:
print(f"LOST {path}: {body.strip()[:100]}\n {why}")
for path, body, elsewhere in moved:
Expand Down Expand Up @@ -195,6 +204,33 @@ def g(*a):
g("add", "-A"); g("commit", "-qm", "head")
return td

# 0. THE CRASH ARM: a guard REWRITTEN in place, identifiers still present -> note, rc 0, no unpack
# error. This path appended a 2-tuple into a list the printer unpacks as 3, so the tool raised
# ValueError and exited 1: a crash wearing the LOST exit code.
td0 = scratch({"src/a.cpp": "int f(void*p,size_t n){ if (n % TENSOR_ALIGNMENT != 0) { return -1; } return 0; }\n"},
{"src/a.cpp": "int f(void*p,size_t TENSOR_ALIGNMENT){ if (TENSOR_ALIGNMENT == 0) { return -2; } return 0; }\n"})
buf0 = io.StringIO()
with contextlib.redirect_stdout(buf0):
rc_rw = check(td0, "HEAD^", "HEAD")
chk("a guard rewritten with its identifiers present is a note, not a crash", rc_rw, 0)
chk(" ... and it is reported as rewritten", "rewritten" in buf0.getvalue(), True)

# 0b. THE SKIP ARM (engine#2451): a guard deleted under tests/ is not reported, and the same guard
# under src/ is - the docstring and SKIP_DIRS must say the same thing, and the skip must not be
# so wide that it silences product code.
guard = "int f(void*p,size_t n){ if (p == nullptr || n % TENSOR_ALIGNMENT != 0) { return -1; } return 0; }\n"
gone = "int f(void*p,size_t n){ return 0; }\n"
td_t = scratch({"tests/a.cpp": guard}, {"tests/a.cpp": gone})
buf_t = io.StringIO()
with contextlib.redirect_stdout(buf_t):
rc_test = check(td_t, "HEAD^", "HEAD")
chk("a guard deleted under tests/ is skipped (fixtures are not refusals)", rc_test, 0)
td_s = scratch({"src/a.cpp": guard}, {"src/a.cpp": gone})
buf_s = io.StringIO()
with contextlib.redirect_stdout(buf_s):
rc_src = check(td_s, "HEAD^", "HEAD")
chk("the same guard under src/ is still reported", rc_src, 1)

# 1. a guard deleted outright, nothing else changed -> LOST, rc 1
td = scratch({"src/a.cpp": "int f(void*p,size_t n){ if (p == nullptr || n % TENSOR_ALIGNMENT != 0) { return -1; } return 0; }\n"},
{"src/a.cpp": "int f(void*p,size_t n){ return 0; }\n"})
Expand Down
Loading