test(consume): the lookup partition still wins, and the CLI defaults agree with the signature

Two guarantees this round STATED, now each with a test that goes red if it
stops being true.

The partition lands BELOW `lookup_hits`: asserted with its own control, since
with the lookup off the covered concept IS first on the same fixture, so the
assertion measures which partition wins rather than that only one fires.

`build_payload`'s signature defaults against the consume CLI's argparse
defaults, for every same-named parameter. This is O6's defect in the other
command: `cli.build` defaulted two flags `False` in the signature and `True`
in argparse, and a caller reaching it as a function read the signature.

Suite: 1582 passed, 1 skipped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-09-10 22:20:42 +02:00
commit ff06b92c35

View file

@ -173,3 +173,70 @@ def test_the_rule_has_an_explicit_opt_out_the_cli_exposes(tmp_path: Path) -> Non
arguments = okf_consume.parse_args([str(root), "--question", QUESTION, "--no-title-covered"])
assert arguments.title_covered is False
assert okf_consume.parse_args([str(root), "--question", QUESTION]).title_covered is True
def test_a_question_that_NAMES_a_concept_still_reads_that_one_first(tmp_path: Path) -> None:
"""The partition lands BELOW `lookup_hits`, and that is asserted rather than
remembered.
A question carrying an identifier a concept holds verbatim is a lookup, not
a search, and this rule must not out-rank it. Without the assertion the
ordering of the two partitions is a property of the source's line order.
"""
root = _covered_bundle(tmp_path / "bundle")
concepts = [
okf_consume.read_concept(
root / f"{concept_id}.md", bundle_root=root, root_bundle_id="covered-fixture"
)
for concept_id in okf_consume.enumerate_concepts(root)
]
question = "Which requirements apply to anchoring on a bridge under 4.2-1?"
(root / "part" / "ee-named.md").write_text(
_FRONTMATTER.format(
title="Clause 4.2-1 on temporary works", slug="ee-named", digest="2" * 64
)
+ "## Clause 4.2-1 on temporary works\n\nA clause about works.\n",
encoding="utf-8",
)
named = okf_consume.read_concept(
root / "part" / "ee-named.md", bundle_root=root, root_bundle_id="covered-fixture"
)
concepts.append(named)
assert okf_consume.lookup_hits(concepts, question) == (named.concept_id,)
assert okf_consume.title_covered_hits(concepts, question)
# THE CONTROL, so this is not green for want of a competitor: with the
# lookup partition off, the covered concept IS first, so the assertion
# below measures which partition wins rather than that only one fires.
without_lookup = okf_consume.concept_scores(
concepts, question, okf_consume.document_scores(root, question), lookup=False
)
assert without_lookup[0][0].concept_id.endswith("aa-broad")
ranked = okf_consume.concept_scores(
concepts, question, okf_consume.document_scores(root, question)
)
assert ranked[0][0].concept_id == named.concept_id
def test_the_payload_signature_defaults_are_the_consume_command_defaults() -> None:
"""O6's defect, in the other command.
`cli.build`'s signature defaulted two flags to `False` while argparse
defaulted both to `True`, and a caller reaching `build()` as a function read
the signature -- so two build paths emitted different bundles and the test
that held them equal compared the wrong side against itself. `build_payload`
has the same two entry points, so it gets the same check: every
same-named parameter must carry the same default on both sides.
"""
import inspect
signature = inspect.signature(okf_consume.build_payload).parameters
parsed = okf_consume.parse_args(["bundle", "--question", "q"])
shared = {name for name in signature if hasattr(parsed, name)}
assert "title_covered" in shared, "the new parameter is not reachable from the CLI"
mismatched = {
name: (signature[name].default, getattr(parsed, name))
for name in sorted(shared)
if signature[name].default is not inspect.Parameter.empty
and signature[name].default != getattr(parsed, name)
}
assert mismatched == {}, f"signature and argparse disagree: {mismatched}"