mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
Some checks are pending
CI / Python packages / Build and verify distributions (push) Waiting to run
CI / Python quality / GitHub Actions (push) Waiting to run
CI / Python quality / Pre-commit (push) Waiting to run
CI / Python tests / Hermes embedded - ubuntu-latest (push) Waiting to run
CI / Python tests / Hermes embedded - windows-latest (push) Waiting to run
CI / Python tests / Unit Tests - py3.11 (push) Waiting to run
CI / Python tests / Unit Tests - py3.12 (push) Waiting to run
CI / Python tests / Unit Tests - py3.13 (push) Waiting to run
CI / Python tests / Unit Tests - py3.14 (push) Waiting to run
CI / ReMe Studio / Studio checks (push) Waiting to run
CI / Windows / CLI smoke - py3.11 (push) Waiting to run
Deploy / Documentation / Build documentation (push) Waiting to run
Deploy / Documentation / deploy (push) Blocked by required conditions
Security / CodeQL / Analyze javascript-typescript (push) Waiting to run
Security / CodeQL / Analyze python (push) Waiting to run
* refactor(proactive)!: separate runtime ownership and unify delivery * refactor(proactive): finish runtime and Studio migration * test(proactive): make scheduled skip coverage deterministic * refactor(studio): unify navigation and notebook resource loading * feat(studio): edit workspace documents and update proactive task names * refactor(studio): simplify task settings and navigation * feat(studio): secure and supervise backend settings * feat(studio): unify workbench timelines and refine desktop updates Use shared timeline panes for notebook, memory, and resources. Add Todo creation ordering, persist companion visibility, and align desktop update handling and release artifacts. Recheck editor file versions at read and publication boundaries. Retry reminder detail requests from the resource view. * fix(studio): support unsigned GitHub preview releases * fix: verify container state and isolate proactive view errors Mount private supervisor state in Docker smoke tests and verify token and settings persistence. Exercise Studio startup with a loopback-only model fixture, and exclude packaged desktop output from Docker contexts. Keep Remy subscriptions and healthy tasks available when an individual task has an invalid workspace path or session history. * fix(home): align candidate Docker context exclusions * chore(deps): update openai-codex dependency to v0.172.0 - Bump openai-codex from version 0.169.0 to 0.172.0 in pyproject.toml - Keep other dependencies unchanged - Ensure compatibility with latest openai-codex features and fixes * fix(daemon): discover parent dotenv and isolate listeners Restore parent-directory environment discovery in workers while retaining system precedence. Partition the default supervisor profile and lock by the configured bind address and port.
146 lines
7.7 KiB
Python
146 lines
7.7 KiB
Python
"""Named management actions and small model results."""
|
|
|
|
# pylint: disable=missing-function-docstring,protected-access
|
|
|
|
from datetime import datetime
|
|
from unittest.mock import AsyncMock
|
|
|
|
import pytest
|
|
|
|
from reme.schema.proactive_agent import ManageProactiveAgentRequest
|
|
from reme.steps.proactive.tools.manage_proactive_agent import ManageProactiveAgentStep
|
|
from .test_proactive_runtime import running_manager
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"arguments",
|
|
[
|
|
{"action": "list", "agent_name": "task"},
|
|
{"action": "list", "agent_name": None},
|
|
{"action": "create", "agent_name": "task", "task_description": "Observe", "agent_type": "proactive"},
|
|
{
|
|
"action": "create",
|
|
"agent_name": "task",
|
|
"task_description": "Observe",
|
|
"agent_type": "cron",
|
|
"cron": "0 8 * * *",
|
|
},
|
|
{"action": "create", "agent_name": "task", "task_description": "Observe", "temporary": True},
|
|
{"action": "create", "agent_name": "task"},
|
|
{"action": "create", "agent_name": "task", "task_description": " "},
|
|
{
|
|
"action": "create",
|
|
"config": {"agent_name": "task", "task_description": "Do work"},
|
|
},
|
|
{"action": "status", "agent_id": "task"},
|
|
{"action": "status", "name": "task"},
|
|
{"action": "create", "agent_name": "task", "task_description": "Observe", "agent_type": "event"},
|
|
{"action": "create", "agent_name": "task", "task_description": "Observe", "agent_type": "chat"},
|
|
{"action": "create", "agent_name": "task", "instructions": "Observe"},
|
|
{"action": "create", "agent_name": "task", "description": "Observe"},
|
|
{"action": "create", "agent_name": "task", "task_description": "Observe", "trigger_type": "event"},
|
|
{"action": "status"},
|
|
{"action": "status", "agent_name": "task", "enabled": True},
|
|
{"action": "update", "agent_name": "task"},
|
|
{"action": "update", "agent_name": "task", "task_description": "New work"},
|
|
{"action": "update", "agent_name": "task", "temporary": True},
|
|
{"action": "update", "agent_name": "task", "max_batch_events": 10},
|
|
{"action": "update", "agent_name": "task", "min_trigger_interval_seconds": True},
|
|
{"action": "delete", "agent_name": "task", "cron": None},
|
|
{"action": "query", "agent_name": "task", "query": "Progress?"},
|
|
{"action": "query", "agent_name": "task", "question": " "},
|
|
],
|
|
)
|
|
def test_action_arguments_reject_legacy_and_irrelevant_fields(arguments):
|
|
with pytest.raises(ValueError):
|
|
ManageProactiveAgentRequest.model_validate(arguments)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_all_actions_expose_only_their_results_and_keep_task_files(tmp_path, monkeypatch):
|
|
async with running_manager(tmp_path) as (runtime, context, _):
|
|
now = datetime.fromisoformat("2026-11-17T07:00:00+08:00")
|
|
monkeypatch.setattr(runtime, "now", lambda: now)
|
|
tool = ManageProactiveAgentStep(app_context=context)
|
|
arguments = {
|
|
"action": "create",
|
|
"agent_name": "tech_news",
|
|
"task_description": "每天08:00整理科技新闻。\n保留来源。\n",
|
|
"cron": "0 8 * * *",
|
|
}
|
|
created = (await tool(**arguments)).answer
|
|
assert created == (await runtime.read_agent("tech_news"))["agent"]
|
|
assert created["agent_type"] == "time" and created["cron"] == "0 8 * * *"
|
|
assert created["next_trigger_at"] == "2026-11-17T08:00:00+08:00"
|
|
task_file = tmp_path / created["task_path"]
|
|
assert task_file.read_text() == arguments["task_description"]
|
|
assert runtime.runtimes["tech_news"].schedule is None
|
|
assert (await tool(action="list")).answer == {"items": [created], "total": 1}
|
|
assert (await tool(action="status", agent_name="tech_news")).answer == created
|
|
updated = (await tool(action="update", agent_name="tech_news", cron="0 9 * * *")).answer
|
|
assert updated["cron"] == "0 9 * * *" and updated["next_trigger_at"] == "2026-11-17T09:00:00+08:00"
|
|
paused = (await tool(action="update", agent_name="tech_news", enabled=False)).answer
|
|
assert not paused["enabled"] and paused["cron"] == "0 9 * * *"
|
|
assert task_file.read_text() == arguments["task_description"]
|
|
|
|
query = AsyncMock(return_value={"status": "completed", "result": "今天的早报已经完成。"})
|
|
monkeypatch.setattr(tool, "query_reply", query)
|
|
assert (
|
|
await tool(action="query", agent_name="tech_news", question="进展如何?")
|
|
).answer == "今天的早报已经完成。"
|
|
query.assert_awaited_once_with("tech_news", "进展如何?")
|
|
deleted = (await tool(action="delete", agent_name="tech_news")).answer
|
|
assert deleted == "Deleted task 'tech_news'; history files retained."
|
|
assert (await tool(action="list")).answer == {"items": [], "total": 0}
|
|
assert task_file.read_text() == arguments["task_description"]
|
|
restored = (await tool(**{**arguments, "task_description": "Changed request"})).answer
|
|
assert restored == (await runtime.read_agent("tech_news"))["agent"]
|
|
assert task_file.read_text() == arguments["task_description"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize("cron, other_cron, agent_type", [(None, "0 * * * *", "event"), ("0 * * * *", None, "time")])
|
|
async def test_trigger_type_is_fixed_after_creation_and_on_restore(tmp_path, cron, other_cron, agent_type):
|
|
async with running_manager(tmp_path) as (runtime, context, _):
|
|
tool = ManageProactiveAgentStep(app_context=context)
|
|
name = "experiment_watch"
|
|
task = {"agent_name": name, "task_description": "跟进实验", "cron": cron}
|
|
created = (await tool(action="create", **task)).answer
|
|
assert created["agent_type"] == agent_type
|
|
path = runtime.registry.path(name) / "config.json"
|
|
before = path.read_bytes()
|
|
with pytest.raises(ValueError, match="trigger type cannot change"):
|
|
await tool(action="update", agent_name=name, cron=other_cron, enabled=False)
|
|
assert path.read_bytes() == before
|
|
|
|
changes = {"min_trigger_interval_seconds": 60}
|
|
if cron is not None:
|
|
changes["cron"] = "0 8 * * *"
|
|
updated = (await tool(action="update", agent_name=name, **changes)).answer
|
|
assert updated["agent_type"] == agent_type and updated["cron"] == changes.get("cron")
|
|
assert updated["min_trigger_interval_seconds"] == 60
|
|
await tool(action="update", agent_name=name, notify_window={"start": "09:00", "end": "18:00"})
|
|
assert (await runtime.definition(name)).notify_window.start == "09:00"
|
|
cleared = (await tool(action="update", agent_name=name, notify_window=None)).answer
|
|
assert cleared["notify_window"] is None
|
|
|
|
await tool(action="delete", agent_name=name)
|
|
deleted = path.read_bytes()
|
|
with pytest.raises(ValueError, match="trigger type cannot change"):
|
|
await tool(action="create", **{**task, "cron": other_cron})
|
|
assert path.read_bytes() == deleted
|
|
restored = (await tool(action="create", **task)).answer
|
|
assert restored["agent_type"] == agent_type and restored["cron"] == cron
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_query_errors_remain_failed_tool_results(tmp_path, monkeypatch):
|
|
async with running_manager(tmp_path) as (_, context, _):
|
|
tool = ManageProactiveAgentStep(app_context=context)
|
|
monkeypatch.setattr(
|
|
tool,
|
|
"query_reply",
|
|
AsyncMock(return_value={"status": "failed", "error": "No completed run"}),
|
|
)
|
|
result = await tool(action="query", agent_name="experiment_watch", question="进展如何?")
|
|
assert not result.success and result.answer == "No completed run"
|