feat: 添加日历批量操作与客户端时区感知功能,优化前端 UI 交互体验
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
from ag_ui.core import RunAgentInput
|
||||
from agentscope.message import Msg
|
||||
@@ -208,3 +210,89 @@ async def test_execute_uses_router_ui_mode_to_select_worker_output_model(
|
||||
]
|
||||
assert result["router"]["ui"]["ui_mode"] == "rich"
|
||||
assert result["worker"]["answer"] == "done"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_execute_passes_runtime_client_time_to_router_and_worker(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
runner = AgentScopeRunner()
|
||||
pipeline = _FakePipeline()
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
class _CommitSession:
|
||||
async def commit(self) -> None:
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(
|
||||
"core.agentscope.runtime.runner.AsyncSessionLocal",
|
||||
lambda: _FakeSessionCtx(_CommitSession()),
|
||||
)
|
||||
|
||||
async def _load_system_agent_config(**kwargs):
|
||||
return SystemAgentRuntimeConfig(
|
||||
agent_type=kwargs["agent_type"],
|
||||
model_code="model-a",
|
||||
llm_config=SystemAgentLLMConfig(
|
||||
temperature=0.1, max_tokens=256, timeout_seconds=30
|
||||
),
|
||||
)
|
||||
|
||||
monkeypatch.setattr(runner, "_load_system_agent_config", _load_system_agent_config)
|
||||
|
||||
async def _run_router_stage(**kwargs):
|
||||
captured["router_timezone"] = kwargs["runtime_client_time"].device_timezone
|
||||
return StageExecutionResult(
|
||||
message=Msg(name="router", content="", role="assistant"),
|
||||
payload=_router_output(ui_mode=UiMode.NONE).model_dump(mode="json"),
|
||||
response_metadata={},
|
||||
)
|
||||
|
||||
async def _run_worker_stage(**kwargs):
|
||||
captured["worker_timezone"] = kwargs["runtime_client_time"].device_timezone
|
||||
return StageExecutionResult(
|
||||
message=Msg(name="worker", content="ok", role="assistant"),
|
||||
payload={
|
||||
"status": "success",
|
||||
"answer": "ok",
|
||||
"key_points": [],
|
||||
"result_type": "direct_answer",
|
||||
"suggested_actions": [],
|
||||
"error": None,
|
||||
},
|
||||
response_metadata={},
|
||||
)
|
||||
|
||||
monkeypatch.setattr(runner, "_run_router_stage", _run_router_stage)
|
||||
monkeypatch.setattr(runner, "_run_worker_stage", _run_worker_stage)
|
||||
monkeypatch.setattr(
|
||||
"core.agentscope.runtime.runner.persist_router_message", AsyncMock()
|
||||
)
|
||||
|
||||
run_input = RunAgentInput.model_validate(
|
||||
{
|
||||
"threadId": "00000000-0000-0000-0000-000000000010",
|
||||
"runId": "run-client-time",
|
||||
"state": {},
|
||||
"messages": [{"id": "u1", "role": "user", "content": "hello"}],
|
||||
"tools": [],
|
||||
"context": [],
|
||||
"forwardedProps": {
|
||||
"client_time": {
|
||||
"device_timezone": "America/Los_Angeles",
|
||||
"client_now_iso": "2026-03-16T09:12:33-07:00",
|
||||
"client_epoch_ms": 1773658353000,
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
await runner.execute(
|
||||
user_context=_user_context(),
|
||||
context_messages=[],
|
||||
pipeline=pipeline,
|
||||
run_input=run_input,
|
||||
)
|
||||
|
||||
assert captured["router_timezone"] == "America/Los_Angeles"
|
||||
assert captured["worker_timezone"] == "America/Los_Angeles"
|
||||
|
||||
Reference in New Issue
Block a user