stage-6: model selection and advanced commands
/model (show/change), /restart (owner), /logs, set_session_model API, model reset on /clear. 20 new tests (161 total). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,21 +20,94 @@ def reset_router_config():
|
||||
|
||||
|
||||
class TestClearCommand:
|
||||
@patch("src.router._get_config")
|
||||
@patch("src.router.clear_session")
|
||||
def test_clear_active_session(self, mock_clear):
|
||||
def test_clear_active_session(self, mock_clear, mock_get_config):
|
||||
mock_clear.return_value = True
|
||||
mock_cfg = MagicMock()
|
||||
mock_cfg.get.return_value = "sonnet"
|
||||
mock_get_config.return_value = mock_cfg
|
||||
response, is_cmd = route_message("ch-1", "user-1", "/clear")
|
||||
assert response == "Session cleared."
|
||||
assert response == "Session cleared. Model reset to sonnet."
|
||||
assert is_cmd is True
|
||||
mock_clear.assert_called_once_with("ch-1")
|
||||
|
||||
@patch("src.router._get_config")
|
||||
@patch("src.router.clear_session")
|
||||
def test_clear_no_session(self, mock_clear):
|
||||
def test_clear_no_session(self, mock_clear, mock_get_config):
|
||||
mock_clear.return_value = False
|
||||
mock_cfg = MagicMock()
|
||||
mock_cfg.get.return_value = "sonnet"
|
||||
mock_get_config.return_value = mock_cfg
|
||||
response, is_cmd = route_message("ch-1", "user-1", "/clear")
|
||||
assert response == "No active session."
|
||||
assert is_cmd is True
|
||||
|
||||
@patch("src.router._get_config")
|
||||
@patch("src.router.clear_session")
|
||||
def test_clear_mentions_model_reset(self, mock_clear, mock_get_config):
|
||||
mock_clear.return_value = True
|
||||
mock_cfg = MagicMock()
|
||||
mock_cfg.get.return_value = "opus"
|
||||
mock_get_config.return_value = mock_cfg
|
||||
response, is_cmd = route_message("ch-1", "user-1", "/clear")
|
||||
assert "model reset" in response.lower()
|
||||
assert "opus" in response
|
||||
|
||||
|
||||
# --- /model command ---
|
||||
|
||||
|
||||
class TestModelCommand:
|
||||
@patch("src.router.get_active_session")
|
||||
def test_model_show_current_with_session(self, mock_get):
|
||||
mock_get.return_value = {"model": "opus"}
|
||||
response, is_cmd = route_message("ch-1", "user-1", "/model")
|
||||
assert is_cmd is True
|
||||
assert "opus" in response
|
||||
assert "haiku" in response # available models listed
|
||||
|
||||
@patch("src.router._get_config")
|
||||
@patch("src.router._get_channel_config")
|
||||
@patch("src.router.get_active_session")
|
||||
def test_model_show_current_no_session(self, mock_get, mock_chan_cfg, mock_get_config):
|
||||
mock_get.return_value = None
|
||||
mock_chan_cfg.return_value = None
|
||||
mock_cfg = MagicMock()
|
||||
mock_cfg.get.return_value = "sonnet"
|
||||
mock_get_config.return_value = mock_cfg
|
||||
response, is_cmd = route_message("ch-1", "user-1", "/model")
|
||||
assert is_cmd is True
|
||||
assert "sonnet" in response
|
||||
|
||||
@patch("src.router.set_session_model")
|
||||
@patch("src.router.get_active_session")
|
||||
def test_model_change_opus(self, mock_get, mock_set):
|
||||
mock_get.return_value = {"model": "sonnet", "session_id": "abc"}
|
||||
response, is_cmd = route_message("ch-1", "user-1", "/model opus")
|
||||
assert is_cmd is True
|
||||
mock_set.assert_called_once_with("ch-1", "opus")
|
||||
assert "opus" in response
|
||||
|
||||
def test_model_invalid_choice(self):
|
||||
response, is_cmd = route_message("ch-1", "user-1", "/model gpt4")
|
||||
assert is_cmd is True
|
||||
assert "invalid" in response.lower()
|
||||
assert "gpt4" in response
|
||||
|
||||
@patch("src.claude_session._save_sessions")
|
||||
@patch("src.claude_session._load_sessions")
|
||||
@patch("src.router.get_active_session")
|
||||
def test_model_change_no_session_presets(self, mock_get, mock_load, mock_save):
|
||||
mock_get.return_value = None
|
||||
mock_load.return_value = {}
|
||||
response, is_cmd = route_message("ch-1", "user-1", "/model haiku")
|
||||
assert is_cmd is True
|
||||
mock_save.assert_called_once()
|
||||
saved = mock_save.call_args[0][0]
|
||||
assert saved["ch-1"]["model"] == "haiku"
|
||||
assert "haiku" in response
|
||||
|
||||
|
||||
# --- /status command ---
|
||||
|
||||
@@ -186,3 +259,13 @@ class TestModelResolution:
|
||||
|
||||
route_message("ch-1", "user-1", "hello")
|
||||
mock_send.assert_called_once_with("ch-1", "hello", model="sonnet")
|
||||
|
||||
@patch("src.router.get_active_session")
|
||||
@patch("src.router.send_message")
|
||||
def test_session_model_takes_priority(self, mock_send, mock_get_session):
|
||||
"""Session model takes priority over channel and global defaults."""
|
||||
mock_send.return_value = "ok"
|
||||
mock_get_session.return_value = {"model": "opus", "session_id": "abc"}
|
||||
|
||||
route_message("ch-1", "user-1", "hello")
|
||||
mock_send.assert_called_once_with("ch-1", "hello", model="opus")
|
||||
|
||||
Reference in New Issue
Block a user