From 9e18643ea00e6dc74058c4e0b97f770e0fbfa1bd Mon Sep 17 00:00:00 2001 From: Alpamys Date: Thu, 14 May 2026 21:58:58 +0500 Subject: [PATCH] test(advise): fix cross-platform CI failures in test_v0540 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- tests/test_v0540.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_v0540.py b/tests/test_v0540.py index a209c9a..1909512 100644 --- a/tests/test_v0540.py +++ b/tests/test_v0540.py @@ -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.0–8.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):