Compare commits

...
Author SHA1 Message Date
praisonai-triage-agent[bot]andMervin Praison 7c44cb8572 fix: exercise real ProjectSessionStore in isolation fixture and guard marker misuse
- conftest: instantiate real ProjectSessionStore (patching sessions dir to
  tmp) instead of DefaultSessionStore, so project_id/project_name/
  get_last_session_id are actually tested (Gemini)
- conftest: raise UsageError if no_session_isolation marker is combined with
  an explicit isolated_session_stores fixture request, detecting explicit
  requests via the test function signature (Greptile)
- test_session_continuity: drop defensive getattr/hasattr fallbacks now that
  the real ProjectSessionStore is used

Co-authored-by: Mervin Praison <[email protected]>
2026-07-06 22:11:11 +00:00
2 changed files with 29 additions and 8 deletions

No files matched your search

+26 -1
View File
@@ -10,12 +10,37 @@ from praisonaiagents.session.store import DefaultSessionStore
def isolated_session_stores(request, monkeypatch, tmp_path):
"""Keep session I/O off shared dirs when pytest-xdist runs workers in parallel."""
if request.node.get_closest_marker("no_session_isolation"):
# Tests that opt out must NOT also explicitly request this fixture as a
# parameter, because they would receive None and fail to unpack it.
# ``fixturenames`` always contains this autouse fixture, so inspect the
# test function's own signature to detect an *explicit* request.
test_fn = getattr(request.node, "function", None)
code = getattr(test_fn, "__code__", None)
arg_count = getattr(code, "co_argcount", 0)
explicit_args = getattr(code, "co_varnames", ())[:arg_count]
if "isolated_session_stores" in explicit_args:
raise pytest.UsageError(
f"{request.node.name}: 'no_session_isolation' marker cannot be "
"combined with an explicit 'isolated_session_stores' fixture parameter."
)
return None
import praisonaiagents.session.store as store_mod
base = tmp_path / "session-isolation"
project_store = DefaultSessionStore(session_dir=str(base / "project"))
# Redirect the project-scoped store to a temp dir while still exercising the
# real ProjectSessionStore class (so project_id/project_name/get_last_session_id
# remain testable). Falls back to DefaultSessionStore if the project variant
# is unavailable for any reason.
project_dir = base / "project"
monkeypatch.setattr(
project_sessions, "get_project_sessions_dir", lambda *a, **k: project_dir
)
project_store_cls = getattr(project_sessions, "ProjectSessionStore", None)
if project_store_cls is not None:
project_store = project_store_cls()
else:
project_store = DefaultSessionStore(session_dir=str(project_dir))
global_store = DefaultSessionStore(session_dir=str(base / "global"))
monkeypatch.setattr(
project_sessions, "get_project_session_store", lambda *a, **k: project_store
@@ -45,8 +45,8 @@ def test_project_session_store():
store = project_sessions.get_project_session_store()
print("✅ Session store created")
print(f" Project ID: {getattr(store, 'project_id', 'n/a')}")
print(f" Project Name: {getattr(store, 'project_name', 'n/a')}")
print(f" Project ID: {store.project_id}")
print(f" Project Name: {store.project_name}")
print(f" Session Dir: {store.session_dir}")
# Test adding messages
@@ -71,11 +71,7 @@ def test_project_session_store():
print(f" ID: {session.get('session_id')}, Messages: {session.get('message_count')}")
# Test getting last session
if hasattr(store, "get_last_session_id"):
last_session_id = store.get_last_session_id()
else:
sessions = store.list_sessions(limit=1)
last_session_id = sessions[0].get("session_id") if sessions else None
last_session_id = store.get_last_session_id()
print(f"✅ Last session ID: {last_session_id}")
# Cleanup