fix timezone handling and logging fallback robustness

This commit is contained in:
windyboy
2026-02-09 20:16:39 +08:00
parent 976a1fa1d0
commit aa0dc8ec47
13 changed files with 492 additions and 86 deletions
+23
View File
@@ -11,6 +11,7 @@ from vlm.logging_config import (
get_logger,
log_operation,
MAX_LOG_SIZE,
default_log_dir,
)
@@ -71,6 +72,28 @@ class TestLoggingSetup:
logger = setup_logging(log_level=level, log_dir=tmp_path)
assert logger is not None
def test_setup_logging_falls_back_when_file_logging_unwritable(self, tmp_path, monkeypatch):
"""Test setup continues with console logging if file logging cannot initialize."""
def fail_mkdir(self, parents=False, exist_ok=False):
raise PermissionError("mock permission denied")
monkeypatch.setattr(Path, "mkdir", fail_mkdir)
logger = setup_logging(log_level="INFO", log_dir=tmp_path / "logs")
logger.info("Console-only logging still works")
assert len(logger.handlers) == 1
assert isinstance(logger.handlers[0], logging.StreamHandler)
class TestDefaultPathResolution:
"""Test runtime default path resolution."""
def test_default_log_dir_resolves_at_runtime(self, tmp_path, monkeypatch):
"""Test default log directory follows current Path.home() value."""
monkeypatch.setattr(Path, "home", lambda: tmp_path)
assert default_log_dir() == tmp_path / ".vlm" / "logs"
class TestDualOutput:
"""Test dual output to console and file."""