"""Tests for the generic DownstreamPolicy type and its invariants.""" import pytest from core.hardening.policy import DownstreamPolicy def test_policy_rejects_reset_shorter_than_read(): """A reset_timeout below read_timeout is rejected at construction.""" with pytest.raises(ValueError, match='reset_timeout'): DownstreamPolicy( connect_timeout=3, read_timeout=30, fail_max=5, reset_timeout=10 ) def test_policy_rejects_retries_on_long_read(): """Retries are disallowed on long-read resources.""" with pytest.raises(ValueError, match='retries'): DownstreamPolicy( connect_timeout=3, read_timeout=30, fail_max=5, reset_timeout=30, retries=1 ) def test_policy_allows_retries_on_short_read(): """Retries are allowed when read_timeout is below the long-read threshold.""" p = DownstreamPolicy( connect_timeout=3, read_timeout=10, fail_max=3, reset_timeout=60, retries=2 ) assert p.retries == 2