- 集成MCP连接管理器,支持MCP服务器连接 - 添加多种内置工具:ClarifyTool、CronTool、DelegateTool、ExecuteCodeTool、 PatchFileTool、ProcessTool、SendMessageTool、SpawnTool、TerminalTool、 TodoTool、WebFetchTool、WebSearchTool、WriteFileTool等 - 实现工具注册和装配功能 - 添加技能选择上下文参数 - 支持思考模式控制参数thinking_enabled feat(coordinator): 重构任务执行计划器参数命名 - 将learning_candidate_enabled重命名为allow_candidate_generation - 更新TeamGraphScheduler中的参数传递 - 修改LocalAgentRunner中的相关参数处理 - 更新README文档中的相应描述 refactor(context): 标准化工具调用参数格式 - 添加_json导入用于参数序列化 - 实现_provider_tool_calls方法标准化OpenAI兼容的工具调用载荷 - 修复工具调用中参数非字符串类型的序列化问题 refactor(session): 优化消息历史记录过滤逻辑 - 修改get_messages_as_conversation为基于运行状态过滤消息 - 排除未完成、失败或错误结束的运行记录 - 改进对话历史的可见性控制机制 fix(store): 修复FTS索引重建逻辑 - 添加异常处理防止FTS索引创建失败 - 实现_rebuild_fts_index方法重新构建全文搜索索引 - 优化索引触发器和表的维护流程
108 lines
3.8 KiB
Python
108 lines
3.8 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from beaver.engine.session import SessionManager
|
|
from beaver.interfaces.web.app import create_app
|
|
from beaver.services.agent_service import AgentService
|
|
|
|
|
|
def test_archived_sessions_can_be_hidden_from_default_web_list(tmp_path: Path) -> None:
|
|
manager = SessionManager(tmp_path)
|
|
manager.ensure_session("web:keep", source="web")
|
|
manager.ensure_session("web:archived", source="web")
|
|
manager.end_session("web:archived", "archived")
|
|
|
|
visible = manager.list_sessions_rich(exclude_end_reasons=["archived"])
|
|
visible_ids = {row["id"] for row in visible}
|
|
|
|
assert "web:keep" in visible_ids
|
|
assert "web:archived" not in visible_ids
|
|
assert manager.get_session("web:archived")["end_reason"] == "archived"
|
|
|
|
|
|
def test_archived_sessions_remain_available_to_history_search(tmp_path: Path) -> None:
|
|
manager = SessionManager(tmp_path)
|
|
manager.ensure_session("web:archived", source="web")
|
|
manager.end_session("web:archived", "archived")
|
|
|
|
all_sessions = manager.list_sessions_rich()
|
|
|
|
assert {row["id"] for row in all_sessions} == {"web:archived"}
|
|
|
|
|
|
def test_visible_history_excludes_error_and_incomplete_runs(tmp_path: Path) -> None:
|
|
manager = SessionManager(tmp_path)
|
|
manager.ensure_session("web:history", source="web")
|
|
manager.append_message("web:history", run_id="ok-run", role="user", content="hello")
|
|
manager.append_message("web:history", run_id="ok-run", role="assistant", content="hi", finish_reason="stop")
|
|
manager.append_message(
|
|
"web:history",
|
|
run_id="ok-run",
|
|
role="assistant",
|
|
content=None,
|
|
tool_calls=[{"id": "call-1", "type": "function", "function": {"name": "echo", "arguments": "{}"}}],
|
|
)
|
|
manager.append_message(
|
|
"web:history",
|
|
run_id="ok-run",
|
|
role="tool",
|
|
content="tool result",
|
|
tool_call_id="call-1",
|
|
)
|
|
manager.append_message(
|
|
"web:history",
|
|
run_id="ok-run",
|
|
role="system",
|
|
event_type="run_completed",
|
|
content="hi",
|
|
context_visible=False,
|
|
)
|
|
manager.append_message("web:history", run_id="error-run", role="user", content="bad")
|
|
manager.append_message(
|
|
"web:history",
|
|
run_id="error-run",
|
|
role="assistant",
|
|
content="Error: provider failed",
|
|
finish_reason="error",
|
|
)
|
|
manager.append_message(
|
|
"web:history",
|
|
run_id="error-run",
|
|
role="system",
|
|
event_type="run_completed",
|
|
content="Error: provider failed",
|
|
finish_reason="error",
|
|
context_visible=False,
|
|
)
|
|
manager.append_message("web:history", run_id="pending-run", role="user", content="pending")
|
|
|
|
history = manager.get_visible_history("web:history")
|
|
|
|
assert [(message["role"], message["content"]) for message in history] == [
|
|
("user", "hello"),
|
|
("assistant", "hi"),
|
|
]
|
|
|
|
|
|
def test_web_archive_route_does_not_create_archive_suffix_session(tmp_path: Path) -> None:
|
|
service = AgentService(workspace=tmp_path)
|
|
app = create_app(service=service, manage_service_lifecycle=False)
|
|
|
|
with TestClient(app) as client:
|
|
create_response = client.post("/api/sessions/web:alpha")
|
|
archive_response = client.post("/api/sessions/web:alpha/archive")
|
|
sessions_response = client.get("/api/sessions")
|
|
|
|
assert create_response.status_code == 200
|
|
assert archive_response.status_code == 200
|
|
assert archive_response.json() == {"ok": True, "archived": True}
|
|
assert sessions_response.status_code == 200
|
|
|
|
loaded = service.create_loop().boot()
|
|
assert loaded.session_manager.get_session("web:alpha")["end_reason"] == "archived" # type: ignore[union-attr]
|
|
assert loaded.session_manager.get_session("web:alpha/archive") is None # type: ignore[union-attr]
|
|
assert sessions_response.json() == []
|