import json import importlib import sys from pathlib import Path import pytest sys.path.insert(0, str(Path(__file__).resolve().parents[1])) sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "SHARED")) @pytest.fixture def bridge(tmp_path, monkeypatch): monkeypatch.setenv("STORAGE_VOL_PATH", str(tmp_path)) import BOT.receiver_bridge as rb importlib.reload(rb) return rb async def test_publish_replay_batch_writes_tss_envelope(bridge, tmp_path): await bridge.publish_replay_batch([{"sessionIdHex": "abc", "x": 1}]) line = (tmp_path / "tss_bridge_outbox.jsonl").read_text(encoding="utf-8").strip() env = json.loads(line) assert env["type"] == "tss.replay_batch" assert env["source"] == "tss" assert env["version"] == 1 assert env["payload"]["replays"][0]["sessionIdHex"] == "abc" assert isinstance(env["sent_at"], float) async def test_publish_replay_batch_empty_is_noop(bridge, tmp_path): await bridge.publish_replay_batch([]) assert not (tmp_path / "tss_bridge_outbox.jsonl").exists()