test(advise): fix cross-platform CI failures in test_v0540

Two failures on ubuntu/macos/windows × py3.9/3.11/3.12 after v0.54.0
push:

1. test_env_null_byte_falls_back: monkeypatch.setenv can't set raw
   NUL into the OS env layer (POSIX execve + Win32 SetEnv both
   refuse). Switched to a temporary `advise_history.os.environ` swap
   so the helper's defence-in-depth NUL guard is still exercised
   without going through the C env layer.

2. test_default_missing_data: Click 8.0–8.1 returns rc=0 on
   `no_args_is_help=True` invocations; Click 8.2+ returns rc=2 (the
   "missing command" convention). CI runners had the newer Click;
   dev box had the older. Accept both renderings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alpamys 2026-05-14 21:58:58 +05:00
parent 600686cd70
commit 9e18643ea0
1 changed files with 15 additions and 4 deletions

View File

@ -644,8 +644,17 @@ class TestHistoryPath:
assert p != "/etc/advise.jsonl"
def test_env_null_byte_falls_back(self, monkeypatch):
monkeypatch.setenv("SOUP_ADVISE_HISTORY_PATH", "x\x00y")
p = history_path()
# OS env layer rejects raw NUL bytes (POSIX execve / Win32 SetEnv
# both refuse `\x00`), so we exercise the helper's defence-in-depth
# NUL guard via a stubbed env dict rather than `monkeypatch.setenv`.
from soup_cli.utils import advise_history
original = advise_history.os.environ
try:
advise_history.os.environ = {"SOUP_ADVISE_HISTORY_PATH": "x\x00y"} # type: ignore[assignment]
p = history_path()
finally:
advise_history.os.environ = original # type: ignore[assignment]
assert "\x00" not in p
@ -714,8 +723,10 @@ class TestCLI:
def test_default_missing_data(self):
result = runner.invoke(advise_cmd.app, [])
# no_args_is_help — prints help and exits 0.
assert result.exit_code == 0
# `no_args_is_help=True`: Click 8.08.1 returns rc=0, Click 8.2+
# returns rc=2 (the "missing command" convention). Both renderings
# print the help text, so accept either.
assert result.exit_code in (0, 2)
assert "Usage" in result.output or "advise" in result.output.lower()
def test_default_nonexistent_data(self, tmp_path):