GRM-54: fix: fix broken automation pipeline (auto-merge, Vikunja, CI enforcement)
This commit is contained in:
@@ -275,3 +275,54 @@ class TestFromGit:
|
||||
result = runner.invoke(main, [])
|
||||
assert result.exit_code != 0
|
||||
assert "commit_msg" in result.output
|
||||
|
||||
|
||||
class TestGitSha:
|
||||
"""Tests for the --git-sha option (race condition fix)."""
|
||||
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
@patch("scripts.ci.post_merge.VikunjaClient")
|
||||
def test_git_sha_reads_commit_from_specific_sha(self, mock_client_cls: MagicMock) -> None:
|
||||
"""--git-sha reads commit message from a specific SHA, not HEAD."""
|
||||
mock_client = MagicMock()
|
||||
mock_client.list_project_tasks.return_value = [
|
||||
{"id": 267, "identifier": "GRM-20"},
|
||||
]
|
||||
mock_client_cls.return_value = mock_client
|
||||
mock_result = subprocess.CompletedProcess(args=[], returncode=0, stdout="GRM-20: fix: bug\n", stderr="")
|
||||
with patch("subprocess.run", return_value=mock_result):
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--git-sha", "abc123"])
|
||||
assert result.exit_code == 0
|
||||
assert "updated and marked done" in result.output
|
||||
mock_client.post_comment.assert_called_once()
|
||||
# Verify the SHA was passed to the comment
|
||||
args, _ = mock_client.post_comment.call_args
|
||||
assert "abc123" in args[1]
|
||||
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_git_sha_failure_raises(self) -> None:
|
||||
"""--git-sha with invalid SHA should raise."""
|
||||
mock_result = subprocess.CompletedProcess(args=[], returncode=1, stdout="", stderr="bad sha")
|
||||
with patch("subprocess.run", return_value=mock_result):
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--git-sha", "badsha"])
|
||||
assert result.exit_code != 0
|
||||
assert "git log failed" in result.output
|
||||
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
@patch("scripts.ci.post_merge.VikunjaClient")
|
||||
def test_git_sha_with_explicit_commit_sha(self, mock_client_cls: MagicMock) -> None:
|
||||
"""--git-sha with --commit-sha uses the explicit SHA for the comment."""
|
||||
mock_client = MagicMock()
|
||||
mock_client.list_project_tasks.return_value = [
|
||||
{"id": 267, "identifier": "GRM-20"},
|
||||
]
|
||||
mock_client_cls.return_value = mock_client
|
||||
mock_result = subprocess.CompletedProcess(args=[], returncode=0, stdout="GRM-20: fix: bug\n", stderr="")
|
||||
with patch("subprocess.run", return_value=mock_result):
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--git-sha", "abc123", "--commit-sha", "explicit_sha"])
|
||||
assert result.exit_code == 0
|
||||
args, _ = mock_client.post_comment.call_args
|
||||
assert "explicit_sha" in args[1]
|
||||
|
||||
Reference in New Issue
Block a user