fix: logs CLI _resolve crashes on a non-string name (#1631)
This commit is contained in:
parent
0051023056
commit
6b2618dab4
2 changed files with 27 additions and 0 deletions
|
|
@ -58,6 +58,8 @@ def _resolve(name: str) -> Path | None:
|
||||||
"""Match a log by exact filename, basename-without-extension, or
|
"""Match a log by exact filename, basename-without-extension, or
|
||||||
substring. Returns the most-recently-modified match if there are
|
substring. Returns the most-recently-modified match if there are
|
||||||
ties."""
|
ties."""
|
||||||
|
if not isinstance(name, str):
|
||||||
|
return None
|
||||||
candidates = []
|
candidates = []
|
||||||
for base in (_APP_LOGS, _TMUX_LOGS):
|
for base in (_APP_LOGS, _TMUX_LOGS):
|
||||||
if not base.is_dir():
|
if not base.is_dir():
|
||||||
|
|
|
||||||
25
tests/test_logs_cli_resolve_nonstring.py
Normal file
25
tests/test_logs_cli_resolve_nonstring.py
Normal 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
|
||||||
Loading…
Add table
Reference in a new issue