Skip to content

Properties instead of examples, a styled help, and a mutation command - #38

Merged
rayondemiel merged 3 commits into
mainfrom
chore/property-tests-and-help
Sep 9, 2026
Merged

rayondemiel merged 3 commits into
mainfrom
chore/property-tests-and-help

Conversation

@rayondemiel

Copy link
Copy Markdown
Member

Three tools aimed at one thing: the defect that cost the last PR six
review rounds.

tests/test_text_properties.py

The recurring failure in this repository is a width sweep that starts
above the widths where the bug lives — the first of the five hollow
shapes in docs/developer-guide.md, and it slipped through four
separate sweeps. More examples is not the cure.

report/text.py is pure arithmetic whose docstrings state their own
invariants — never wider, the leaf is kept whole, the half that
survives whole
— so Hypothesis picks the widths and the strings
instead, including a CJK glyph two cells wide and a newline out of an
httpx message.

It found two defects in pad on its first two runs. An empty right
half took the padding branch, so pad("label", "", 20) returned the
label and fifteen spaces — noise in a log file, noise someone strips out
of a pasted issue — and a right half made only of spaces did the same. I
had worked the first one around by hand in info.py a week ago, with a
branch and a comment, instead of asking why pad did it. That branch is
gone.

rich-argparse

--help is the front door of a program whose premise is a visible UX,
and rich is already a dependency. One formatter class, set by
subclassing ArgumentParser: argparse propagates the parser CLASS to
its subparsers and not formatter_class, so the naive version
styles one help out of nine, and passing it at each of the eight
add_parser calls is eight chances to forget the ninth. The test walks
every subparser.

My first comment there claimed parser_class= was load-bearing. The
mutation pass showed it was redundant — which is the kind of thing a
comment should not be allowed to say.

scripts/mutate.py

The check CLAUDE.md asks for in capitals, as a command:

scripts/mutate.py teille_douce/report/text.py:120 tests/test_text_properties.py
scripts/mutate.py --changed        # every statement this branch touched

Not mutmut, which mutates nine thousand statements over hours. The
question here is narrow — the line I just changed, against the test I
just wrote
— so a mutation is a FILE:LINE and a test. Four mutations,
the ones that turn a guard into no guard. It works on the syntax tree,
because a line is not a unit of Python and replacing the first line of a
two-line statement with pass is a tool failure that reads as a result.
A mutation that makes the tests hang counts as caught.

Its own first run on a real branch is why half of it exists. A
timeout killed it mid-mutation and the finally never ran, leaving
report/text.py in the working tree unparsed and stripped of every
comment — a finally does not run when the process is KILLED. The
original goes to a sibling file first now, and the next invocation puts
back whatever a killed one left; .gitignore covers the sibling.

The same run showed that --changed offered 275 targets (227 inside the
tool itself, the rest one statement counted once per line), that ten
targets against the whole suite is half an hour without -x, and that a
bare header printed for a def makes a report look like it found
nothing when it did not look. Thirty targets, then ten, then seconds
each.

And on this branch it found a real hole: deleting the line that
renders info's layer rows left the whole suite green. Every test
around it asserts the resolved data — which layer offered what, which
one took effect — and none looked at the output. Printing the four
layers is the entire point of teille-douce info NAME.

Numbers

1542 tests, coverage 93.3 %, ratchet unchanged at 92.9.
scripts/mutate.py comes out of the coverage omit with its tests: the
three launchers are one line each and stay out, this one is a real tool,
and omitting tested code takes from the ratchet what it is there to
count.

CONTRIBUTING.md's pre-PR list gains mutate.py --changed and the
other thing a green suite does not catch — the CI has no OCR/ and two
cores, so parking the corpus once is the cheapest way to find a test
that leans on either.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ToHE2uzVAPzcxaZbKktYGz

rayondemiel and others added 3 commits September 7, 2026 20:19
…command

Three tools for the defect that cost this project six review rounds.

**`tests/test_text_properties.py`.** The recurring failure is a width
sweep that starts above the widths where the bug lives — the first of
the five hollow shapes, and it slipped through four separate sweeps.
More examples is not the cure; `report/text.py` is pure arithmetic whose
docstrings state their own invariants, so Hypothesis picks the widths
and the strings instead, including a CJK glyph two cells wide and a
newline out of an httpx message.

It found two defects in `pad` on its first two runs. An empty right half
took the padding branch, so `pad("label", "", 20)` returned the label
and fifteen spaces — noise in a log file, noise someone strips out of a
pasted issue — and a right half made only of spaces did the same. I had
worked the first one around by hand in `info.py` a week ago, with a
branch and a comment, instead of asking why `pad` did it. That branch is
gone.

**`rich-argparse`.** `--help` is the front door of a program whose whole
premise is a visible UX, and rich is already a dependency. One formatter
class, set by subclassing `ArgumentParser`: argparse propagates the
parser CLASS to its subparsers and not `formatter_class`, so the naive
version styles one help out of nine and passing it at each of the eight
`add_parser` calls is eight chances to forget the ninth. The test walks
every subparser. My first comment there claimed `parser_class=` was
load-bearing; the mutation pass showed it was redundant, which is the
kind of thing a comment should not be allowed to say.

**`scripts/mutate.py`.** The check CLAUDE.md asks for in capitals, as a
command. Not `mutmut`, which mutates nine thousand statements over
hours: the question here is narrow — *the line I just changed, against
the test I just wrote* — so a mutation is a `FILE:LINE` and a test, and
`--changed` is every line a branch added. It works on the syntax tree,
because a line is not a unit of Python and replacing the first line of a
two-line statement with `pass` is a tool failure that reads as a result.
A mutation that makes the tests hang counts as caught.

`CONTRIBUTING.md`'s pre-PR list gains it, and the second thing a green
suite does not catch: the CI has no `OCR/` and two cores, so parking the
corpus once is the cheapest way to find a test that leans on either.

1524 tests, coverage 93.3 %.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ToHE2uzVAPzcxaZbKktYGz
It edits files under version control, so the first thing it did on a
real branch mattered: a `timeout` killed it mid-mutation and the
`finally` never ran, leaving `report/text.py` in the working tree
unparsed and stripped of every comment. A `finally` does not run when
the process is KILLED. The original now goes to a sibling file first,
and the next invocation puts back whatever a killed one left — the
recovery has to live there, because that is the only place it can.
`.gitignore` covers the sibling, since a `git add -A` after a kill would
otherwise commit it.

Three more things its own first run showed:

`--changed` offered 275 targets for this branch, 227 of them inside the
tool itself and the rest the same statement counted once per line.
Statements, deduplicated, and `scripts/` and `tests/` skipped for the
reason the coverage `omit` already gives: thirty targets, then ten.

Ten targets against the whole suite is half an hour, which is "slow" as
documented and unusable in practice. `-x` makes a CAUGHT mutation cost
seconds instead of eighty — and most mutations are caught, so most of
the run is that saving.

And a bare header printed for a `def` or a `try`, where emptying the
whole block says nothing and no mutation is offered: a report full of
blanks reads as a report that found nothing when it did not look.

`scripts/mutate.py` comes out of the coverage `omit` with it. The three
launchers are still one line each and stay out; this one is a real tool
with tests, and omitting tested code takes from the ratchet what it is
there to count. 90 % of it, and the total holds at 93.3 %.

1541 tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ToHE2uzVAPzcxaZbKktYGz
Found by running the new tool on its own branch. Deleting the line that
renders the layer rows left the whole suite green: every test around it
asserts the resolved DATA — which layer offered what, which one took
effect — and none of them looked at the output. `info NAME` printing its
four layers is the entire point of the command.

Its first real use, and the survivor it reported was in code written the
same afternoon.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ToHE2uzVAPzcxaZbKktYGz
@rayondemiel
rayondemiel merged commit 77a0ae1 into main Sep 9, 2026
1 check passed
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.

1 participant