mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
test: cover gateway session model backfill
Add regression coverage for backfilling NULL gateway session models in SQLite, preserving existing models, and forwarding the resolved agent model through SessionStore updates.
This commit is contained in:
parent
2046a4c08c
commit
8602e61fca
2 changed files with 40 additions and 1 deletions
|
|
@ -577,3 +577,28 @@ class TestLastPromptTokens:
|
|||
|
||||
store.update_session("k1", last_prompt_tokens=0)
|
||||
assert entry.last_prompt_tokens == 0
|
||||
|
||||
def test_update_session_passes_model_to_db(self, tmp_path):
|
||||
"""Gateway session updates should forward the resolved model to SQLite."""
|
||||
config = GatewayConfig()
|
||||
with patch("gateway.session.SessionStore._ensure_loaded"):
|
||||
store = SessionStore(sessions_dir=tmp_path, config=config)
|
||||
store._loaded = True
|
||||
store._save = MagicMock()
|
||||
store._db = MagicMock()
|
||||
|
||||
from gateway.session import SessionEntry
|
||||
from datetime import datetime
|
||||
entry = SessionEntry(
|
||||
session_key="k1",
|
||||
session_id="s1",
|
||||
created_at=datetime.now(),
|
||||
updated_at=datetime.now(),
|
||||
)
|
||||
store._entries = {"k1": entry}
|
||||
|
||||
store.update_session("k1", model="openai/gpt-5.4")
|
||||
|
||||
store._db.update_token_counts.assert_called_once_with(
|
||||
"s1", 0, 0, model="openai/gpt-5.4"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -55,13 +55,27 @@ class TestSessionLifecycle:
|
|||
|
||||
def test_update_token_counts(self, db):
|
||||
db.create_session(session_id="s1", source="cli")
|
||||
db.update_token_counts("s1", input_tokens=100, output_tokens=50)
|
||||
db.update_token_counts("s1", input_tokens=200, output_tokens=100)
|
||||
db.update_token_counts("s1", input_tokens=100, output_tokens=50)
|
||||
|
||||
session = db.get_session("s1")
|
||||
assert session["input_tokens"] == 300
|
||||
assert session["output_tokens"] == 150
|
||||
|
||||
def test_update_token_counts_backfills_model_when_null(self, db):
|
||||
db.create_session(session_id="s1", source="telegram")
|
||||
db.update_token_counts("s1", input_tokens=10, output_tokens=5, model="openai/gpt-5.4")
|
||||
|
||||
session = db.get_session("s1")
|
||||
assert session["model"] == "openai/gpt-5.4"
|
||||
|
||||
def test_update_token_counts_preserves_existing_model(self, db):
|
||||
db.create_session(session_id="s1", source="cli", model="anthropic/claude-opus-4.6")
|
||||
db.update_token_counts("s1", input_tokens=10, output_tokens=5, model="openai/gpt-5.4")
|
||||
|
||||
session = db.get_session("s1")
|
||||
assert session["model"] == "anthropic/claude-opus-4.6"
|
||||
|
||||
def test_parent_session(self, db):
|
||||
db.create_session(session_id="parent", source="cli")
|
||||
db.create_session(session_id="child", source="cli", parent_session_id="parent")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue