chore: auto-commit from dashboard
This commit is contained in:
@@ -203,20 +203,47 @@ class TestRegularMessage:
|
||||
assert is_cmd is False
|
||||
mock_send.assert_called_once_with("ch-1", "hello", model="opus", on_text=None, voice_mode=False, adapter_name=None)
|
||||
|
||||
@patch("src.router._local_fallback_reply")
|
||||
@patch("src.router._get_channel_config")
|
||||
@patch("src.router._get_config")
|
||||
@patch("src.router.send_message")
|
||||
def test_claude_error(self, mock_send, mock_get_config, mock_chan_cfg):
|
||||
def test_claude_error(self, mock_send, mock_get_config, mock_chan_cfg, mock_fallback):
|
||||
# Non-rate-limit failure (timeout, crash) now also attempts local
|
||||
# fallback; raw error only surfaces if that's unavailable too.
|
||||
mock_send.side_effect = RuntimeError("API timeout")
|
||||
mock_chan_cfg.return_value = None
|
||||
mock_cfg = MagicMock()
|
||||
mock_cfg.get.return_value = "sonnet"
|
||||
mock_get_config.return_value = mock_cfg
|
||||
mock_fallback.return_value = None
|
||||
|
||||
response, is_cmd = route_message("ch-1", "user-1", "hello")
|
||||
assert "Error: API timeout" in response
|
||||
assert is_cmd is False
|
||||
|
||||
@patch("src.router._local_fallback_reply")
|
||||
@patch("src.router._get_channel_config")
|
||||
@patch("src.router._get_config")
|
||||
@patch("src.router.send_message")
|
||||
def test_non_rate_limit_error_also_falls_back_to_local_llm(
|
||||
self, mock_send, mock_get_config, mock_chan_cfg, mock_fallback,
|
||||
):
|
||||
"""T-rootcause: timeouts/crashes must get the same local-fallback
|
||||
rescue as confirmed rate limits — the prior code only tried fallback
|
||||
when `_is_rate_limit_error` matched, so a dead Claude CLI process or
|
||||
a 300s timeout surfaced the raw exception to the user instead."""
|
||||
mock_send.side_effect = RuntimeError("Claude CLI error: no result line in stream. stderr:")
|
||||
mock_chan_cfg.return_value = None
|
||||
mock_cfg = MagicMock()
|
||||
mock_cfg.get.return_value = "sonnet"
|
||||
mock_get_config.return_value = mock_cfg
|
||||
mock_fallback.return_value = "⚠️ fallback reply"
|
||||
|
||||
response, is_cmd = route_message("ch-1", "user-1", "hello")
|
||||
assert response == "⚠️ fallback reply"
|
||||
assert is_cmd is False
|
||||
mock_fallback.assert_called_once_with("hello", channel_id="ch-1")
|
||||
|
||||
@patch("src.router._local_fallback_reply")
|
||||
@patch("src.router._get_channel_config")
|
||||
@patch("src.router._get_config")
|
||||
|
||||
@@ -425,6 +425,9 @@ def test_pending_steers_logged_without_on_text(monkeypatch, caplog):
|
||||
router, "send_message",
|
||||
lambda *a, **kw: (_ for _ in ()).throw(RuntimeError("boom")),
|
||||
)
|
||||
# Local fallback unreachable here — isolates the "no on_text" logging
|
||||
# behavior under test from the (now equally attempted) fallback path.
|
||||
monkeypatch.setattr(router, "_local_fallback_reply", lambda *a, **kw: None)
|
||||
|
||||
with caplog.at_level("WARNING"):
|
||||
result, is_cmd = router.route_message("ch-c3b", "user-1", "hello")
|
||||
|
||||
Reference in New Issue
Block a user