test(updates): keep launchd regression proofs faithful (#5175)

This commit is contained in:
Rod Boev authored and nesquena-hermes committed 2026-06-29 04:22:51 +00:00
1 parent a052f390f8
commit a98b0551c9
2 files changed
+13 -13

No files matched your search

+3 -8
View File
@@ -18,10 +18,7 @@ def test_run_git_uses_which_result_when_available(tmp_path):
def test_run_git_falls_back_to_usr_bin_git_on_darwin(tmp_path):
def fake_run(cmd, **kwargs):
if cmd[0] == 'git':
raise FileNotFoundError
if cmd[0] != '/usr/bin/git':
raise AssertionError(f'unexpected executable: {cmd[0]!r}')
assert cmd[0] == '/usr/bin/git'
return MagicMock(returncode=0, stdout='v0.51.999\n', stderr='')
with patch.object(updates.shutil, 'which', return_value=None), \
@@ -74,8 +71,7 @@ def test_run_git_returns_not_found_when_usr_bin_git_absent_on_darwin(tmp_path):
def test_detect_webui_version_recovers_via_launchd_fallback(tmp_path):
def fake_run(cmd, **kwargs):
if cmd[0] == 'git':
raise FileNotFoundError
assert cmd[0] == '/usr/bin/git'
if cmd[1:] == ['describe', '--tags', '--always']:
return MagicMock(returncode=0, stdout='v0.51.999\n', stderr='')
if cmd[1:] == ['diff-index', '--quiet', 'HEAD', '--']:
@@ -96,8 +92,7 @@ def test_check_repo_does_not_report_git_not_found_via_launchd_fallback(tmp_path)
(tmp_path / '.git').mkdir()
def fake_run(cmd, **kwargs):
if cmd[0] == 'git':
raise FileNotFoundError
assert cmd[0] == '/usr/bin/git'
git_args = cmd[1:]
if git_args == ['fetch', 'origin', '--tags', '--force']:
return MagicMock(returncode=0, stdout='', stderr='')
+10 -5
View File
@@ -288,7 +288,8 @@ def test_update_cache_is_scoped_by_agent_inclusion(tmp_path):
def test_run_git_returns_stderr_on_failure(tmp_path):
"""When a git command fails, _run_git should return stderr (not empty string)."""
with patch('subprocess.run') as mock_run:
with patch.object(updates.shutil, 'which', return_value='C:/Tools/git.exe'), \
patch('subprocess.run') as mock_run:
mock_run.return_value = MagicMock(
returncode=1,
stdout='',
@@ -302,7 +303,8 @@ def test_run_git_returns_stderr_on_failure(tmp_path):
def test_run_git_returns_stdout_when_no_stderr(tmp_path):
"""If stderr is empty on failure, fall back to stdout."""
with patch('subprocess.run') as mock_run:
with patch.object(updates.shutil, 'which', return_value='C:/Tools/git.exe'), \
patch('subprocess.run') as mock_run:
mock_run.return_value = MagicMock(
returncode=128,
stdout='Already up to date.',
@@ -316,7 +318,8 @@ def test_run_git_returns_stdout_when_no_stderr(tmp_path):
def test_run_git_returns_exit_code_when_no_output(tmp_path):
"""If both stdout and stderr are empty, report the exit code."""
with patch('subprocess.run') as mock_run:
with patch.object(updates.shutil, 'which', return_value='C:/Tools/git.exe'), \
patch('subprocess.run') as mock_run:
mock_run.return_value = MagicMock(
returncode=1,
stdout='',
@@ -330,7 +333,8 @@ def test_run_git_returns_exit_code_when_no_output(tmp_path):
def test_run_git_uses_utf8_replacement_for_windows_console_output(tmp_path):
"""Git output can contain Unicode even when Windows' active code page cannot."""
with patch('subprocess.run') as mock_run:
with patch.object(updates.shutil, 'which', return_value='C:/Tools/git.exe'), \
patch('subprocess.run') as mock_run:
mock_run.return_value = MagicMock(returncode=0, stdout='v0.51.184\n', stderr=None)
out, ok = updates._run_git(['describe', '--tags'], tmp_path)
@@ -344,7 +348,8 @@ def test_run_git_uses_utf8_replacement_for_windows_console_output(tmp_path):
def test_run_git_handles_missing_stdout_after_decode_thread_failure(tmp_path):
"""A subprocess reader failure must not make version detection crash on import."""
with patch('subprocess.run') as mock_run:
with patch.object(updates.shutil, 'which', return_value='C:/Tools/git.exe'), \
patch('subprocess.run') as mock_run:
mock_run.return_value = MagicMock(returncode=0, stdout=None, stderr=None)
out, ok = updates._run_git(['diff', '--binary', 'HEAD', '--'], tmp_path)