from __future__ import annotations import pytest from yuxi.channel.domain.exception.agent_crash_error import AgentCrashError from yuxi.channel.domain.exception.recoverable_error import RecoverableError from yuxi.channel.domain.exception.unrecoverable_error import UnrecoverableError from yuxi.channel.domain.exception.channel_error import ChannelError from yuxi.channel.domain.exception.abort_mapping import AbortMapping class TestAgentCrashError: def test_creation(self): error = AgentCrashError("agent crashed") assert str(error) == "agent crashed" assert error.message == "agent crashed" def test_creation_with_details(self): error = AgentCrashError("agent crashed", details={"agent_id": "1"}) assert error.details == {"agent_id": "1"} class TestRecoverableError: def test_creation(self): error = RecoverableError("temporary failure") assert str(error) == "temporary failure" assert error.message == "temporary failure" def test_creation_with_retry_after(self): error = RecoverableError("temporary failure", retry_after=5) assert error.retry_after == 5 class TestUnrecoverableError: def test_creation(self): error = UnrecoverableError("permanent failure") assert str(error) == "permanent failure" assert error.message == "permanent failure" class TestChannelError: def test_creation(self): error = ChannelError("channel error") assert str(error) == "channel error" assert error.message == "channel error" def test_creation_with_code(self): error = ChannelError("channel error", code="CHANNEL_ERROR") assert error.code == "CHANNEL_ERROR" class TestAbortMapping: def test_creation(self): mapping = AbortMapping( code="AUTH_FAILED", reason="Authentication failed", status_code=401, ) assert mapping.code == "AUTH_FAILED" assert mapping.reason == "Authentication failed" assert mapping.status_code == 401 def test_default_status_code(self): mapping = AbortMapping( code="TEST", reason="Test", ) assert mapping.status_code == 400