import os, sys, json sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "src")) from pgar.events import normalise, parse_result_line def test_normalise_types(): line = json.dumps({"type": "assistant", "session_id": "s", "message": {"content": [{"type": "tool_use", "name": "Bash", "input": {"command": "ls"}}], "usage": {"input_tokens": 10}}}) ev = normalise(line, "R1", 3, 1.5) assert ev["event_type"] == "assistant" and ev["tool_name"] == "Bash" and ev["event_id"] == "R1:00003" res = json.dumps({"type": "result", "subtype": "success", "total_cost_usd": 0.5, "num_turns": 4, "session_id": "s"}) assert parse_result_line(res)["total_cost_usd"] == 0.5 assert normalise("not json", "R1", 4, 2.0)["event_type"] == "unparsed"