Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/app/test_agent_startup_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
async def test_a_process_that_exits_during_startup_is_reported(workspace):
agent = command(sys.executable, "-c", "import sys; sys.stdin.readline() # exits_during_startup")
async with workspace.app(size=(139, 25), binding=AgentAttached(agent)) as ui:
await ui.until_shows("ACP process closed", seconds=20)
await ui.until_shows("ACP session startup failed", seconds=20)
assert not ui.agent_ready()
await ui.until(lambda: not workspace.child_processes("exits_during_startup"), why="the agent process to be gone")

Expand Down
31 changes: 3 additions & 28 deletions tests/model/test_agent_process_retirement.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,22 @@
"""An agent process ends through EOF, cancellation or an explicit stop with its child gone, its session retired and the default-route lock released."""
"""An agent process ends through EOF, cancellation or an explicit stop with its child gone and its session retired."""

import asyncio
import fcntl
import os
import sys

import psutil
import pytest

from agent_comms.active_route import active_route_path
from support.agents import command
from toad.acp.agent import Agent


@pytest.fixture
def home(tmp_path, monkeypatch):
"""The user's home is private, so the default route and its lock directory are this test's own."""
"""The user's home is private to this test."""
monkeypatch.setenv("HOME", str(tmp_path))
return tmp_path


@pytest.fixture
def launch_root(home):
"""The published default root: only its borrowers take the default-route lock."""
from agent_comms.active_route import LocalRoute
from agent_comms.launch_root import LaunchRoot

return LaunchRoot.from_path(LocalRoute.default().root)


def route_lock_available():
directory = os.open(active_route_path().parent, os.O_RDONLY | os.O_DIRECTORY)
try:
try:
fcntl.flock(directory, fcntl.LOCK_EX | fcntl.LOCK_NB)
except BlockingIOError:
return False
return True
finally:
os.close(directory)


async def until(ui_condition, why):
try:
async with asyncio.timeout(8):
Expand All @@ -51,7 +27,7 @@ async def until(ui_condition, why):


@pytest.mark.parametrize("how", ["cancel", "stop", "eof"])
async def test_the_child_and_session_are_retired_and_the_route_released(home, how, app_agents):
async def test_the_child_and_session_are_retired(home, how, app_agents):
pid_file = home / f"{how}.pid"
code = (
"import subprocess,sys,time;from pathlib import Path;"
Expand Down Expand Up @@ -80,4 +56,3 @@ async def session():
await until(lambda: not descendant.is_running() or descendant.status() == psutil.STATUS_ZOMBIE, "the child to end")
assert agent.process.process is None and agent.session.task is None
assert not agent.session.responses and not agent.session.accepts_updates
assert route_lock_available(), "retired process retained the route lock"
Loading