fix: logs CLI _resolve crashes on a non-string name (#1631)

This commit is contained in:
Afonso Coutinho
2026-06-03 00:59:30 +01:00
committed by GitHub
parent 0051023056
commit 6b2618dab4
2 changed files with 27 additions and 0 deletions

View File

@@ -58,6 +58,8 @@ def _resolve(name: str) -> Path | None:
"""Match a log by exact filename, basename-without-extension, or
substring. Returns the most-recently-modified match if there are
ties."""
if not isinstance(name, str):
return None
candidates = []
for base in (_APP_LOGS, _TMUX_LOGS):
if not base.is_dir():

View File

@@ -0,0 +1,25 @@
"""Regression: logs CLI _resolve must tolerate a non-string name.
`_resolve` did `name in p.name` and `p.name == name`; a non-string `name`
(e.g. None) raised TypeError once any *.log file existed. Non-strings now
return None (no match).
"""
import importlib.machinery
import importlib.util
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def _load():
loader = importlib.machinery.SourceFileLoader("odysseus_logs_cli", str(ROOT / "scripts" / "odysseus-logs"))
spec = importlib.util.spec_from_loader(loader.name, loader)
m = importlib.util.module_from_spec(spec)
loader.exec_module(m)
return m
def test_non_string_name_returns_none():
cli = _load()
assert cli._resolve(None) is None
assert cli._resolve(123) is None