aminghadersohi commented on code in PR #44603:
URL: https://github.com/apache/superset/pull/44603#discussion_r4162529824


##########
tests/unit_tests/mcp_service/chart/tool/test_column_suggestions.py:
##########
@@ -0,0 +1,481 @@
+# 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.
+
+"""Column-error guidance uses only bounded, authorized dataset metadata."""
+
+from contextlib import nullcontext
+from typing import Any
+from unittest.mock import AsyncMock, Mock, patch
+
+import pytest
+
+from superset.mcp_service.chart.schemas import ColumnRef, GenerateChartRequest
+from superset.mcp_service.chart.tool.generate_chart import generate_chart
+from superset.mcp_service.chart.validation.dataset_validator import (
+    DatasetValidator,
+    MAX_ERROR_CONTEXT_COLUMNS,
+)
+from superset.mcp_service.common.error_schemas import DatasetContext
+from superset.mcp_service.utils.error_builder import ChartErrorBuilder
+
+GET_DATASET_INFO = "Use get_dataset_info to see available columns"
+
+
+def _orm_dataset(names: list[str]) -> Mock:

Review Comment:
   VALID — fixed in 4a10169594b6b98f84aaba2e888bd06f25f8d18f. Added a one-line 
docstring describing the ORM dataset mock returned by _orm_dataset, as required 
for new helpers. Column-suggestion and dataset-validator tests: 38 passed. 
Pre-commit passed on all changed files.



##########
tests/unit_tests/mcp_service/chart/tool/test_column_suggestions.py:
##########
@@ -0,0 +1,481 @@
+# 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.
+
+"""Column-error guidance uses only bounded, authorized dataset metadata."""
+
+from contextlib import nullcontext
+from typing import Any
+from unittest.mock import AsyncMock, Mock, patch
+
+import pytest
+
+from superset.mcp_service.chart.schemas import ColumnRef, GenerateChartRequest
+from superset.mcp_service.chart.tool.generate_chart import generate_chart
+from superset.mcp_service.chart.validation.dataset_validator import (
+    DatasetValidator,
+    MAX_ERROR_CONTEXT_COLUMNS,
+)
+from superset.mcp_service.common.error_schemas import DatasetContext
+from superset.mcp_service.utils.error_builder import ChartErrorBuilder
+
+GET_DATASET_INFO = "Use get_dataset_info to see available columns"
+
+
+def _orm_dataset(names: list[str]) -> Mock:
+    return Mock(
+        id=268,
+        table_name="sales_fixture",
+        schema=None,
+        database=Mock(database_name="fixture", db_engine_spec=None),
+        columns=[
+            Mock(
+                column_name=name,
+                type="VARCHAR",
+                is_temporal=False,
+                is_numeric=name == "revenue",
+            )
+            for name in names
+        ],
+        metrics=[
+            Mock(
+                metric_name="gross_margin",
+                expression="SUM(revenue)",
+                description="not a physical column",
+            )
+        ],
+    )
+
+
+def _bar_request(column: str) -> GenerateChartRequest:

Review Comment:
   VALID — fixed in 4a10169594b6b98f84aaba2e888bd06f25f8d18f. Added a one-line 
docstring describing the unsaved bar-chart request built by _bar_request. 
Column-suggestion and dataset-validator tests: 38 passed. Pre-commit passed on 
all changed files.



##########
tests/unit_tests/mcp_service/chart/tool/test_column_suggestions.py:
##########
@@ -0,0 +1,481 @@
+# 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.
+
+"""Column-error guidance uses only bounded, authorized dataset metadata."""
+
+from contextlib import nullcontext
+from typing import Any
+from unittest.mock import AsyncMock, Mock, patch
+
+import pytest
+
+from superset.mcp_service.chart.schemas import ColumnRef, GenerateChartRequest
+from superset.mcp_service.chart.tool.generate_chart import generate_chart
+from superset.mcp_service.chart.validation.dataset_validator import (
+    DatasetValidator,
+    MAX_ERROR_CONTEXT_COLUMNS,
+)
+from superset.mcp_service.common.error_schemas import DatasetContext
+from superset.mcp_service.utils.error_builder import ChartErrorBuilder
+
+GET_DATASET_INFO = "Use get_dataset_info to see available columns"
+
+
+def _orm_dataset(names: list[str]) -> Mock:
+    return Mock(
+        id=268,
+        table_name="sales_fixture",
+        schema=None,
+        database=Mock(database_name="fixture", db_engine_spec=None),
+        columns=[
+            Mock(
+                column_name=name,
+                type="VARCHAR",
+                is_temporal=False,
+                is_numeric=name == "revenue",
+            )
+            for name in names
+        ],
+        metrics=[
+            Mock(
+                metric_name="gross_margin",
+                expression="SUM(revenue)",
+                description="not a physical column",
+            )
+        ],
+    )
+
+
+def _bar_request(column: str) -> GenerateChartRequest:
+    return GenerateChartRequest.model_validate(
+        {
+            "dataset_id": 268,
+            "save_chart": False,
+            "config": {
+                "chart_type": "xy",
+                "kind": "bar",
+                "x": {"name": column},
+                "y": [{"name": "revenue", "aggregate": "SUM"}],
+            },
+        }
+    )
+
+
+def _ctx() -> Mock:

Review Comment:
   VALID — fixed in 4a10169594b6b98f84aaba2e888bd06f25f8d18f. Added a one-line 
docstring describing the asynchronous MCP logging and progress context mocked 
by _ctx. Column-suggestion and dataset-validator tests: 38 passed. Pre-commit 
passed on all changed files.



##########
superset/mcp_service/chart/validation/dataset_validator.py:
##########
@@ -45,6 +50,11 @@
     r"DOUBLE(?:\s+PRECISION)?|DECIMAL|NUMERIC|REAL|NUMBER|(?:SMALL)?MONEY)\b"
 )
 
+# How many dataset names a column error may carry as context. Callers that need
+# the full schema are pointed at ``get_dataset_info``.
+MAX_ERROR_CONTEXT_COLUMNS = 10
+MAX_ERROR_CONTEXT_METRICS = 10

Review Comment:
   VALID — fixed in 4a10169594b6b98f84aaba2e888bd06f25f8d18f. Removed the 
duplicate context caps and used MAX_ERROR_SUGGESTIONS throughout error-response 
list limits, including saved-metric guidance and template list formatting. The 
shared limit remains 10; the separate Did-you-mean limit remains 3. Extended 
coverage verifies columns and saved metrics remain bounded to 10 with 
names-only context. No behavior change. Column-suggestion and dataset-validator 
tests: 38 passed. Pre-commit passed on all changed files.



-- 
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