"""ASV benchmarks for TDD Issue #592 — actor list validation error.

Measures the performance of ``ActorRegistry.list_actors()`` when a provider
has a default model containing ``/`` characters.  Establishes a baseline
before and after the bug fix.

Root cause: ``_actor_name()`` builds names via ``f"{provider}/{model}"``.
Multi-slash model names produce actor names with 2+ slashes, which
``ActorService._normalize_name()`` rejects with a ``ValidationError``.
"""

from __future__ import annotations

import contextlib
import sys
from pathlib import Path

from pydantic import ValidationError

# Ensure the local *source* tree is importable even when ASV has an
# older build of the package installed.
_SRC = str(Path(__file__).resolve().parents[1] / "src")
if _SRC not in sys.path:
    sys.path.insert(0, _SRC)

# Ensure the features directory is importable so we can reuse shared
# mock stubs instead of duplicating them locally.
_FEATURES = str(Path(__file__).resolve().parents[1] / "features")
if _FEATURES not in sys.path:
    sys.path.insert(0, _FEATURES)

from mocks.fake_provider import FakeProviderInfo, make_registry  # noqa: E402


class TDDActorListValidationSuite:
    """Benchmark actor list with multi-slash provider models (TDD issue #592)."""

    timeout = 60

    def setup(self) -> None:
        _, self._empty_registry = make_registry()
        _, self._slash_registry = make_registry(
            providers=[
                FakeProviderInfo(
                    name="Openrouter",
                    default_model="anthropic/claude-sonnet-4-20250514",
                ),
            ]
        )

    def time_list_empty(self) -> None:
        """List actors with zero configured providers."""
        self._empty_registry.list_actors()

    def time_list_multi_slash_provider(self) -> None:
        """List actors when a multi-slash provider is configured."""
        with contextlib.suppress(ValidationError):
            self._slash_registry.list_actors()

    def track_multi_slash_succeeds(self) -> int:
        """Track whether listing with a multi-slash provider succeeds.

        Returns 1 when ``list_actors()`` completes without error; 0 if
        ``ValidationError`` is raised.
        """
        try:
            self._slash_registry.list_actors()
            return 1
        except ValidationError:
            return 0


_track = TDDActorListValidationSuite.track_multi_slash_succeeds
_track.unit = "success"  # type: ignore[attr-defined]
