"""{{ display_name }} MCP server — generated by mcpify. Do not hand-edit."""

from __future__ import annotations

import pytest

from {{ module_name }}.core.circuit_breaker import CircuitBreaker
from {{ module_name }}.core.errors import CircuitBreakerOpenError


async def _fail() -> None:
    raise ValueError("boom")


async def _succeed() -> str:
    return "ok"


async def test_opens_after_the_failure_threshold_is_reached() -> None:
    breaker = CircuitBreaker(failure_threshold=2, reset_timeout_s=30.0)

    for _ in range(2):
        with pytest.raises(ValueError):
            await breaker.execute(_fail)

    with pytest.raises(CircuitBreakerOpenError):
        await breaker.execute(_succeed)


async def test_a_success_resets_the_failure_count() -> None:
    breaker = CircuitBreaker(failure_threshold=2, reset_timeout_s=30.0)

    with pytest.raises(ValueError):
        await breaker.execute(_fail)
    assert await breaker.execute(_succeed) == "ok"

    # A single further failure shouldn't open a breaker with threshold 2,
    # since the prior success reset the counter.
    with pytest.raises(ValueError):
        await breaker.execute(_fail)
    assert await breaker.execute(_succeed) == "ok"
