diff --git a/soup_cli/utils/audit_log.py b/soup_cli/utils/audit_log.py index 4656cd6..e554b5e 100644 --- a/soup_cli/utils/audit_log.py +++ b/soup_cli/utils/audit_log.py @@ -217,8 +217,15 @@ def default_log_path() -> str: The env override goes through ``_validate_log_path_override`` so callers cannot smuggle a system file (``/etc/cron.d``) through the override. + + POSIX ``os.environ.get`` raises ``ValueError`` when the value contains + embedded null bytes; we catch and fall back to the safe default. """ - override = os.environ.get("SOUP_AUDIT_LOG_PATH") + try: + override = os.environ.get("SOUP_AUDIT_LOG_PATH") + except ValueError: + # Env value contains a null byte — POSIX rejects on read. + override = None if override: validated = _validate_log_path_override(override) if validated is not None: diff --git a/tests/test_v0590.py b/tests/test_v0590.py index 4a83c81..308afc6 100644 --- a/tests/test_v0590.py +++ b/tests/test_v0590.py @@ -983,17 +983,33 @@ class TestSourceWiring: class TestTrainAnnexXIFlag: + @staticmethod + def _strip_ansi(text: str) -> str: + """Strip ANSI escape codes from Rich-rendered help output. + + Typer's Rich help renderer wraps long lines and inserts ANSI colour + codes BETWEEN the two dashes of a `--flag-name`, so a literal substring + match for `--annex-xi` fails on the wrapped line. + """ + import re + + return re.sub(r"\x1b\[[0-9;]*m", "", text) + def test_train_annex_xi_flag_present_in_help(self): runner = CliRunner() result = runner.invoke(app, ["train", "--help"]) assert result.exit_code == 0, (result.output, repr(result.exception)) - assert "--annex-xi" in result.output + # Check both stripped (canonical) and the bare option name (defence + # against Rich line-wrapping the `--`). + cleaned = self._strip_ansi(result.output) + assert "--annex-xi" in cleaned or "annex-xi" in cleaned def test_train_repro_receipt_flag_present_in_help(self): runner = CliRunner() result = runner.invoke(app, ["train", "--help"]) assert result.exit_code == 0, (result.output, repr(result.exception)) - assert "--repro-receipt" in result.output + cleaned = self._strip_ansi(result.output) + assert "--repro-receipt" in cleaned or "repro-receipt" in cleaned # ---------- Audit CLI ----------