tmux-amq/tests/test_control.py
tegwick 17b6bd7ae7
Some checks failed
tamq-ci / test (push) Failing after 6s
feat: add reliable trigger and worker message blocks
Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a03397-4d51-7fd1-8ff2-946eb22ea2bc
2026-08-25 23:22:39 +02:00

71 lines
2.2 KiB
Python

from tamq import control
import pytest
from tamq.control import ControlModeClient, ControlModeError, shell_quote
from tamq.tmux import shell_join
def test_shell_quote():
quoted = shell_quote("hello 'world'")
assert quoted.startswith("'") and quoted.endswith("'")
assert "\\'" in quoted
def test_tmux_shell_join_quotes_arguments():
assert shell_join(["tamq", "tap", "--repo", "net-kingdom", "--", "codex"]) == "tamq tap --repo net-kingdom -- codex"
def test_pane_tty_is_resolved_through_tmux(monkeypatch):
calls = []
def run(command, **kwargs):
calls.append(command)
return type("Result", (), {"returncode": 0, "stdout": "/dev/pts/7|12|8|24|0\n", "stderr": ""})()
monkeypatch.setattr(control.subprocess, "run", run)
client = ControlModeClient(
"tamq", tmux_command=("tmux", "-L", "test"), submit_delay=0.15
)
assert client.pane_tty("tamq:audit-core") == "/dev/pts/7"
assert calls == [[
"tmux", "-L", "test", "display-message", "-p", "-t",
"tamq:audit-core", "#{pane_tty}|#{cursor_x}|#{cursor_y}|#{pane_height}|#{alternate_on}",
]]
def test_submit_sends_literal_input_then_one_enter(monkeypatch):
calls = []
def run(command, **kwargs):
calls.append(command)
return type("Result", (), {"returncode": 0, "stderr": ""})()
monkeypatch.setattr(control.subprocess, "run", run)
client = ControlModeClient("tamq", tmux_command=("tmux", "-L", "test"))
client.submit("tamq:audit-core", "#flex-auth: What's up? [m-1]")
assert calls == [
[
"tmux", "-L", "test",
"send-keys", "-t", "tamq:audit-core", "-l", "--",
"#flex-auth: What's up? [m-1]",
";",
"run-shell", "sleep 0.150",
";",
"send-keys", "-t", "tamq:audit-core", "Enter",
]
]
def test_submit_surfaces_tmux_rejection(monkeypatch):
monkeypatch.setattr(
control.subprocess,
"run",
lambda *args, **kwargs: type(
"Result", (), {"returncode": 1, "stderr": "missing pane"}
)(),
)
client = ControlModeClient("tamq")
with pytest.raises(ControlModeError, match="missing pane"):
client.submit("tamq:missing", "message")