test(propose): count the arm attribution per option chunk, not per output

`test_the_help_attributes_arm_d_inside_its_own_option_chunk` ended with
`assert squeezed.count("not defined upstream") == 1`, with the comment "the
literal belongs to Arm D alone". That was true when it was written and it is a
guard worth keeping -- but it goes red the moment a SECOND arm is attributed
the same way, on an axis that has nothing to do with whether the new arm is
correct. Left as it was, the cheapest way past it during the Arm E round would
have been to weaken Arm E's attribution, which is the opposite of what the
guard is for.

The assertion is now derived from a declaration:

    ARM_ATTRIBUTION = {"outline-run": True, "max-segment-chars": False}

Per chunk, an arm either carries the literal or must not; the whole-output
count is `sum(attributed)`. Arm C stays False on purpose -- its help says "not
defined in the K3 method file" instead, and the point of the check is that
each arm's attribution sits in its OWN chunk rather than anywhere in the file.

Semantically identical this commit (1 == 1). It is committed on its own, before
the flag it unblocks exists, so the generalisation is visible as a deliberate
change rather than as collateral inside a feature diff.

Tests first: not applicable -- this commit's product IS the test, and its
correctness is that it stays green against unmodified production code.
1233 -> 1233. ruff check: exit 0. ruff format --check: exit 0. pytest -q: exit 0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-09-07 10:46:10 +02:00
commit 45f1013308

View file

@ -1054,36 +1054,50 @@ def test_a_non_integer_outline_run_is_refused_by_argparse(
assert "usage:" in capsys.readouterr().err
def test_the_help_attributes_arm_d_inside_its_own_option_chunk(
#: Which arm flags carry the literal "not defined upstream" in their own help
#: chunk, and which must NOT. Data rather than a hand-counted assertion: the
#: whole-output count below is derived from this table, so adding an arm is one
#: line here instead of an edit to a number nobody can trace back to a rule.
#: Arm C is False on purpose -- its help says "not defined in the K3 method
#: file" instead, and the point of the check is that each arm's attribution
#: sits in its OWN chunk.
ARM_ATTRIBUTION = {"outline-run": True, "max-segment-chars": False}
def test_each_arm_flag_carries_its_attribution_inside_its_own_option_chunk(
capsys: pytest.CaptureFixture[str],
) -> None:
"""The attribution must sit in the `--outline-run` help, not merely in the file.
"""Each attribution must sit in its own option's help, not merely in the file.
Sliced between option headers on purpose: a whole-output grep would be
satisfied by adding the literal to Arm C's block, which would attribute the
wrong rule. And the squeeze is `tr -s '[:space:]'`, not a newline swap --
argparse wraps its help, so a newline-only normalisation leaves the run of
spaces behind and the literal stays unfindable.
satisfied by adding the literal to another arm's block, which would
attribute the wrong rule. And the squeeze is `tr -s '[:space:]'`, not a
newline swap -- argparse wraps its help, so a newline-only normalisation
leaves the run of spaces behind and the literal stays unfindable.
The whole-output count is DERIVED from `ARM_ATTRIBUTION` rather than
written down. A hard-coded `== 1` is correct only until a second arm is
attributed the same way, and it then goes red on an axis that has nothing
to do with whether the new arm is right.
"""
with pytest.raises(SystemExit) as exit_info:
okf_propose_segments.main(["--help"])
assert exit_info.value.code == 0
squeezed = " ".join(capsys.readouterr().out.split())
# Drop the usage line: it repeats every option name, so slicing the whole
# output would find two `outline-run` chunks and neither would be the help.
# output would find two chunks per flag and neither would be the help.
assert "options:" in squeezed
options = squeezed.split("options:", 1)[1]
chunks = options.split(" --")
outline_chunk = [c for c in chunks if c.startswith("outline-run")]
assert len(outline_chunk) == 1, f"expected exactly one chunk, got {len(outline_chunk)}"
assert "not defined upstream" in outline_chunk[0]
# The negative half: Arm C's chunk must NOT carry the literal, or the
# attribution would name the wrong rule while the grep still passed.
arm_c_chunk = [c for c in chunks if c.startswith("max-segment-chars")]
assert len(arm_c_chunk) == 1
assert "not defined upstream" not in arm_c_chunk[0]
# The whole-output count must also be 1: the literal belongs to Arm D alone.
assert squeezed.count("not defined upstream") == 1
for flag, attributed in ARM_ATTRIBUTION.items():
matching = [c for c in chunks if c.startswith(flag)]
assert len(matching) == 1, f"expected exactly one {flag} chunk, got {len(matching)}"
if attributed:
assert "not defined upstream" in matching[0], flag
else:
assert "not defined upstream" not in matching[0], flag
expected = sum(1 for attributed in ARM_ATTRIBUTION.values() if attributed)
assert squeezed.count("not defined upstream") == expected
# --- Arm E: the grid-rule join --------------------------------------------