Skip to content

tools: register the self-tests nothing ran, and teach the sweep to see a tools/*.py at all (fixes #1901) - #1916

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
fix/1901-tool-selftests
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
fix/1901-tool-selftests

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

#1824's check asks whether every tests/*.sh is referenced by something that can run it — need is that glob and nothing else, so a tool shipping a --self-test was invisible to it. Two were unregistered when the issue was filed; the rule below finds three, and the third is the reason the rule exists rather than the hand-picked pair:

tools/batched_repeat.py           --selftest      (not in the issue's list)
tools/whisper_encoder_baseline.py --self-test

Both are registered here through #1891's add_python_test() — batched_repeat.py --selftest (its own spelling, from before the hyphenated convention) and whisper_encoder_baseline.py --self-test. Both pass on this tree, device-free.

The rule, and why it is narrow. need now also includes any tools/*.py that declares a self-test. The blanket version ("every tools/*.py referenced by nothing") found 16 of 60 on this tree — most legitimately CLI-only — and a list that noisy is one nobody reads. A tool that ships a check and is registered nowhere is the defect; a tool that only has a CLI is not.

And the sweep was green on a disabled registration — the same defect one layer in. referenced() counted a basename anywhere in a place that can run things, so # add_python_test(...), or # add_test(...) for the 73 scripts, read as a runner. Comment-only lines are dropped now, and the mutation shows it: with both of this PR's registrations commented out, the sweep names them instead of passing.

Self-test

Two cases in the file's own style (synthetic roots; the verdict must NAME the offender):

  • a self-testing tool nothing registers → drift, named;
  • the same tool registered → clean, and a tools/*.py with no self-test is not a row (the negative that keeps the rule narrow).

Verified

tools/ci/tests_referenced_check.py --check --root .   -> 73 script(s) and 17 self-testing tool(s) are referenced (rc 0)
tools/ci/tests_referenced_check.py --self-test        -> 0 failure(s)
python3 tools/batched_repeat.py --selftest            -> selftest: ok
python3 tools/whisper_encoder_baseline.py --self-test -> whisper_encoder_baseline: ok
ctest -R 'tests_referenced|tool_selftest|ci_targets'  -> 100% tests passed, 0 failed out of 6
mutation: comment out both registrations              -> the sweep names both tools
tools/copyright.py --check (staged)                   -> rc 0

Fixes #1901. Refs #1824, #1891.

…e a tools/*.py at all (fixes #1901)

#1824's check asks whether every `tests/*.sh` is referenced by something that can run it -- `need` is that glob and
nothing else, so a tool shipping a `--self-test` was invisible to it. Two were unregistered at the time the issue was
filed; the rule below finds **three**, and the third is the reason the rule exists rather than the two hand-picked
files:

```
tools/batched_repeat.py           --selftest      (not in the issue's list)
tools/whisper_encoder_baseline.py --self-test
```

Both are registered here through #1891's `add_python_test()`: `batched_repeat.py --selftest` (its own spelling, since
before the hyphenated convention) and `whisper_encoder_baseline.py --self-test`. Both pass on this tree, device-free.

**The rule, and why it is narrow.** `need` now also includes any `tools/*.py` that *declares* a self-test. The blanket
version ("every tools/*.py referenced by nothing") found 16 of 60 on this tree -- most legitimately CLI-only -- and a
list that noisy is one nobody reads. A tool that ships a check and is registered nowhere is the defect; a tool that
only has a CLI is not.

**And the sweep was green on a disabled registration**, which is the same defect one layer in. `referenced()` counted a
basename anywhere in a place that can run things, so `# add_python_test(...)` — or `# add_test(...)` for the 73
scripts — read as a runner. Comment-only lines are dropped now, and the mutation shows it: with both of this PR's
registrations commented out the sweep names them instead of passing.

## Self-test

Two cases added, in the file's own style (synthetic roots, and the verdict has to NAME the offender):

* a self-testing tool nothing registers → drift, named;
* the same tool registered → clean, **and** a `tools/*.py` with no self-test is not a row (the negative that keeps the
  rule narrow).

## Verified

```
tools/ci/tests_referenced_check.py --check --root .   -> 73 script(s) and 17 self-testing tool(s) are referenced (rc 0)
tools/ci/tests_referenced_check.py --self-test        -> 0 failure(s)
python3 tools/batched_repeat.py --selftest            -> selftest: ok
python3 tools/whisper_encoder_baseline.py --self-test -> whisper_encoder_baseline: ok
ctest -R 'tests_referenced|tool_selftest|ci_targets'  -> 100% tests passed, 0 failed out of 6
mutation: comment out both registrations              -> the sweep names both tools
tools/copyright.py --check (staged)                   -> rc 0
```

Fixes #1901. Refs #1824, #1891.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing as a duplicate of #1910 (475ba3e, opened at 11:43 — 19 minutes before this one), which does the same job better and found more of it.

What #1910 has that this does not:

  • five registrations, not two — I treated referenced()'s by-basename match as proof that mtp_head_ref.py runs (two sibling tools import it) and never registered logprob_agree.py or template_bom.py. Importable is not run: their --selftest has never executed in CI. Registering all five is the correct reading;
  • the per-tool flag spelling (--selftest for three, --self-test for two) is called out in the registration, which is the difference between an arm and a green no-op.

What I have handed to #1910 and would like kept, because it is a real hole in the sweep this PR extends:

referenced()  counts a basename in a COMMENT as a runner

Measured on my copy: commenting out both registrations left --check at rc 0 saying "all referenced". Same defect class as #1901 itself, one layer in — an arm that exists textually and never executes. Four lines of comment-stripping fixes it and strengthens the tests/*.sh half on the same head, which is why I suggested it there rather than in a separate PR.

I also reviewed #1912 (the third PR for this issue) and asked for it to be closed in favour of #1910, with one piece to fold in: argparse-parsed detection rather than a substring match, so a docstring mentioning --self-test does not turn a CLI-only tool into a row.

Rule for me, again: gh issue list and the board did not show a claim at the moment I took #1901; a gh pr list --search "1901 in:body" before writing would have found both.

@bong-water-water-bong
bong-water-water-bong deleted the fix/1901-tool-selftests branch November 12, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tools: a tools/*.py that declares a --self-test and is registered nowhere is invisible to the #1824 sweep (2 files today)

1 participant