From 5f948a33412dfde6d0a210746e61ac9c8477c9e8 Mon Sep 17 00:00:00 2001 From: tanaka takashi Date: Thu, 25 Jun 2026 02:41:58 +0900 Subject: 各モデルの機能を取得するように修正。thinking, tools, vision対応モデルに応じて機能を変えるように変更。クリアボタンのバグを修正 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_clear_messages.py | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/test_clear_messages.py (limited to 'tests/test_clear_messages.py') diff --git a/tests/test_clear_messages.py b/tests/test_clear_messages.py new file mode 100644 index 0000000..91a2556 --- /dev/null +++ b/tests/test_clear_messages.py @@ -0,0 +1,63 @@ +"""Tests for clearing session messages and files.""" + +from __future__ import annotations + +import json +import tempfile +from pathlib import Path + +from ollama_web.sessions import SessionStore, is_valid_id + + +def make_store() -> SessionStore: + tmp = tempfile.mkdtemp() + return SessionStore(data_dir=tmp) + + +def test_clear_messages_removes_history_and_files(): + store = make_store() + session = store.create(title="test") + session_id = session["id"] + assert is_valid_id(session_id) + + chat_file = store.add_file( + session_id=session_id, + name="notes.txt", + data=b"hello", + mime="text/plain", + text="hello", + ) + store.add_message( + session_id=session_id, + role="user", + content="hi", + attachments=[chat_file.id], + ) + store.add_message(session_id=session_id, role="assistant", content="hello") + + files_dir = store._files_dir(session_id) + stored_path = store.data_dir / chat_file.path + assert stored_path.exists() + assert (files_dir / f"{chat_file.id}.txt").exists() + + cleared = store.clear_messages(session_id) + assert cleared is not None + assert cleared["messages"] == [] + assert cleared["files"] == [] + assert not stored_path.exists() + assert files_dir.exists() + + reloaded = store.get(session_id) + assert reloaded is not None + assert reloaded["messages"] == [] + assert reloaded["files"] == [] + + +def test_clear_messages_invalid_session_id(): + store = make_store() + assert store.clear_messages("not-a-valid-id") is None + + +def test_clear_messages_missing_session(): + store = make_store() + assert store.clear_messages("0" * 32) is None \ No newline at end of file -- cgit v1.2.3