import json
from pathlib import Path
from src.events import UserRequestEvent

def test_user_request_event_serialization():
 # Setup payload with nested Path objects
 file_items = [
  {"path": Path("some/file.txt"), "mtime": 1234.5},
  {"path": Path("another/path"), "metadata": {"sub_path": Path("sub/path")}}
 ]
 base_dir = Path("C:/projects/test")
 
 event = UserRequestEvent(
  prompt="Test prompt",
  stable_md="# Context",
  file_items=file_items,
  disc_text="Discussion history",
  base_dir=str(base_dir)
 )
 
 # Execute serialization
 result = event.to_dict()
 
 # Verify no Path objects remain
 assert isinstance(result["file_items"][0]["path"], str)
 assert result["file_items"][0]["path"] == str(Path("some/file.txt"))
 assert isinstance(result["file_items"][1]["metadata"]["sub_path"], str)
 assert result["file_items"][1]["metadata"]["sub_path"] == str(Path("sub/path"))
 
 # Verify JSON serializability
 try:
  json.dumps(result)
 except (TypeError, OverflowError) as e:
  assert False, f"Result not JSON serializable: {e}"

if __name__ == "__main__":
 test_user_request_event_serialization()
 print("Test passed!")
