feat: 统一自动化任务调度配置并增强聊天流恢复
This commit is contained in:
@@ -114,6 +114,28 @@ def test_build_router_messages_skips_injection_when_context_last_is_user() -> No
|
||||
assert msg.content == existing_context[i].content
|
||||
|
||||
|
||||
def test_build_router_messages_appends_user_input_to_context_tail() -> None:
|
||||
runner = AgentScopeRunner()
|
||||
run_input = _run_input()
|
||||
|
||||
from agentscope.message import Msg
|
||||
|
||||
existing_context = [
|
||||
Msg(name="assistant", role="assistant", content="上一轮回复"),
|
||||
Msg(name="tool", role="assistant", content="工具结果"),
|
||||
]
|
||||
|
||||
messages = runner._build_router_messages(
|
||||
context_messages=existing_context,
|
||||
run_input=run_input,
|
||||
)
|
||||
|
||||
assert len(messages) == len(existing_context) + 1
|
||||
assert messages[-1].role == "user"
|
||||
assert messages[-1].content == "hello"
|
||||
assert messages[0].content == "上一轮回复"
|
||||
|
||||
|
||||
def test_build_model_omits_none_generate_kwargs(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
|
||||
@@ -8,6 +8,8 @@ import pytest
|
||||
from models.automation_jobs import AutomationJob as OrmAutomationJob, ScheduleType
|
||||
from schemas.automation import (
|
||||
RuntimeConfig,
|
||||
ScheduleConfig,
|
||||
ScheduleRunAt,
|
||||
)
|
||||
from v1.automation_jobs.service import AutomationJobsService, _compute_next_run_at
|
||||
|
||||
@@ -50,7 +52,6 @@ def _make_orm_job(
|
||||
*,
|
||||
job_id: UUID | None = None,
|
||||
owner_id: UUID | None = None,
|
||||
schedule_type: ScheduleType = ScheduleType.DAILY,
|
||||
next_run_at: datetime | None = None,
|
||||
) -> OrmAutomationJob:
|
||||
now = datetime(2026, 3, 19, 12, 0, tzinfo=timezone.utc)
|
||||
@@ -66,9 +67,14 @@ def _make_orm_job(
|
||||
"window_count": 2,
|
||||
},
|
||||
"input_template": "auto input: {date}",
|
||||
"schedule": {
|
||||
"type": "daily",
|
||||
"run_at": {
|
||||
"hour": 8,
|
||||
"minute": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
schedule_type=schedule_type,
|
||||
run_at=now - timedelta(hours=1),
|
||||
next_run_at=next_run_at or now - timedelta(minutes=1),
|
||||
timezone="UTC",
|
||||
last_run_at=None,
|
||||
@@ -108,12 +114,14 @@ async def test_scan_and_dispatch_calls_dispatch_fn_with_runtime_config() -> None
|
||||
|
||||
def test_compute_next_run_at_daily() -> None:
|
||||
now = datetime(2026, 3, 19, 12, 0, tzinfo=timezone.utc)
|
||||
current = datetime(2026, 3, 19, 11, 0, tzinfo=timezone.utc)
|
||||
|
||||
computed = _compute_next_run_at(
|
||||
current_next_run_at=current,
|
||||
schedule=ScheduleConfig(
|
||||
type=ScheduleType.DAILY,
|
||||
run_at=ScheduleRunAt(hour=11, minute=0),
|
||||
),
|
||||
timezone_str="UTC",
|
||||
now_utc=now,
|
||||
schedule_type=ScheduleType.DAILY,
|
||||
)
|
||||
|
||||
assert computed == datetime(2026, 3, 20, 11, 0, tzinfo=timezone.utc)
|
||||
@@ -121,12 +129,15 @@ def test_compute_next_run_at_daily() -> None:
|
||||
|
||||
def test_compute_next_run_at_weekly() -> None:
|
||||
now = datetime(2026, 3, 19, 12, 0, tzinfo=timezone.utc)
|
||||
current = datetime(2026, 3, 10, 11, 0, tzinfo=timezone.utc)
|
||||
|
||||
computed = _compute_next_run_at(
|
||||
current_next_run_at=current,
|
||||
schedule=ScheduleConfig(
|
||||
type=ScheduleType.WEEKLY,
|
||||
run_at=ScheduleRunAt(hour=11, minute=0),
|
||||
weekdays=[2],
|
||||
),
|
||||
timezone_str="UTC",
|
||||
now_utc=now,
|
||||
schedule_type=ScheduleType.WEEKLY,
|
||||
)
|
||||
|
||||
assert computed == datetime(2026, 3, 24, 11, 0, tzinfo=timezone.utc)
|
||||
|
||||
@@ -13,7 +13,7 @@ def test_memory_automation_static_config_contract() -> None:
|
||||
"memory.forget",
|
||||
]
|
||||
assert config.input_template is not None
|
||||
assert "提取" in config.input_template
|
||||
assert "回顾" in config.input_template
|
||||
assert "遗忘" in config.input_template
|
||||
assert config.schedule is not None
|
||||
assert config.schedule.type.value == "daily"
|
||||
|
||||
Reference in New Issue
Block a user