Refactor test cases for improved readability and consistency
- Added blank lines for better separation of test cases in multiple test files. - Reformatted event handling in tests for clarity and consistency. - Ensured consistent use of multi-line formatting for dictionary arguments in event handling. - Improved assertions and test descriptions for better understanding. - Updated test cases across various modules including test_stream_state, test_stream_utils, test_summarization, test_thread_selector, test_tool_error_handler, test_tui_widgets, test_ui_runtime, and test_wechat_channel.
This commit is contained in:
@@ -11,6 +11,7 @@ from typing import Any, Dict
|
||||
@dataclass
|
||||
class StreamEvent:
|
||||
"""Unified stream event."""
|
||||
|
||||
type: str
|
||||
data: Dict[str, Any]
|
||||
|
||||
@@ -21,7 +22,9 @@ class StreamEventEmitter:
|
||||
@staticmethod
|
||||
def thinking(content: str, thinking_id: int = 0) -> StreamEvent:
|
||||
"""Thinking content event."""
|
||||
return StreamEvent("thinking", {"type": "thinking", "content": content, "id": thinking_id})
|
||||
return StreamEvent(
|
||||
"thinking", {"type": "thinking", "content": content, "id": thinking_id}
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def text(content: str) -> StreamEvent:
|
||||
@@ -31,52 +34,67 @@ class StreamEventEmitter:
|
||||
@staticmethod
|
||||
def tool_call(name: str, args: Dict[str, Any], tool_id: str = "") -> StreamEvent:
|
||||
"""Tool call event."""
|
||||
return StreamEvent("tool_call", {"type": "tool_call", "name": name, "args": args, "id": tool_id})
|
||||
return StreamEvent(
|
||||
"tool_call",
|
||||
{"type": "tool_call", "name": name, "args": args, "id": tool_id},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def tool_result(name: str, content: str, success: bool = True) -> StreamEvent:
|
||||
"""Tool result event."""
|
||||
return StreamEvent("tool_result", {
|
||||
"type": "tool_result",
|
||||
"name": name,
|
||||
"content": content,
|
||||
"success": success,
|
||||
})
|
||||
return StreamEvent(
|
||||
"tool_result",
|
||||
{
|
||||
"type": "tool_result",
|
||||
"name": name,
|
||||
"content": content,
|
||||
"success": success,
|
||||
},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def subagent_start(name: str, description: str) -> StreamEvent:
|
||||
"""Sub-agent delegation started."""
|
||||
return StreamEvent("subagent_start", {
|
||||
"type": "subagent_start",
|
||||
"name": name,
|
||||
"description": description,
|
||||
})
|
||||
return StreamEvent(
|
||||
"subagent_start",
|
||||
{
|
||||
"type": "subagent_start",
|
||||
"name": name,
|
||||
"description": description,
|
||||
},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def subagent_tool_call(
|
||||
subagent: str, name: str, args: Dict[str, Any], tool_id: str = ""
|
||||
) -> StreamEvent:
|
||||
"""Tool call from inside a sub-agent."""
|
||||
return StreamEvent("subagent_tool_call", {
|
||||
"type": "subagent_tool_call",
|
||||
"subagent": subagent,
|
||||
"name": name,
|
||||
"args": args,
|
||||
"id": tool_id,
|
||||
})
|
||||
return StreamEvent(
|
||||
"subagent_tool_call",
|
||||
{
|
||||
"type": "subagent_tool_call",
|
||||
"subagent": subagent,
|
||||
"name": name,
|
||||
"args": args,
|
||||
"id": tool_id,
|
||||
},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def subagent_tool_result(
|
||||
subagent: str, name: str, content: str, success: bool = True
|
||||
) -> StreamEvent:
|
||||
"""Tool result from inside a sub-agent."""
|
||||
return StreamEvent("subagent_tool_result", {
|
||||
"type": "subagent_tool_result",
|
||||
"subagent": subagent,
|
||||
"name": name,
|
||||
"content": content,
|
||||
"success": success,
|
||||
})
|
||||
return StreamEvent(
|
||||
"subagent_tool_result",
|
||||
{
|
||||
"type": "subagent_tool_result",
|
||||
"subagent": subagent,
|
||||
"name": name,
|
||||
"content": content,
|
||||
"success": success,
|
||||
},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def subagent_end(name: str) -> StreamEvent:
|
||||
@@ -86,45 +104,62 @@ class StreamEventEmitter:
|
||||
@staticmethod
|
||||
def done(response: str = "") -> StreamEvent:
|
||||
"""Done event."""
|
||||
return StreamEvent("done", {"type": "done", "content": response, "response": response})
|
||||
return StreamEvent(
|
||||
"done", {"type": "done", "content": response, "response": response}
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def usage_stats(input_tokens: int, output_tokens: int) -> StreamEvent:
|
||||
"""Token usage statistics event."""
|
||||
return StreamEvent("usage_stats", {
|
||||
"type": "usage_stats",
|
||||
"input_tokens": input_tokens,
|
||||
"output_tokens": output_tokens,
|
||||
})
|
||||
return StreamEvent(
|
||||
"usage_stats",
|
||||
{
|
||||
"type": "usage_stats",
|
||||
"input_tokens": input_tokens,
|
||||
"output_tokens": output_tokens,
|
||||
},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def interrupt(
|
||||
interrupt_id: str, action_requests: list, review_configs: list | None = None,
|
||||
interrupt_id: str,
|
||||
action_requests: list,
|
||||
review_configs: list | None = None,
|
||||
) -> StreamEvent:
|
||||
"""Human-in-the-loop interrupt event."""
|
||||
return StreamEvent("interrupt", {
|
||||
"type": "interrupt",
|
||||
"interrupt_id": interrupt_id,
|
||||
"action_requests": action_requests,
|
||||
"review_configs": review_configs or [],
|
||||
})
|
||||
return StreamEvent(
|
||||
"interrupt",
|
||||
{
|
||||
"type": "interrupt",
|
||||
"interrupt_id": interrupt_id,
|
||||
"action_requests": action_requests,
|
||||
"review_configs": review_configs or [],
|
||||
},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def ask_user_interrupt(
|
||||
interrupt_id: str, questions: list, tool_call_id: str = "",
|
||||
interrupt_id: str,
|
||||
questions: list,
|
||||
tool_call_id: str = "",
|
||||
) -> StreamEvent:
|
||||
"""Agent-initiated ask_user interrupt event."""
|
||||
return StreamEvent("ask_user", {
|
||||
"type": "ask_user",
|
||||
"interrupt_id": interrupt_id,
|
||||
"questions": questions,
|
||||
"tool_call_id": tool_call_id,
|
||||
})
|
||||
return StreamEvent(
|
||||
"ask_user",
|
||||
{
|
||||
"type": "ask_user",
|
||||
"interrupt_id": interrupt_id,
|
||||
"questions": questions,
|
||||
"tool_call_id": tool_call_id,
|
||||
},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def summarization(content: str) -> StreamEvent:
|
||||
"""Context summarization event."""
|
||||
return StreamEvent("summarization", {"type": "summarization", "content": content})
|
||||
return StreamEvent(
|
||||
"summarization", {"type": "summarization", "content": content}
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def error(message: str) -> StreamEvent:
|
||||
|
||||
Reference in New Issue
Block a user