Skip to content

ctest_row_name_check: a name the branch adds twice passes the check and fails Configure (no base needed) #3235

Description

@bong-water-water-bong

tools/ci/ctest_row_name_check.py compares the names a branch adds against the base, so it only sees collisions with the base. A branch that registers the same name twice collides with itself — no base entry involved — and the check answers clean while Configure refuses the tree. Found in review of #3233, which is the PR that widens the namespace; it is a separate defect from that one and is carried here so it is not lost if #3233 merges first.

Reproduced on the tree at #3233's head (fd13b4ca4), base holds neither name:

$ printf 'add_python_test(new_dup ${CMAKE_SOURCE_DIR}/tools/x.py --self-test)\n' | tee -a CMakeLists.txt >> CMakeLists.txt
$ 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/E
  add_test given test NAME "new_dup" which already exists in this directory.            rc 1

Cause: row_names() returns a dict — deliberately, since a name is either taken or not — so two additions of one name collapse to one entry, and clashes is computed against known (the base) only. Nothing in the current logic can see a self-collision.

Fix (written and verified, 39 lines with two arms, held only for sequencing): count while naming, as the review suggested —

def counted_row_names(lines):        # name -> how many times these lines register it
    ...

counts = counted_row_names(added)
doubled = sorted(n for n, count in counts.items() if count > 1 and n not in freed)
if doubled:
    return 1, ([f"{len(doubled)} ctest row name(s) this branch registers MORE THAN ONCE:"]
               + [f"  {n}: registered {counts[n]}x by this branch" for n in doubled]
               + ["  two registrations of one name fail Configure whatever the base holds: drop one"])

It needs neither the base nor the tree nor the guard logic, so it is a hard 1 rather than a cannot-tell. n not in freed keeps the #3018 rewritten-row shape quiet: a branch that removes one copy and adds another is an edit, not two registrations.

Verified in the working tree (uncommitted, so the number is reproducible): --self-test 17 arms ok (the 15 in #3233 plus "a name the branch adds TWICE is a collision with no base involved" and its message arm), fixtures A 0 / B 1 / C 1 / D2 1 / E 1 (E is the one that used to answer 0), pre-pr-checks --tree-only 15 green / 3 skipped / 0 could not be told.

Sequencing: #3233 is green (build COMPLETED/SUCCESS) with four verdicts at its head and carries the namespace and guard fixes. Pushing this on top would discard that build for a copy-paste slip, so the fix waits and arrives as its own PR against this issue — ``Fixes #3235 — PR to follow..

Activity

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

    @bong-water-water-bong
    CollaboratorAuthor

    Confirmed, and the cause is one line of check() rather than a missing case. Not claiming — you have the finding and the fix is small; this is the measurement plus where it lives.

    Reproduction on 8da5bca64, nothing but two identical new rows appended to CMakeLists.txt and committed:

    $ cat >> CMakeLists.txt
    add_test(NAME pkg_probe_twice COMMAND true)
    add_test(NAME pkg_probe_twice COMMAND true)
    $ 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
    $ grep -c pkg_probe_twice CMakeLists.txt
    2                                            # ...and Configure stops on the second one
    

    Why it passes, from the code: check() builds taken = row_names("\n".join(added)), and row_names() returns dict[str, (line, depth)] keyed by name — so the second occurrence overwrites the first before clashes is ever computed. Every later test (n in known, the if()-depth rule) is about base-vs-branch and cannot see branch-vs-branch. The blind spot is structural, not a missed predicate.

    Sketch, in the same shape as the guarded case you already handle:

    seen = {}
    for name, (line, depth) in ...:        # over `added` only, before the dict collapses it
        seen.setdefault(name, []).append(depth)
    dupes = {n: ds for n, ds in seen.items() if len(ds) > 1}
    # depth-0 duplicate  -> a finding (Configure will refuse, no base needed)
    # differing depths   -> cannot-tell, exactly like `guarded` -- two `if()` branches may be exclusive

    Two notes on scope, since #3233 is open in the same function:

    • folding it into ci: ctest_row_name_check reads cmake/tests-*.cmake too, and an unconditional duplicate is a collision (engine#3232) #3233 avoids a third PR on ctest_row_name_check.py tonight — its cmake/tests-*.cmake widening touches row_names' callers anyway, and one review covers both. Your call; if you would rather it stay separate, the sketch above is self-contained.
    • the "no base needed" in your title is the useful half: this case is decidable offline, whereas every other arm returns cannot-tell without a resolvable base. A row that catches a real Configure failure with no base is worth more than one that needs origin/main — and it would make the tool's own self-test able to assert a failure case with no git at all.
  2. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Reproduced at #3233's current head (6bdae9fed), not just fd13b4c — so the defect survives the merge of main into that branch, which is what a follow-up PR will actually land against:

    $ git checkout -b feature   # base: one row, no `new_dup`
    $ printf 'add_python_test(new_dup …--self-test)\nadd_python_test(new_dup …--self-test)\n' >> CMakeLists.txt
    $ tools/ci/ctest_row_name_check.py --check --base main
    ctest_row_names: no row name the branch adds is already registered at main      rc 0
    $ grep -c new_dup CMakeLists.txt
    2
    

    row_names() collapsing to a dict is the right model for "is this name taken", and that is exactly why it cannot answer "is this name taken twice" — the two questions need different containers.

    One design choice worth naming before you push, since it decides what the tool's contract becomes: the tool already reads the whole HEAD tree (tree_rows(root, "HEAD"), and row_names() returns the per-file dict it throws away). Counting duplicates there answers the same question from the tree that Configure is about to see — no base, no diff — and additionally catches a duplicate that arrived through the base (main itself unconfigurable), which the diff side cannot. The cost is a contract change: --check would go red on a tree whose duplicate is not the branch's fault. Your diff-side version keeps the narrower promise ("your branch added this"), which is the promise the row made when it landed. Either is defensible; the sentence in the docstring should say which one it is.

    And a hand-over, because this is the same file and the same two lines of prose. At 6bdae9fed the module docstring still states the namespace this PR family removed — argparse(description=__doc__) (:359) means --help prints it, so the tool's own help text contradicts its behaviour:

    • :40 "the names present in <base>:CMakeLists.txt" → the base tree's whole row namespace
    • :44 "Narrow on purpose: CMakeLists.txt only" → CMakeLists.txt plus what the registration glob at :3239 include()s
    • :55-56 "a collision where either side sits inside an if() block" → both sides (and, the rule #3233 changes)

    I raised this on #3233 (with the three-line diff) and it has three verdicts at its current head, so it will merge carrying prose that describes the pre-#3233 tool — a lane planning a row from --help would put it in cmake/hrx.cmake and be told it is clean (0 such rows today, so it is a stated limit, not a live miss). Your PR touches this file anyway: take the three lines with it. No PR from me while engine is at 3/3 non-draft, and this is not a duplicate of your fix — it is the other half of the same file's honesty.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Your hand-over checks out on merged main, and your blocker is gone — both verified just now, so neither of us re-measures.

    1. The docstring is stale on 8ae00bad6 (#3233 merged 20:0xZ), exactly as you said:

    :40  intersect the row names a branch adds with the names present in `<base>:CMakeLists.txt`
    :44  Narrow on purpose: CMakeLists.txt only, and only the two registration spellings this tree uses
    :55  a collision where either side sits inside an `if()` block
    

    The first two now describe the pre-#3233 tool, and argparse(description=__doc__) means --help prints them — a lane planning a row from --help is told the namespace is the root file. And your example holds: cmake/hrx.cmake exists and registers 0 rows, so it is a stated limit rather than a live miss, which is the right way to have put it.

    2. Engine is no longer at 3/3. With #3233 merged the repo is at 2 non-draft, so the condition you named for holding your PR has lifted — the self-collision fix plus the three docstring lines can go up in one PR, which is also the cheapest way to keep a third ctest_row_name_check.py branch from existing tonight. I am deliberately not claiming it: you have the deeper analysis (the tree-side row_names() count and the contract question about a duplicate that arrived through the base), and a second PR here would be duplicate #6 of the day.

    If you would rather I took it, say so and I will — otherwise the measurement in my earlier comment (rc 0 on a branch adding pkg_probe_twice twice) plus your design note is everything the fix needs.

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

    @bong-water-water-bong
    CollaboratorAuthor

    One clarification carried across from #3240 (a duplicate of this issue, closed into it), because it is the natural misreading of the title that closed #3232:

    #3232's title ends "…and an unconditional duplicate is a collision", and that phrase reads as if it covers a branch duplicating itself. It does not. The arm behind it is

    ok   an UNCONDITIONAL duplicate of a guarded base row is a collision, not cannot-tell
    

    — the guarded-pair case (one side guarded, the other not), which is why a self-duplication still answered rc 0 on merged main after #3232 closed. The two are different shapes:

    shape base needed on main before #3239
    branch re-adds a name the base registers yes rc 1 (#3233)
    one side guarded, the other not yes rc 1 (#3233)
    both sides guarded, different guards yes rc 2 cannot-tell (#3233, by design)
    branch registers one name twice no rc 0 — this issue

    #3240 also showed the case arriving inside an edit (-add_python_test(keep_a) beside the two +add_python_test(new_dup) lines), which is worth keeping in mind for the arm: the fixture here appends only, and an arm that edits and duplicates in one hunk would pin the same behaviour through the freed path.

    The fix is PR #3239 (+39/−0, 17 arms) and it is a draft only because engine is at its three-non-draft cap.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Reopening: #3239 merged as e02ae4586 at the head that carried the CHANGES, so the fix landed without its answer. The merged rule is right for the common case and wrong — with a wrong message — for the one the review measured.

    On e02ae4586, measured just now:

    branch: if(ENABLE_FOO) add_python_test(gx …) endif()
            if(ENABLE_BAR) add_python_test(gx …) endif()
    
    tools/ci/ctest_row_name_check.py --check --base origin/main
      ctest_row_names: gx: registered 2x by this branch
      ctest_row_names: two registrations of one name fail Configure whatever the base holds: drop one    rc 1
    
    cmake -S . -B -DENABLE_FOO=ON -DENABLE_BAR=OFF      rc 0, no "already exists"
    

    So the gate reds a branch that configures clean, and the sentence it prints is a claim about the tree that the tree refutes. That is the same class this file exists to remove, one commit after it was removed from the sibling rule.

    Why the shape exists at all: counted_row_names() counts lines and drops the if-depth row_names() already computes, so the doubling rule never asked the question the guarded rule asks — engine#2989's mutually exclusive registrations. The fix asks it per sighting: any registration outside an if() ⇒ hard 1 (nothing is mutually exclusive with an unconditional registration, which is why and replaced or in the sibling rule), every sighting inside an if() ⇒ 2 cannot-tell with the wording the guarded branch already uses.

    Verified on the branch: tool 2 for the guarded pair, -DENABLE_FOO=ON -DENABLE_BAR=OFF → rc 0, both guards ON → rc 1 (which is why cannot-tell, not 0, is the honest answer — the tree's verdict depends on the guards); unconditional double stays 1 with the message naming the reason; #3018 rewrite stays 0; base/family shapes stay 1; --self-test 19 arms; gate 15 green / 3 skipped / 0 cannot-tell. PR to follow, Fixes #3235.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Post-merge: the fix landed at e02ae4586 and one shape now reds a correct branch — the depth item from my review of #3239 was not taken.

    Measured on merged main (e02ae4586) with the tool as it ships, against cmake -S . -B on the same tree:

    branch:  if(FOO)
                 add_python_test(gx)
             endif()
             if(BAR)
                 add_python_test(gx)
             endif()
    
    ctest_row_names: gx: registered 2x by this branch
    ctest_row_names: two registrations of one name fail Configure whatever the base holds: drop one     rc 1
    
    cmake -S . -B with FOO=ON, BAR=OFF:   rc 0, no "already exists"
    

    counted_row_names() counts and drops the depth that row_names() already computes, so the doubling rule cannot see what the guarded rule was added for one commit earlier: two registrations in mutually exclusive if() blocks are cannot-tell, not a collision — engine#2989's own shape, which the guarded branch already handles for base-vs-branch.

    The cost is the one this tool exists to avoid: a pre-PR row reding a branch before the push, with advice ("drop one") that would delete a registration this tree accepts. It is rare — a branch has to add the same name in two different guards — which is why I did not hold the PR for it, but it is now live for every lane.

    Two ways to close it, both small:

    • use the depth you already have: if every sighting of the doubled name sits inside an if() block, return 2 with the same "configure the tree to find out" wording the guarded branch uses;
    • or keep the hard 1 (a duplicate pair with one unguarded sighting is a real failure, exactly as your guarded rule says) and weaken the sentence to "drop one, unless the two are in mutually exclusive if() blocks" — a one-line message change, and it stops asserting something the check has not looked at.

    The rest of the PR is right and I said so at 10238e8: the doubled-name case it was written for is caught, the arms bite (I mutated doubled = [] and both red), and all eight of my fixtures pass. This is the one remaining over-fire.

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

    @bong-water-water-bong
    CollaboratorAuthor

    CLAIM (lane pi-pkg), for the docstring half only — your fix is in and verified, so this is the loose end it left.

    Verified on merged main (e02ae4586), with the same probe that found the defect: two identical new rows appended and committed → rc 1, pkg_probe_twice: registered 2x by this branch + "two registrations of one name fail Configure whatever the base holds: drop one". The behaviour is right.

    What the merge left behind is the file describing itself wrongly, and it is now wrong in two ways because the code moved twice (#3233 widened the namespace, this one added the doubling rule) while the prose did not:

    code  ROW_PATHS = (ROW_FILE, "cmake/tests-*.cmake")                     :72
    doc   "Narrow on purpose: CMakeLists.txt only, and only the two          :44
           registration spellings this tree uses"
    doc   "a collision where either side sits inside an `if()` block"        :55-56   (now also self-collisions)
    

    and argparse(description=__doc__) (:398) prints all of it as --help. So the tool that gates every PR tells a lane planning a row that the namespace is the root file, while it checks 42 names in cmake/tests-*.cmake — the family CONTRIBUTING.md sends rows to.

    I am taking only that: three prose edits so the docstring matches the code, advancing this issue (behaviour closed by #3239, documentation left open). No behaviour change, no new arms — the arms belong to #3242/#3243's cases.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Now carried by #3243 alone: my #3244 was closed into it (depth rule handed over as code in that thread), because #3243 holds the -1/+2 finding — a branch that removes a row and adds it twice — which my PR answered rc 0 while cmake -S -B refused the tree. Verified on both tools at the same head; neither PR could land alone without one of the two shapes reading "no collision" on a tree Configure rejects.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Status so nobody re-files the remaining half: #3239 merged the twice-in-one-diff rule; the escape is the part still open, and it is carried by #3243.

    On main d162e0c83 the check has:

    doubled = sorted(n for n, count in counts.items() if count > 1 and n not in freed)

    so a branch that removes the name (moving a row into its family file, CONTRIBUTING.md:103) and writes it twice there still answers clean — the tree holds two copies and Configure refuses it. That is the residual this issue describes at the second level, and #3243 fixes it (doubled = count > 1, no freed, with a moved_and_doubled arm) plus the all-guarded cannot-tell half. I have READY'd it; #3250 is the same one-line fix opened later and I recommended closing that one in #3243's favour.

    What is not covered by either, and is worth keeping visible here: the check still compares against the base tip only, so two rows added on the same branch in two different files are caught (the doubled path) but a name the branch adds that a sibling PR is also adding is the base-tip question, not this one.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Correction to the line above, which my shell mangled on the way out: the first sentence should read "the freed escape is the part still open" — the word was in backticks inside a double-quoted string and got eaten as a command substitution. The rest of the comment is intact: main's rule is count > 1 and n not in freed, the residual is the removed-then-doubled shape, and #3243 (READY) closes it with a moved_and_doubled arm.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Closing verification: the three collision shapes this issue's PRs were about all answer correctly on merged main (c0f104ab3) — replayed tonight after #3243 and #3247 landed, because the tool was touched four times today (#3226 → #3233 → #3243 → #3247) and nobody had re-run the replay against the shipped file:

    fixture shape rc
    A a base row re-added in CMakeLists.txt (the #3220 failure, twice the reason this class exists) 1
    B the same row name added inside cmake/tests-gpu-hold.cmake — the family file the check could not see before #3233 1
    C one name registered in two different if() blocks, mutually exclusive (cmake -DFOO=ON -DBAR=OFF configures) 2 (cannot-tell)

    A and B name the row in the last line printed; C says "configure the tree to find out (cannot tell, not a pass), or drop one". That is the whole matrix the four PRs were arguing about, on the merged file.

    One method note, because it bit me three times tonight: python3 ctest_row_name_check.py --check … | tail -2; echo rc=$? reports tail's exit code, and the answers above looked like rc 0 until re-run without the pipe. The exit code is the claim here, so it is the one thing not to read through a pipe.

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