test(docs): pin docs/redos-sweep.py under test.py's contract
It was the only docs/ measurement script without a row here, and this repo just made it load-bearing for two published LIMITATIONS.md numbers (the 1.5 ms floor, the 2.6 flag ratio). Pins structure only, per the sweep's own docstring: the suite clock (not a reimplemented wall clock), the constants against the doc's prose, and the 152-pattern/11-table collector count. Never pins a timing outcome -- that would be red several runs in twenty.
This commit is contained in:
parent
74656123f9
commit
01f6f382c4
1 changed files with 36 additions and 0 deletions
|
|
@ -28,10 +28,12 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
import redos_clock
|
||||
from llm_ingestion_guard import Disposition, PRESET_USER_UPLOAD, Risk, screen_output
|
||||
from llm_ingestion_guard import active_content as ac
|
||||
|
||||
_DOCS = Path(__file__).resolve().parent.parent / "docs"
|
||||
_LIMITATIONS = _DOCS / "LIMITATIONS.md"
|
||||
|
||||
|
||||
def _load(filename: str):
|
||||
|
|
@ -41,6 +43,7 @@ def _load(filename: str):
|
|||
spec = importlib.util.spec_from_file_location(name, path)
|
||||
assert spec and spec.loader, f"cannot load {path}"
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[name] = module # @dataclass resolves its own module via sys.modules
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
|
@ -49,6 +52,7 @@ def _load(filename: str):
|
|||
# script's import list fails the whole file loudly instead of one quiet test.
|
||||
fp_sweep = _load("fp-sweep.py")
|
||||
census = _load("rawhtml-census.py")
|
||||
redos_sweep = _load("redos-sweep.py")
|
||||
|
||||
|
||||
# --- docs/fp-sweep.py --------------------------------------------------------
|
||||
|
|
@ -245,6 +249,38 @@ def test_census_production_row_equals_its_shipped_candidate(name, attrs):
|
|||
assert candidate(name, attrs) == ac.active_tag_class(name, attrs)
|
||||
|
||||
|
||||
# --- docs/redos-sweep.py ------------------------------------------------------
|
||||
|
||||
|
||||
def test_redos_sweep_times_on_the_suite_clock_not_a_reimplementation():
|
||||
# Until 1.1.0 this script timed on `time.monotonic()`, a different instrument
|
||||
# than every ReDoS bound in the suite. `t()` must call the shared
|
||||
# `scan_seconds` — imported, not restated — and the module must not import
|
||||
# `time` itself, else a drift back to a wall clock would go unnoticed here.
|
||||
assert redos_sweep.scan_seconds is redos_clock.scan_seconds
|
||||
assert not hasattr(redos_sweep, "time"), "module must not import time itself"
|
||||
|
||||
|
||||
def test_redos_sweep_floor_and_flag_match_the_published_numbers():
|
||||
# docs/LIMITATIONS.md publishes the 1.5 ms floor and the 2.6 flag ratio this
|
||||
# script derives from twelve full runs. Pin both sides: the constants, and
|
||||
# that the doc still states the same numbers — either drifting alone is a bug.
|
||||
assert redos_sweep.NOISE_FLOOR == 0.0015
|
||||
assert redos_sweep.RATIO_FLAG == 2.6
|
||||
text = _LIMITATIONS.read_text(encoding="utf-8")
|
||||
assert "1.5 ms noise floor" in text
|
||||
assert "2.6 flag threshold" in text
|
||||
|
||||
|
||||
def test_redos_sweep_collector_covers_152_patterns_across_11_tables():
|
||||
# The count docs/LIMITATIONS.md carries as "all 152 compiled patterns across
|
||||
# all eleven regex-bearing modules". A pattern added or removed in `src/`
|
||||
# without re-measuring would drift the doc's claim silently otherwise.
|
||||
assert len(redos_sweep.TABLES) == 11
|
||||
total = sum(len(collect()) for collect in redos_sweep.TABLES.values())
|
||||
assert total == 152
|
||||
|
||||
|
||||
# --- both scripts: the argument-less contract --------------------------------
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue