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

@ -4,7 +4,13 @@ import pty
import struct
import termios
from tamq.ptytap import PtyTap, copy_winsize, observed_line, write_all
from tamq.ptytap import (
PtyTap,
TerminalOutputObserver,
copy_winsize,
observed_line,
write_all,
)
class RecordingBroker:
@ -13,7 +19,7 @@ class RecordingBroker:
def inspect_line(self, line):
self.lines.append(line)
return line.startswith(("@", "#"))
return line.startswith("To:")
def test_input_observer_accepts_raw_terminal_carriage_returns():
@ -22,11 +28,11 @@ def test_input_observer_accepts_raw_terminal_carriage_returns():
tap = PtyTap(["true"], broker, on_line=observed.append)
buffer = bytearray()
tap._observe_input(buffer, b"#activity-core: hel")
tap._observe_input(buffer, b"To:activity-core: hel")
tap._observe_input(buffer, b"lo\rplain line\n")
assert broker.lines == ["#activity-core: hello", "plain line"]
assert observed == ["#activity-core: hello"]
assert broker.lines == ["To:activity-core: hello", "plain line"]
assert observed == ["To:activity-core: hello"]
def test_input_observer_accepts_enhanced_terminal_enter_sequences():
@ -35,17 +41,17 @@ def test_input_observer_accepts_enhanced_terminal_enter_sequences():
tap = PtyTap(["true"], broker, on_line=observed.append)
buffer = bytearray()
tap._observe_input(buffer, b"#activity-core: CSI-u\x1b[13;1")
tap._observe_input(buffer, b"To:activity-core: CSI-u\x1b[13;1")
assert broker.lines == []
tap._observe_input(buffer, b":1u#other: modify\x1b[27;1;13~")
tap._observe_input(buffer, b":1uTo:other: modify\x1b[27;1;13~")
tap._observe_input(buffer, b"plain\x1bOM")
assert broker.lines == [
"#activity-core: CSI-u",
"#other: modify",
"To:activity-core: CSI-u",
"To:other: modify",
"plain",
]
assert observed == ["#activity-core: CSI-u", "#other: modify"]
assert observed == ["To:activity-core: CSI-u", "To:other: modify"]
def test_input_observer_ignores_terminal_replies_before_typed_line():
@ -55,20 +61,36 @@ def test_input_observer_ignores_terminal_replies_before_typed_line():
buffer = bytearray()
tap._observe_input(buffer, b"\x1b[9;1R\x1b[?1;2;4c")
tap._observe_input(buffer, b"#activity-core: Helol\x7f\x7flo\r")
tap._observe_input(buffer, b"To:activity-core: Helol\x7f\x7flo\r")
assert broker.lines == ["#activity-core: Hello"]
assert observed == ["#activity-core: Hello"]
assert broker.lines == ["To:activity-core: Hello"]
assert observed == ["To:activity-core: Hello"]
def test_observed_line_removes_common_terminal_protocol_wrappers():
raw = (
b"\x1b[200~#target: pasted\x1b[201~"
b"\x1b[200~To:target: pasted\x1b[201~"
b"\x1b]10;rgb:ffff/ffff/ffff\x07"
b"\x1bP1$r0m\x1b\\"
)
assert observed_line(raw) == "#target: pasted"
assert observed_line(raw) == "To:target: pasted"
def test_output_observer_normalizes_ansi_and_deduplicates_redraws():
lines = []
observer = TerminalOutputObserver(lines.append)
observer.feed(b"plain\r\n\x1b[31mTo:target: worker\x1b[0m\r")
observer.feed(b"To:target: worker\r")
assert lines == ["plain", "To:target: worker"]
def test_output_observer_fails_closed_on_recent_operator_echo():
lines = []
observer = TerminalOutputObserver(lines.append)
observer.note_operator_line("To:target: operator")
observer.feed(b"To:target: operator\r\nTo:target: worker\r\n")
assert lines == ["To:target: worker"]
def test_copy_winsize_preserves_rows_columns_and_pixels():