-
Notifications
You must be signed in to change notification settings - Fork 0
add GH_TOKEN #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add GH_TOKEN #18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a manual test script for CodeQL installer error handling and updates the GitHub Actions workflow to use a custom GH_TOKEN secret.
- Introduces
test_error_handling.pywith manual test functions for network and HTTP error scenarios. - Modifies
.github/workflows/release.ymlto replaceGITHUB_TOKENwithGH_TOKEN.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test_error_handling.py | Added manual tests for get_latest_version and install error handling. |
| .github/workflows/release.yml | Switched environment variables from GITHUB_TOKEN to GH_TOKEN. |
Comments suppressed due to low confidence (2)
.github/workflows/release.yml:138
- Ensure that the secret
GH_TOKENis defined in the repository settings or switch back to the built-inGITHUB_TOKENto avoid authentication failures during auto-merge steps.
GH_TOKEN: ${{ secrets.GH_TOKEN }}
.github/workflows/release.yml:153
- Mapping
secrets.GH_TOKENtoGITHUB_TOKENmay be confusing and could lead to a missing token; consider aligning the environment variable name with your secret or using the defaultGITHUB_TOKENsecret.
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
test_error_handling.py
Outdated
| from unittest.mock import patch | ||
| from urllib.error import URLError | ||
|
|
||
| from codeql_wrapper.infrastructure.codeql_installer import CodeQLInstaller | ||
|
|
||
| def test_get_latest_version_exception(): | ||
| """Test that get_latest_version raises proper exceptions.""" | ||
| installer = CodeQLInstaller() | ||
|
|
||
| # Test with network error | ||
| with patch("codeql_wrapper.infrastructure.codeql_installer.urlopen") as mock_urlopen: | ||
| mock_urlopen.side_effect = URLError("Network error") | ||
|
|
||
| try: | ||
| installer.get_latest_version() | ||
| print("❌ FAIL: Expected exception but none was raised") | ||
| return False | ||
| except Exception as e: | ||
| if "Unable to fetch latest CodeQL version" in str(e): | ||
| print("✅ PASS: Correct exception raised for network error") | ||
| else: | ||
| print(f"❌ FAIL: Wrong exception message: {e}") | ||
| return False | ||
|
|
||
| # Test with HTTP error | ||
| from unittest.mock import Mock | ||
| with patch("codeql_wrapper.infrastructure.codeql_installer.urlopen") as mock_urlopen: | ||
| mock_response = Mock() | ||
| mock_response.status = 404 | ||
| mock_urlopen.return_value.__enter__ = Mock(return_value=mock_response) | ||
| mock_urlopen.return_value.__exit__ = Mock(return_value=None) | ||
|
|
||
| try: | ||
| installer.get_latest_version() | ||
| print("❌ FAIL: Expected exception but none was raised") | ||
| return False | ||
| except Exception as e: | ||
| if "GitHub API returned status 404" in str(e): | ||
| print("✅ PASS: Correct exception raised for HTTP error") | ||
| else: | ||
| print(f"❌ FAIL: Wrong exception message: {e}") | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
| def test_install_propagates_exception(): | ||
| """Test that install() propagates exceptions correctly.""" | ||
| installer = CodeQLInstaller() | ||
|
|
||
| # Test with network error during version fetch | ||
| with patch("codeql_wrapper.infrastructure.codeql_installer.urlopen") as mock_urlopen: | ||
| mock_urlopen.side_effect = URLError("Network error") | ||
|
|
||
| try: | ||
| installer.install(version=None) # This should trigger get_latest_version | ||
| print("❌ FAIL: Expected exception but none was raised") | ||
| return False | ||
| except Exception as e: | ||
| if "Unable to fetch latest CodeQL version" in str(e): | ||
| print("✅ PASS: Install correctly propagates version fetch exception") | ||
| else: | ||
| print(f"❌ FAIL: Wrong exception message: {e}") | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
| def main(): | ||
| """Run all tests.""" | ||
| print("Testing CodeQL installer error handling...") | ||
|
|
||
| tests = [ | ||
| test_get_latest_version_exception, | ||
| test_install_propagates_exception, | ||
| ] | ||
|
|
||
| passed = 0 | ||
| total = len(tests) | ||
|
|
||
| for test in tests: | ||
| if test(): | ||
| passed += 1 | ||
| print() | ||
|
|
||
| print(f"Results: {passed}/{total} tests passed") | ||
| return passed == total | ||
|
|
||
| if __name__ == "__main__": | ||
| import sys | ||
| sys.exit(0 if main() else 1) |
Copilot
AI
Jul 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider using a testing framework like pytest or unittest with assert statements instead of manual prints and return values to integrate with standard test runners and improve readability.
| from unittest.mock import patch | |
| from urllib.error import URLError | |
| from codeql_wrapper.infrastructure.codeql_installer import CodeQLInstaller | |
| def test_get_latest_version_exception(): | |
| """Test that get_latest_version raises proper exceptions.""" | |
| installer = CodeQLInstaller() | |
| # Test with network error | |
| with patch("codeql_wrapper.infrastructure.codeql_installer.urlopen") as mock_urlopen: | |
| mock_urlopen.side_effect = URLError("Network error") | |
| try: | |
| installer.get_latest_version() | |
| print("❌ FAIL: Expected exception but none was raised") | |
| return False | |
| except Exception as e: | |
| if "Unable to fetch latest CodeQL version" in str(e): | |
| print("✅ PASS: Correct exception raised for network error") | |
| else: | |
| print(f"❌ FAIL: Wrong exception message: {e}") | |
| return False | |
| # Test with HTTP error | |
| from unittest.mock import Mock | |
| with patch("codeql_wrapper.infrastructure.codeql_installer.urlopen") as mock_urlopen: | |
| mock_response = Mock() | |
| mock_response.status = 404 | |
| mock_urlopen.return_value.__enter__ = Mock(return_value=mock_response) | |
| mock_urlopen.return_value.__exit__ = Mock(return_value=None) | |
| try: | |
| installer.get_latest_version() | |
| print("❌ FAIL: Expected exception but none was raised") | |
| return False | |
| except Exception as e: | |
| if "GitHub API returned status 404" in str(e): | |
| print("✅ PASS: Correct exception raised for HTTP error") | |
| else: | |
| print(f"❌ FAIL: Wrong exception message: {e}") | |
| return False | |
| return True | |
| def test_install_propagates_exception(): | |
| """Test that install() propagates exceptions correctly.""" | |
| installer = CodeQLInstaller() | |
| # Test with network error during version fetch | |
| with patch("codeql_wrapper.infrastructure.codeql_installer.urlopen") as mock_urlopen: | |
| mock_urlopen.side_effect = URLError("Network error") | |
| try: | |
| installer.install(version=None) # This should trigger get_latest_version | |
| print("❌ FAIL: Expected exception but none was raised") | |
| return False | |
| except Exception as e: | |
| if "Unable to fetch latest CodeQL version" in str(e): | |
| print("✅ PASS: Install correctly propagates version fetch exception") | |
| else: | |
| print(f"❌ FAIL: Wrong exception message: {e}") | |
| return False | |
| return True | |
| def main(): | |
| """Run all tests.""" | |
| print("Testing CodeQL installer error handling...") | |
| tests = [ | |
| test_get_latest_version_exception, | |
| test_install_propagates_exception, | |
| ] | |
| passed = 0 | |
| total = len(tests) | |
| for test in tests: | |
| if test(): | |
| passed += 1 | |
| print() | |
| print(f"Results: {passed}/{total} tests passed") | |
| return passed == total | |
| if __name__ == "__main__": | |
| import sys | |
| sys.exit(0 if main() else 1) | |
| import unittest | |
| from unittest.mock import patch | |
| from urllib.error import URLError | |
| from codeql_wrapper.infrastructure.codeql_installer import CodeQLInstaller | |
| class TestCodeQLInstaller(unittest.TestCase): | |
| """Unit tests for CodeQLInstaller error handling.""" | |
| def test_get_latest_version_exception(self): | |
| """Test that get_latest_version raises proper exceptions.""" | |
| installer = CodeQLInstaller() | |
| # Test with network error | |
| with patch("codeql_wrapper.infrastructure.codeql_installer.urlopen") as mock_urlopen: | |
| mock_urlopen.side_effect = URLError("Network error") | |
| with self.assertRaises(Exception) as context: | |
| installer.get_latest_version() | |
| self.assertIn("Unable to fetch latest CodeQL version", str(context.exception)) | |
| # Test with HTTP error | |
| from unittest.mock import Mock | |
| with patch("codeql_wrapper.infrastructure.codeql_installer.urlopen") as mock_urlopen: | |
| mock_response = Mock() | |
| mock_response.status = 404 | |
| mock_urlopen.return_value.__enter__ = Mock(return_value=mock_response) | |
| mock_urlopen.return_value.__exit__ = Mock(return_value=None) | |
| with self.assertRaises(Exception) as context: | |
| installer.get_latest_version() | |
| self.assertIn("GitHub API returned status 404", str(context.exception)) | |
| def test_install_propagates_exception(self): | |
| """Test that install() propagates exceptions correctly.""" | |
| installer = CodeQLInstaller() | |
| # Test with network error during version fetch | |
| with patch("codeql_wrapper.infrastructure.codeql_installer.urlopen") as mock_urlopen: | |
| mock_urlopen.side_effect = URLError("Network error") | |
| with self.assertRaises(Exception) as context: | |
| installer.install(version=None) # This should trigger get_latest_version | |
| self.assertIn("Unable to fetch latest CodeQL version", str(context.exception)) | |
| if __name__ == "__main__": | |
| import unittest | |
| unittest.main() |
No description provided.