ReMe/tests/unit/test_agent_active_delivery.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

155 lines
6.6 KiB
Python

"""All backends share active snapshots and P0 delivery; P1/P2 retain idle scheduling."""
# pylint: disable=missing-function-docstring,protected-access
import asyncio
from unittest.mock import AsyncMock
import pytest
from reme.schema import Event, SessionSnapshot, SessionStatus
from reme.core.context import RuntimeContext
from reme.steps.proactive.agent import AskAgentStep, ProcessChatRemindersStep
from reme.steps.proactive.tools.chat_reminders import SubmitChatReminderStep
from reme.steps.proactive.tools.manage_proactive_agent import ManageProactiveAgentStep
from .test_proactive_runtime import create_agent, running_manager
from .test_inbox_fork import append_message, prepare
@pytest.mark.asyncio
@pytest.mark.parametrize(
"step_class, arguments",
[
(AskAgentStep, {"query": "Current progress?"}),
(ManageProactiveAgentStep, {"action": "query", "question": "Current progress?"}),
],
)
async def test_query_forks_latest_running_session_instead_of_previous_receipt(tmp_path, step_class, arguments):
async with running_manager(tmp_path) as (runtime, context, wrapper):
await create_agent(runtime)
previous = await runtime.sessions.ensure("monitor", wrapper, {}, runtime.now())
await runtime.run_round(
"monitor",
AsyncMock(return_value=(None, previous)),
)
await runtime.append_events("monitor", [Event(event_ts=runtime.now(), source="test", description="New")])
entered, release = asyncio.Event(), asyncio.Event()
source = None
async def execute(_agent, _events):
nonlocal source
source = await runtime.sessions.ensure("monitor", wrapper, {}, runtime.now(), new=True)
entered.set()
await release.wait()
return None, source
running = asyncio.create_task(runtime.run_round("monitor", execute))
try:
await asyncio.wait_for(entered.wait(), 1)
response = await asyncio.wait_for(
step_class(app_context=context)(
RuntimeContext(stream_queue=asyncio.Queue()),
agent_name="monitor",
**arguments,
),
1,
)
assert response.success
assert wrapper.created[-1]["resume"] == source != previous
assert (await runtime.sessions.current("monitor")).session_id == source
assert not running.done()
assert (await runtime.inbox.snapshot("monitor"))["in_flight_count"] == 1
assert wrapper.turns[-1][0] == "Current progress?"
assert "monitor" not in runtime.live_turns.turns
finally:
release.set()
await running
@pytest.mark.asyncio
async def test_p0_forks_and_appends_while_foreground_chat_keeps_running(tmp_path):
async with running_manager(tmp_path) as (runtime, context, wrapper):
arguments = await prepare(runtime, context, priority="P0")
source = (await runtime.sessions.current("Remy")).session_id
wrapper.get_session_status = AsyncMock(return_value=SessionStatus(session_id=source, status="active"))
wrapper.read_session = AsyncMock(
return_value=SessionSnapshot(
session_id=source,
state=SessionStatus(session_id=source, status="active"),
last_turn_id="active-turn",
),
)
entered, release = asyncio.Event(), asyncio.Event()
async def foreground():
async with runtime.chat_turn():
entered.set()
await release.wait()
task = asyncio.create_task(foreground())
await asyncio.wait_for(entered.wait(), 1)
async def append(session_id, content, **kwargs):
assert runtime.chat_lock.locked() and not task.done()
assert kwargs["delivery"] == "immediate"
assert kwargs["expected_turn_id"] == "active-turn"
assert kwargs["expected_revision"] is None
return append_message(session_id, content, **kwargs)
async def reply(_hint, **options):
assert options["resume"] == source and options["fork_session"]
bound = options["injected_job_kwargs"]
await SubmitChatReminderStep(app_context=context)(content="Urgent update", **bound)
return {"status": "completed", "result": ""}
wrapper.append_session = AsyncMock(side_effect=append)
wrapper.reply = AsyncMock(side_effect=reply)
try:
response = await asyncio.wait_for(ProcessChatRemindersStep(app_context=context)(**arguments), 1)
assert response.answer == {"sent": True}
assert not task.done() and not runtime.notifications.pending
assert (await runtime.sessions.current("Remy")).session_id == source
finally:
release.set()
await task
@pytest.mark.parametrize("priority", ["P1", "P2"])
@pytest.mark.asyncio
async def test_nonurgent_forks_keep_waiting_for_chat_idle(tmp_path, priority):
async with running_manager(tmp_path) as (runtime, context, wrapper):
arguments = await prepare(runtime, context, priority=priority)
wrapper.reply = AsyncMock()
async with runtime.chat_lock:
response = await asyncio.wait_for(ProcessChatRemindersStep(app_context=context)(**arguments), 1)
assert response.answer == {"skipped": "busy"}
wrapper.reply.assert_not_awaited()
assert list(runtime.notifications.pending) == arguments["msg_ids"]
@pytest.mark.asyncio
async def test_p0_defers_when_a_new_user_turn_is_already_queued(tmp_path):
async with running_manager(tmp_path) as (runtime, context, wrapper):
arguments = await prepare(runtime, context, priority="P0")
source = (await runtime.sessions.current("Remy")).session_id
wrapper.get_session_status = AsyncMock(return_value=SessionStatus(session_id=source, status="active"))
wrapper.reply = AsyncMock()
entered, release = asyncio.Event(), asyncio.Event()
async def foreground():
async with runtime.chat_turn():
entered.set()
await release.wait()
first = asyncio.create_task(foreground())
await asyncio.wait_for(entered.wait(), 1)
second = asyncio.create_task(foreground())
try:
await asyncio.sleep(0)
assert len(runtime.chat_tasks) == 2
response = await asyncio.wait_for(ProcessChatRemindersStep(app_context=context)(**arguments), 1)
assert response.answer == {"skipped": "busy"}
wrapper.reply.assert_not_awaited()
finally:
release.set()
await asyncio.gather(first, second)