diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2025-04-05 21:30:25 +0200 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2025-04-05 21:30:25 +0200 |
| commit | fdfb3abd3c595e4c5c42b4d854b152262c3b4614 (patch) | |
| tree | 209a4f23eb83cc3c6197f7097dd068c2ad024783 /servers/gitlab_glab/tests | |
| parent | fa91e3fcbdd3b1d70f01de256e1c48fe7726ebd4 (diff) | |
feat: add listing gitlab issues to glab mcp server
Diffstat (limited to 'servers/gitlab_glab/tests')
| -rw-r--r-- | servers/gitlab_glab/tests/test_integration.py | 7 | ||||
| -rw-r--r-- | servers/gitlab_glab/tests/test_server.py | 154 |
2 files changed, 159 insertions, 2 deletions
diff --git a/servers/gitlab_glab/tests/test_integration.py b/servers/gitlab_glab/tests/test_integration.py index 6915348..5d7eed5 100644 --- a/servers/gitlab_glab/tests/test_integration.py +++ b/servers/gitlab_glab/tests/test_integration.py @@ -23,7 +23,12 @@ class TestIntegration: mock_fastmcp.assert_called_once_with("GitLab CLI", host="127.0.0.1", port=8080) # Verify tools were registered - assert mock_server.tool.call_count == 3 # check_availability, find_project, create_issue + # Verify all tools are registered: + # - check_availability + # - find_project + # - search_issues + # - create_issue + assert mock_server.tool.call_count == 4 # Verify that the tool decorator was called with functions that have # working_directory parameter. We can't directly access the decorated functions diff --git a/servers/gitlab_glab/tests/test_server.py b/servers/gitlab_glab/tests/test_server.py index 0c7ce64..ab93026 100644 --- a/servers/gitlab_glab/tests/test_server.py +++ b/servers/gitlab_glab/tests/test_server.py @@ -278,7 +278,11 @@ class TestGitLabServer: assert "error" in result assert "not found" in result["error"] mock_execute.assert_called_once_with( - ["api", "/projects?search_namespaces=true&search=nonexistent-project"], working_dir + [ + "api", + "/projects?search_namespaces=true&search=nonexistent-project", + ], + working_dir ) @patch.object(GitLabServer, "execute_glab_command") @@ -298,6 +302,154 @@ class TestGitLabServer: ) @patch.object(GitLabServer, "execute_glab_command") + def test_search_issues_success(self, mock_execute: MagicMock) -> None: + """Test successful issue search with default parameters.""" + # Mock successful command execution with JSON output + mock_execute.return_value = ( + True, + [ + { + "id": 1, + "iid": 101, + "title": "Test Issue 1", + "web_url": "https://gitlab.com/group/project/issues/101", + "state": "opened", + "created_at": "2025-01-01T00:00:00Z", + "updated_at": "2025-01-02T00:00:00Z", + }, + { + "id": 2, + "iid": 102, + "title": "Test Issue 2", + "web_url": "https://gitlab.com/group/project/issues/102", + "state": "closed", + "created_at": "2025-01-03T00:00:00Z", + "updated_at": "2025-01-04T00:00:00Z", + }, + ], + ) + + server = GitLabServer() + working_dir = "/test/directory" + result = server.search_issues(working_directory=working_dir) + + assert "issues" in result + assert len(result["issues"]) == 2 + assert result["issues"][0]["id"] == 1 + assert result["issues"][0]["title"] == "Test Issue 1" + assert result["issues"][1]["id"] == 2 + assert result["issues"][1]["title"] == "Test Issue 2" + + # Verify command was called with correct arguments + mock_execute.assert_called_once_with( + ["issue", "list", "-O", "json"], + working_dir, + ) + + @patch.object(GitLabServer, "execute_glab_command") + def test_search_issues_with_filters(self, mock_execute: MagicMock) -> None: + """Test issue search with various filters.""" + # Mock successful command execution with JSON output + mock_execute.return_value = ( + True, + [ + { + "id": 1, + "iid": 101, + "title": "Test Issue 1", + "web_url": "https://gitlab.com/group/project/issues/101", + "state": "opened", + "created_at": "2025-01-01T00:00:00Z", + "updated_at": "2025-01-02T00:00:00Z", + }, + ], + ) + + server = GitLabServer() + working_dir = "/test/directory" + result = server.search_issues( + working_directory=working_dir, + author="user1", + assignee="user2", + closed=True, + confidential=True, + group="test-group", + issue_type="incident", + iteration=123, + label=["bug", "critical"], + milestone="v1.0", + not_assignee="user3", + not_author="user4", + not_label=["wontfix"], + page=2, + per_page=10, + project="group/project", + ) + + assert "issues" in result + assert len(result["issues"]) == 1 + assert result["issues"][0]["id"] == 1 + assert result["issues"][0]["title"] == "Test Issue 1" + + # Verify command was called with correct arguments + mock_execute.assert_called_once_with( + [ + "issue", "list", "-O", "json", + "--author", "user1", + "-a", "user2", + "-c", + "-C", + "-g", "test-group", + "-t", "incident", + "-i", "123", + "-l", "bug", + "-l", "critical", + "-m", "v1.0", + "--not-assignee", "user3", + "--not-author", "user4", + "--not-label", "wontfix", + "-p", "2", + "-P", "10", + "-R", "group/project", + ], + working_dir, + ) + + @patch.object(GitLabServer, "execute_glab_command") + def test_search_issues_failure(self, mock_execute: MagicMock) -> None: + """Test failed issue search.""" + # Mock failed command execution + mock_execute.return_value = (False, {"error": "Failed to list issues"}) + + server = GitLabServer() + working_dir = "/test/directory" + result = server.search_issues(working_directory=working_dir) + + assert "error" in result + assert result["error"] == "Failed to list issues" + mock_execute.assert_called_once_with( + ["issue", "list", "-O", "json"], + working_dir, + ) + + @patch.object(GitLabServer, "execute_glab_command") + def test_search_issues_invalid_json(self, mock_execute: MagicMock) -> None: + """Test issue search with invalid JSON response.""" + # Mock successful command execution but with invalid JSON + mock_execute.return_value = (True, "invalid json") + + server = GitLabServer() + working_dir = "/test/directory" + result = server.search_issues(working_directory=working_dir) + + assert "error" in result + assert result["error"] == "Failed to parse issues list" + mock_execute.assert_called_once_with( + ["issue", "list", "-O", "json"], + working_dir, + ) + + @patch.object(GitLabServer, "execute_glab_command") def test_create_issue_success(self, mock_execute: MagicMock) -> None: """Test successful issue creation with required parameters.""" # Mock successful command execution with actual glab output format |
