-
Notifications
You must be signed in to change notification settings - Fork 52
feat: display build commit SHA in CLI version output #176
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
Merged
sergio-sisternes-epam
merged 5 commits into
microsoft:main
from
sergio-sisternes-epam:feat/sha-version
Mar 6, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92b9b20
feat: display build commit SHA in CLI version output
sergio-sisternes-epam c268e8a
Merge branch 'main' into feat/sha-version
sergio-sisternes-epam d1630d1
Merge branch 'main' into feat/sha-version
sergio-sisternes-epam 5d7750b
fix: address Copilot review feedback on PR #176
sergio-sisternes-epam ca27472
Merge branch 'main' into feat/sha-version
sergio-sisternes-epam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Tests for get_build_sha() function.""" | ||
|
|
||
| import subprocess | ||
| import unittest | ||
| from unittest.mock import patch, MagicMock | ||
|
|
||
| from apm_cli.version import get_build_sha | ||
|
|
||
|
|
||
| class TestGetBuildSha(unittest.TestCase): | ||
| """Test build SHA retrieval across all code paths.""" | ||
|
|
||
| @patch("apm_cli.version.__BUILD_SHA__", "abc1234") | ||
| def test_returns_build_time_constant_when_set(self): | ||
| """Build-time constant takes priority over git.""" | ||
| assert get_build_sha() == "abc1234" | ||
|
|
||
| @patch("apm_cli.version.__BUILD_SHA__", None) | ||
| def test_returns_empty_when_frozen_and_no_constant(self): | ||
| """Frozen binary without build constant returns empty string.""" | ||
| with patch.object(__import__("sys"), "frozen", True, create=True): | ||
| assert get_build_sha() == "" | ||
|
|
||
| @patch("apm_cli.version.__BUILD_SHA__", None) | ||
| @patch("subprocess.run") | ||
| def test_falls_back_to_git_in_development(self, mock_run): | ||
| """In development, queries git rev-parse.""" | ||
| mock_run.return_value = MagicMock(returncode=0, stdout="d1630d1\n") | ||
| with patch("sys.frozen", False, create=True): | ||
| result = get_build_sha() | ||
| assert result == "d1630d1" | ||
| mock_run.assert_called_once() | ||
| args = mock_run.call_args | ||
| assert args[0][0] == ["git", "rev-parse", "--short", "HEAD"] | ||
|
|
||
| @patch("apm_cli.version.__BUILD_SHA__", None) | ||
| @patch("subprocess.run", side_effect=FileNotFoundError("git not found")) | ||
| def test_returns_empty_when_git_unavailable(self, _mock_run): | ||
| """Returns empty string when git is not installed.""" | ||
| with patch("sys.frozen", False, create=True): | ||
| assert get_build_sha() == "" | ||
|
|
||
| @patch("apm_cli.version.__BUILD_SHA__", None) | ||
| @patch("subprocess.run") | ||
| def test_returns_empty_when_git_fails(self, mock_run): | ||
| """Returns empty string when git command fails (e.g., not a repo).""" | ||
| mock_run.return_value = MagicMock(returncode=128, stdout="") | ||
| with patch("sys.frozen", False, create=True): | ||
| assert get_build_sha() == "" | ||
|
|
||
| @patch("apm_cli.version.__BUILD_SHA__", None) | ||
| @patch("subprocess.run", side_effect=subprocess.TimeoutExpired(cmd="git", timeout=5)) | ||
| def test_returns_empty_on_timeout(self, _mock_run): | ||
| """Returns empty string when git times out.""" | ||
| with patch("sys.frozen", False, create=True): | ||
| assert get_build_sha() == "" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.