mirror of https://github.com/razor-ai/soup.git
fix(v0.59.0): macOS CI — strip ANSI from train --help assert + handle null-byte env
Three macOS-3.11 CI failures in test_v0590.py post-merge:
1+2. test_train_annex_xi_flag_present_in_help / test_train_repro_receipt_flag_present_in_help
— Typer's Rich-renderer wraps long lines and inserts ANSI colour codes
BETWEEN the two dashes of `--annex-xi` / `--repro-receipt`, so the
literal substring match fails. Strip ANSI escape codes via regex before
asserting; also accept the bare option name as a defence-in-depth
fallback against future Rich line-wrap quirks.
3. test_default_log_path_rejects_null_byte_env — POSIX `os.environ.get` raises
`ValueError("embedded null byte")` when the env value contains a NUL
character, while Windows allows the read. Wrap the env read in
`try/except ValueError` so the function falls back to the safe default
(~/.soup/audit.jsonl) on either platform.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6d44f0f931
commit
d0f5e35c99
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 ----------
|
||||
|
|
|
|||
Loading…
Reference in New Issue