test: separate preparation responsiveness from persistence timing
This commit is contained in:
1 parent
475b045b6f
commit
3918ece17f
2 files changed
+31
-23
No files matched your search
@@ -11,7 +11,7 @@ from nanobot.agent.tools.context import current_request_context
|
|||||||
from nanobot.providers.base import LLMProvider, LLMResponse, LLMUsage
|
from nanobot.providers.base import LLMProvider, LLMResponse, LLMUsage
|
||||||
from nanobot.runtime_context import public_history_message
|
from nanobot.runtime_context import public_history_message
|
||||||
from nanobot.security.workspace_access import current_workspace_scope
|
from nanobot.security.workspace_access import current_workspace_scope
|
||||||
from nanobot.session.manager import Session
|
from nanobot.session.manager import Session, SessionPolicy
|
||||||
|
|
||||||
|
|
||||||
class ControlledProvider(LLMProvider):
|
class ControlledProvider(LLMProvider):
|
||||||
@@ -126,7 +126,10 @@ async def test_preparation_allows_status_heartbeat_and_cancellation(
|
|||||||
tasks = [task, pulse]
|
tasks = [task, pulse]
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(entered.wait(), timeout=5)
|
await asyncio.wait_for(entered.wait(), timeout=5)
|
||||||
status = await asyncio.wait_for(loop.process_direct("/status", session_key="cli:status"), 5)
|
# Measure preparation responsiveness, not command-history disk writes.
|
||||||
|
status = await asyncio.wait_for(loop.process_direct(
|
||||||
|
"/status", session_key="cli:status", _session_policy=SessionPolicy(persist=False),
|
||||||
|
), 5)
|
||||||
assert status is not None and "test-model" in status.content
|
assert status is not None and "test-model" in status.content
|
||||||
heartbeat_requested.set()
|
heartbeat_requested.set()
|
||||||
await asyncio.wait_for(heartbeat_progress.wait(), 5)
|
await asyncio.wait_for(heartbeat_progress.wait(), 5)
|
||||||
|
|||||||
@@ -62,6 +62,27 @@ def gateway_for(manager, sessions, workspace):
|
|||||||
return gateway, SimpleNamespace(remote_address=("127.0.0.1", 12345)), Headers({"Authorization": f"Bearer {token}"})
|
return gateway, SimpleNamespace(remote_address=("127.0.0.1", 12345)), Headers({"Authorization": f"Bearer {token}"})
|
||||||
|
|
||||||
|
|
||||||
|
async def wait_for_model_requests(manager, task_id, requests, count):
|
||||||
|
task = manager._running_tasks[task_id]
|
||||||
|
for _ in range(count):
|
||||||
|
request = asyncio.create_task(requests.get())
|
||||||
|
try:
|
||||||
|
done, _ = await asyncio.wait(
|
||||||
|
(request, task), timeout=5, return_when=asyncio.FIRST_COMPLETED,
|
||||||
|
)
|
||||||
|
if task in done:
|
||||||
|
result = task.result()
|
||||||
|
status = manager.check(task_id, "websocket:parent")
|
||||||
|
pytest.fail(
|
||||||
|
"subagent ended before its activity was ready: "
|
||||||
|
f"state={status.state}, error={status.error!r}, result={result!r}"
|
||||||
|
)
|
||||||
|
assert request in done, "subagent made no progress to its next model request"
|
||||||
|
finally:
|
||||||
|
request.cancel()
|
||||||
|
await asyncio.gather(request, return_exceptions=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.parametrize("wait", [False, True])
|
@pytest.mark.parametrize("wait", [False, True])
|
||||||
async def test_cancelled_task_creation_removes_committed_child(tmp_path, monkeypatch, wait):
|
async def test_cancelled_task_creation_removes_committed_child(tmp_path, monkeypatch, wait):
|
||||||
@@ -119,18 +140,18 @@ async def test_child_thread_reads_real_session_through_parent_without_new_persis
|
|||||||
workspace.mkdir()
|
workspace.mkdir()
|
||||||
(workspace / "config.txt").write_text("configured value", encoding="utf-8")
|
(workspace / "config.txt").write_text("configured value", encoding="utf-8")
|
||||||
manager, sessions, runtime = manager_with_storage(workspace, root)
|
manager, sessions, runtime = manager_with_storage(workspace, root)
|
||||||
entered, release = asyncio.Event(), asyncio.Event()
|
model_requests, release = asyncio.Queue(), asyncio.Event()
|
||||||
final_text = ("## Findings\n\n" + "Verified configuration.\n" * 1000).rstrip()
|
final_text = ("## Findings\n\n" + "Verified configuration.\n" * 1000).rstrip()
|
||||||
calls = 0
|
calls = 0
|
||||||
|
|
||||||
async def respond(**_kwargs):
|
async def respond(**_kwargs):
|
||||||
nonlocal calls
|
nonlocal calls
|
||||||
calls += 1
|
calls += 1
|
||||||
|
model_requests.put_nowait(None)
|
||||||
if calls == 1:
|
if calls == 1:
|
||||||
return LLMResponse(content="Inspecting configuration", tool_calls=[
|
return LLMResponse(content="Inspecting configuration", tool_calls=[
|
||||||
ToolCallRequest("read-config", "read_file", {"path": "config.txt"}),
|
ToolCallRequest("read-config", "read_file", {"path": "config.txt"}),
|
||||||
])
|
])
|
||||||
entered.set()
|
|
||||||
await release.wait()
|
await release.wait()
|
||||||
return LLMResponse(content=final_text)
|
return LLMResponse(content=final_text)
|
||||||
|
|
||||||
@@ -138,8 +159,9 @@ async def test_child_thread_reads_real_session_through_parent_without_new_persis
|
|||||||
gateway, connection, headers = gateway_for(manager, sessions, workspace)
|
gateway, connection, headers = gateway_for(manager, sessions, workspace)
|
||||||
try:
|
try:
|
||||||
await manager.spawn("Inspect configuration", session_key="websocket:parent", runtime=runtime)
|
await manager.spawn("Inspect configuration", session_key="websocket:parent", runtime=runtime)
|
||||||
await asyncio.wait_for(entered.wait(), 5)
|
|
||||||
task_id, = manager.statuses_for_session("websocket:parent")
|
task_id, = manager.statuses_for_session("websocket:parent")
|
||||||
|
# Bound each round, rather than the combined startup/tool/persistence work.
|
||||||
|
await wait_for_model_requests(manager, task_id, model_requests, 2)
|
||||||
child_key = SubagentSessions.key(task_id)
|
child_key = SubagentSessions.key(task_id)
|
||||||
path = f"/api/sessions/websocket%3Aparent/subagents/{task_id}/webui-thread"
|
path = f"/api/sessions/websocket%3Aparent/subagents/{task_id}/webui-thread"
|
||||||
files_before = set(root.rglob("*"))
|
files_before = set(root.rglob("*"))
|
||||||
@@ -244,24 +266,7 @@ async def test_child_activity_replays_real_tool_errors_and_file_diffs(tmp_path):
|
|||||||
try:
|
try:
|
||||||
await manager.spawn("Edit and inspect files", session_key="websocket:parent", runtime=runtime)
|
await manager.spawn("Edit and inspect files", session_key="websocket:parent", runtime=runtime)
|
||||||
task_id, = manager.statuses_for_session("websocket:parent")
|
task_id, = manager.statuses_for_session("websocket:parent")
|
||||||
task = manager._running_tasks[task_id]
|
await wait_for_model_requests(manager, task_id, model_requests, 4)
|
||||||
for _ in range(4):
|
|
||||||
request = asyncio.create_task(model_requests.get())
|
|
||||||
try:
|
|
||||||
done, _ = await asyncio.wait(
|
|
||||||
(request, task), timeout=5, return_when=asyncio.FIRST_COMPLETED,
|
|
||||||
)
|
|
||||||
if task in done:
|
|
||||||
result = task.result()
|
|
||||||
status = manager.check(task_id, "websocket:parent")
|
|
||||||
pytest.fail(
|
|
||||||
"subagent ended before its activity was ready: "
|
|
||||||
f"state={status.state}, error={status.error!r}, result={result!r}"
|
|
||||||
)
|
|
||||||
assert request in done, "subagent made no progress to its next model request"
|
|
||||||
finally:
|
|
||||||
request.cancel()
|
|
||||||
await asyncio.gather(request, return_exceptions=True)
|
|
||||||
path = f"/api/sessions/websocket%3Aparent/subagents/{task_id}/webui-thread"
|
path = f"/api/sessions/websocket%3Aparent/subagents/{task_id}/webui-thread"
|
||||||
|
|
||||||
async def assert_activity(gateway, connection, headers):
|
async def assert_activity(gateway, connection, headers):
|
||||||
|
|||||||
Reference in new issue
Block a user