Files
ai-agent-book/chapter3/user-memory/test_search_history_limit_zero.py
T
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

39 lines
1.3 KiB
Python

"""Regression test for ConversationHistory.search_history limit=0 handling.
Proves contract: Requesting limit<=0 from search_history returns an empty list
without executing text or vector search.
Locks out bug where limit=0 appended the first match before breaking, returning 1 result instead of 0.
"""
import sys
from pathlib import Path
SRC = Path(__file__).resolve().parent
sys.path.insert(0, str(SRC))
from conversation_history import ConversationHistory # noqa: E402
from config import Config # noqa: E402
def make_history(tmp_path, monkeypatch):
monkeypatch.setattr(Config, "CONVERSATION_HISTORY_DIR", str(tmp_path))
monkeypatch.setattr(Config, "ENABLE_HISTORY_SEARCH", False)
return ConversationHistory("user1")
def test_search_history_limit_zero_returns_empty_list(tmp_path, monkeypatch):
history = make_history(tmp_path, monkeypatch)
history.add_turn("session-1", "Hello assistant", "Hello user")
history.add_turn("session-1", "Search for something", "Here is your result")
results = history.search_history("hello", limit=0)
assert results == []
def test_search_history_limit_negative_returns_empty_list(tmp_path, monkeypatch):
history = make_history(tmp_path, monkeypatch)
history.add_turn("session-1", "Hello assistant", "Hello user")
results = history.search_history("hello", limit=-1)
assert results == []