from pathlib import Path

from app.core.server_logging import build_uvicorn_log_config, ensure_server_log_file


def test_ensure_server_log_file(tmp_path, monkeypatch):
    log_file = tmp_path / "logs" / "server.log"
    monkeypatch.setattr("app.core.server_logging.settings.server_log_path", str(log_file))
    path = ensure_server_log_file()
    assert path.is_file()
    assert "server log initialized" in path.read_text(encoding="utf-8")


def test_build_uvicorn_log_config(tmp_path, monkeypatch):
    log_file = tmp_path / "logs" / "server.log"
    monkeypatch.setattr("app.core.server_logging.settings.server_log_path", str(log_file))
    cfg = build_uvicorn_log_config()
    assert cfg["handlers"]["file"]["filename"] == str(log_file.resolve())
