`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.
Parallel directories for one source package, folded into the mirror:
tests/acp -> tests/acp_adapter (its __init__/conftest move with it)
tests/cli -> tests/hermes_cli (prompt_toolkit fixture merged into
hermes_cli/conftest.py)
tests/run_agent -> tests/agent (backoff fixture becomes
agent/conftest.py)
tests/relay -> tests/gateway/relay
tests/state -> tests/hermes_state
246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.
Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.
Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).
Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
118 lines
5.7 KiB
Python
118 lines
5.7 KiB
Python
"""Blocking prompts reclaim input from the nested monitor without a keypress."""
|
|
import asyncio
|
|
import threading
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.parametrize('paint_source', ['modal', 'tick'])
|
|
def test_prompt_paint_yields_monitor_but_ordinary_paint_does_not(monkeypatch, paint_source):
|
|
from hermes_cli.cli_subagent_monitor import SubagentMonitor, build_monitor_application, install_dock
|
|
from hermes_cli.cli_terminal_mixin import CLITerminalMixin
|
|
from prompt_toolkit.input import create_pipe_input
|
|
from prompt_toolkit.output import DummyOutput
|
|
|
|
async def run():
|
|
for name in ('_approval_state', '_clarify_state', '_secret_state', '_sudo_state',
|
|
'_slash_confirm_state'):
|
|
dock_cli = SimpleNamespace(agent=None)
|
|
install_dock(dock_cli)
|
|
dock_cli._subagent_monitor.entries = [{}]
|
|
assert dock_cli._subagent_dock_widget.filter()
|
|
setattr(dock_cli, name, {'pending': True})
|
|
assert not dock_cli._subagent_dock_widget.filter(), 'dock crowds the blocking prompt'
|
|
cli = SimpleNamespace(_app=None)
|
|
monitor = SubagentMonitor(cli)
|
|
cli._subagent_monitor = monitor
|
|
with create_pipe_input() as pipe:
|
|
app = build_monitor_application(monitor, input=pipe, output=DummyOutput())
|
|
monitor.app = app
|
|
rendered = asyncio.Event()
|
|
app.after_render += lambda app: rendered.set()
|
|
task = asyncio.create_task(app.run_async())
|
|
await asyncio.wait_for(rendered.wait(), 3)
|
|
try:
|
|
rendered.clear()
|
|
await asyncio.to_thread(CLITerminalMixin._paint_now, cli)
|
|
await asyncio.wait_for(rendered.wait(), 3)
|
|
assert not task.done(), 'ordinary paints must not dismiss the monitor'
|
|
loop = asyncio.get_running_loop()
|
|
ui_thread = threading.get_ident()
|
|
stopped = threading.Event()
|
|
task.add_done_callback(lambda _: stopped.set())
|
|
schedule = loop.call_soon_threadsafe
|
|
|
|
def schedule_with_teardown(callback, *args, **kwargs):
|
|
handle = schedule(callback, *args, **kwargs)
|
|
if (callback == app.on_invalidate.fire
|
|
and threading.get_ident() != ui_thread):
|
|
# Let an already-queued frame see the modal and finish
|
|
# teardown while the worker is still in invalidate().
|
|
schedule(app._redraw)
|
|
assert stopped.wait(3), 'monitor did not finish teardown'
|
|
return handle
|
|
|
|
setattr(cli, name, {'pending': True})
|
|
with monkeypatch.context() as patch:
|
|
patch.setattr(loop, 'call_soon_threadsafe', schedule_with_teardown)
|
|
if paint_source == 'tick':
|
|
patch.setattr(monitor, 'refresh', lambda: True)
|
|
await asyncio.to_thread(monitor.tick)
|
|
else:
|
|
await asyncio.to_thread(CLITerminalMixin._paint_now, cli)
|
|
done, _ = await asyncio.wait({task}, timeout=1)
|
|
assert task in done, f'{name} remained hidden behind the monitor'
|
|
await task
|
|
finally:
|
|
if not task.done():
|
|
app.exit()
|
|
await task
|
|
asyncio.run(run())
|
|
|
|
|
|
def test_secret_callback_yields_monitor_and_restores_composer():
|
|
from hermes_cli.cli_subagent_monitor import SubagentMonitor, build_monitor_application
|
|
from hermes_cli.cli_terminal_mixin import CLITerminalMixin
|
|
from hermes_cli.cli_modal_mixin import CLIModalMixin
|
|
from prompt_toolkit.buffer import Buffer
|
|
from prompt_toolkit.document import Document
|
|
from prompt_toolkit.input import create_pipe_input
|
|
from prompt_toolkit.output import DummyOutput
|
|
|
|
class CLI(CLIModalMixin, CLITerminalMixin):
|
|
def _ring_bell(self, **kwargs):
|
|
pass
|
|
|
|
async def run():
|
|
cli = CLI()
|
|
draft = Document('keep my draft', 4)
|
|
buffer = Buffer(document=draft)
|
|
cli._app = SimpleNamespace(current_buffer=buffer, invalidate=lambda: None)
|
|
cli._modal_input_snapshot = None
|
|
monitor = cli._subagent_monitor = SubagentMonitor(cli)
|
|
with create_pipe_input() as pipe:
|
|
monitor.app = build_monitor_application(monitor, input=pipe, output=DummyOutput())
|
|
rendered = asyncio.Event()
|
|
monitor.app.after_render += lambda app: rendered.set()
|
|
task = asyncio.create_task(monitor.app.run_async())
|
|
await asyncio.wait_for(rendered.wait(), 3)
|
|
callback = asyncio.create_task(asyncio.to_thread(
|
|
cli._secret_capture_callback, 'FIXTURE_SECRET', 'Owned fixture'))
|
|
try:
|
|
done, _ = await asyncio.wait({task}, timeout=1)
|
|
assert task in done, 'secret arrival did not immediately reclaim input'
|
|
assert buffer.text == '', 'draft must not be submitted as a secret'
|
|
cli._submit_secret_response('')
|
|
result = await asyncio.wait_for(callback, 3)
|
|
assert result['skipped']
|
|
assert buffer.document == draft
|
|
finally:
|
|
if not task.done():
|
|
monitor.app.exit()
|
|
await task
|
|
if not callback.done():
|
|
cli._submit_secret_response('')
|
|
await callback
|
|
asyncio.run(run())
|