mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-08 16:02:20 +02:00
fix(tests): isolate database and module state
This commit is contained in:
@@ -9,30 +9,21 @@ inconsistent with the actual rows. get_session relies on message_count>0 to
|
||||
decide whether to lazily hydrate from the DB, so an inflated count is a latent
|
||||
correctness hazard.
|
||||
"""
|
||||
import os
|
||||
import tempfile
|
||||
import pytest
|
||||
|
||||
from tests.helpers.database import isolated_session_database
|
||||
|
||||
|
||||
def _make_manager():
|
||||
db_fd, db_path = tempfile.mkstemp(suffix=".db")
|
||||
os.close(db_fd)
|
||||
os.environ["DATABASE_URL"] = f"sqlite:///{db_path}"
|
||||
|
||||
# Import after DATABASE_URL is set so the engine binds to the temp DB.
|
||||
import importlib
|
||||
import core.database as database
|
||||
importlib.reload(database)
|
||||
database.Base.metadata.create_all(bind=database.engine)
|
||||
|
||||
import core.session_manager as sm_mod
|
||||
importlib.reload(sm_mod)
|
||||
return sm_mod.SessionManager(), database, sm_mod
|
||||
@pytest.fixture
|
||||
def manager_database(tmp_path):
|
||||
with isolated_session_database(tmp_path) as resources:
|
||||
yield resources
|
||||
|
||||
|
||||
def test_truncate_keep_count_exceeds_total_does_not_inflate_count():
|
||||
def test_truncate_keep_count_exceeds_total_does_not_inflate_count(manager_database):
|
||||
from core.models import ChatMessage
|
||||
|
||||
sm, database, sm_mod = _make_manager()
|
||||
sm, database = manager_database
|
||||
sid = "short-session"
|
||||
sm.create_session(session_id=sid, name="t", endpoint_url="x",
|
||||
model="m", rag=False, owner="u")
|
||||
@@ -59,10 +50,10 @@ def test_truncate_keep_count_exceeds_total_does_not_inflate_count():
|
||||
db.close()
|
||||
|
||||
|
||||
def test_truncate_keeps_history_alias_for_context_messages():
|
||||
def test_truncate_keeps_history_alias_for_context_messages(manager_database):
|
||||
from core.models import ChatMessage
|
||||
|
||||
sm, database, sm_mod = _make_manager()
|
||||
sm, database = manager_database
|
||||
sid = "alias-after-truncate"
|
||||
sm.create_session(session_id=sid, name="t", endpoint_url="x",
|
||||
model="m", rag=False, owner="u")
|
||||
|
||||
Reference in New Issue
Block a user