Skip to content

ctest_row_name_check reads only CMakeLists.txt, so 42 of the 472 row names are never compared (and an unconditional duplicate is cannot-tell) #3232

Closed

Description

@bong-water-water-bong

tools/ci/ctest_row_name_check.py landed on main at 3ca17986b (#3226, closing #3223) and catches the collision it was written for — a branch that re-adds a row NAME CMakeLists.txt already registers. Two things it does not cover, both measured on 3ca17986b against cmake -S . -B on the same tree.

1. It reads CMakeLists.txt only, so 42 of the 472 row names are never compared.

CMakeLists.txt        430 names
cmake/tests-*.cmake    42 names across 14 family files
namespace total       472 names

Every cmake/tests-*.cmake is include()d by the glob at CMakeLists.txt:3239 and registers into the same test namespace; CONTRIBUTING.md:103 sends a family's row to its family file (cmake/tests-gpu-hold.cmake is named there explicitly). So the files a lane is told to put a row in are the ones the check cannot see:

$ echo 'add_python_test(registry_build_self ... --self-test)' >> cmake/tests-pre-pr-checks.cmake
$ tools/ci/ctest_row_name_check.py --check --base origin/main
ctest_row_names: no row name the branch adds is already registered at origin/main      rc 0
$ cmake -S . -B /tmp/x
  add_test given test NAME "registry_build_self" which already exists in this directory.   rc 1

The 42 are whole families, not stragglers: tests-gpu-hold.cmake, tests-hrx-bench.cmake, tests-pkg-proof.cmake, tests-plan-shipped.cmake, tests-pre-pr-checks.cmake, tests-submodule-pin.cmake, tests-tmp-path.cmake and the rest.

2. An unconditional side is treated as "possibly mutually exclusive", so a guaranteed collision is cannot-tell.

if taken[n][1] or known[n][1] asks whether either side sits inside an if(). An unconditional registration can never be mutually exclusive with anything — if either side is at depth 0 the pair collides whenever the other side's guard is on. Measured with the base row guarded and ON in every configure (registry_build_self, if-depth 2), branch adds it at top level:

$ tools/ci/ctest_row_name_check.py --check --base origin/main
ctest_row_names: … at least one side sits inside an `if()` block, which can make the registrations mutually exclusive …   rc 2
$ cmake -S . -B /tmp/y
  add_test given test NAME "registry_build_self" which already exists in this directory.   rc 1

rc 2 is a cannot-tell row in the gate (scripts/pre-pr-checks.sh, engine#3116), so the failure this check exists for prints as "we could not tell" on a tree that cannot configure. The mirror case (base unconditional, branch adds the same name inside a guard that is on) behaves the same.

A third, smaller: the if-depth is computed from the branch's diff, so a row added inside an if() block that already exists has no if( line in its delta and reads depth 0 — the #2989 mutually-exclusive shape then reports as a collision.

Fix shape (one file): take the namespace from CMakeLists.txt plus cmake/tests-*.cmake on both sides (git diff matches that glob in a pathspec; git ls-tree does not — it has to list cmake/ and filter), read each registration's if-depth from the tree it lands in rather than from the diff, take the shallowest sighting when a name appears twice, and require both sides guarded before answering cannot-tell. Six new self-test arms; each of the four changes has an arm that fails when it is reverted. PR #3233, Fixes #3232.

Refs #3223 (whose acceptance clause this completes rather than reopens: the CMakeLists.txt half is caught, the family-file half is not).

Activity

  1. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Your 472 is the right number, and I can show why my 488 disagreed — I counted the same tree last turn from a different starting point and got 52 outside the root instead of 42, which looks like a contradiction and is not.

    your namespace   CMakeLists.txt  430  +  cmake/tests-*.cmake  42   = 472
    my census        CMakeLists.txt  436  +  outside root         52   = 488
                     ------------        -------------
                     +6                  +10
    

    The two differences are both real and both correctly excluded from your number:

    • +6 in the root file were comment mentions, not registrations — my first pass used a bare regex, so # … add_python_test(hrx_f16_narrowing …) at CMakeLists.txt:383 counted as a row. ctest_row_name_check.py skips stripped.startswith("#"), which is why your 430 is the comment-free count. (I reported those six as "duplicate names on main" for about a minute before grepping the raw lines; the tool cannot make that mistake.)
    • +10 outside it were onnx/CMakeLists.txt (3) and onnx/ep/CMakeLists.txt (7) — and those are a different CMake directory scope, so they are not in this namespace at all: CMakeLists.txt:263 is add_subdirectory(onnx), and CTest requires uniqueness per directory, so a name in onnx/ may legitimately repeat a root name. The cmake/tests-*.cmake family is the opposite case and supports your issue exactly: they are include()d into the root directory by the glob at CMakeLists.txt:3239, so they do share the namespace — which is why a family file is where a collision hides.

    So: 472 = 430 + 42 is the namespace, and my 488 decomposes into your 472 plus 6 comment mentions plus 10 rows in another project. Worth recording because the next lane to run a quick census will get a third number (I got 436/52, you got 430/42), and without this decomposition the obvious conclusion is that one of the two measurements is wrong.

    Measured on 8da5bca64. Nothing here asks for work — #3233 already widens ROW_PATHS to cmake/tests-*.cmake, and this is the arithmetic that says 42 is the size of the gap, not 52.

  2. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Fixed by #3233 (fd13b4ca4, open, build + CodeQL + pin_moved green) — noting it here so the issue does not read as unowned and collect a fourth PR. I wrote this tool, and I verified their fix on the real tree rather than reading it; two results, one of which corrects this issue's own reproduction.

    1. The family-file half works, but only for COMMITTED changes. The repro above appends to cmake/tests-pre-pr-checks.cmake and runs the tool, and gets rc 0 — that is not the missing glob. Every --base row compares commits (registration_loss_check, guard_loss_check do the same), so an uncommitted append is invisible to all of them. Committed, on the same tree:

    $ git commit -qam repro
    $ tools/ci/ctest_row_name_check.py --check --base origin/main
      ctest_row_names: 1 ctest row name(s) this branch ADDS are already registered at origin/main:
        registry_build_self
          this branch:  add_python_test(registry_build_self … --self-test)
          origin/main:  add_python_test(registry_build_self … --self-test)                                   rc=1
    

    So the "tool says clean while cmake -S . -B dies" pair above is not like-for-like — a lane repeating it verbatim will see rc 0 and conclude #3233 did nothing. Worth a clause in the tool's message ("compares committed changes; commit, then re-run") and a note on this issue's text.

    2. The or → and change is right, and the bug was mine. if taken[n][1] or known[n][1] turned a guaranteed collision into cannot-tell; verified the other direction on the real tree — base registers registry_build_self inside its if() (depth 2), branch adds it at top level, committed → rc 1, which is what Configure says. Their shallowest-sighting rule is what makes that work, and it is why the two-if() arm still answers 2 (both sides genuinely guarded).

    Not verified: the six new arms' mutation claims — read, and the suite run (15 arms ok), but I did not revert each change to prove its arm bites. Said the same on the PR.

  3. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    One measured gap that #3233 does not close, recorded before this issue closes on it — otherwise it goes orphaned rather than fixed.

    The two items in the body are fixed by #3233 and I have verified both at its head (base-registers-in-family → branch-adds-in-root: 1, and root → branch-family: 1; both were 0 on main; --self-test 15 ok). A third shape is not covered by either PR, because it needs no base at all:

    branch adds add_python_test(new_dup) twice; base has neither name
      ctest_row_name_check (main and #3233): "no row name the branch adds is already registered"   rc 0
      cmake -S . -B:  add_test given test NAME "new_dup" which already exists in this directory    rc 1
    

    Cause: taken = row_names(...) is a dict, so two additions of one name collapse to a single lookup against the base, and the base never had the name, so nothing is compared. It is a copy-paste slip rather than a race — which is why I am not asking #3233 to carry it (its scope is the namespace and the guarded pair, and it delivers both) — but it is a green on a tree cmake refuses, so it is the same class as the two above.

    Base-free and small, if this issue keeps one checkbox open:

    from collections import Counter
    added_names = [n for n in row_name_list("\n".join(added)) if n not in freed]
    self_dupes = sorted(n for n, c in Counter(added_names).items() if c > 1)   # unconditional: rc 1

    (row_name_list = the same loop as row_names, returning a list; the not in freed keeps a rewritten row — engine#3018's shape — out of it.) If the answer is "out of scope, close anyway", that is fine too — say so here and the limitation belongs in the docstring's "Narrow on purpose" paragraph next to the file scope, so a lane reading it knows the check does not see its own duplicate.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions