PageIndex/tests/test_events.py
Ray 6f200927cb fix: enforce collection membership on cloud query doc_ids
Cloud query()/query_stream() now run the same _require_document membership
guard the four doc-scoped ops received in 929b3df, so a doc_id from another
collection raises DocumentNotFoundError (matching the local backend's
_scoped_docs) instead of silently answering from another collection's
document. The guard runs after doc_ids normalization and before the
completion request; query_stream runs it via asyncio.to_thread. Folders
unavailable on the plan -> guard skips, as with the sibling ops.

Also rename the streaming QueryEvent types answer_delta/answer_done ->
text_delta/text_done: text_done fires once per assistant text message, which
is honest for the local agent loop's multi-message stream (the last one
before the stream ends carries the final answer). Corrects the cloud
backend's now-inaccurate "single terminal contract" comment. reasoning
stays reserved for future model-reasoning tokens. QueryEvent is unreleased
API (0.3.0.dev1), so the rename is not a breaking change.
2026-07-16 14:40:19 +08:00

26 lines
768 B
Python

from pageindex.events import QueryEvent
from pageindex.backend.protocol import AgentTools
def test_query_event():
event = QueryEvent(type="text_delta", data="hello")
assert event.type == "text_delta"
assert event.data == "hello"
def test_query_event_types():
for t in ["reasoning", "tool_call", "tool_result", "text_delta", "text_done"]:
event = QueryEvent(type=t, data="test")
assert event.type == t
def test_agent_tools_default_empty():
tools = AgentTools()
assert tools.function_tools == []
assert tools.mcp_servers == []
def test_agent_tools_with_values():
tools = AgentTools(function_tools=["tool1"], mcp_servers=["server1"])
assert len(tools.function_tools) == 1
assert len(tools.mcp_servers) == 1