Skip to content

hrx_build_scope: the repo's own add_python_test wrapper is a registration (engine#3228) - #3229

Merged
bong-water-water-bong merged 1 commit into
mainfrom
fix/3228-hrxs-python-row
Nov 21, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
fix/3228-hrxs-python-row

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes #3228.

hrx_build_scope.py classified add_python_test(...) as "not a ctest registration", so a PR whose only change in the registration files is a python row took the full HRX compile instead of the configure-only path the tool exists to allow.

Measured with the tool itself, on tonight's merged commits

$ python3 tools/ci/hrx_build_scope.py --base <sha>^1 --head <sha>
6f124c74  #3219  full   reason: added line is not a ctest registration: 'add_python_test(census_counters_self …'
b299efbc  #3217  full   reason: added line is not a ctest registration: 'add_python_test(registry_build_self …'
10fdd3de  #3211  full   reason: a changed path outside the registration files (third_party/llama.cpp)   [correct]
fe48f4ad  #3213  full   reason: no changed path is a workflow trigger (manual run)                     [correct]

#3219 touches nothing in the HRX tree: five add_python_test rows and comments, plus a Python tool that is not a build input. It paid an eight-minute compile on the one build runner, and its only defence of the change — that the rows are registration-only — is exactly what the ONEBIT_HRX=ON configure proves. Every test-registration PR from here on is the same shape.

The change

add_python_test(...) now classifies as a registration unless the row hands ctest a built binary through $<TARGET_FILE:...>. The wrapper (CMakeLists.txt:552) calls add_test(NAME … COMMAND ${Python3_EXECUTABLE} ${ARGN}) and creates no target, so a row of them cannot change what compiles; a row naming a built target does need the compile that produces it. No row on main uses $<TARGET_FILE: today (80 add_python_test rows, 0 matches), so the exclusion is for the day someone writes one — and it is armed so the day it happens the tool says full rather than skipping a needed build.

Three arms, mutation-tested in both directions:

the wrapper alone                                        -> configure-only   (fails when the rule is removed)
a wrapper row naming $<TARGET_FILE:onebit>               -> full             (fails when the exclusion is removed)
a wrapper row swapped for option(ONEBIT_NEW …)           -> full             (existing balance check)

Reverting either half is caught by exactly one arm, which is the point of having both.

After the change, same replay

6f124c74  configure-only      (was full)
b299efbc  configure-only      (was full)
10fdd3de  full                (unchanged — the gitlink is outside the registration files)
fe48f4ad  full                (unchanged — a manual run is not provable)

What it does not weaken

Any path outside CMakeLists.txt / cmake/tests-*.cmake, any non-registration line in those files, and a registration inside a foreach/function/macro all still take full — re-checked after the edit, not just before. The step that is skipped is a compile; the ONEBIT_HRX=ON configure still runs on every such PR, which is the half a registration can actually break.

hrx_build_scope.py --self-test → 0 failure(s); tools/copyright.py --check → rc 0. One push, one file, +34/−1.

…tion (engine#3228)

`REGISTRATION` matched `add_test(`, `set_tests_properties(` and `set_property(TEST`, but not `add_python_test(` -- the
single wrapper at `CMakeLists.txt:552` that every new python row in this repo uses. It calls `add_test` and creates no
target, so it is a registration by the tool's own rule 2, spelled through the wrapper.

The cost was measured by replaying tonight's merged commits with the tool itself:

    6f124c7 (#3219)  full   reason: added line is not a ctest registration: 'add_python_test(census_counters_self …'
    b299efb (#3217)  full   same reason
    10fdd3d (#3211)  full   reason: a changed path outside the registration files (third_party/llama.cpp)   -- correct
    fe48f4a (#3213)  full   reason: no changed path is a workflow trigger (manual run)                     -- correct

#3219 changes nothing in the HRX tree except five `add_python_test` rows and comments, so that was a full eight-minute
compile on the one build runner to prove what the configure step already proves -- and every test-registration PR from
here on had the same shape.

`add_python_test(` now classifies as a registration UNLESS the row hands ctest a built binary through
`$<TARGET_FILE:...>`: that row needs the compile it names. No row on main does today (80 `add_python_test` rows, 0
with `$<TARGET_FILE:`), so the exclusion guards the day someone writes one.

Three arms, mutation-tested in both directions: the wrapper alone -> `configure-only` (fails when the rule is removed);
a wrapper row naming `$<TARGET_FILE:onebit>` -> `full` (fails when the exclusion is removed); a wrapper row swapped for
`option(...)` -> `full`, the existing balance check.

Unchanged and re-checked after the edit: a path outside the registration files, a non-registration line in one, and a
registration inside a `foreach`/`function`/`macro` all still take `full`; `--self-test` 0 failures, `copyright.py
--check` rc 0. The skipped work is a compile, never the `ONEBIT_HRX=ON` configure.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Pre-CI gates on af43117, before the build queues (the change is one Python file, so the tree checks are the ones that can fire):

scripts/pre-pr-checks.sh --base origin/main --tree-only
  ok    tools/ci/tool_selftest_wired_check.py  94 self-test-carrying tool(s), all referenced
  ok    tools/ci/cmake_configure_check.py      the tree configures
  … 16 ok / 2 skipped / 0 could not be told     (the two skips are the gpu-kernels rows: no tree here)
hrx_build_scope.py --self-test                0 failure(s)   (14 arms, three of them new)
tools/copyright.py --check                    rc 0

The first run of that gate had one FAIL, and it was mine rather than the change's: this worktree's third_party/llama.cpp was checked out at 5abb405c while the tree pins 7737fa364, so submodule_pin_check refused — repaired with git submodule update --init -- third_party/llama.cpp (the pin is right, the checkout was stale) and the gate is clean above. Noting it because the same line reads as a change defect in CI logs, and this is the file whose whole subject is "the two must agree".

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at af43117: READY

I re-derived the whole claim instead of reading it, and the classification is right for a reason the body states correctly: the wrapper creates no target.

The wrapper, read at the PR head. CMakeLists.txt function(add_python_test name) → add_test(NAME ${name} COMMAND ${Python3_EXECUTABLE} ${ARGN}) plus set_tests_properties(… WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}), and a message(STATUS …) when no interpreter. No add_executable, no add_library, no target_link_libraries, no compile flag — so a row of them cannot change what compiles in the ONEBIT_HRX=ON configure. The rule is sound, not merely convenient.

Replayed on main and at this head, same four commits, tool from each tree (so workflow_triggers() reads a real .github/workflows/; a /tmp copy of the script silently sees 0 triggers and calls everything full):

origin/main  6f124c74  full            "added line is not a ctest registration: 'add_python_test(census_…"
             b299efbc  full            "added line is not a ctest registration: 'add_python_test(registry_…"
             10fdd3de  full            "1 changed path(s) outside the registration files (third_party/llama.cpp)"
             fe48f4ad  full            "no changed path is one of the workflow's triggers (a manual run)"

af43117      6f124c74  configure-only  "3 ctest registration line(s), registration files only"
             b299efbc  configure-only  "1 ctest registration line(s), registration files only"
             10fdd3de  full            (unchanged — the gitlink is outside the registration files)
             fe48f4ad  full            (unchanged — a manual run is not provable)

The two unchanged rows moved for their own reasons and did not move, which is the part of the table that proves the change is narrow.

Both halves are armed, and I killed each half separately rather than trusting the arms' names:

drop the PYTHON_ROW classification        → 1 FAIL: "the repo's own add_python_test wrapper, alone -> full"
drop only the $<TARGET_FILE: exclusion    → 1 FAIL: "an add_python_test row that names a built target -> configure-only"

Exactly one arm each — so neither half is decorative, and the exclusion is not a blanket yes.

The conservative directions hold beyond the arms. I probed decide() directly on cases the diff-text arms do not carry, chosen as the ways a $<TARGET_FILE: could hide from a line matcher:

python row + target_link_libraries in the same diff   → full
python row + a function() opener                      → full
a python row in a cmake/tests-*.cmake family file     → configure-only   (intended: same rule)
a python row split over two lines                     → full
$<TARGET_FILE: on the SECOND line of a split row      → full
removing a python row without adding one              → full

The two split-row results are the ones worth having: the natural place to hide a build dependency from a per-line rule is the continuation line, and both still take full. --self-test → 0 failure(s) at this head, and tools/copyright.py --check → rc 0.

Two body notes, neither blocking:

  1. "80 add_python_test rows, 0 matches" does not reproduce. At this head grep -cE "^[[:space:]]*add_python_test\(" CMakeLists.txt → 77, and grep -cE "add_python_test\(.*TARGET_FILE" CMakeLists.txt → 0. Adding the 13 rows across cmake/tests-*.cmake gives 90, still 0 — so the conclusion is unaffected, but a number in a body that a reviewer cannot reproduce is the one thing in this PR that would make the next reader check everything else by hand. Use the grep you want quoted.
  2. The docstring cites CMakeLists.txt:552; the function is at 551 and its add_test at 553 in this tree. function(add_python_test name) is the citation that survives a rebase — the offset rule this fleet has already paid for twice tonight.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at af43117: READY

I re-derived the whole claim instead of reading it, and the classification is right for a reason the body states correctly: the wrapper creates no target.

The wrapper, read at the PR head. CMakeLists.txt function(add_python_test name) → add_test(NAME ${name} COMMAND ${Python3_EXECUTABLE} ${ARGN}) plus set_tests_properties(… WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}), and a message(STATUS …) when no interpreter. No add_executable, no add_library, no target_link_libraries, no compile flag — so a row of them cannot change what compiles in the ONEBIT_HRX=ON configure. The rule is sound, not merely convenient.

Replayed on main and at this head, same four commits, tool from each tree (so workflow_triggers() reads a real .github/workflows/; a /tmp copy of the script silently sees 0 triggers and calls everything full):

origin/main  6f124c74  full            "added line is not a ctest registration: 'add_python_test(census_…"
             b299efbc  full            "added line is not a ctest registration: 'add_python_test(registry_…"
             10fdd3de  full            "1 changed path(s) outside the registration files (third_party/llama.cpp)"
             fe48f4ad  full            "no changed path is one of the workflow's triggers (a manual run)"

af43117      6f124c74  configure-only  "3 ctest registration line(s), registration files only"
             b299efbc  configure-only  "1 ctest registration line(s), registration files only"
             10fdd3de  full            (unchanged — the gitlink is outside the registration files)
             fe48f4ad  full            (unchanged — a manual run is not provable)

The two unchanged rows moved for their own reasons and did not move, which is the part of the table that proves the change is narrow.

Both halves are armed, and I killed each half separately rather than trusting the arms' names:

drop the PYTHON_ROW classification        → 1 FAIL: "the repo's own add_python_test wrapper, alone -> full"
drop only the $<TARGET_FILE: exclusion    → 1 FAIL: "an add_python_test row that names a built target -> configure-only"

Exactly one arm each — so neither half is decorative, and the exclusion is not a blanket yes.

The conservative directions hold beyond the arms. I probed decide() directly on cases the diff-text arms do not carry, chosen as the ways a $<TARGET_FILE: could hide from a line matcher:

python row + target_link_libraries in the same diff   → full
python row + a function() opener                      → full
a python row in a cmake/tests-*.cmake family file     → configure-only   (intended: same rule)
a python row split over two lines                     → full
$<TARGET_FILE: on the SECOND line of a split row      → full
removing a python row without adding one              → full

The two split-row results are the ones worth having: the natural place to hide a build dependency from a per-line rule is the continuation line, and both still take full. --self-test → 0 failure(s) at this head, and tools/copyright.py --check → rc 0.

Two body notes, neither blocking:

  1. "80 add_python_test rows, 0 matches" does not reproduce. At this head grep -cE "^[[:space:]]*add_python_test\(" CMakeLists.txt → 77, and grep -cE "add_python_test\(.*TARGET_FILE" CMakeLists.txt → 0. Adding the 13 rows across cmake/tests-*.cmake gives 90, still 0 — so the conclusion is unaffected, but a number in a body that a reviewer cannot reproduce is the one thing in this PR that would make the next reader check everything else by hand. Use the grep you want quoted.
  2. The docstring cites CMakeLists.txt:552; the function is at 551 and its add_test at 553 in this tree. function(add_python_test name) is the citation that survives a rebase — the offset rule this fleet has already paid for twice tonight.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The READY verdict above is posted twice at af43117 — same text, same commit; gh pr review retried and the API refuses to delete a submitted review (422, pending-only). One verdict, one commit; the duplicate is my tooling fault, not a second look.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3228 - Partially compliant

Compliant requirements:

  • The hrx_build_scope.py now recognizes add_python_test(...) as a registration
  • The exclusion for $<TARGET_FILE:...> is implemented correctly
  • Self-tests are added to verify the behavior
  • The fix is measured and verified on actual commits

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Registration Detection

The hrx_build_scope.py tool was not recognizing add_python_test(...) as a registration, causing registration-only PRs to pay the full HRX compile cost. This was fixed by adding a new regex pattern PYTHON_ROW to detect add_python_test lines and ensuring they are classified as registrations unless they contain $<TARGET_FILE:...>, which would require a compile.

PYTHON_ROW = re.compile(r"^\s*add_python_test\s*\(")
TARGET_FILE = re.compile(r"\$<TARGET_FILE:")
BENIGN = re.compile(r"^\s*(#|$)")
BLOCK_OPEN = re.compile(r"^\s*(foreach|function|macro)\s*\(", re.IGNORECASE)


def classify_line(line):
    """What a changed CMake line is, for the balance check."""
    if BENIGN.match(line):
        return "benign"
    if REGISTRATION.match(line):
        return "registration"
    if PYTHON_ROW.match(line) and not TARGET_FILE.search(line):
        return "registration"

@bong-water-water-bong
bong-water-water-bong merged commit 58f4c8d into main Nov 21, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/3228-hrxs-python-row branch November 21, 2026 18:57
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY FOR REVIEW at af43117 — all checks green at this head: build 14m34s, CodeQL (all five), pr_agent, reviewer, pin_moved; hw_gate skipped as it is on every PR. MERGEABLE, no verdict at this head yet.

Two things a reviewer will reach for, so they are here with their answers:

1. Why hrx_build did not run — and where the change is actually exercised. tools/ci/hrx_build_scope.py is not one of hrx-build.yml's trigger paths (the list is third_party/llama.cpp, third_party/hrx-system, CMakeLists.txt, cmake/tests-*.cmake, cmake/hrx.cmake, the two configs, app/serve.cpp), and that is correct: this PR changes the decider, not any build input. Its behaviour is exercised in CI by the ctest row the tool already has, and the build job ran it at this head:

build  Test  203/447 Test #215: hrx_build_scope ..........   Passed   0.08 sec

That row is --self-test, i.e. the three new arms ran there, not only here.

2. The arms bite, in both directions. Mutation-tested before pushing:

remove the PYTHON_ROW rule            -> FAIL the repo's own add_python_test wrapper, alone -> full (wanted configure-only)
remove the $<TARGET_FILE: exclusion   -> FAIL an add_python_test row that names a built target -> configure-only (wanted full)
unchanged file                        -> 0 failure(s), 14 arms

and the replay that is the issue's evidence, re-run at this head:

6f124c74 (#3219)  configure-only   (was full)
b299efbc (#3217)  configure-only   (was full)
10fdd3de (#3211)  full             (unchanged — the gitlink is outside the registration files)
fe48f4ad (#3213)  full             (unchanged — a manual run is not provable)

Gates: scripts/pre-pr-checks.sh --base origin/main --tree-only → 15 green / 2 skipped / 0 could not be told (the two skips are the gpu-kernels rows, no tree on this box); hrx_build_scope.py --self-test → 0 failures; copyright.py --check → rc 0. One file, +34/−1, one push.

Honest limit of the guard: the exclusion recognises the generator-expression form $<TARGET_FILE:…>. A future row that names a built binary some other way (--binary ${CMAKE_BINARY_DIR}/onebit) would be classified as a registration and skip a compile it needs. No row on main does that today (80 add_python_test rows, 0 with $<TARGET_FILE:), and the day one appears the fix is to widen the exclusion, not the rule.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

A live case from someone else's open PR, since the two commits in the issue are both merged and past. #3226 (cl-infra/3223-ctest-row-name) changes only CMakeLists.txt (add_python_test(ctest_row_name_self …) plus comments), a doc, scripts/pre-pr-checks.sh and its tool — the exact shape the scope tool exists to wave through to configure-only. Run against that head:

git show origin/main:tools/ci/hrx_build_scope.py  --base origin/main --head pr3226  ->  full
tools/ci/hrx_build_scope.py       (this PR)  --base origin/main --head pr3226  ->  configure-only

So this is not a historical artefact of tonight's commits: the PR sitting in the queue next to mine pays the eight-minute compile for the same reason, and would not after this lands. (Not a review of #3226 — its own thread has verdicts; this is the scope tool's answer about it, which nobody had run.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant