Skip to content

Correct confidence range validation - #514

Open
kingthorin wants to merge 1 commit into
enthec:mainfrom
kingthorin:conf-range-fix
Open

kingthorin wants to merge 1 commit into
enthec:mainfrom
kingthorin:conf-range-fix

Conversation

@kingthorin

@kingthorin kingthorin commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

This issue was pointed out by Grok while checking that issue #9 was completed.

The confidence range check is currently incorrect due to Python operator chaining.

prove_confidence_bug.py
#!/usr/bin/env python3
"""Prove the confidence range check bug in technology_validator.py"""

def buggy_check(tag_value: str) -> bool:
    """Replicates the exact logic from _validate_tags"""
    if not tag_value.isnumeric():
        return False  # rejected as non-numeric
    # The buggy line:
    if 0 >= int(tag_value) >= 100:
        return False  # this never triggers
    return True  # accepted


# Test cases that should be rejected but aren't
test_values = ["-5", "0", "50", "100", "101", "999", "abc"]

print("tag_value | isnumeric | buggy_check result | expected")
print("-" * 55)
for v in test_values:
    is_num = v.isnumeric()
    result = buggy_check(v)
    # Expected: True only for 0 <= x <= 100
    try:
        expected = 0 <= int(v) <= 100 if is_num else False
    except ValueError:
        expected = False
    status = "BUG" if result != expected else "ok"
    print(f"{v:9} | {str(is_num):9} | {str(result):17} | {expected}  ({status})")

print()
print("Demonstration of the chained comparison:")
for x in [-5, 0, 50, 100, 101]:
    print(f"  0 >= {x} >= 100  →  {0 >= x >= 100}")
tag_value isnumeric buggy_check result expected
-5 False False False (ok)
0 True True True (ok)
50 True True True (ok)
100 True True True (ok)
101 True True False (BUG)
999 True True False (BUG)
abc False False False (ok)

Demonstration of the chained comparison:
0 >= -5 >= 100 → False
0 >= 0 >= 100 → False
0 >= 50 >= 100 → False
0 >= 100 >= 100 → False
0 >= 101 >= 100 → False

@kingthorin

kingthorin commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Luckily the existing data/values all seem to be in the appropriate/expected range.

Count Value
108 50
46 25
16 0
10 75
5 99
5 80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant