TUI now generates a UUID session_id on mount and on chat clear
This commit is contained in:
parent
aaa9b6a32f
commit
a7b79c433d
3 changed files with 29 additions and 6 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- **TUI session context not updating**: The Chat TUI now generates a UUID `session_id` on mount and on chat clear, fixing background summarization which requires a non-empty `session_id`.
|
||||||
|
|
||||||
## [0.29.1] - 2026-02-10
|
## [0.29.1] - 2026-02-10
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,7 @@ class ChatApp(App):
|
||||||
# Create agent and session state
|
# Create agent and session state
|
||||||
self.agent = create_chat_agent(self.config)
|
self.agent = create_chat_agent(self.config)
|
||||||
self.session_state = ChatSessionState(
|
self.session_state = ChatSessionState(
|
||||||
|
session_id=str(uuid.uuid4()),
|
||||||
initial_context=self._initial_context,
|
initial_context=self._initial_context,
|
||||||
document_filter=self._document_filter,
|
document_filter=self._document_filter,
|
||||||
)
|
)
|
||||||
|
|
@ -328,6 +329,7 @@ class ChatApp(App):
|
||||||
# Reset context lock and session state (reset to CLI value)
|
# Reset context lock and session state (reset to CLI value)
|
||||||
self._context_locked = False
|
self._context_locked = False
|
||||||
self.session_state = ChatSessionState(
|
self.session_state = ChatSessionState(
|
||||||
|
session_id=str(uuid.uuid4()),
|
||||||
initial_context=self._initial_context,
|
initial_context=self._initial_context,
|
||||||
document_filter=self._document_filter,
|
document_filter=self._document_filter,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -245,9 +245,25 @@ async def test_chat_history_thinking_indicator(temp_db_path: Path):
|
||||||
assert len(list(thinking)) == 0
|
assert len(list(thinking)) == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_chat_app_generates_session_id(temp_db_path: Path):
|
||||||
|
"""Test that ChatApp generates a UUID session_id on mount."""
|
||||||
|
from haiku.rag.chat.app import ChatApp
|
||||||
|
|
||||||
|
mock_client = AsyncMock()
|
||||||
|
mock_client.__aenter__ = AsyncMock(return_value=mock_client)
|
||||||
|
mock_client.__aexit__ = AsyncMock(return_value=None)
|
||||||
|
|
||||||
|
with patch("haiku.rag.chat.app.HaikuRAG", return_value=mock_client):
|
||||||
|
app = ChatApp(temp_db_path, read_only=True)
|
||||||
|
|
||||||
|
async with app.run_test():
|
||||||
|
assert app.session_state.session_id != ""
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_clear_chat_resets_session(temp_db_path: Path):
|
async def test_clear_chat_resets_session(temp_db_path: Path):
|
||||||
"""Test that clearing chat resets the session state."""
|
"""Test that clearing chat resets the session state with a new session_id."""
|
||||||
from haiku.rag.chat.app import ChatApp
|
from haiku.rag.chat.app import ChatApp
|
||||||
from haiku.rag.chat.widgets.chat_history import ChatHistory
|
from haiku.rag.chat.widgets.chat_history import ChatHistory
|
||||||
|
|
||||||
|
|
@ -266,9 +282,9 @@ async def test_clear_chat_resets_session(temp_db_path: Path):
|
||||||
await chat_history.add_message("assistant", "Hi there")
|
await chat_history.add_message("assistant", "Hi there")
|
||||||
assert len(chat_history.messages) == 2
|
assert len(chat_history.messages) == 2
|
||||||
|
|
||||||
# Mutate session state to simulate an active session
|
# Record the original session_id
|
||||||
assert app.session_state is not None
|
original_session_id = app.session_state.session_id
|
||||||
app.session_state.session_id = "active-session-123"
|
assert original_session_id != ""
|
||||||
|
|
||||||
# Clear chat via action (available through command palette)
|
# Clear chat via action (available through command palette)
|
||||||
await app.action_clear_chat()
|
await app.action_clear_chat()
|
||||||
|
|
@ -277,9 +293,10 @@ async def test_clear_chat_resets_session(temp_db_path: Path):
|
||||||
# Verify messages cleared
|
# Verify messages cleared
|
||||||
assert len(chat_history.messages) == 0
|
assert len(chat_history.messages) == 0
|
||||||
|
|
||||||
# Verify session state reset
|
# Verify session state reset with a new session_id
|
||||||
assert app.session_state is not None
|
assert app.session_state is not None
|
||||||
assert app.session_state.session_id == ""
|
assert app.session_state.session_id != ""
|
||||||
|
assert app.session_state.session_id != original_session_id
|
||||||
assert app.session_state.qa_history == []
|
assert app.session_state.qa_history == []
|
||||||
assert app.session_state.citations == []
|
assert app.session_state.citations == []
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue