"""S2.5 MAF version-guard — a TEST-TIME tripwire + a two-sided install pin. The offline simulation depends on MAF's PRIVATE API (the ``_inner_get_response`` keyword-only signature + ``_build_response_stream`` construction — see ``conftest`` / ``simulation``'s scripted client). A major ``agent-framework-core`` bump could change those without notice. This is NOT a runtime guard (an un-wired ``src`` helper would be green-but-dead); it is a test-time tripwire against the installed distribution PLUS a two-sided pin in ``pyproject.toml`` (install-time). Critical: the guard reads the DISTRIBUTION version via ``importlib.metadata.version("agent-framework-core")`` (verified ``1.9.0``), NOT ``agent_framework.__version__`` (verified ``0.0.0`` placeholder — reading that would make the guard permanently RED / meaningless). Modelled on ``test_smoke``'s version-assert + ``test_portfolio``'s grep-pin. """ from __future__ import annotations import importlib.metadata from pathlib import Path import pytest _DIST = "agent-framework-core" def assert_supported_maf_version(version_str: str) -> None: """Raise ``ValueError`` when ``version_str`` is outside the supported ``>=1.9.0,<2`` range, naming the private-API premises to re-verify before a bump. Pure string parse — no import side effects, so a fake version can be passed directly (the RED-proof) without touching the real install.""" parts = version_str.split(".") major = int(parts[0]) minor = int(parts[1]) if len(parts) > 1 else 0 if not (major == 1 and minor >= 9): raise ValueError( f"{_DIST} {version_str} is outside the supported range >=1.9.0,<2. Before bumping, " "re-verify the private-API premises the offline sim relies on: the _inner_get_response " "keyword-only signature (messages/options/stream) and the _build_response_stream " "construction. Update the pin in pyproject.toml once confirmed." ) def test_installed_maf_version_is_supported() -> None: """T-2.5d: the real installed distribution (verified 1.9.0) passes the guard — read from ``importlib.metadata.version``, NOT ``agent_framework.__version__`` (a 0.0.0 placeholder).""" assert_supported_maf_version(importlib.metadata.version(_DIST)) def test_guard_rejects_future_major() -> None: """T-2.5d: a future major (``2.0.0``) trips the guard with the actionable upgrade message — RED-proof without touching the real install.""" with pytest.raises(ValueError, match="private-API premises"): assert_supported_maf_version("2.0.0") def test_guard_rejects_too_old_minor() -> None: """T-2.5d: a pre-1.9 minor (``1.8.0``) also trips the guard (the pin is two-sided).""" with pytest.raises(ValueError, match="private-API premises"): assert_supported_maf_version("1.8.0") def test_pyproject_pins_agent_framework_core_below_2() -> None: """T-2.5d: ``pyproject.toml`` pins ``agent-framework-core>=1.9.0,<2`` — the install-time half of the guard (the test above is the test-time half).""" pyproject = (Path(__file__).resolve().parents[1] / "pyproject.toml").read_text(encoding="utf-8") assert "agent-framework-core>=1.9.0,<2" in pyproject