refactor(anaf): remove dead code in sanitize_cui, fix empty test

Remove unreachable OCR-skip fallback (raw_bare can't be all-digits
if strip_ro_prefix changed it via OCR fix). Add real test for the
checksum result==10→0 branch using CUI 14186770.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-04-02 14:46:10 +00:00
parent 1d871c8215
commit 0992744490
2 changed files with 8 additions and 15 deletions

View File

@@ -43,7 +43,6 @@ def validate_cui_checksum(bare_cui: str) -> bool:
digits = [int(d) for d in bare_cui] digits = [int(d) for d in bare_cui]
check_digit = digits[-1] check_digit = digits[-1]
body = digits[:-1] body = digits[:-1]
# Pad left with zeros to 9 positions
padded = [0] * (9 - len(body)) + body padded = [0] * (9 - len(body)) + body
total = sum(d * k for d, k in zip(padded, _CUI_KEY)) total = sum(d * k for d, k in zip(padded, _CUI_KEY))
result = (total * 10) % 11 result = (total * 10) % 11
@@ -66,11 +65,6 @@ def sanitize_cui(raw_cf: str) -> tuple[str, str | None]:
if validate_cui(bare) and validate_cui_checksum(bare): if validate_cui(bare) and validate_cui_checksum(bare):
return bare, None return bare, None
# Try without OCR fix (raw, just stripped)
raw_bare = re.sub(r'^RO\s*', '', raw_cf.strip().upper())
if raw_bare != bare and validate_cui(raw_bare) and validate_cui_checksum(raw_bare):
return raw_bare, None
# Sanitized version passes format but not checksum # Sanitized version passes format but not checksum
if validate_cui(bare): if validate_cui(bare):
return bare, f"CUI {bare} nu trece verificarea cifrei de control" return bare, f"CUI {bare} nu trece verificarea cifrei de control"

View File

@@ -148,15 +148,14 @@ class TestValidateCuiChecksum:
assert validate_cui_checksum("1") is False assert validate_cui_checksum("1") is False
def test_checksum_result_10_becomes_0(self): def test_checksum_result_10_becomes_0(self):
"""When (sum*10)%11 == 10, check digit should be 0.""" """When (sum*10)%11 == 10, check digit should be 0.
# Build a CUI where the algorithm yields 10
# Body 12345678 → pad to 9: 012345678 CUI 14186770: body=1418677, padded=001418677,
# 0*7+1*5+2*3+3*2+4*1+5*7+6*5+7*3+8*2 = 0+5+6+6+4+35+30+21+16 = 123 sum=0+0+3+8+1+42+35+21+14=124, 1240%11=10 → check=0.
# 123*10=1230, 1230%11 = 111*11=1221, remainder=9 → check=9 → not 10 """
# Let's just verify a known CUI ending in 0 works assert validate_cui_checksum("14186770") is True
# CUI 46628322 from data: check=2, not 0. Skip this specific edge case test # Wrong check digit for same body
# and just verify the code path exists assert validate_cui_checksum("14186771") is False
pass
# =========================================================================== # ===========================================================================