Repository navigation
test: harden README defaults and example checks - #558
mangeshraut712 wants to merge 7 commits into
Conversation
vawsgit
left a comment
There was a problem hiding this comment.
needs changes
Two of the new checks do not catch the drift that #436 asks them to pin. Everything else in the PR works. Measured at head facaa4b with stickler imported from that checkout's src.
1. The threshold Default check never reads the enum / const / format clause.
stickler/tests/test_readme_examples.py
Lines 344 to 346 in facaa4b
The `([0-9.]+)` for a free-form pattern takes the number before "free-form" and applies it to the enum, const and format fields as well. Editing README.md:351 to say 0.5 for "any property or array items with enum, const, or a string format" (the code still returns 1.0) gives 40 passed. That is the #352 drift from #436 item 1. Fix: give that clause its own pattern and field list.
2. The element-threshold tests cannot tell the element's threshold from the parent's.
stickler/tests/test_readme_examples.py
Lines 132 to 134 in facaa4b
stickler/tests/test_readme_examples.py
Lines 495 to 497 in facaa4b
stickler/tests/test_readme_examples.py
Lines 532 to 534 in facaa4b
Both tests set Item.match_threshold = 0.7, which is also the parent model's default. Changing line 133 to return model.match_threshold gives 40 passed. With Item.match_threshold = 0.8, the same change fails (assert 0.7 == 0.8). Fix: give the element class and the parent model different thresholds (for example 0.8 and 0.6).
Verified and cleared
- The module passes 40/40 on Python 3.12 and 3.10, and with
-n 4. The full suite on a local merge with currentdevpasses (3498 passed, 12 skipped, 1 xfailed, integrations excluded). - Each mutation the PR claims it catches does fail: removing the element-class branch, an import-time README read, README weight Default
2.0, comparator-table date threshold0.5, model-list threshold0.8, an untested comparator-table row, an extra Position row. - Ruff check and format pass. No conflict with
dev.
Non-blocking (low)
- An annotation on any line of a multi-line
printother than the last is ignored without failing (L63). - An import-time read written with
open()passes the import-time check (L511). - The
x-aws-stickler-infer-unspecifiedandx-aws-stickler-comparator-configrows are still unchecked, so "complete documentation-table coverage" in the CHANGELOG line overstates it. - Some doc edits fail with a bare
AttributeError/KeyError/ValueErrorrather than the "Docs table changed" message (L244-250, L289, L415).
The threshold Default check read one number for the free-form object clause and applied it to the enum, const and format fields too, so the README could give that clause a different value without a failure. The clause now has its own pattern, which requires it to follow the free-form number with no new value in between. The element-threshold tests used match_threshold 0.7 for the element class, which is also the parent model's default, so returning the parent's threshold passed. They now use 0.8 for the element and 0.6 for the parent. The CHANGELOG line no longer claims complete documentation-table coverage; two extension rows are still unchecked.
|
@vawsgit Both fixed in
The module gives 40 passed, and Ruff check and format pass. I also changed the CHANGELOG line so it no longer claims complete documentation-table coverage, since the two extension rows you noted are still unchecked. Could you re-review? |
…ults # Conflicts: # CHANGELOG.md
|
Merged current |
sromoam
left a comment
There was a problem hiding this comment.
Thank you, @mangeshraut712! Pinning the README's own defaults and example numbers is a great idea, and the tests pass on this branch. A few of the new checks would fail when nothing is wrong, and one checks the wrong threshold, so this needs some changes before it can merge.
Needs changes
- List-of-models fields use the wrong threshold (
_matching_threshold, aroundtests/test_readme_examples.py:129). For a list of models, the check compares the list'sfield_scoresvalue against the element class'smatch_threshold(0.7). That threshold only gates individual Hungarian pairs. The list score itself is judged against the field's ownthreshold(0.5), which is also whatexplain()reports for it. As written, a READMELine Itemsrow measuring 0.701 against an annotated 0.69 fails although no verdict changes. A 0.49 vs 0.51 change that does cross 0.5 isn't caught. - Unwrap
Annotatedin the same helper.get_origin(...) is listreturnsAnnotatedforAnnotated[List[LineItem], ...], so the helper silently falls back. The library already has helpers for this (unwrap_annotated,_annotation_is_list), and reusing them would avoid a second copy of that logic. - Labels with leading spaces never match (around
:79). The label is stripped, but output lines are matched unstripped. Reproduced:print(f" Customer: {s:.3f}") # 0.562fails withREADME output missing labels: {'Customer:'}. - Prose comments are treated as numbers (around
:64).re.match(r"[+\-.\d]", ...)matches any comment starting with-,+or., soprint(...) # ...or# -> see belownow fails withREADME numeric annotation is invalid. The old regex skipped these. - Unannotated prints sharing a label fail (around
:92). Every output line starting with an annotated label has to parse as a number, so a laterprint(f"Score: {detail}")printingn/afails the test. Please match only the annotated print's own output line. - Keep the four fields the threshold-pattern check dropped (around
:343):int_enum,num_const,typeless_enumanddated_levenshtein. The prose it checks says "any property ... withenum,const", so they still apply. The third pattern is also an exact prefix of the fourth, so one of them can go.
Smaller things
- The
Item/Documentmodel pair is defined twice with small differences (around:535). One module-level helper would keep them in sync. - In
test_readme_comparator_table_matches_schema(around:425), dispatching onpositionalone would be simpler and safer than mixing field-name and position checks. test_module_import_defers_document_reads_and_schema_buildingreruns the module and relies on pytest's fixture__wrapped__, which is an internal detail and may break on a pytest upgrade. A simpler check, or none, would be more robust.- This change touches only tests, so its CHANGELOG entry shouldn't sit under the user-facing
### Changed. Either drop it or note it as internal. The newtests/README.mdtree line is also slightly misaligned.
Thanks again for taking this on!
|
Thank you @sromoam for the careful review! All items have been addressed in
Whenever you have a chance, please let me know if anything further is needed. |
vawsgit
left a comment
There was a problem hiding this comment.
needs changes
Thanks for the round, @mangeshraut712. Nearly everything from both earlier reviews is fixed. One change in d1c5fee undoes item 2 of #436, and this PR says Fixes #436, so merging it would close the issue with item 2 still open.
Blocking: the example verdict check uses a threshold the library does not apply to lists of models
d1c5fee changed _matching_threshold (tests/test_readme_examples.py#L156-L160) back to _get_comparison_info(field).threshold for every field. That is what dev already does. Commit 0dde58e used the element class's match_threshold, which is what #436 item 2 asks for.
The library decides a list-of-models field's TP/FD with the element's match_threshold, not with the field threshold. I measured this on this PR's head, with stickler imported from the PR worktree's src, using the PR's own _threshold_model() (Item.match_threshold = 0.8, field threshold 0.5) and one-item lists:
score=0.800 tp=1 fd=0 PR check says pass (>= 0.5): True
score=0.700 tp=0 fd=1 PR check says pass (>= 0.5): True
score=0.502 tp=0 fd=1 PR check says pass (>= 0.5): True
Two more facts point the same way:
ComparableField(threshold=0.9)on aList[Item]field raisesValueError: Field 'items' is a List[StructuredModel] and cannot have a 'threshold' parameter in ComparableField. Hungarian matching uses each StructuredModel's 'match_threshold' class attribute instead.- On a model whose list field reports a threshold of 0.9, a list score of 0.800 is still
tp=1. The reported field threshold is not consulted.
So a README Line Items annotation that reads 0.802 (a TP) while the code measures 0.798 (an FD) passes this check. The review comment that prompted the change (item 1 of the 2026-11-11 review, "the list score itself is judged against the field's own threshold (0.5)") does not match this measured behaviour.
What to change:
- In
_matching_threshold, return_element_matching_threshold(model, field)when the field is a list of models. Keep theunwrap_annotated/_annotation_is_listhandling you added. - Invert
test_example_verdict_check_uses_the_field_thresholdandtest_an_element_threshold_crossing_does_not_change_the_fields_verdict. A crossing of the element threshold (0.798 vs 0.802 withmatch_threshold = 0.8) must fail the check, and a crossing of 0.5 only must pass it. - If you would rather not do 1 and 2 here, change
Fixes #436toRefs #436and say that item 2 is left.
Earlier findings: all fixed except two LOW items
- The
enum/const/formatthreshold clause is now checked. A mutated0.5in that README clause failstest_readme_extension_defaults_match_schema. - The element and parent thresholds are now distinct (0.8 and 0.6), and the
Annotatedunwrap is pinned. Removingunwrap_annotated(item)fails the[True]case. - Multi-line
printannotations, leading-space labels, prose comments, unannotated prints that share a label, and the four restored threshold-pattern fields all behave correctly, and each has a test. runpy.run_pathreplaces the__wrapped__dependency. An import-timePath.read_textorfrom_json_schemacall fails that test.- The CHANGELOG entry is gone, and the
tests/README.mdtree line is aligned.
What was verified
- The diff against current
devtouches onlytests/test_readme_examples.pyandtests/README.md. The PR adds no production or dependency changes. - The branch merges cleanly into current
dev. After the merge, the 55 focused tests pass, and the non-integration suite gives 3584 passed, 2 skipped, 1 xfailed. - At the head, the suite gives 3553 passed, 2 skipped, 1 xfailed, as the PR body says. The focused module passes on Python 3.10, 3.12 and 3.14. Ruff passes.
- I ran 22 mutations against the README text, the docs tables, the production default and the test helpers. The tests caught 20 of them. The two misses are the LOW items below.
Non-blocking (LOW)
- An annotation that starts with a word or symbol (
# about 0.9,# ≈0.9) is silently dropped.assert rowscatches only a block that loses every claim. - The
formatlist in the threshold Default prose is not checked. Deletinguuidfrom it still passes. - An import-time read written with
open()still passes the import-deferral test. - A Position cell without backticks fails with
AttributeErrorat line 324, and a renamed extension row fails withKeyErrorat lines 279-283, instead of a "docs changed" message. - The PR body says the tests "explicitly import this checkout's src/stickler". There is no conftest or
sys.pathchange, so the import depends on the environment.
| @pytest.mark.parametrize( | ||
| "measured, claimed", [(0.498, 0.502), (0.502, 0.498), (0.5, 0.499)] | ||
| ) | ||
| def test_example_verdict_check_uses_the_field_threshold(monkeypatch, measured, claimed): |
There was a problem hiding this comment.
Blocking. This test pins the field threshold (0.5) as the verdict line for items. The library does not use 0.5 there: 0.502 is fd=1 when Item.match_threshold = 0.8. After the _matching_threshold fix, this case should pass the check instead of raising.
| test_readme_example_does_not_annotate_a_miss_as_a_pass("", "unused") | ||
|
|
||
|
|
||
| def test_an_element_threshold_crossing_does_not_change_the_fields_verdict(monkeypatch): |
There was a problem hiding this comment.
Blocking. 0.798 vs 0.802 crosses Item.match_threshold = 0.8, so the library reports FD for one and TP for the other. That is the miss-annotated-as-a-pass case #436 item 2 targets. This test should expect an AssertionError.
The library decides a list-of-models field's TP/FD with the element class's match_threshold, so the README verdict check now uses it for those fields. A crossing of the element threshold fails the check; a crossing of the field threshold alone passes.
|
@vawsgit Fixed in
|
vawsgit
left a comment
There was a problem hiding this comment.
✅ LGTM!
Thanks, @mangeshraut712. d3761c8 fixes the blocking item from my last review, so Fixes #436 is now accurate. I measured at head d3761c8 with stickler imported from that checkout's src, on Python 3.12.
The blocking item is fixed. For a list-of-models field, _matching_threshold now returns the element class's match_threshold. Non-list fields still use their field threshold. The new _model_list_element helper keeps the _unwrap_optional / unwrap_annotated / _annotation_is_list handling.
Before and after, using _threshold_model() (Item.match_threshold = 0.8, field threshold 0.5) and one-item lists:
| List score | Library result | Check at d1c5fee (0.5) | Check at d3761c8 (0.8) |
|---|---|---|---|
| 0.800 | tp=1 fd=0 | pass | pass |
| 0.799 | tp=0 fd=1 | pass (wrong) | fail |
| 0.700 | tp=0 fd=1 | pass (wrong) | fail |
| 0.502 | tp=0 fd=1 | pass (wrong) | fail |
The check gives the same result for the plain annotation and for the Annotated / Optional one. For non-list fields with threshold=0.9, the check still matches the library at 0.9, 0.899 and 0.6.
The two tests are inverted, and they catch the regression.
test_example_verdict_check_uses_the_element_match_thresholdrequires a crossing of 0.8 to fail the check.test_a_field_threshold_crossing_does_not_change_a_model_lists_verdictrequires a crossing of only 0.5 to pass it.
Restoring the field-threshold branch fails 8 tests, as you said. Other mutations of the changed code:
| Mutation | Tests that fail (of 57) |
|---|---|
The list branch returns the parent's match_threshold |
5 |
Drop either unwrap_annotated call |
1 |
Drop the outer _unwrap_optional |
9 |
Change >= to > in the verdict check |
1 |
| Turn off the verdict check | 3 |
What was verified
- The diff against current
devchanges onlytests/test_readme_examples.pyandtests/README.md. It has no production or dependency changes. - At the head, the focused module gives 57 passed. The suite without
tests/integrationsgives 3555 passed, 2 skipped, 1 xfailed. The full suite gives 4196 passed, 3 skipped, 1 xfailed. Ruff passes. - The branch merges into current
dev(b59c7ce) with no conflicts. After the merge, the focused module gives 57 passed and the full suite gives 4252 passed, 3 skipped, 1 xfailed. - The README rows use the correct threshold. The Quick Start and schema-example
Line Itemsrows use the element'smatch_threshold(0.7). The scalar rows use their field thresholds.
Non-blocking (LOW)
_model_list_elementraisesIndexError: tuple index out of rangeat line 162 for a field annotated with a barelist. Before this commit, such a field returned its field threshold. No README model has such a field, and the error is a crash, not a silent pass.- The PR body is out of date. It still says "Field verdicts use field thresholds" and quotes "55 focused / 3,553 passed".
- Your "non-integration suite 4179 passed, 13 skipped" matches neither of my runs. It looks like the full suite run with fewer optional extras installed. Nothing fails either way.
- The LOW items from my last review still apply, as you said.
|
Merged current |
Fixes #436.
The README regression tests now execute annotated print calls and associate each numeric claim with its source call, including loops, repeated labels and multiline annotations. Unannotated output and prose comments do not become claims. Field verdicts use field thresholds; model-list pairing separately uses the unwrapped element threshold, including Optional/Annotated types.
The default-pattern checks cover scalar, enum, const and mapping fields. Fixtures defer document/schema loading until test execution, helper regressions share model setup, and the README tree is aligned. No production or dependency changes relative to dev.
Validation against dev
7034ec07ddf6084a0541e1c48c3fe8418c737922, Python 3.12.16:AI-assisted implementation and independent review. GitHub workflows remain subject to maintainer authorization; this does not claim hosted CI completion.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.