The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(tui): cover launch SessionDB binding under profile override windows
HexLab98342705135a5d
diff --git a/tests/tui_gateway/test_launch_db_home_override_race.py b/tests/tui_gateway/test_launch_db_home_override_race.pynew file mode 100644index 00000000000..5110f1f44a2--- /dev/null+++ b/tests/tui_gateway/test_launch_db_home_override_race.py@@ -0,0 +1,52 @@+"""Regression for #102526.++The launch backend's lazy ``_get_db()`` handle must bind to the import-time+launch home, not whatever ``get_hermes_home()`` resolves to at first-touch+time. The desktop multiplex cron ticker installs per-profile override windows+at startup; if the first ``session.*`` RPC races into a foreign window, the+backend permanently serves the wrong profile's state.db.+"""++from __future__ import annotations++from pathlib import Path+from types import SimpleNamespace++import pytest++from hermes_constants import reset_hermes_home_override, set_hermes_home_override+from tui_gateway import server+++def launch_db_env(monkeypatch, tmp_path):+ launch_home = tmp_path / "launch"+ foreign_home = tmp_path / "foreign"+ launch_home.mkdir()+ foreign_home.mkdir()++ monkeypatch.setenv("HERMES_HOME", str(launch_home))+ monkeypatch.setattr(server, "_hermes_home", str(launch_home))+ monkeypatch.setattr(server, "_db", None)+ monkeypatch.setattr(server, "_db_error", None)++ captured: list[Path | None] = []++ def _factory(db_path=None, **_kwargs):+ captured.append(Path(db_path) if db_path is not None else None)+ return SimpleNamespace(db_path=db_path)++ monkeypatch.setattr("hermes_state.get_shared_session_db", _factory)+ return launch_home, foreign_home, captured+++def test_get_db_first_touch_under_foreign_override_uses_launch_path(launch_db_env):+ launch_home, foreign_home, captured = launch_db_env+ token = set_hermes_home_override(str(foreign_home))+ try:+ db = server._get_db()+ assert db is not None+ assert captured == [launch_home / "state.db"]+ assert server._get_db() is db+ finally:+ reset_hermes_home_override(token)diff --git a/tests/tui_gateway/test_session_resume_db_ownership.py b/tests/tui_gateway/test_session_resume_db_ownership.pyindex 53e7df166ff..2f912e83bea 100644--- a/tests/tui_gateway/test_session_resume_db_ownership.py+++ b/tests/tui_gateway/test_session_resume_db_ownership.py@@ -116,20 +116,20 @@ def _resume(**params):)-def test_resume_closes_profile_db_when_session_not_found(profile_dbs):+def test_resume_closes_profile_db_when_session_not_found(profile_dbs, tmp_path):"""The 'session not found' early return must not leak the handle.The stranded-session adoption fallback (#93296 follow-up) may lazilyconstruct the SHARED launch handle via ``_get_db()`` while probing the- default store for a donor row; that handle carries ``db_path=None`` and- is never closed by design (see module docstring). Only the dedicated- profile-scoped open (``db_path=<profile>/state.db``) is the caller's to- close, so the leak assertion filters to path-scoped opens.+ default store for a donor row; that handle is never closed by design (see+ module docstring). Only the dedicated profile-scoped open is the caller's+ to close, so the leak assertion filters to the profile store path."""+ profile_store = tmp_path / "work" / "state.db"resp = _resume(session_id="missing", profile="work")assert resp["error"]["code"] == 4007- scoped = [db for db in profile_dbs if db.db_path is not None]+ scoped = [db for db in profile_dbs if db.db_path == profile_store]assert len(scoped) == 1assert scoped[0].closed == 1