codeant-ai-for-open-source[bot] commented on code in PR #41472: URL: https://github.com/apache/superset/pull/41472#discussion_r3555941421
########## tests/unit_tests/mcp_service/dashboard/tool/test_delete_dashboard.py: ########## @@ -0,0 +1,233 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Unit tests for the delete_dashboard MCP tool. + +Run through the async MCP Client; auth is mocked via the autouse mock_auth +fixture, matching the other dashboard tool test files. +""" + +from collections.abc import Iterator +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client + +from superset.mcp_service.app import mcp + +_FIND = ( + "superset.mcp_service.dashboard.tool.delete_dashboard._find_dashboard_by_identifier" +) +_RUN = "superset.commands.dashboard.delete.DeleteDashboardCommand.run" +_FLAG = "superset.mcp_service.dashboard.tool.delete_dashboard.is_feature_enabled" + + [email protected] +def mcp_server() -> object: + """Provide the FastMCP app instance under test.""" + return mcp + + [email protected](autouse=True) +def mock_auth() -> Iterator[Mock]: + """Authenticate every tool call as a mock admin user.""" + with patch("superset.mcp_service.auth.get_user_from_request") as mock_get_user: + mock_user = Mock() + mock_user.id = 1 + mock_user.username = "admin" + mock_get_user.return_value = mock_user + yield mock_get_user + + +def _mock_dashboard(dashboard_id: int = 1, title: str = "Sales Dashboard") -> Mock: + """Build a minimal dashboard stand-in with the attributes the tool reads.""" + dashboard = Mock() + dashboard.id = dashboard_id + dashboard.dashboard_title = title + return dashboard + + +@patch(_FIND) [email protected] +async def test_delete_dashboard_not_found(mock_find: Mock, mcp_server: object) -> None: + mock_find.return_value = None + + async with Client(mcp_server) as client: + result = await client.call_tool( + "delete_dashboard", {"request": {"identifier": 999}} + ) + + content = result.structured_content + assert content["success"] is False + assert content["error_type"] == "NotFound" + assert "999" in (content["error"] or "") + + +@patch(_RUN) +@patch(_FIND) [email protected] +async def test_delete_dashboard_success( + mock_find: Mock, mock_run: Mock, mcp_server: object +) -> None: + mock_find.return_value = _mock_dashboard(1, "Sales Dashboard") + mock_run.return_value = None + + async with Client(mcp_server) as client: + result = await client.call_tool( + "delete_dashboard", {"request": {"identifier": 1}} + ) + + content = result.structured_content + assert content["success"] is True + assert content["deleted_id"] == 1 + assert content["deleted_name"] == "Sales Dashboard" + assert content["permission_denied"] is False + assert "Its charts were not deleted" in (content["message"] or "") + mock_run.assert_called_once() + + +@patch(_FLAG) +@patch(_RUN) +@patch(_FIND) [email protected] +async def test_delete_dashboard_soft_delete_reports_restorable( + mock_find: Mock, mock_run: Mock, mock_flag: Mock, mcp_server: object +) -> None: + mock_find.return_value = _mock_dashboard(1, "Sales Dashboard") + mock_run.return_value = None + mock_flag.side_effect = lambda flag: flag == "SOFT_DELETE" Review Comment: **Suggestion:** Replace the inline lambda with a typed helper callable so the new function parameter is type-annotated. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This inline lambda introduces a new callable without any type hints, which falls under the rule requiring type hints for new Python functions or callables where annotations can be applied. Replacing it with a typed helper is therefore a valid identification of a rule violation. </details> <details> <summary><b>Rule source 📖 </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0245c3ade9534159bf3bf24791f3faf0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0245c3ade9534159bf3bf24791f3faf0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/mcp_service/dashboard/tool/test_delete_dashboard.py **Line:** 112:112 **Comment:** *Custom Rule: Replace the inline lambda with a typed helper callable so the new function parameter is type-annotated. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41472&comment_hash=e3684d8988c56b4173a3d24e2a2eab6163b6e6520ca457a69a7fb2c2e828a84e&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41472&comment_hash=e3684d8988c56b4173a3d24e2a2eab6163b6e6520ca457a69a7fb2c2e828a84e&reaction=dislike'>👎</a> ########## tests/unit_tests/mcp_service/dashboard/tool/test_delete_dashboard.py: ########## @@ -0,0 +1,233 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Unit tests for the delete_dashboard MCP tool. + +Run through the async MCP Client; auth is mocked via the autouse mock_auth +fixture, matching the other dashboard tool test files. +""" + +from collections.abc import Iterator +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client + +from superset.mcp_service.app import mcp + +_FIND = ( + "superset.mcp_service.dashboard.tool.delete_dashboard._find_dashboard_by_identifier" +) +_RUN = "superset.commands.dashboard.delete.DeleteDashboardCommand.run" +_FLAG = "superset.mcp_service.dashboard.tool.delete_dashboard.is_feature_enabled" Review Comment: **Suggestion:** Add explicit type annotations to the module-level constants so these new variables are fully typed. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> The file is new Python code and these module-level variables are plainly annotatable (for example, as `str`). The custom rule requires type hints on relevant variables in new or modified Python code, so leaving these constants unannotated is a real rule violation. </details> <details> <summary><b>Rule source 📖 </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ad1719e9545a40b7a924e48c7656e8b3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=ad1719e9545a40b7a924e48c7656e8b3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/mcp_service/dashboard/tool/test_delete_dashboard.py **Line:** 32:36 **Comment:** *Custom Rule: Add explicit type annotations to the module-level constants so these new variables are fully typed. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41472&comment_hash=8fb49f57639d67f0e345656f8c55ed970b78933d5db68c8ed2723d4938d0c536&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41472&comment_hash=8fb49f57639d67f0e345656f8c55ed970b78933d5db68c8ed2723d4938d0c536&reaction=dislike'>👎</a> ########## tests/unit_tests/mcp_service/chart/tool/test_delete_chart.py: ########## @@ -0,0 +1,229 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Unit tests for the delete_chart MCP tool. + +Run through the async MCP Client (not direct calls); auth is mocked via the +autouse mock_auth fixture, matching the other chart tool test files. +""" + +from collections.abc import Iterator +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client + +from superset.mcp_service.app import mcp + + [email protected] +def mcp_server() -> object: + """Provide the FastMCP app instance under test.""" + return mcp + + [email protected](autouse=True) +def mock_auth() -> Iterator[Mock]: + """Authenticate every tool call as a mock admin user.""" + with patch("superset.mcp_service.auth.get_user_from_request") as mock_get_user: + mock_user = Mock() + mock_user.id = 1 + mock_user.username = "admin" + mock_get_user.return_value = mock_user + yield mock_get_user + + +def _mock_chart(chart_id: int = 10, slice_name: str = "Test Chart") -> Mock: + """Build a minimal chart stand-in with the attributes the tool reads.""" + chart = Mock() + chart.id = chart_id + chart.slice_name = slice_name + return chart + + +@patch("superset.mcp_service.chart.tool.delete_chart.find_chart_by_identifier") [email protected] +async def test_delete_chart_not_found(mock_find: Mock, mcp_server: object) -> None: + mock_find.return_value = None + + async with Client(mcp_server) as client: + result = await client.call_tool( + "delete_chart", {"request": {"identifier": 999}} + ) + + content = result.structured_content + assert content["success"] is False + assert content["error_type"] == "NotFound" + assert "999" in (content["error"] or "") + + +@patch("superset.commands.chart.delete.DeleteChartCommand.run") +@patch("superset.mcp_service.chart.tool.delete_chart.find_chart_by_identifier") [email protected] +async def test_delete_chart_success( + mock_find: Mock, mock_run: Mock, mcp_server: object +) -> None: + mock_find.return_value = _mock_chart(chart_id=10, slice_name="Sales") + mock_run.return_value = None + + async with Client(mcp_server) as client: + result = await client.call_tool("delete_chart", {"request": {"identifier": 10}}) + + content = result.structured_content + assert content["success"] is True + assert content["deleted_id"] == 10 + assert content["deleted_name"] == "Sales" + assert content["permission_denied"] is False + mock_run.assert_called_once() + + +@patch("superset.mcp_service.chart.tool.delete_chart.is_feature_enabled") +@patch("superset.commands.chart.delete.DeleteChartCommand.run") +@patch("superset.mcp_service.chart.tool.delete_chart.find_chart_by_identifier") [email protected] +async def test_delete_chart_soft_delete_reports_restorable( + mock_find: Mock, mock_run: Mock, mock_flag: Mock, mcp_server: object +) -> None: + mock_find.return_value = _mock_chart(chart_id=10, slice_name="Sales") + mock_run.return_value = None + mock_flag.side_effect = lambda flag: flag == "SOFT_DELETE" Review Comment: **Suggestion:** Replace the untyped lambda with a small named helper function that includes an explicit parameter type annotation (and return type), then assign it to the mock side effect. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This is new Python code with an untyped lambda. Under the type-hint rule, a callable that can be annotated should not be left without parameter and return type hints; replacing it with a typed helper function would satisfy the rule. </details> <details> <summary><b>Rule source 📖 </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9d86b6b10a744be4aa72b6e954067a42&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9d86b6b10a744be4aa72b6e954067a42&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/mcp_service/chart/tool/test_delete_chart.py **Line:** 103:103 **Comment:** *Custom Rule: Replace the untyped lambda with a small named helper function that includes an explicit parameter type annotation (and return type), then assign it to the mock side effect. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41472&comment_hash=7add9ba70d6089893c2f9531fc28c259873e24d15556f12053c73bde65e42577&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41472&comment_hash=7add9ba70d6089893c2f9531fc28c259873e24d15556f12053c73bde65e42577&reaction=dislike'>👎</a> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
