From 8c8237954e3f5416c6c5f77a3b0c1354635b0533 Mon Sep 17 00:00:00 2001 From: Andrey Epifancev Date: Sun, 4 Oct 2026 02:45:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=80=D0=B5=D0=B7=200=20[3.1]=20T6.1,=20?= =?UTF-8?q?T6.2:=20is=5Fsupported=5Fmajor=20=D0=B1=D0=B5=D0=B7=20int()=20?= =?UTF-8?q?=E2=80=94=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=20=D1=81=D1=85?= =?UTF-8?q?=D0=B5=D0=BC=D1=8B=20^1\.\d+$,=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=B4=D0=BB=D0=B8=D0=BD=D0=BD=D1=83=D1=8E=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=BE=D0=BA=D1=83=20=D0=B8=20"01.0"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5.1 --- api/src/contract/common.py | 6 +++--- api/tests/unit/test_contract.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api/src/contract/common.py b/api/src/contract/common.py index 9534d2e..75dce31 100644 --- a/api/src/contract/common.py +++ b/api/src/contract/common.py @@ -36,7 +36,7 @@ RESULT_SCHEMA_VERSION_PATTERN = r"^\d+\.\d+$" # recognition-result-message.resu T = TypeVar("T") -_VERSION_RE = re.compile(r"(\d+)\.\d+", re.ASCII) +_SUPPORTED_VERSION_RE = re.compile(SCHEMA_VERSION_PATTERN, re.ASCII) # ровно шаблон схемы, без int() def is_supported_major(schema_version: object) -> bool: @@ -46,8 +46,8 @@ def is_supported_major(schema_version: object) -> bool: """ if not isinstance(schema_version, str): return False - match = _VERSION_RE.fullmatch(schema_version) - return match is not None and int(match.group(1)) == SUPPORTED_MAJOR + # `$` Python допускает перевод строки в конце, `fullmatch` — нет; шаблон — тот же, что у схемы и модели + return _SUPPORTED_VERSION_RE.fullmatch(schema_version) is not None class _NotNull: diff --git a/api/tests/unit/test_contract.py b/api/tests/unit/test_contract.py index cf90984..7799b78 100644 --- a/api/tests/unit/test_contract.py +++ b/api/tests/unit/test_contract.py @@ -669,6 +669,8 @@ def test_integer_valued_float_is_normalized_to_int() -> None: ("2.0", False), ("0.9", False), ("10.0", False), + ("01.0", False), # шаблон схемы `^1\\.\\d+$`: ведущий ноль в MAJOR недопустим + ("9" * 5000 + ".0", False), # длиннее лимита int() (4300 цифр): без исключения ("11.0", False), ("1", False), ("1.", False), @@ -691,7 +693,7 @@ def test_supported_major_is_one() -> None: assert SUPPORTED_MAJOR == 1 -@pytest.mark.parametrize("version", ["1.0", "1.7", "2.0", "1", "1.0.1", "0.9"]) +@pytest.mark.parametrize("version", ["1.0", "1.7", "2.0", "1", "1.0.1", "0.9", "01.0", "9" * 5000 + ".0"]) def test_is_supported_major_agrees_with_schema_pattern(version: str) -> None: """Проверка MAJOR совпадает с `schema_version` запроса по схеме (pattern `^1\\.\\d+$`).""" payload = _example("request-image.json")