fix(config): respect quoted false for session vacuum_after_prune

This commit is contained in:
hharry11 2026-04-25 02:24:14 +03:00
parent 4fade39c90
commit 7da299ddb0
6 changed files with 94 additions and 15 deletions

View file

@ -15,6 +15,7 @@ logger = logging.getLogger(__name__)
TRUTHY_STRINGS = frozenset({"1", "true", "yes", "on"})
FALSY_STRINGS = frozenset({"0", "false", "no", "off"})
def is_truthy_value(value: Any, default: bool = False) -> bool:
@ -28,6 +29,28 @@ def is_truthy_value(value: Any, default: bool = False) -> bool:
return bool(value)
def coerce_bool(value: Any, default: bool = False) -> bool:
"""Coerce bool-ish config values while preserving the caller's default.
Unlike ``bool(value)``, this treats quoted config strings like
``"false"`` and ``"0"`` as ``False`` instead of truthy non-empty
strings. Unrecognized strings fall back to ``default`` so malformed
YAML values don't silently flip behavior.
"""
if value is None:
return default
if isinstance(value, bool):
return value
if isinstance(value, str):
lowered = value.strip().lower()
if lowered in TRUTHY_STRINGS:
return True
if lowered in FALSY_STRINGS:
return False
return default
return bool(value)
def env_var_enabled(name: str, default: str = "") -> bool:
"""Return True when an environment variable is set to a truthy value."""
return is_truthy_value(os.getenv(name, default), default=False)