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:
MoltBot Service
2026-02-13 13:13:38 +00:00
parent a1a6ca9a3f
commit 5bdceff732
6 changed files with 475 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ from src.claude_session import (
list_sessions,
resume_session,
send_message,
set_session_model,
start_session,
)
@@ -574,3 +575,46 @@ class TestListSessions:
claude_session, "_SESSIONS_FILE", tmp_path / "nonexistent.json"
)
assert list_sessions() == {}
# ---------------------------------------------------------------------------
# set_session_model
# ---------------------------------------------------------------------------
class TestSetSessionModel:
def test_updates_model_in_active_json(self, tmp_path, monkeypatch):
sessions_dir = tmp_path / "sessions"
sessions_dir.mkdir()
sf = sessions_dir / "active.json"
monkeypatch.setattr(claude_session, "SESSIONS_DIR", sessions_dir)
monkeypatch.setattr(claude_session, "_SESSIONS_FILE", sf)
sf.write_text(json.dumps({
"general": {
"session_id": "abc",
"model": "sonnet",
"message_count": 1,
}
}))
result = set_session_model("general", "opus")
assert result is True
data = json.loads(sf.read_text())
assert data["general"]["model"] == "opus"
def test_returns_false_when_no_session(self, tmp_path, monkeypatch):
sessions_dir = tmp_path / "sessions"
sessions_dir.mkdir()
sf = sessions_dir / "active.json"
monkeypatch.setattr(claude_session, "SESSIONS_DIR", sessions_dir)
monkeypatch.setattr(claude_session, "_SESSIONS_FILE", sf)
sf.write_text("{}")
result = set_session_model("general", "opus")
assert result is False
def test_invalid_model_raises(self):
with pytest.raises(ValueError, match="Invalid model"):
set_session_model("general", "gpt4")