codeant-ai-for-open-source[bot] commented on code in PR #42070: URL: https://github.com/apache/superset/pull/42070#discussion_r3599827374
########## tests/unit_tests/mcp_service/chart/test_waterfall_chart.py: ########## @@ -0,0 +1,257 @@ +# 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. + +"""Tests for the waterfall chart type plugin. + +Schema validation, form_data mapping (matching the frontend Waterfall +buildQuery/transformProps contract for viz_type ``waterfall``), native +vocabulary aliases, and registry integration. +""" + +import pytest +from pydantic import TypeAdapter, ValidationError + +from superset.mcp_service.chart.chart_utils import map_waterfall_config +from superset.mcp_service.chart.schemas import ChartConfig, WaterfallChartConfig + + +class TestWaterfallChartConfigSchema: + """WaterfallChartConfig schema validation.""" + + def test_basic_waterfall_config(self) -> None: + config = WaterfallChartConfig( Review Comment: **Suggestion:** Add an explicit variable type annotation for this local configuration object to satisfy the type-hint requirement. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> The variable `config` is assigned the result of `WaterfallChartConfig(...)` without an explicit type annotation. This is a newly added Python line in a new test file, and it matches the rule's requirement to annotate relevant variables that can be typed. </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=d1847eba8b784a3aa588b82871617033&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=d1847eba8b784a3aa588b82871617033&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/test_waterfall_chart.py **Line:** 36:36 **Comment:** *Custom Rule: Add an explicit variable type annotation for this local configuration object 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%2F42070&comment_hash=2e8e534af9f8d3e3de0fe0002b4956140cf03479a01d6071ca0d212d8994ce88&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42070&comment_hash=2e8e534af9f8d3e3de0fe0002b4956140cf03479a01d6071ca0d212d8994ce88&reaction=dislike'>๐</a> ########## tests/unit_tests/mcp_service/chart/test_waterfall_chart.py: ########## @@ -0,0 +1,257 @@ +# 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. + +"""Tests for the waterfall chart type plugin. + +Schema validation, form_data mapping (matching the frontend Waterfall +buildQuery/transformProps contract for viz_type ``waterfall``), native +vocabulary aliases, and registry integration. +""" + +import pytest +from pydantic import TypeAdapter, ValidationError + +from superset.mcp_service.chart.chart_utils import map_waterfall_config +from superset.mcp_service.chart.schemas import ChartConfig, WaterfallChartConfig + + +class TestWaterfallChartConfigSchema: + """WaterfallChartConfig schema validation.""" + + def test_basic_waterfall_config(self) -> None: + config = WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "month"}, + metric={"name": "revenue_delta", "aggregate": "SUM"}, + ) + assert config.x_axis.name == "month" + assert config.breakdown is None + assert config.show_total is True # frontend controlPanel default + + def test_waterfall_missing_x_axis(self) -> None: + with pytest.raises(ValidationError): + WaterfallChartConfig( + chart_type="waterfall", + metric={"name": "revenue", "aggregate": "SUM"}, + ) + + def test_waterfall_missing_metric(self) -> None: + with pytest.raises(ValidationError): + WaterfallChartConfig(chart_type="waterfall", x_axis={"name": "month"}) + + def test_waterfall_rejects_extra_fields(self) -> None: + with pytest.raises(ValidationError): + WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "month"}, + metric={"name": "revenue", "aggregate": "SUM"}, + bogus=1, + ) + + def test_waterfall_breakdown_rejects_saved_metric(self) -> None: + """The breakdown is a dimension, not a metric.""" + with pytest.raises(ValidationError): + WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "month"}, + metric={"name": "revenue", "aggregate": "SUM"}, + breakdown={"name": "count", "saved_metric": True}, + ) + + def test_waterfall_x_axis_rejects_saved_metric(self) -> None: + with pytest.raises(ValidationError): + WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "count", "saved_metric": True}, + metric={"name": "revenue", "aggregate": "SUM"}, + ) + + def test_groupby_alias_for_breakdown(self) -> None: + """Superset-native 'groupby' is accepted for the breakdown field.""" + config = WaterfallChartConfig.model_validate( + { + "chart_type": "waterfall", + "x_axis": {"name": "month"}, + "metric": {"name": "revenue", "aggregate": "SUM"}, + "groupby": {"name": "region"}, + } + ) + assert config.breakdown is not None + assert config.breakdown.name == "region" + + def test_chart_config_union_dispatches_waterfall(self) -> None: + config = TypeAdapter(ChartConfig).validate_python( + { + "chart_type": "waterfall", + "x_axis": {"name": "month"}, + "metric": {"name": "revenue", "aggregate": "SUM"}, + } + ) + assert isinstance(config, WaterfallChartConfig) + + +class TestMapWaterfallConfig: + """form_data mapping must match the frontend Waterfall buildQuery.""" + + def test_basic_waterfall_form_data(self) -> None: + config = WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "month"}, + metric={"name": "revenue_delta", "aggregate": "SUM"}, + ) + form_data = map_waterfall_config(config) + assert form_data["viz_type"] == "waterfall" + assert form_data["x_axis"] == "month" + assert form_data["groupby"] == [] + assert form_data["metric"]["label"] == "SUM(revenue_delta)" + assert form_data["show_total"] is True + + def test_waterfall_form_data_with_breakdown_and_filters(self) -> None: + config = WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "month"}, + metric={"name": "revenue", "aggregate": "SUM"}, + breakdown={"name": "region"}, + filters=[{"column": "year", "op": "=", "value": 2026}], + show_total=False, + ) + form_data = map_waterfall_config(config) + # single breakdown maps to the groupby list (frontend multi: false) + assert form_data["groupby"] == ["region"] + assert form_data["show_total"] is False + assert form_data["adhoc_filters"], "filters must map to adhoc_filters" + + +class TestWaterfallPluginRegistry: + """Plugin registration and viz-type resolution.""" + + def test_waterfall_plugin_registered(self) -> None: + from superset.mcp_service.chart import registry + + plugin = registry.get("waterfall") + assert plugin is not None Review Comment: **Suggestion:** Add an explicit type annotation for this plugin variable so the method body remains fully compliant with the required typing standard. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> `plugin` is assigned from `registry.get("waterfall")` without a type annotation. This is a newly added local variable in Python code and is a valid target for the required type-hinting 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=27185b3fa45846eea18197488f758682&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=27185b3fa45846eea18197488f758682&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/test_waterfall_chart.py **Line:** 146:146 **Comment:** *Custom Rule: Add an explicit type annotation for this plugin variable so the method body remains fully compliant with the required typing standard. 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%2F42070&comment_hash=56bcc182d647461912af17d9283e1dc7b5ada09d37c5cae1b4e6eec8a349062e&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42070&comment_hash=56bcc182d647461912af17d9283e1dc7b5ada09d37c5cae1b4e6eec8a349062e&reaction=dislike'>๐</a> ########## tests/unit_tests/mcp_service/chart/test_waterfall_chart.py: ########## @@ -0,0 +1,257 @@ +# 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. + +"""Tests for the waterfall chart type plugin. + +Schema validation, form_data mapping (matching the frontend Waterfall +buildQuery/transformProps contract for viz_type ``waterfall``), native +vocabulary aliases, and registry integration. +""" + +import pytest +from pydantic import TypeAdapter, ValidationError + +from superset.mcp_service.chart.chart_utils import map_waterfall_config +from superset.mcp_service.chart.schemas import ChartConfig, WaterfallChartConfig + + +class TestWaterfallChartConfigSchema: + """WaterfallChartConfig schema validation.""" + + def test_basic_waterfall_config(self) -> None: + config = WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "month"}, + metric={"name": "revenue_delta", "aggregate": "SUM"}, + ) + assert config.x_axis.name == "month" + assert config.breakdown is None + assert config.show_total is True # frontend controlPanel default + + def test_waterfall_missing_x_axis(self) -> None: + with pytest.raises(ValidationError): + WaterfallChartConfig( + chart_type="waterfall", + metric={"name": "revenue", "aggregate": "SUM"}, + ) + + def test_waterfall_missing_metric(self) -> None: + with pytest.raises(ValidationError): + WaterfallChartConfig(chart_type="waterfall", x_axis={"name": "month"}) + + def test_waterfall_rejects_extra_fields(self) -> None: + with pytest.raises(ValidationError): + WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "month"}, + metric={"name": "revenue", "aggregate": "SUM"}, + bogus=1, + ) + + def test_waterfall_breakdown_rejects_saved_metric(self) -> None: + """The breakdown is a dimension, not a metric.""" + with pytest.raises(ValidationError): + WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "month"}, + metric={"name": "revenue", "aggregate": "SUM"}, + breakdown={"name": "count", "saved_metric": True}, + ) + + def test_waterfall_x_axis_rejects_saved_metric(self) -> None: + with pytest.raises(ValidationError): + WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "count", "saved_metric": True}, + metric={"name": "revenue", "aggregate": "SUM"}, + ) + + def test_groupby_alias_for_breakdown(self) -> None: + """Superset-native 'groupby' is accepted for the breakdown field.""" + config = WaterfallChartConfig.model_validate( + { + "chart_type": "waterfall", + "x_axis": {"name": "month"}, + "metric": {"name": "revenue", "aggregate": "SUM"}, + "groupby": {"name": "region"}, + } + ) + assert config.breakdown is not None + assert config.breakdown.name == "region" + + def test_chart_config_union_dispatches_waterfall(self) -> None: + config = TypeAdapter(ChartConfig).validate_python( + { + "chart_type": "waterfall", + "x_axis": {"name": "month"}, + "metric": {"name": "revenue", "aggregate": "SUM"}, + } + ) + assert isinstance(config, WaterfallChartConfig) + + +class TestMapWaterfallConfig: + """form_data mapping must match the frontend Waterfall buildQuery.""" + + def test_basic_waterfall_form_data(self) -> None: + config = WaterfallChartConfig( + chart_type="waterfall", + x_axis={"name": "month"}, + metric={"name": "revenue_delta", "aggregate": "SUM"}, + ) + form_data = map_waterfall_config(config) Review Comment: **Suggestion:** Add a concrete type annotation for this mapped form-data variable (for example a dictionary type) to comply with required variable hints. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> `form_data` is a local variable inferred from a function call and is left unannotated. Since it is a new Python statement in the added test file, it falls under the type-hint rule for relevant variables that can be annotated. </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=b31864c1d5874c3caf1ac3daa1371e44&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=b31864c1d5874c3caf1ac3daa1371e44&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/test_waterfall_chart.py **Line:** 116:116 **Comment:** *Custom Rule: Add a concrete type annotation for this mapped form-data variable (for example a dictionary type) to comply with required variable hints. 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%2F42070&comment_hash=fe2f2ffdad2afeef7d4281fba085f74b2172de140d6b09076644a7db5dff82d9&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42070&comment_hash=fe2f2ffdad2afeef7d4281fba085f74b2172de140d6b09076644a7db5dff82d9&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]
