diff --git a/scripts/tests/test_check_review_verdict.py b/scripts/tests/test_check_review_verdict.py index 5670c947e..435b7933e 100644 --- a/scripts/tests/test_check_review_verdict.py +++ b/scripts/tests/test_check_review_verdict.py @@ -419,3 +419,55 @@ def test_non_hex_head_is_an_input_error(): text=True, ) assert p.returncode == 2 + + +# --- the disjointness invariant, rescued from the withdrawn parity test (ersatztv#774) --------- + + +# The vocabulary as BOTH scripts spell it. A literal list, and per +# `testing.guard-derives-population-from-source` that is legitimate HERE and would not be for a +# completeness claim: the property below is PER-MEMBER — "each of these words classifies as exactly +# one thing" — so a word missing from this list is simply an untested word, not a defect the list +# conceals. It is emphatically NOT a claim that these are the only words the scripts accept. Proving +# THAT needs one shared vocabulary both scripts read, which is ersatztv#788. +POSITIVE_WORDS = ["MERGEABLE", "APPROVED", "LGTM"] +NEGATIVE_WORDS = ["BLOCKED", "NOT-MERGEABLE"] + + +@pytest.mark.parametrize( + ("word", "expected"), + [(w, "positive") for w in POSITIVE_WORDS] + [(w, "negative") for w in NEGATIVE_WORDS], +) +def test_each_verdict_word_classifies_as_EXACTLY_one_thing(word, expected): + """No word may be in both vocabularies — carried over from the parity test #774 withdrew. + + WHY IT SURVIVED ITS PARENT. That test asserted set equality between the write side's `case` arms + and the read side's `POS_RE`/`NEG_RE` by parsing shell with regexes, and six review rounds each + found another construction it mis-read; it was deleted rather than patched a seventh time. But + it carried a SECOND, separable invariant that had nothing to do with parsing, and deleting the + file silently took that with it — caught by cold review of the deletion, which is exactly the + "enumerate what a workaround provided before removing it" rule + (`process.enumerate-workaround-behaviors-before-deleting`). + + WHY THIS VERSION IS SOUND WHERE ITS PARENT WAS NOT. It EXECUTES the real classifier instead of + reading its source, so no shell construction can fool it. `check-review-verdict.sh` sets + `is_pos` and `is_neg` from two INDEPENDENT `grep -iqE` calls, so a word in both patterns sets + both flags and precedence decides. + + WHICH DIRECTION THIS CATCHES, MEASURED RATHER THAN REASONED — the first draft of this docstring + asserted it and was checked afterwards, which is the wrong order. `check-review-verdict.sh:212` + reads `if [ "$is_pos" = 1 ]; then head_pos=1; else head_neg=1; fi`, so `is_pos` wins per line + and an overlapping word resolves POSITIVE. Both mutations were run against this test: + + * `blocked` added to `POS_RE` -> `BLOCKED` classifies `positive` -> RED. That is the dangerous + direction — a verdict meant to block reporting as approval — and it is caught. + * `mergeable` added to `NEG_RE` -> still `positive`, stays green. NOT a gap: because `is_pos` + wins, that edit has no observable effect at all. `NEG_RE` is shadowed by `POS_RE` for any + overlapping word, so there is no behaviour there to catch. + """ + got, rc = classify([verdict(word, HEAD)]) + assert (got, rc) == (expected, 0), ( + f"'{word}' classified as {got!r} (rc={rc}), expected {expected!r}. If it now matches BOTH " + "POS_RE and NEG_RE, the classifier's two independent greps both fire and precedence picks " + "the verdict instead of the reviewer — a word meant to block could report positive." + )