Repository navigation
Properties instead of examples, a styled help, and a mutation command - #38
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three tools aimed at one thing: the defect that cost the last PR six
review rounds.
tests/test_text_properties.pyThe 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 fourseparate sweeps. More examples is not the cure.
report/text.pyis pure arithmetic whose docstrings state their owninvariants — 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
padon its first two runs. An empty righthalf took the padding branch, so
pad("label", "", 20)returned thelabel 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.pya week ago, with abranch and a comment, instead of asking why
paddid it. That branch isgone.
rich-argparse--helpis 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 toits subparsers and not
formatter_class, so the naive versionstyles one help out of nine, and passing it at each of the eight
add_parsercalls is eight chances to forget the ninth. The test walksevery subparser.
My first comment there claimed
parser_class=was load-bearing. Themutation pass showed it was redundant — which is the kind of thing a
comment should not be allowed to say.
scripts/mutate.pyThe check
CLAUDE.mdasks 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 touchedNot
mutmut, which mutates nine thousand statements over hours. Thequestion here is narrow — the line I just changed, against the test I
just wrote — so a mutation is a
FILE:LINEand 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
passis 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
timeoutkilled it mid-mutation and thefinallynever ran, leavingreport/text.pyin the working tree unparsed and stripped of everycomment — a
finallydoes not run when the process is KILLED. Theoriginal goes to a sibling file first now, and the next invocation puts
back whatever a killed one left;
.gitignorecovers the sibling.The same run showed that
--changedoffered 275 targets (227 inside thetool itself, the rest one statement counted once per line), that ten
targets against the whole suite is half an hour without
-x, and that abare header printed for a
defmakes a report look like it foundnothing 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 testaround 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.pycomes out of the coverageomitwith its tests: thethree 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 gainsmutate.py --changedand theother thing a green suite does not catch — the CI has no
OCR/and twocores, 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