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_recorded_transcript_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
TranscriptSnapshotUpdate,
decode_updates,
)
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates
from agent_comms.coordination.errors import HistoricalSourceChanged, ReloadRequired
from agent_comms.execution.session_file import RegistrySessionLocation
from agent_comms.execution.transcript_sources import (
Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_transcript_recipient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import replace

from agent_comms.acp_extension import TranscriptSnapshotUpdate
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates
from agent_comms.execution.session_file import RegistrySessionLocation
from agent_comms.projects.checkouts import Checkout
from agent_comms.registry.threads import NativeThread
Expand Down
6 changes: 2 additions & 4 deletions tests/model/test_session_updates_after_binding_change.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""A session update that was being validated when its session or process was replaced publishes nothing."""
from acp import schema
from agent_comms.text_route_update import (
TextRouteUpdate,
encode_updates,
)
from agent_comms.execution.session_updates import encode_updates
from agent_comms.text_route_update import TextRouteUpdate
from agent_comms.messaging.routing import MessageRoute
from support.agents import RecordedEvents, deliver

Expand Down
2 changes: 1 addition & 1 deletion tests/support/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def queued_session_response(session: str, *, next_owner: bool = False):
from agent_comms.execution.child_process import ProcessIdentity
from agent_comms.nominal.field_codec import InputId
from agent_comms.registry.thread_identity import ClaimedIdentity, RecordedThreadIncarnation
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates

generation = 2 if next_owner else 1
scope = LiveQueueScope(
Expand Down
2 changes: 1 addition & 1 deletion tests/support/coordination.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path

from agent_comms.acp_extension import CoordinationChangedUpdate
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates
from agent_comms.execution.child_process import ProcessIdentity
from agent_comms.execution.context_reading import ContextReading, UnmeasuredContext
from agent_comms.projects.checkouts import Checkout
Expand Down
2 changes: 1 addition & 1 deletion tests/support/core_adapters/mcp_turn_boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
McpClientAcknowledgementUpdate,
TurnChangedUpdate,
)
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates
from agent_comms.comms import wire
from agent_comms.coordination.coordinator import Coordination
from agent_comms.execution.launch_runtime import ThreadLaunch
Expand Down
4 changes: 2 additions & 2 deletions tests/support/core_adapters/typed_turn_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
import agent_comms.agent_events as agent_events
from agent_comms.agent_event_updates import AcpEventConsumer
from agent_comms.coordination.coordinator import Coordination
from agent_comms.execution.controller import SessionUpdateSink
from agent_comms.nominal.field_codec import AcpSessionId, TurnId
from agent_comms.transport.acp_update_sink import AcpUpdateSink
from mcp_turn_boundaries import turn_source

SESSION = AcpSessionId("pilot")


class Pipe(SessionUpdateSink):
class Pipe(AcpUpdateSink):
async def publish_update(self, *, session_id, update):
print(json.dumps({"jsonrpc": "2.0", "method": "session/update", "params": {
"sessionId": session_id,
Expand Down
2 changes: 1 addition & 1 deletion tests/support/peers/delayed_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
CoordinationChangedUpdate,
TranscriptSnapshotUpdate,
)
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates
from agent_comms.execution.session_file import RegistrySessionLocation
from base import Peer

Expand Down
12 changes: 8 additions & 4 deletions tests/support/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import asyncio
import inspect
from abc import ABC, abstractmethod
from collections.abc import Callable, Iterator
from contextlib import contextmanager
from collections.abc import AsyncIterator, Callable
from contextlib import asynccontextmanager
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -509,8 +509,8 @@ def core_service(self):
def failure(self) -> BaseException | None:
return self.app._exception or self.errors.unexpected(self)

@contextmanager
def reporting_error(self) -> Iterator[None]:
@asynccontextmanager
async def reporting_error(self) -> AsyncIterator[None]:
"""The enclosed steps show exactly one error on purpose; it is acknowledged when they end,
and any second error saved in the same steps fails the test instead of hiding behind it."""
if unexpected := self.errors.unexpected(self):
Expand All @@ -519,6 +519,10 @@ def reporting_error(self) -> Iterator[None]:
self.errors = ExpectsErrors()
try:
yield
await self.until(
lambda: frozenset(self.reported_errors()) - before,
why="the expected error reported",
)
finally:
saved = frozenset(self.reported_errors())
self.errors = RefusesErrors(saved)
Expand Down
3 changes: 2 additions & 1 deletion tests/support/warm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def become_helper(numbers: list[int], received: list[int], *, pipe: int,
and one that does starts its own tracker on demand."""
os.environ.clear()
os.environ.update(environment)
moved = [fcntl.fcntl(fd, fcntl.F_DUPFD_CLOEXEC, 1024) for fd in received]
# Preserve every source before restoring targets, without assuming a file limit.
moved = [fcntl.fcntl(fd, fcntl.F_DUPFD_CLOEXEC, max(numbers) + 1) for fd in received]
for fd in received:
os.close(fd)
for fd, number in zip(moved, numbers):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async def test_a_settings_file_that_cannot_be_written_is_reported_kept_dirty_and
original = path.read_bytes()
path.unlink()
path.mkdir()
with ui.reporting_error():
async with ui.reporting_error():
app.saved_settings.set(SETTINGS.ui.footer, False)
await app.saved_settings.save()
assert app.saved_settings.unsaved and path.is_dir()
Expand Down
2 changes: 1 addition & 1 deletion tests/textual/test_cursor_request_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
CursorEnvelope,
VerifiedCursorObservation,
)
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates
from agent_comms.execution.child_process import ProcessIdentity
from agent_comms.nominal.field_codec import AcpSessionId, RootId
from agent_comms.execution.native_input_record import (
Expand Down
2 changes: 1 addition & 1 deletion tests/textual/test_error_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def test_an_error_with_markup_brackets_is_shown_verbatim(workspace):
async with workspace.app(size=(110, 30)) as ui:
app, pilot = ui.textual
record_notifications(app)
with ui.reporting_error():
async with ui.reporting_error():
app.show_error(ValueError("bad [bold] value"), "Settings")
await pilot.pause()
# Toad presents notifications through TerminalAttention, which parsed markup and crashed on brackets.
Expand Down
2 changes: 1 addition & 1 deletion tests/textual/test_initial_session_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest
from acp.schema import AgentCapabilities, InitializeResponse, LoadSessionResponse, NewSessionResponse
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates

from support.agents import command
from support.coordination import coordination_fact
Expand Down
53 changes: 31 additions & 22 deletions tests/textual/test_input_failure_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

from acp.exceptions import RequestError
from agent_comms.execution.acp_failure import (
ACPFailure,
InputFailedUpdate,
RequestFailedUpdate,
)
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates
from agent_comms.execution.acp_failure import BackendDeliveryFailure
from support.agents import deliver

from toad.command_catalog import CommandCatalog
from toad.conversation_submission import ImmediateInputSubmission
from toad.core.input_events import UserInputSubmitted

Expand All @@ -38,9 +40,10 @@ async def test_a_prompt_whose_request_fails_is_restored_to_the_composer(workspac
receiver = ui.detached_agent("fixture")
ui.attach_agent(receiver)
await ui.write_draft("")
with patch.object(receiver.process, "prompt", side_effect=error):
await receiver.controller.submit("rpc prompt")
await ui.until(lambda: ui.draft() == "rpc prompt", why="the failed request's text back in the draft")
async with ui.reporting_error():
with patch.object(receiver.process, "prompt", side_effect=error):
await receiver.controller.submit("rpc prompt")
await ui.until(lambda: ui.draft() == "rpc prompt", why="the failed request's text back in the draft")
if isinstance(error, ConnectionError):
failure = receiver.session.disposition.failure
assert "Unconfirmed" in failure.details
Expand All @@ -64,18 +67,22 @@ async def test_a_provider_error_fails_its_turn_and_keeps_the_thread_and_model_se
ui.attach_agent(receiver)
receiver.configuration.receive([schema.SessionConfigOptionSelect.model_validate(MODEL_ADVERTISEMENT)])
disposition = receiver.session.disposition
assert ui.conversation.model_selection_available
assert receiver.configuration.model.available
await ui.write_draft("")
with patch.object(receiver.process, "prompt",
side_effect=RequestError.internal_error({"details": "WebSocket error"})):
await receiver.controller.submit("rpc prompt")
await ui.until(lambda: ui.draft() == "rpc prompt", why="the failed request's text back in the draft")
await deliver(receiver, {
"sessionUpdate": "session_info_update",
"_meta": encode_updates(RequestFailedUpdate(BackendDeliveryFailure("provider refused the model")))})
await ui.step()
async with ui.reporting_error():
with patch.object(receiver.process, "prompt",
side_effect=RequestError.internal_error({"details": "WebSocket error"})):
await receiver.controller.submit("rpc prompt")
await ui.until(lambda: ui.draft() == "rpc prompt", why="the failed request's text back in the draft")
async with ui.reporting_error():
await deliver(receiver, {
"sessionUpdate": "session_info_update",
"_meta": encode_updates(RequestFailedUpdate(ACPFailure.from_detail(None, "provider refused the model")))})
await ui.step()
assert receiver.session.disposition is disposition
assert ui.conversation.model_selection_available
assert receiver.configuration.model.available
await CommandCatalog.execute("/model", ui.conversation)
await ui.until(lambda: ui.conversation.prompt.model_switcher.is_open, why="model selection after provider failure")
await receiver.stop()


Expand All @@ -85,10 +92,11 @@ async def test_a_prompt_the_agent_cannot_be_reached_for_is_restored_to_the_compo
receiver = ui.detached_agent("fixture")
ui.attach_agent(receiver)
await ui.write_draft("")
with patch.object(receiver.process, "prompt", side_effect=FileNotFoundError(2, "agent socket disappeared")):
worker = await ImmediateInputSubmission("the local failure prompt", ()).execute(conversation.submissions)
await worker.wait()
await ui.until(lambda: ui.draft() == "the local failure prompt", why="the failed prompt back in the draft")
async with ui.reporting_error():
with patch.object(receiver.process, "prompt", side_effect=FileNotFoundError(2, "agent socket disappeared")):
worker = await ImmediateInputSubmission("the local failure prompt", ()).execute(conversation.submissions)
await worker.wait()
await ui.until(lambda: ui.draft() == "the local failure prompt", why="the failed prompt back in the draft")
await receiver.stop()


Expand Down Expand Up @@ -193,9 +201,10 @@ async def test_a_send_whose_reply_cannot_be_read_returns_the_draft(workspace):
await ui.open_direct("peer", actor=workspace.viewer)
chat = ui.app.selected_session.query_one(CommsChatView)
unreadable = UnsupportedFieldType("Unsupported JSON type: ToolResult")
with patch.object(Observing, "send_user_message", side_effect=unreadable), ui.reporting_error():
worker = await chat.submissions.submit(UserInputSubmitted("UNREADABLE_REPLY_SEND"))
with pytest.raises(WorkerFailed):
await worker.wait()
with patch.object(Observing, "send_user_message", side_effect=unreadable):
async with ui.reporting_error():
worker = await chat.submissions.submit(UserInputSubmitted("UNREADABLE_REPLY_SEND"))
with pytest.raises(WorkerFailed):
await worker.wait()
assert not chat.submissions.delivering
assert chat.prompt.text == "UNREADABLE_REPLY_SEND"
2 changes: 1 addition & 1 deletion tests/textual/test_observation_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def test_an_observer_dying_during_shutdown_still_releases_its_resources(wo
process = access.observation.observed().process
assert not (await asyncio.wait_for(process.read(empty_read(workspace)), 30)).outcomes
reading = None
with ui.reporting_error():
async with ui.reporting_error():
try:
async with held(process) as pid:
reading = asyncio.create_task(process.read(empty_read(workspace)))
Expand Down
2 changes: 1 addition & 1 deletion tests/textual/test_quit_with_unsaved_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def test_quit_that_cannot_save_stays_open_and_a_retry_saves_the_edit_and_e
original = path.read_bytes()
path.unlink()
path.mkdir()
with ui.reporting_error():
async with ui.reporting_error():
await ui.press('home', 'shift+end', '1', '3', '7', 'ctrl+q')
await ui.until_shows('Failed to write')
assert app.is_running and not app._exit
Expand Down
2 changes: 1 addition & 1 deletion tests/textual/test_sent_message_drawn_once.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
NoQueueScope,
UnidentifiedInputStarted,
)
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates
from agent_comms.execution.session_file import RegistrySessionLocation
from agent_comms.nominal.field_codec import InputId
from agent_comms.projects.checkouts import Checkout
Expand Down
2 changes: 1 addition & 1 deletion tests/textual/test_session_agent_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from agent_comms.acp_extension import CoordinationChangedUpdate
from agent_comms.text_route_update import encode_updates
from agent_comms.execution.session_updates import encode_updates
from agent_comms.execution.child_process import ProcessIdentity
from agent_comms.ui_model.delivery import DeliveryView

Expand Down
7 changes: 4 additions & 3 deletions tests/textual/test_session_start_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ async def test_a_failed_mount_names_the_session_and_leaves_no_dead_view(workspac
async with workspace.app(size=(110, 35)) as ui:
app, _ = ui.textual
before = set(app.workspace_sessions.views)
with ui.reporting_error(), pytest.raises(SessionStartFailed):
await app.session_navigation.new(
await saved_tab(app), lambda: FailsToStart(Checkout(workspace.project)))
async with ui.reporting_error():
with pytest.raises(SessionStartFailed):
await app.session_navigation.new(
await saved_tab(app), lambda: FailsToStart(Checkout(workspace.project)))
assert set(app.workspace_sessions.views) == before
2 changes: 1 addition & 1 deletion tests/textual/test_transcript_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def record_unhandled(loop: asyncio.AbstractEventLoop, context: dict[str, object]
async def failed_read():
raise error

with ui.reporting_error():
async with ui.reporting_error():
worker = history.reserve_source_work().schedule(history, failed_read)
await ui.until(lambda: worker.is_finished, why="the failed pager finishes")
logs = set(get_errors().glob("*.txt")) - before
Expand Down
Loading