feat: add readable duplex messaging
Some checks failed
tamq-ci / test (push) Failing after 6s

Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a03397-4d51-7fd1-8ff2-946eb22ea2bc
This commit is contained in:
tegwick 2026-08-25 19:26:27 +02:00
parent 788eb8e2ed
commit 92881b6b56
35 changed files with 1206 additions and 806 deletions

View file

@ -8,6 +8,7 @@ from uuid import uuid4
import pytest
from tamq.tmux import LaunchPlan, TmuxManager
from tamq.store import Store
@pytest.mark.skipif(shutil.which("tmux") is None, reason="tmux is not installed")
@ -98,3 +99,82 @@ def test_tap_propagates_terminal_size_resize_and_raw_mouse_input(tmp_path, monke
assert f"RESIZE {resized}" in output
finally:
manager._run("kill-server", check=False)
@pytest.mark.skipif(shutil.which("tmux") is None, reason="tmux is not installed")
def test_real_pty_attributes_worker_output_and_suppresses_operator_echo(
tmp_path, monkeypatch
):
source = tmp_path / "source"
source.mkdir()
fixture = tmp_path / "duplex_fixture.py"
fixture.write_text(
"import sys\n"
"print('READY', flush=True)\n"
"for line in sys.stdin:\n"
" print(line.rstrip('\\r\\n'), flush=True)\n"
" print('To:target: worker reply', flush=True)\n",
encoding="utf-8",
)
bin_dir = tmp_path / "bin"
bin_dir.mkdir()
gita = bin_dir / "gita"
gita.write_text(
"#!/bin/sh\n"
"if [ \"$1\" = ls ]; then printf 'source target\\n'; exit 0; fi\n"
"exit 2\n",
encoding="utf-8",
)
gita.chmod(0o755)
project_src = str(Path(__file__).resolve().parents[1] / "src")
monkeypatch.setenv("PYTHONPATH", project_src)
monkeypatch.setenv("PATH", f"{bin_dir}:{os.environ['PATH']}")
state = tmp_path / "state"
monkeypatch.setenv("TAMQ_STATE_DIR", str(state))
socket_name = f"tamq-duplex-{uuid4().hex[:8]}"
session = f"tamq-duplex-{uuid4().hex[:8]}"
manager = TmuxManager(
session,
tmux_command=("tmux", "-L", socket_name),
tamq_command=(sys.executable, "-m", "tamq.cli"),
command_dir=tmp_path / "commands",
)
plan = LaunchPlan(
("source",), {"source": str(source)}, (sys.executable, str(fixture))
)
store = None
try:
endpoint = manager.ensure_plan(plan, tap=True, tap_limits=(8, 1024, 32768))
deadline = time.monotonic() + 5
while time.monotonic() < deadline:
if "READY" in manager._run(
"capture-pane", "-p", "-t", f"{session}:source"
):
break
time.sleep(0.05)
manager._run(
"send-keys",
"-t",
f"{session}:source",
"-l",
"--",
"To:target: operator request",
)
manager._run("send-keys", "-t", f"{session}:source", "Enter")
store = Store(state / "tamq.sqlite3")
deadline = time.monotonic() + 5
rows = []
while time.monotonic() < deadline:
rows = store.list()
if len(rows) >= 2:
break
time.sleep(0.05)
assert [(row["body"], row["provenance"]) for row in rows] == [
("operator request", "operator_input"),
("worker reply", "worker_output"),
]
assert all(row["endpoint_id"] == endpoint.instance_id for row in rows)
finally:
if store is not None:
store.close()
manager._run("kill-server", check=False)