1
0
Fork 0

refactor(calibration): consolidate tunable thresholds into calibration.py

Session D: move every calibration constant (entropy floors 5.4/128, 5.1/64,
4.7/40 + shape floors; MAX_SCAN_CHARS; rot13-min; cognitive-load lengths
2000/2500; disposition ranks; active-content severities) into one documented
calibration.py, so a parallel Node/TS port can mirror exactly the same numbers.

Pure refactor, zero behavior change: calibration is a leaf module (imports only
report.Severity) that entropy/lexicon/disposition/active_content now source
their thresholds from. MAX_SCAN_CHARS is re-exported from lexicon so output.py
and existing callers are unaffected. The 347 pre-existing tests pass unmodified;
new test_calibration.py freezes the values and asserts each detector actually
reads its threshold from calibration (identity-checked, not a dead copy).
This commit is contained in:
Kjell Tore Guttormsen 2026-07-15 09:44:53 +02:00
commit ee402e4ea8
6 changed files with 212 additions and 34 deletions

View file

@ -25,6 +25,7 @@ from dataclasses import dataclass
from enum import Enum
from typing import Callable, Optional
from .calibration import DISPOSITION_RANK
from .report import Report, Severity, severity_rank
@ -82,11 +83,10 @@ _CARRIER_LABELS = frozenset({
"lexicon:unicode-tags-present",
})
_DISPOSITION_RANK = {
Disposition.WARN: 0,
Disposition.QUARANTINE_REVIEW: 1,
Disposition.FAIL_SECURE: 2,
}
# Enum-keyed rank rebuilt from calibration's value-keyed source of truth
# (calibration is a leaf module and cannot import the Disposition enum without a
# cycle). Higher = more severe.
_DISPOSITION_RANK = {d: DISPOSITION_RANK[d.value] for d in Disposition}
def _more_severe(a: Disposition, b: Disposition) -> Disposition: