feat: improve session navigation

This commit is contained in:
2026-07-30 19:45:05 +02:00
parent 112ae6d1da
commit 43c1f76d84
7 changed files with 284 additions and 15 deletions
+50 -3
View File
@@ -3,14 +3,18 @@ import tempfile
import unittest
from pathlib import Path
from javis.memory.sqlite_store import SessionNotFoundError, SQLiteSessionStore
from javis.memory.sqlite_store import (
AmbiguousSessionReferenceError,
SessionNotFoundError,
SQLiteSessionStore,
)
class SQLiteSessionStoreTests(unittest.TestCase):
def setUp(self) -> None:
self.temporary_directory = tempfile.TemporaryDirectory()
database = Path(self.temporary_directory.name) / "sessions.sqlite3"
self.store = SQLiteSessionStore(database)
self.database = Path(self.temporary_directory.name) / "sessions.sqlite3"
self.store = SQLiteSessionStore(self.database)
def tearDown(self) -> None:
self.temporary_directory.cleanup()
@@ -119,6 +123,49 @@ class SQLiteSessionStoreTests(unittest.TestCase):
["Alte Nachricht"],
)
def test_rename_and_search_only_titles_and_user_messages(self) -> None:
first = self.store.create_session("ollama", "test-model")
second = self.store.create_session("ollama", "test-model")
self.store.rename_session(first.id, "SQLite Hilfe")
self.store.append_exchange(first.id, "Transaktion erklären", "Privates Lösungswort")
self.store.append_exchange(second.id, "Andere Frage", "Nur SQLite in Antwort")
self.assertEqual(self.store.get_session(first.id).title, "SQLite Hilfe")
self.assertEqual(
[session.id for session in self.store.search_sessions("Transaktion")],
[first.id],
)
self.assertEqual(self.store.search_sessions("Lösungswort"), [])
self.assertEqual(self.store.search_sessions("SQLite"), [self.store.get_session(first.id)])
def test_search_treats_sql_wildcards_and_injection_as_plain_text(self) -> None:
session = self.store.create_session("ollama", "test-model")
self.store.rename_session(session.id, "100% SQLite_Name")
self.assertEqual(self.store.search_sessions("%")[0].id, session.id)
self.assertEqual(self.store.search_sessions("_")[0].id, session.id)
self.assertEqual(self.store.search_sessions("' OR 1=1 --"), [])
def test_unique_and_ambiguous_session_prefixes(self) -> None:
with sqlite3.connect(self.database) as connection:
connection.executemany(
"""
INSERT INTO sessions
(id, created_at, updated_at, provider, model, title, last_provider)
VALUES (?, '2026-01-01', '2026-01-01', 'ollama', 'model', ?, 'ollama')
""",
(
("abc111", "Eins"),
("abc222", "Zwei"),
("unique333", "Drei"),
),
)
connection.close()
self.assertEqual(self.store.resolve_unique_prefix("unique").id, "unique333")
with self.assertRaises(AmbiguousSessionReferenceError):
self.store.resolve_unique_prefix("abc")
if __name__ == "__main__":
unittest.main()