test(state): cover update_session_model overwrite + getattr-guard text path
Follow-up to LengR's #35181 salvage: - gateway text-path uses getattr(self, '_session_db', None) to match the picker callback path (defensive for object.__new__() gateway test pattern). - add SessionDB.update_session_model test asserting it overwrites the COALESCE-pinned model and survives subsequent token updates (#34850).
This commit is contained in:
@@ -152,6 +152,30 @@ class TestSessionLifecycle:
|
||||
session = db.get_session("s1")
|
||||
assert session["model"] == "anthropic/claude-opus-4.6"
|
||||
|
||||
def test_update_session_model_overwrites_existing(self, db):
|
||||
"""A mid-session /model switch must overwrite the stored model.
|
||||
|
||||
update_token_counts uses COALESCE(model, ?) (first-writer-wins), so
|
||||
the dashboard kept showing the original model after a switch (#34850).
|
||||
update_session_model sets the column unconditionally.
|
||||
"""
|
||||
db.create_session(session_id="s1", source="telegram",
|
||||
model="xiaomi/mimo-v2.5-pro")
|
||||
# Token updates never change the model once set.
|
||||
db.update_token_counts("s1", input_tokens=10, output_tokens=5,
|
||||
model="xiaomi/mimo-v2.5-pro")
|
||||
assert db.get_session("s1")["model"] == "xiaomi/mimo-v2.5-pro"
|
||||
|
||||
# Explicit switch overwrites it.
|
||||
db.update_session_model("s1", "xiaomi/mimo-v2.5")
|
||||
assert db.get_session("s1")["model"] == "xiaomi/mimo-v2.5"
|
||||
|
||||
# And a subsequent token update does NOT revert it (COALESCE no-ops
|
||||
# because the column is now non-NULL).
|
||||
db.update_token_counts("s1", input_tokens=10, output_tokens=5,
|
||||
model="xiaomi/mimo-v2.5-pro")
|
||||
assert db.get_session("s1")["model"] == "xiaomi/mimo-v2.5"
|
||||
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user