ReMe/tests/unit/test_agent_task.py
jinliyl ae55e2e570
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
feat!: split proactive runtimes and add Studio backend management (#776)
* 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.
2026-11-25 21:33:16 +08:00

87 lines
3.6 KiB
Python

"""Named task editing preserves workspace ownership and optimistic file writes."""
# pylint: disable=missing-function-docstring
import os
import pytest
from reme.core.context import RuntimeContext
from reme.schema.agent_view import TaskDocumentRequest
from reme.steps.proactive.agent.api import TaskDocumentStep
from .test_proactive_runtime import running_manager
@pytest.mark.asyncio
async def test_task_editor_preserves_text_and_rejects_stale_writes(tmp_path):
async with running_manager(tmp_path) as (runtime, context, wrapper):
await runtime.create({"agent_name": "monitor", "task_description": "Original\n"})
step = TaskDocumentStep(app_context=context)
opened = (await step(action="read", agent_name="monitor")).answer
assert opened["content"] == "Original\n"
assert opened["path"] == "reme_agents/monitor/TASK.md"
saved = await step(
action="save",
agent_name="monitor",
content="# Task\n\n保留原样。\n",
expected_mtime=opened["mtime"],
)
assert saved.success and "content" not in saved.answer
target = tmp_path / opened["path"]
assert target.read_text() == "# Task\n\n保留原样。\n"
reopened = (await step(action="read", agent_name="monitor")).answer
target.write_text("External edit\n")
os.utime(target, (target.stat().st_atime, target.stat().st_mtime + 10))
conflict = await step(
action="save",
agent_name="monitor",
content="Do not overwrite",
expected_mtime=reopened["mtime"],
)
assert not conflict.success and conflict.metadata["code"] == "file_conflict"
assert target.read_text() == "External edit\n"
assert not wrapper.turns
@pytest.mark.asyncio
async def test_task_editor_rejects_remy_deleted_agents_and_outside_paths(tmp_path):
async with running_manager(tmp_path) as (runtime, context, _):
step = TaskDocumentStep(app_context=context)
await runtime.create({"agent_name": "monitor", "task_description": "Original"})
for agent_name in ("Remy", "missing"):
with pytest.raises(ValueError):
await step(action="read", agent_name=agent_name)
with pytest.raises(PermissionError):
await step(RuntimeContext(_allowed_paths=["daily"]), action="read", agent_name="monitor")
with pytest.raises(ValueError):
await step(action="read", agent_name="monitor", path="daily/other.md")
target = runtime.registry.task_path(await runtime.definition("monitor"))
outside = tmp_path.parent / f"{tmp_path.name}-outside.md"
outside.write_text("Outside")
target.unlink()
target.symlink_to(outside)
try:
with pytest.raises(ValueError):
await step(action="read", agent_name="monitor")
assert outside.read_text() == "Outside"
finally:
outside.unlink()
target.unlink()
target.write_text("Original")
await runtime.delete("monitor")
with pytest.raises(ValueError):
await step(action="read", agent_name="monitor")
@pytest.mark.parametrize(
"fields",
[
{"action": "save", "agent_name": "task", "content": "text"},
{"action": "save", "agent_name": "task", "content": " ", "expected_mtime": "revision"},
{"action": "read", "agent_name": "task", "expected_mtime": None},
{"action": "read", "agent_name": "../task"},
],
)
def test_task_editor_requires_a_revision_and_action_specific_fields(fields):
with pytest.raises(ValueError):
TaskDocumentRequest.model_validate(fields)