hermes-agent/tests/tools/test_bot_mode_dm_entry.py

161 lines
7.7 KiB
Python
Raw Permalink Normal View History

fix(bot-mode): the delivery runner and reply waiter activate Hermes dependencies when spawned on the bare store interpreter message_agent spawns its background runner as `<sys.executable> tools/bot_mode_dm.py --run-delivery ...`, and the relay's reply waiter (bot_relay.waiter_command) as `... bot_mode_dm.py --wait-reply ...`. Both enter through the shared `if __name__ == "__main__":` block, which only put the repo root on sys.path. Under a PM-managed install sys.executable is the bare store interpreter: dependencies are activated in-process at boot by hermes_bootstrap (pm.environments.activate_dependencies), and the terminal backend strips the Hermes-owned PYTHONPATH, so the child has no third-party packages. Live, every local Bot Chat DM returned `{"status": "ambiguous", "error": "Live admission outcome unknown: No module named 'ruamel'. Do not resend."}` from _run_delivery -> _admit_live_dm. The __main__ block now imports hermes_bootstrap after putting the repo root on sys.path (run as a script path, sys.path[0] is tools/). This is the same pattern as tui_gateway/compute_host.py and agent/transports/hermes_tools_mcp_server.py: only the script entry bootstraps, so importing tools.bot_mode_dm as a library stays side-effect free and the module's top-level imports stay stdlib-only. hermes_bootstrap rather than a bare activate_dependencies() call, because the runner is a real entry point and needs what every entry point gets: dependency activation plus early recovery of an interrupted update, the Windows UTF-8 stdio bootstrap (its stdout carries the teammate's reply as the completion notification), and import-path hardening against a cwd package shadowing Hermes modules. The runner argv is safe for the bootstrap: command_argv() reads `--run-delivery`/`--wait-reply` as flags, so it is neither `update --post-swap` nor `pm repair`. prepare_launch acts only on a self-updated install whose dependencies are behind or whose interpreter is not the store Python, and its relaunch re-runs the same script path with the same argv (runpy.run_path), so the runner keeps its contract there too. tests/tools/test_bot_mode_dm_entry.py launches the real script under `-I -S` with a PM-committed dependency record in a temp HERMES_HOME as the only route to the packages: the --run-delivery case fails on the parent commit with the exact live `No module named 'ruamel'` error and passes here; the --wait-reply case drives the argv waiter_command builds through the same entry.
2026-09-25 23:18:49 +03:00
"""The ``bot_mode_dm.py`` runner entry boots Hermes' dependency environment itself.
``message_agent`` spawns ``<sys.executable> tools/bot_mode_dm.py --run-delivery …`` and the relay
spawns ``… --wait-reply …`` (``bot_relay.waiter_command``). Under a PM-managed install
``sys.executable`` is the bare store interpreter: dependencies are activated in-process at boot,
and the terminal backend strips the Hermes-owned ``PYTHONPATH``, so a runner that does not boot
like every other entry point dies on its first third-party import. Live, every local Bot Chat DM
came back ``Live admission outcome unknown: No module named 'ruamel'. Do not resend.``
Each test launches the real script under ``-I -S`` (no site-packages, no ``PYTHON*`` env), with a
PM-committed dependency record in a temp ``HERMES_HOME`` as the only way to reach the packages.
"""
import json
import os
import shlex
import subprocess
import sys
from pathlib import Path
import pytest
from pm.environments import install_state_dir, runtime_facts_path, site_packages
from tools import bot_relay
from tools.bot_mode_dm import _dm_delivery_id
fix(bot-mode): the delivery runner and reply waiter activate Hermes dependencies when spawned on the bare store interpreter message_agent spawns its background runner as `<sys.executable> tools/bot_mode_dm.py --run-delivery ...`, and the relay's reply waiter (bot_relay.waiter_command) as `... bot_mode_dm.py --wait-reply ...`. Both enter through the shared `if __name__ == "__main__":` block, which only put the repo root on sys.path. Under a PM-managed install sys.executable is the bare store interpreter: dependencies are activated in-process at boot by hermes_bootstrap (pm.environments.activate_dependencies), and the terminal backend strips the Hermes-owned PYTHONPATH, so the child has no third-party packages. Live, every local Bot Chat DM returned `{"status": "ambiguous", "error": "Live admission outcome unknown: No module named 'ruamel'. Do not resend."}` from _run_delivery -> _admit_live_dm. The __main__ block now imports hermes_bootstrap after putting the repo root on sys.path (run as a script path, sys.path[0] is tools/). This is the same pattern as tui_gateway/compute_host.py and agent/transports/hermes_tools_mcp_server.py: only the script entry bootstraps, so importing tools.bot_mode_dm as a library stays side-effect free and the module's top-level imports stay stdlib-only. hermes_bootstrap rather than a bare activate_dependencies() call, because the runner is a real entry point and needs what every entry point gets: dependency activation plus early recovery of an interrupted update, the Windows UTF-8 stdio bootstrap (its stdout carries the teammate's reply as the completion notification), and import-path hardening against a cwd package shadowing Hermes modules. The runner argv is safe for the bootstrap: command_argv() reads `--run-delivery`/`--wait-reply` as flags, so it is neither `update --post-swap` nor `pm repair`. prepare_launch acts only on a self-updated install whose dependencies are behind or whose interpreter is not the store Python, and its relaunch re-runs the same script path with the same argv (runpy.run_path), so the runner keeps its contract there too. tests/tools/test_bot_mode_dm_entry.py launches the real script under `-I -S` with a PM-committed dependency record in a temp HERMES_HOME as the only route to the packages: the --run-delivery case fails on the parent commit with the exact live `No module named 'ruamel'` error and passes here; the --wait-reply case drives the argv waiter_command builds through the same entry.
2026-09-25 23:18:49 +03:00
REPO = Path(__file__).resolve().parents[2]
RUNNER = REPO / "tools" / "bot_mode_dm.py"
# A bare interpreter: isolated (-I ignores PYTHONPATH/PYTHONHOME, user site) and no site
# module (-S), so no third-party package is importable unless the entry activates one.
BARE = [sys.executable, "-I", "-S"]
@pytest.fixture
def committed_home(tmp_path, monkeypatch):
"""A temp ``HERMES_HOME`` whose install state commits a dependency generation for REPO.
The generation's site-packages carries a ``.pth`` naming this interpreter's own package
directories, so activating it (and only activating it) makes the real dependencies importable.
"""
home = tmp_path / "hermes-home"
home.mkdir()
monkeypatch.setenv("HERMES_HOME", str(home))
venv = install_state_dir(REPO) / "environments" / "gen" / "venv"
venv.mkdir(parents=True)
(venv / "pyvenv.cfg").write_text(
"version = {}.{}.{}\n".format(*sys.version_info[:3]), encoding="utf-8")
packages = site_packages(venv)
packages.mkdir(parents=True)
dirs = [p for p in sys.path if p and Path(p).is_dir() and Path(p).resolve() != REPO]
(packages / "hermes-test-deps.pth").write_text("\n".join(dirs) + "\n", encoding="utf-8")
return home, _commit(home, venv)
@pytest.fixture
def uncommittable_home(tmp_path, monkeypatch):
"""A temp ``HERMES_HOME`` whose committed generation is gone, so activation cannot succeed."""
home = tmp_path / "hermes-home"
home.mkdir()
monkeypatch.setenv("HERMES_HOME", str(home))
install_state_dir(REPO).mkdir(parents=True)
return home, _commit(home, install_state_dir(REPO) / "environments" / "missing" / "venv")
def _commit(home, venv):
fix(bot-mode): the delivery runner and reply waiter activate Hermes dependencies when spawned on the bare store interpreter message_agent spawns its background runner as `<sys.executable> tools/bot_mode_dm.py --run-delivery ...`, and the relay's reply waiter (bot_relay.waiter_command) as `... bot_mode_dm.py --wait-reply ...`. Both enter through the shared `if __name__ == "__main__":` block, which only put the repo root on sys.path. Under a PM-managed install sys.executable is the bare store interpreter: dependencies are activated in-process at boot by hermes_bootstrap (pm.environments.activate_dependencies), and the terminal backend strips the Hermes-owned PYTHONPATH, so the child has no third-party packages. Live, every local Bot Chat DM returned `{"status": "ambiguous", "error": "Live admission outcome unknown: No module named 'ruamel'. Do not resend."}` from _run_delivery -> _admit_live_dm. The __main__ block now imports hermes_bootstrap after putting the repo root on sys.path (run as a script path, sys.path[0] is tools/). This is the same pattern as tui_gateway/compute_host.py and agent/transports/hermes_tools_mcp_server.py: only the script entry bootstraps, so importing tools.bot_mode_dm as a library stays side-effect free and the module's top-level imports stay stdlib-only. hermes_bootstrap rather than a bare activate_dependencies() call, because the runner is a real entry point and needs what every entry point gets: dependency activation plus early recovery of an interrupted update, the Windows UTF-8 stdio bootstrap (its stdout carries the teammate's reply as the completion notification), and import-path hardening against a cwd package shadowing Hermes modules. The runner argv is safe for the bootstrap: command_argv() reads `--run-delivery`/`--wait-reply` as flags, so it is neither `update --post-swap` nor `pm repair`. prepare_launch acts only on a self-updated install whose dependencies are behind or whose interpreter is not the store Python, and its relaunch re-runs the same script path with the same argv (runpy.run_path), so the runner keeps its contract there too. tests/tools/test_bot_mode_dm_entry.py launches the real script under `-I -S` with a PM-committed dependency record in a temp HERMES_HOME as the only route to the packages: the --run-delivery case fails on the parent commit with the exact live `No module named 'ruamel'` error and passes here; the --wait-reply case drives the argv waiter_command builds through the same entry.
2026-09-25 23:18:49 +03:00
runtime_facts_path(REPO).write_text(
json.dumps({"packages": {"venv": {"environment": str(venv)}}}), encoding="utf-8")
env = {k: v for k, v in os.environ.items() if k not in ("PYTHONPATH", "PYTHONHOME", "VIRTUAL_ENV")}
env["HERMES_HOME"] = str(home)
return env
fix(bot-mode): the delivery runner and reply waiter activate Hermes dependencies when spawned on the bare store interpreter message_agent spawns its background runner as `<sys.executable> tools/bot_mode_dm.py --run-delivery ...`, and the relay's reply waiter (bot_relay.waiter_command) as `... bot_mode_dm.py --wait-reply ...`. Both enter through the shared `if __name__ == "__main__":` block, which only put the repo root on sys.path. Under a PM-managed install sys.executable is the bare store interpreter: dependencies are activated in-process at boot by hermes_bootstrap (pm.environments.activate_dependencies), and the terminal backend strips the Hermes-owned PYTHONPATH, so the child has no third-party packages. Live, every local Bot Chat DM returned `{"status": "ambiguous", "error": "Live admission outcome unknown: No module named 'ruamel'. Do not resend."}` from _run_delivery -> _admit_live_dm. The __main__ block now imports hermes_bootstrap after putting the repo root on sys.path (run as a script path, sys.path[0] is tools/). This is the same pattern as tui_gateway/compute_host.py and agent/transports/hermes_tools_mcp_server.py: only the script entry bootstraps, so importing tools.bot_mode_dm as a library stays side-effect free and the module's top-level imports stay stdlib-only. hermes_bootstrap rather than a bare activate_dependencies() call, because the runner is a real entry point and needs what every entry point gets: dependency activation plus early recovery of an interrupted update, the Windows UTF-8 stdio bootstrap (its stdout carries the teammate's reply as the completion notification), and import-path hardening against a cwd package shadowing Hermes modules. The runner argv is safe for the bootstrap: command_argv() reads `--run-delivery`/`--wait-reply` as flags, so it is neither `update --post-swap` nor `pm repair`. prepare_launch acts only on a self-updated install whose dependencies are behind or whose interpreter is not the store Python, and its relaunch re-runs the same script path with the same argv (runpy.run_path), so the runner keeps its contract there too. tests/tools/test_bot_mode_dm_entry.py launches the real script under `-I -S` with a PM-committed dependency record in a temp HERMES_HOME as the only route to the packages: the --run-delivery case fails on the parent commit with the exact live `No module named 'ruamel'` error and passes here; the --wait-reply case drives the argv waiter_command builds through the same entry.
2026-09-25 23:18:49 +03:00
def _run(argv, env):
return subprocess.run(argv, capture_output=True, text=True, encoding="utf-8", errors="replace",
env=env, cwd=str(REPO.parent), timeout=120, check=False)
fix(bot-mode): the delivery runner and reply waiter activate Hermes dependencies when spawned on the bare store interpreter message_agent spawns its background runner as `<sys.executable> tools/bot_mode_dm.py --run-delivery ...`, and the relay's reply waiter (bot_relay.waiter_command) as `... bot_mode_dm.py --wait-reply ...`. Both enter through the shared `if __name__ == "__main__":` block, which only put the repo root on sys.path. Under a PM-managed install sys.executable is the bare store interpreter: dependencies are activated in-process at boot by hermes_bootstrap (pm.environments.activate_dependencies), and the terminal backend strips the Hermes-owned PYTHONPATH, so the child has no third-party packages. Live, every local Bot Chat DM returned `{"status": "ambiguous", "error": "Live admission outcome unknown: No module named 'ruamel'. Do not resend."}` from _run_delivery -> _admit_live_dm. The __main__ block now imports hermes_bootstrap after putting the repo root on sys.path (run as a script path, sys.path[0] is tools/). This is the same pattern as tui_gateway/compute_host.py and agent/transports/hermes_tools_mcp_server.py: only the script entry bootstraps, so importing tools.bot_mode_dm as a library stays side-effect free and the module's top-level imports stay stdlib-only. hermes_bootstrap rather than a bare activate_dependencies() call, because the runner is a real entry point and needs what every entry point gets: dependency activation plus early recovery of an interrupted update, the Windows UTF-8 stdio bootstrap (its stdout carries the teammate's reply as the completion notification), and import-path hardening against a cwd package shadowing Hermes modules. The runner argv is safe for the bootstrap: command_argv() reads `--run-delivery`/`--wait-reply` as flags, so it is neither `update --post-swap` nor `pm repair`. prepare_launch acts only on a self-updated install whose dependencies are behind or whose interpreter is not the store Python, and its relaunch re-runs the same script path with the same argv (runpy.run_path), so the runner keeps its contract there too. tests/tools/test_bot_mode_dm_entry.py launches the real script under `-I -S` with a PM-committed dependency record in a temp HERMES_HOME as the only route to the packages: the --run-delivery case fails on the parent commit with the exact live `No module named 'ruamel'` error and passes here; the --wait-reply case drives the argv waiter_command builds through the same entry.
2026-09-25 23:18:49 +03:00
def test_delivery_runner_admits_through_dependencies_it_activates(tmp_path, committed_home):
"""Live admission (``_admit_live_dm``) imports Hermes' third-party graph. Launched bare, the
runner must activate the committed environment and find no live owner — never report an
``ambiguous`` import failure. With no owner the local CLI transport fallback is retired: the
runner answers the typed not-ready refusal and retains the DM, never handing it to the
transport."""
fix(bot-mode): the delivery runner and reply waiter activate Hermes dependencies when spawned on the bare store interpreter message_agent spawns its background runner as `<sys.executable> tools/bot_mode_dm.py --run-delivery ...`, and the relay's reply waiter (bot_relay.waiter_command) as `... bot_mode_dm.py --wait-reply ...`. Both enter through the shared `if __name__ == "__main__":` block, which only put the repo root on sys.path. Under a PM-managed install sys.executable is the bare store interpreter: dependencies are activated in-process at boot by hermes_bootstrap (pm.environments.activate_dependencies), and the terminal backend strips the Hermes-owned PYTHONPATH, so the child has no third-party packages. Live, every local Bot Chat DM returned `{"status": "ambiguous", "error": "Live admission outcome unknown: No module named 'ruamel'. Do not resend."}` from _run_delivery -> _admit_live_dm. The __main__ block now imports hermes_bootstrap after putting the repo root on sys.path (run as a script path, sys.path[0] is tools/). This is the same pattern as tui_gateway/compute_host.py and agent/transports/hermes_tools_mcp_server.py: only the script entry bootstraps, so importing tools.bot_mode_dm as a library stays side-effect free and the module's top-level imports stay stdlib-only. hermes_bootstrap rather than a bare activate_dependencies() call, because the runner is a real entry point and needs what every entry point gets: dependency activation plus early recovery of an interrupted update, the Windows UTF-8 stdio bootstrap (its stdout carries the teammate's reply as the completion notification), and import-path hardening against a cwd package shadowing Hermes modules. The runner argv is safe for the bootstrap: command_argv() reads `--run-delivery`/`--wait-reply` as flags, so it is neither `update --post-swap` nor `pm repair`. prepare_launch acts only on a self-updated install whose dependencies are behind or whose interpreter is not the store Python, and its relaunch re-runs the same script path with the same argv (runpy.run_path), so the runner keeps its contract there too. tests/tools/test_bot_mode_dm_entry.py launches the real script under `-I -S` with a PM-committed dependency record in a temp HERMES_HOME as the only route to the packages: the --run-delivery case fails on the parent commit with the exact live `No module named 'ruamel'` error and passes here; the --wait-reply case drives the argv waiter_command builds through the same entry.
2026-09-25 23:18:49 +03:00
_home, env = committed_home
profile_home = tmp_path / "profile"
profile_home.mkdir()
dm_file = tmp_path / "dm.txt"
dm_file.write_text("hello teammate", encoding="utf-8")
# The transport echoes the DM file it receives via --query-file.
transport = [sys.executable, "-I", "-S", "-c", "import sys; print(open(sys.argv[2], encoding='utf-8').read())"]
result = _run([*BARE, str(RUNNER), "--run-delivery", "query-file", str(dm_file),
"--profile-home", str(profile_home), *transport], env)
assert "No module named" not in result.stdout + result.stderr, result
assert result.returncode == 1, result
payload = json.loads(result.stdout)
assert payload["delivery_id"] == _dm_delivery_id(str(dm_file)), payload
assert "profile authority is not ready" in payload["error"], payload
assert "hello teammate" not in result.stdout # the transport never ran
assert dm_file.read_text(encoding="utf-8") == "hello teammate"
fix(bot-mode): the delivery runner and reply waiter activate Hermes dependencies when spawned on the bare store interpreter message_agent spawns its background runner as `<sys.executable> tools/bot_mode_dm.py --run-delivery ...`, and the relay's reply waiter (bot_relay.waiter_command) as `... bot_mode_dm.py --wait-reply ...`. Both enter through the shared `if __name__ == "__main__":` block, which only put the repo root on sys.path. Under a PM-managed install sys.executable is the bare store interpreter: dependencies are activated in-process at boot by hermes_bootstrap (pm.environments.activate_dependencies), and the terminal backend strips the Hermes-owned PYTHONPATH, so the child has no third-party packages. Live, every local Bot Chat DM returned `{"status": "ambiguous", "error": "Live admission outcome unknown: No module named 'ruamel'. Do not resend."}` from _run_delivery -> _admit_live_dm. The __main__ block now imports hermes_bootstrap after putting the repo root on sys.path (run as a script path, sys.path[0] is tools/). This is the same pattern as tui_gateway/compute_host.py and agent/transports/hermes_tools_mcp_server.py: only the script entry bootstraps, so importing tools.bot_mode_dm as a library stays side-effect free and the module's top-level imports stay stdlib-only. hermes_bootstrap rather than a bare activate_dependencies() call, because the runner is a real entry point and needs what every entry point gets: dependency activation plus early recovery of an interrupted update, the Windows UTF-8 stdio bootstrap (its stdout carries the teammate's reply as the completion notification), and import-path hardening against a cwd package shadowing Hermes modules. The runner argv is safe for the bootstrap: command_argv() reads `--run-delivery`/`--wait-reply` as flags, so it is neither `update --post-swap` nor `pm repair`. prepare_launch acts only on a self-updated install whose dependencies are behind or whose interpreter is not the store Python, and its relaunch re-runs the same script path with the same argv (runpy.run_path), so the runner keeps its contract there too. tests/tools/test_bot_mode_dm_entry.py launches the real script under `-I -S` with a PM-committed dependency record in a temp HERMES_HOME as the only route to the packages: the --run-delivery case fails on the parent commit with the exact live `No module named 'ruamel'` error and passes here; the --wait-reply case drives the argv waiter_command builds through the same entry.
2026-09-25 23:18:49 +03:00
def test_delivery_runner_that_cannot_activate_names_the_repair_remedy(tmp_path, uncommittable_home):
"""When the committed environment cannot be activated, the runner exits with PM's
``hermes pm repair`` remedy before touching the DM, instead of an ambiguous
``No module named …`` outcome the sender is told not to resend."""
_home, env = uncommittable_home
dm_file = tmp_path / "dm.txt"
dm_file.write_text("hello teammate", encoding="utf-8")
result = _run([*BARE, str(RUNNER), "--run-delivery", "query-file", str(dm_file),
sys.executable, "-c", "pass"], env)
assert result.returncode == 1, result
assert "hermes pm repair" in result.stderr
assert "No module named" not in result.stdout + result.stderr
assert result.stdout == "" # nothing was handed over, so no "do not resend" outcome
assert dm_file.read_text(encoding="utf-8") == "hello teammate"
def test_delivery_runner_that_cannot_activate_after_live_admission_stays_ambiguous(tmp_path, uncommittable_home):
"""The sender may already have admitted this DM to the live owner (its pinned intent exists)
and was told not to resend. A runner that then cannot activate must keep that outcome
unknown, with the same delivery id, instead of a bare repair hint that reads as a failure."""
_home, env = uncommittable_home
dm_file = tmp_path / "dm.txt"
dm_file.write_text("hello teammate", encoding="utf-8")
intent = Path(str(dm_file) + ".live.json")
intent.write_text("{}", encoding="utf-8")
result = _run([*BARE, str(RUNNER), "--run-delivery", "query-file", str(dm_file),
"--profile-home", str(tmp_path), sys.executable, "-c", "pass"], env)
assert result.returncode == 1, result
assert "hermes pm repair" in result.stderr
payload = json.loads(result.stdout)
assert payload["status"] == "ambiguous"
assert payload["delivery_id"] == _dm_delivery_id(str(dm_file))
assert "Do not resend" in payload["error"]
assert dm_file.exists() and intent.exists()
@pytest.mark.parametrize("home", ["committed_home", "uncommittable_home"])
def test_reply_waiter_prints_the_reply_whatever_the_dependency_state(tmp_path, request, home):
"""The relay's reply waiter shares the entry but is stdlib only, and its stdout is the
sender's wake-up: its argv, exactly as ``waiter_command`` builds it, must print the reply
whether or not the committed environment can be activated."""
_home, env = request.getfixturevalue(home)
fix(bot-mode): the delivery runner and reply waiter activate Hermes dependencies when spawned on the bare store interpreter message_agent spawns its background runner as `<sys.executable> tools/bot_mode_dm.py --run-delivery ...`, and the relay's reply waiter (bot_relay.waiter_command) as `... bot_mode_dm.py --wait-reply ...`. Both enter through the shared `if __name__ == "__main__":` block, which only put the repo root on sys.path. Under a PM-managed install sys.executable is the bare store interpreter: dependencies are activated in-process at boot by hermes_bootstrap (pm.environments.activate_dependencies), and the terminal backend strips the Hermes-owned PYTHONPATH, so the child has no third-party packages. Live, every local Bot Chat DM returned `{"status": "ambiguous", "error": "Live admission outcome unknown: No module named 'ruamel'. Do not resend."}` from _run_delivery -> _admit_live_dm. The __main__ block now imports hermes_bootstrap after putting the repo root on sys.path (run as a script path, sys.path[0] is tools/). This is the same pattern as tui_gateway/compute_host.py and agent/transports/hermes_tools_mcp_server.py: only the script entry bootstraps, so importing tools.bot_mode_dm as a library stays side-effect free and the module's top-level imports stay stdlib-only. hermes_bootstrap rather than a bare activate_dependencies() call, because the runner is a real entry point and needs what every entry point gets: dependency activation plus early recovery of an interrupted update, the Windows UTF-8 stdio bootstrap (its stdout carries the teammate's reply as the completion notification), and import-path hardening against a cwd package shadowing Hermes modules. The runner argv is safe for the bootstrap: command_argv() reads `--run-delivery`/`--wait-reply` as flags, so it is neither `update --post-swap` nor `pm repair`. prepare_launch acts only on a self-updated install whose dependencies are behind or whose interpreter is not the store Python, and its relaunch re-runs the same script path with the same argv (runpy.run_path), so the runner keeps its contract there too. tests/tools/test_bot_mode_dm_entry.py launches the real script under `-I -S` with a PM-committed dependency record in a temp HERMES_HOME as the only route to the packages: the --run-delivery case fails on the parent commit with the exact live `No module named 'ruamel'` error and passes here; the --wait-reply case drives the argv waiter_command builds through the same entry.
2026-09-25 23:18:49 +03:00
root = tmp_path / "root"
envelope = {"id": "e" * 32, "target_handle": "researcher", "target_connection": "ssh-vps"}
reply_path = bot_relay.relay_root(root) / bot_relay.REPLIES_DIR / f"{envelope['id']}.json"
reply_path.parent.mkdir(parents=True)
reply_path.write_text(json.dumps({"reply": "pong"}), encoding="utf-8")
argv = shlex.split(bot_relay.waiter_command(root, envelope))
result = _run([*BARE, *argv[1:]], env)
assert result.returncode == 0, result
assert result.stdout.splitlines() == ["Reply from @researcher on ssh-vps:", "pong"]