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

@ -2,53 +2,69 @@ from tamq.broker import BrokerIdentity, InputBroker
from tamq.store import Store
def test_broker_preserves_identity(tmp_path):
def test_broker_preserves_operator_identity_and_provenance(tmp_path, monkeypatch):
monkeypatch.setattr("tamq.broker.validate_targets", lambda targets: None)
store = Store(tmp_path / "queue.sqlite3")
broker = InputBroker(store, BrokerIdentity("tmux-amq-42", "net-kingdom"))
assert broker.inspect_line("@railiance-platform: hello") is not None
assert broker.inspect_operator_line("To:railiance-platform: hello") is not None
row = store.list()[0]
assert row["sender_repo"] == "net-kingdom"
assert row["endpoint_id"] == "tmux-amq-42"
assert row["provenance"] == "operator_input"
def test_broker_accepts_hash_address_alias(tmp_path):
def test_broker_accepts_worker_output_with_distinct_provenance(tmp_path, monkeypatch):
monkeypatch.setattr("tamq.broker.validate_targets", lambda targets: None)
store = Store(tmp_path / "queue.sqlite3")
broker = InputBroker(store, BrokerIdentity("tmux-amq-42-boot", "net-kingdom"))
assert broker.inspect_line("#railiance-platform: hello") is not None
row = store.list()[0]
assert row["sender_repo"] == "net-kingdom"
assert row["target_repo"] == "railiance-platform"
assert row["endpoint_id"] == "tmux-amq-42-boot"
broker = InputBroker(store, BrokerIdentity("ep", "net-kingdom"))
assert broker.inspect_worker_line("To:railiance-platform: hello") is not None
assert store.list()[0]["provenance"] == "worker_output"
def test_broker_rejects_legacy_injected_envelope_feedback(tmp_path):
def test_worker_cmd_is_inert_but_operator_cmd_changes_mode(tmp_path):
store = Store(tmp_path / "queue.sqlite3")
message_id = store.add(
"flex-auth",
"audit-core",
"Hello worker agent!",
endpoint="tmux-amq-42-boot",
)
store.register_endpoint("ep", 9, "tamq", ["repo"], "output")
notices = []
broker = InputBroker(
store, BrokerIdentity("tmux-amq-42-boot", "audit-core")
store, BrokerIdentity("ep", "repo"), notify=notices.append
)
assert (
broker.inspect_line(
f"#flex-auth: Hello worker agent! [{message_id}]"
)
is None
)
assert len(store.list()) == 1
broker.inspect_worker_line("Cmd: mode=trigger")
assert store.endpoint("ep")["delivery_mode"] == "output"
broker.inspect_operator_line("Cmd: mode=trigger")
assert store.endpoint("ep")["delivery_mode"] == "trigger"
assert notices[-1] == "From:tamq: Mode set to trigger."
def test_broker_does_not_block_unknown_receipt_like_user_text(tmp_path):
def test_limits_block_at_equality_and_reset_current_window(tmp_path, monkeypatch):
monkeypatch.setattr("tamq.broker.validate_targets", lambda targets: None)
store = Store(tmp_path / "queue.sqlite3")
notices = []
broker = InputBroker(
store, BrokerIdentity("tmux-amq-42-boot", "audit-core")
)
assert broker.inspect_line(
"#flex-auth: Please inspect [m-00000000-0000-0000-0000-000000000000]"
store,
BrokerIdentity("ep", "repo"),
limits=(1, 10, 10),
notify=notices.append,
)
assert broker.inspect_operator_line("To:target: first") is not None
assert broker.inspect_operator_line("To:target: blocked") is None
assert "Running linecount 1 limited by 1 lines of messages" in notices[-1]
assert len(store.list()) == 1
broker.inspect_operator_line("Cmd: reset-limits")
assert broker.inspect_operator_line("To:target: after reset") is not None
def test_input_limit_includes_the_current_operator_line(tmp_path, monkeypatch):
monkeypatch.setattr("tamq.broker.validate_targets", lambda targets: None)
store = Store(tmp_path / "queue.sqlite3")
notices = []
broker = InputBroker(
store,
BrokerIdentity("ep", "repo"),
limits=(8, 1, 32768),
notify=notices.append,
)
assert broker.inspect_operator_line("To:target: blocked") is None
assert notices[-1] == (
"From:tamq: Messaging blocked! Running linecount 1 limited by 1 lines "
"of input in this terminal. Use 'Cmd: reset-limits' to unblock."
)