Files
TSSBOT/tests/test_match_logs.py
T
NotSoToothless 32e747212f Auto merge dev → main (#1332)
* feat(tssbot): build_match_logs + match_logs persistence

* feat(tssbot): create match_logs table and write logs at ingest

* feat(tssbot): one-time match_logs backfill script

* feat(srebot): persist chat/battle logs to match_logs (parity, no backfill)

* feat(tssbot): Battle/Chat Log buttons on Discord scoreboards
2026-06-18 01:02:59 -07:00

61 lines
2.0 KiB
Python

import sys
import pathlib
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2] / "SHARED"))
from BOT.match_logs import build_match_logs
def _game():
return {
"_id": "abc",
"winner": "[WIN]", "loser": "[LOS]",
"players": {
"1": {"name": "alice", "tag": "[WIN]", "team": "1",
"units": [{"unit": "ussr_t_34", "used": True}],
"air_kills": 0, "ground_kills": 1, "assists": 0,
"deaths": 0, "captures": 0, "score": 100},
"2": {"name": "bob", "tag": "[LOS]", "team": "2",
"units": [{"unit": "germ_pz_iv", "used": True}],
"air_kills": 0, "ground_kills": 0, "assists": 0,
"deaths": 1, "captures": 0, "score": 10},
},
"chat": [{"uid": "1", "type": "ALL", "message": "gg", "time": 65000}],
"events": {"kills": [{"time": 60000, "offender_uid": 1,
"offender_unit": "ussr_t_34",
"offended_uid": 2, "offended_unit": "germ_pz_iv",
"crashed": False}]},
}
def test_chat_log_format():
chat, _ = build_match_logs(_game())
assert chat == ["[01:05] [ALL] [WIN] `alice`: gg"]
def test_battle_log_kill_prefix_and_text():
_, battle = build_match_logs(_game())
assert len(battle) == 1
line = battle[0]
assert line.startswith("+[01:00] [WIN]")
assert "alice" in line and "destroyed" in line and "bob" in line
def test_events_base85_zstd_compressed():
import base64
import json
import zstandard
g = _game()
raw = json.dumps(g["events"]).encode()
g["events"] = base64.b85encode(zstandard.ZstdCompressor().compress(raw)).decode()
_, battle = build_match_logs(g)
assert battle and "destroyed" in battle[0]
if __name__ == "__main__":
test_chat_log_format()
test_battle_log_kill_prefix_and_text()
test_events_base85_zstd_compressed()
print("ALL TESTS PASSED")