Some checks failed
tamq-ci / test (push) Failing after 5s
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a03397-4d51-7fd1-8ff2-946eb22ea2bc
40 lines
1.8 KiB
Python
40 lines
1.8 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"))
|
|
monkeypatch.setattr("tamq.cli.validate_targets", lambda targets: None)
|
|
assert main(["replay", str(source)]) == 0
|
|
output = json.loads(capsys.readouterr().out)
|
|
assert output["batch_id"].startswith("replay-")
|
|
assert output["count"] == 1
|
|
assert output["deduplicated"] == 0
|
|
assert main(["replay", str(source)]) == 0
|
|
repeated = json.loads(capsys.readouterr().out)
|
|
assert repeated["count"] == 0
|
|
assert repeated["deduplicated"] == 1
|
|
assert len(Store(tmp_path / "state" / "tamq.sqlite3").list()) == 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"))
|
|
monkeypatch.setattr("tamq.cli.validate_targets", lambda targets: None)
|
|
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"))
|
|
monkeypatch.setattr("tamq.cli.validate_targets", lambda targets: None)
|
|
assert main(["replay", str(source)]) == 2
|
|
assert "cannot replay" in capsys.readouterr().err
|