tmux-amq/tests/test_replay.py
tegwick 4d915a2617
Some checks failed
tamq-ci / test (push) Failing after 36s
Bootstrap tamq local tmux agent message queue
Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a02f34-ead4-7a60-85cd-d7f08e22fa0e
2026-08-24 01:18:40 +02:00

31 lines
1.3 KiB
Python

import json
from tamq.cli import main
from tamq.store import Store
def test_replay_reports_batch(tmp_path, monkeypatch, capsys):
source = tmp_path / "messages.jsonl"
source.write_text(json.dumps({"message_id": "old-1", "sender_repo": "a", "target_repo": "b", "body": "hello"}) + "\n")
monkeypatch.setenv("TAMQ_STATE_DIR", str(tmp_path / "state"))
assert main(["replay", str(source)]) == 0
output = json.loads(capsys.readouterr().out)
assert output["batch_id"].startswith("replay-")
assert output["count"] == 1
def test_replay_preserves_endpoint(tmp_path, monkeypatch, capsys):
source = tmp_path / "messages.jsonl"
source.write_text(json.dumps({"sender_repo": "a", "target_repo": "b", "body": "hello", "endpoint_id": "tmux-amq-42"}) + "\n")
monkeypatch.setenv("TAMQ_STATE_DIR", str(tmp_path / "state"))
assert main(["replay", str(source)]) == 0
row = Store(tmp_path / "state" / "tamq.sqlite3").list()[0]
assert row["endpoint_id"] == "tmux-amq-42"
def test_replay_rejects_bad_json(tmp_path, monkeypatch, capsys):
source = tmp_path / "bad.jsonl"
source.write_text("not-json\n")
monkeypatch.setenv("TAMQ_STATE_DIR", str(tmp_path / "state"))
assert main(["replay", str(source)]) == 2
assert "cannot replay" in capsys.readouterr().err