codeant-ai-for-open-source[bot] commented on code in PR #41497:
URL: https://github.com/apache/superset/pull/41497#discussion_r3540830749


##########
tests/unit_tests/mcp_service/theme/tool/test_list_themes.py:
##########
@@ -0,0 +1,126 @@
+# 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 list_themes MCP tool."""
+
+from collections.abc import Iterator
+from unittest.mock import MagicMock, Mock, patch
+
+import pytest
+from fastmcp import Client
+from pydantic import ValidationError
+
+from superset.mcp_service.app import mcp
+from superset.mcp_service.theme.schemas import ListThemesRequest, ThemeFilter
+from superset.utils import json
+
+
+def create_mock_theme(
+    theme_id: int = 1,
+    theme_name: str = "Corporate Blue",
+    json_data: str = '{"token": {"colorPrimary": "#1d4ed8"}}',
+    uuid: str = "11111111-1111-1111-1111-111111111111",
+) -> MagicMock:
+    theme = MagicMock()
+    theme.id = theme_id
+    theme.theme_name = theme_name
+    theme.json_data = json_data
+    theme.uuid = uuid
+    theme.is_system = False
+    theme.is_system_default = False
+    theme.is_system_dark = False
+    theme.changed_on = None
+    theme.created_on = None
+    return theme
+
+
[email protected]
+def mcp_server() -> object:
+    return mcp
+
+
[email protected](autouse=True)
+def mock_auth() -> Iterator[Mock]:
+    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
+
+
+class TestThemeFilterSchema:
+    """Tests for ThemeFilter schema โ€” filterable columns."""
+
+    def test_invalid_filter_column_rejected(self) -> None:
+        with pytest.raises(ValidationError):
+            ThemeFilter(col="not_a_real_column", opr="eq", value="x")
+
+    def test_valid_theme_name_filter(self) -> None:
+        f = ThemeFilter(col="theme_name", opr="ct", value="blue")
+        assert f.col == "theme_name"
+
+
+@patch("superset.daos.theme.ThemeDAO.list")
[email protected]
+async def test_list_themes_basic(mock_list, mcp_server) -> None:
+    """Basic theme listing returns the mocked theme."""
+    theme = create_mock_theme()
+    mock_list.return_value = ([theme], 1)
+    async with Client(mcp_server) as client:
+        request = ListThemesRequest(page=1, page_size=10)
+        result = await client.call_tool(
+            "list_themes", {"request": request.model_dump()}
+        )
+        assert result.content is not None
+        data = json.loads(result.content[0].text)
+        assert data["themes"] is not None
+        assert len(data["themes"]) == 1
+        assert data["themes"][0]["id"] == 1
+        assert "Corporate Blue" in data["themes"][0]["theme_name"]
+
+
+@patch("superset.daos.theme.ThemeDAO.list")
[email protected]
+async def test_list_themes_without_request(mock_list, mcp_server) -> None:
+    """Listing with no request payload uses defaults."""
+    theme = create_mock_theme()
+    mock_list.return_value = ([theme], 1)
+    async with Client(mcp_server) as client:
+        result = await client.call_tool("list_themes", {})
+        data = json.loads(result.content[0].text)
+        assert data["themes"] is not None
+        assert len(data["themes"]) == 1
+
+
+@patch("superset.daos.theme.ThemeDAO.list")
[email protected]
+async def test_list_themes_multiple(mock_list, mcp_server) -> None:

Review Comment:
   **Suggestion:** Annotate this functionโ€™s input parameters with concrete 
types to satisfy the type-hint requirement. [custom_rule]
   
   **Severity Level:** Minor โš ๏ธ
   <details>
   <summary><b>Why it matters? ๐Ÿค” </b></summary>
   
   This new async test function also leaves both parameters untyped, which 
violates the requirement to add type hints to new or modified Python functions 
where applicable.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=fd39487ab12342e29ac548aacaa5927c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=fd39487ab12342e29ac548aacaa5927c&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/theme/tool/test_list_themes.py
   **Line:** 112:112
   **Comment:**
        *Custom Rule: Annotate this functionโ€™s input parameters with concrete 
types to satisfy the type-hint requirement.
   
   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%2F41497&comment_hash=c8dffeb9a0795e444727e3ad8a80bcae5e0f1b25bcf14720e0663f6a67362d50&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41497&comment_hash=c8dffeb9a0795e444727e3ad8a80bcae5e0f1b25bcf14720e0663f6a67362d50&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/mcp_service/theme/tool/create_theme.py:
##########
@@ -0,0 +1,157 @@
+# 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.
+
+"""
+Create theme FastMCP tool
+
+Creates a reusable Superset theme from an antd design-token configuration.
+The supplied json_data is sanitized and validated with the same routine the
+REST API uses before the theme is persisted via ThemeDAO.
+"""
+
+import logging
+from typing import Any
+
+from fastmcp import Context
+from marshmallow import ValidationError
+from sqlalchemy.exc import SQLAlchemyError
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import db, event_logger
+from superset.mcp_service.theme.schemas import CreateThemeRequest, 
CreateThemeResponse
+from superset.mcp_service.utils.sanitization import sanitize_for_llm_context
+from superset.themes.schemas import _sanitize_and_validate_theme_config
+from superset.utils import json
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["mutate"],
+    class_permission_name="Theme",
+    method_permission_name="write",
+    annotations=ToolAnnotations(
+        title="Create theme",
+        readOnlyHint=False,
+        destructiveHint=False,
+    ),
+)
+async def create_theme(
+    request: CreateThemeRequest, ctx: Context
+) -> CreateThemeResponse:
+    """Create a reusable theme from antd design tokens.
+
+    Accepts a theme name and an antd design-token configuration (json_data),
+    supplied either as a JSON object or a JSON string. The configuration is
+    sanitized and validated the same way the REST API validates themes before
+    the theme is persisted.
+
+    Required fields:
+    - theme_name: Human-readable name for the theme
+    - json_data: The antd design-token configuration (dict or JSON string)
+
+    Example:
+    ```json
+    {
+        "theme_name": "Corporate Blue",
+        "json_data": {"token": {"colorPrimary": "#1d4ed8"}}
+    }
+    ```
+
+    Returns CreateThemeResponse with the new theme's id and uuid on success,
+    or an error response (error_type="ValidationError") if the configuration
+    is invalid.
+    """
+    await ctx.info("Creating theme: theme_name=%s" % (request.theme_name,))
+
+    # Parse json_data into a dict (accept dict or JSON string)
+    config_dict: dict[str, Any]
+    if isinstance(request.json_data, str):
+        try:
+            parsed = json.loads(request.json_data)

Review Comment:
   **Suggestion:** Add an explicit type annotation for this local variable to 
satisfy the type-hint requirement for newly introduced Python code. 
[custom_rule]
   
   **Severity Level:** Minor โš ๏ธ
   <details>
   <summary><b>Why it matters? ๐Ÿค” </b></summary>
   
   The new Python code introduces a local variable without a type annotation, 
and it is straightforwardly annotatable as part of the new implementation. This 
matches the type-hint requirement for newly added Python code.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=e228192e1b604b3ab15be493457ef062&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=e228192e1b604b3ab15be493457ef062&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:** superset/mcp_service/theme/tool/create_theme.py
   **Line:** 85:85
   **Comment:**
        *Custom Rule: Add an explicit type annotation for this local variable 
to satisfy the type-hint requirement for newly introduced Python code.
   
   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%2F41497&comment_hash=3e663933552fff31225fc4e4845b74856a72b5a007b82c4106e2ea22603f131b&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41497&comment_hash=3e663933552fff31225fc4e4845b74856a72b5a007b82c4106e2ea22603f131b&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]

Reply via email to