test: fix 3 CI failures for cross-platform test compatibility
- test_get_token_from_keychain_windows_branch: Also mock is_macos() to False to prevent macOS CI from calling macOS keychain before checking mocked is_windows flag - test_find_git_from_bash_path_env_var: Mock Path.exists to return False to prevent Windows CI from finding actual Git installation at C:\Program Files\Git\bin\bash.exe, ensuring test falls through to shutil.which as expected - test_hash_with_makefile: Add 10ms delay between file writes to ensure different mtime on CI systems with coarse modification time resolution
This commit is contained in:
@@ -1120,9 +1120,10 @@ class TestGetTokenFromKeychainPlatformBranches:
|
||||
assert result == "sk-ant-oat01-macos-token"
|
||||
mock_macos_keychain.assert_called_once_with(None)
|
||||
|
||||
@patch("core.auth.is_macos", return_value=False)
|
||||
@patch("core.auth.is_windows", return_value=True)
|
||||
@patch("core.auth._get_token_from_windows_credential_files")
|
||||
def test_get_token_from_keychain_windows_branch(self, mock__get_token_from_windows_credential_files, mock_is_windows):
|
||||
def test_get_token_from_keychain_windows_branch(self, mock__get_token_from_windows_credential_files, mock_is_windows, mock_is_macos):
|
||||
"""Test get_token_from_keychain calls Windows implementation"""
|
||||
# Arrange
|
||||
mock__get_token_from_windows_credential_files.return_value = "sk-ant-oat01-windows-token"
|
||||
|
||||
@@ -108,13 +108,15 @@ class TestFindGitExecutable:
|
||||
bash_path = "C:\\Program Files\\Git\\bin\\bash.exe"
|
||||
|
||||
with patch.dict(os.environ, {"CLAUDE_CODE_GIT_BASH_PATH": bash_path}, clear=False):
|
||||
# When bash path is set but git is not found, it falls through to shutil.which
|
||||
with patch("shutil.which", return_value="/usr/bin/git"):
|
||||
# Act
|
||||
result = _find_git_executable()
|
||||
# Mock Path.exists to return False so bash path check fails
|
||||
# This ensures we fall through to shutil.which
|
||||
with patch("pathlib.Path.exists", return_value=False):
|
||||
with patch("shutil.which", return_value="/usr/bin/git"):
|
||||
# Act
|
||||
result = _find_git_executable()
|
||||
|
||||
# Assert - should find git from shutil.which
|
||||
assert result == "/usr/bin/git"
|
||||
# Assert - should find git from shutil.which
|
||||
assert result == "/usr/bin/git"
|
||||
|
||||
def test_find_git_from_bash_path_bin_git(self):
|
||||
"""Test finding git.exe in bin/ directory from bash path"""
|
||||
|
||||
@@ -286,11 +286,16 @@ class TestComputeProjectHash:
|
||||
|
||||
def test_hash_with_makefile(self, temp_project_dir: Path):
|
||||
"""Test hash computation with Makefile."""
|
||||
import time
|
||||
|
||||
(temp_project_dir / "Makefile").write_text("build:\n\techo building")
|
||||
|
||||
analyzer = ProjectAnalyzer(temp_project_dir)
|
||||
hash1 = analyzer.compute_project_hash()
|
||||
|
||||
# Small delay to ensure different mtime on systems with coarse mtime resolution
|
||||
time.sleep(0.01)
|
||||
|
||||
# Modify Makefile
|
||||
(temp_project_dir / "Makefile").write_text("build:\n\techo modified")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user