codeant-ai-for-open-source[bot] commented on code in PR #41611: URL: https://github.com/apache/superset/pull/41611#discussion_r3531345734
########## tests/unit_tests/mcp_service/utils/test_query_utils.py: ########## @@ -0,0 +1,62 @@ +# 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 MCP service query utilities. +""" + +from superset.mcp_service.utils.query_utils import validate_names + + +class TestValidateNames: + """Test validate_names function.""" + + def test_all_names_valid_returns_no_errors(self): + """Should return an empty list when every name is valid.""" + errors = validate_names( + ["region", "product"], {"region", "product"}, "dimension" + ) + assert errors == [] + + def test_empty_requested_returns_no_errors(self): + """Should return an empty list when nothing was requested.""" + errors = validate_names([], {"region"}, "dimension") + assert errors == [] + + def test_unknown_name_without_close_match(self): + """Should report an unknown name with no suggestion when nothing is close.""" + errors = validate_names(["zzz_unknown"], {"region", "product"}, "dimension") + assert len(errors) == 1 + assert errors[0] == "Unknown dimension: 'zzz_unknown'" + + def test_unknown_name_with_close_match_suggests_alternatives(self): + """Should suggest close matches when available.""" + errors = validate_names(["regoin"], {"region", "product"}, "dimension") + assert len(errors) == 1 + assert errors[0].startswith("Unknown dimension: 'regoin'") + assert "Did you mean: region" in errors[0] + + def test_multiple_unknown_names_produce_multiple_errors(self): + """Should produce one error per unknown name.""" + errors = validate_names(["revenue", "bogus_metric"], {"revenue"}, "metric") + assert len(errors) == 1 + assert "bogus_metric" in errors[0] Review Comment: **Suggestion:** The test name claims to verify behavior for multiple unknown names, but the input only contains one unknown value (`bogus_metric`) while `revenue` is valid. This leaves the actual multi-unknown path untested and can let regressions slip through; either rename the test to match its real scope or pass two invalid names and assert two errors. [inconsistent naming] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ⚠️ Multi-unknown-name validation behavior not covered by tests. - ⚠️ QueryDataset MCP tool validation may regress unnoticed. - ⚠️ Test name and docstring misleading for maintainers. ``` </details> <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Run the test module `tests/unit_tests/mcp_service/utils/test_query_utils.py` and observe `TestValidateNames.test_multiple_unknown_names_produce_multiple_errors` at lines 53-57, which calls `validate_names(["revenue", "bogus_metric"], {"revenue"}, "metric")` and asserts `len(errors) == 1`. 2. Inspect the implementation of `validate_names()` in `superset/mcp_service/utils/query_utils.py:23-39`, which iterates over each requested name and appends an error message for every name not present in the `valid` set. 3. Note that in the test at lines 53-57 only `bogus_metric` is invalid because `"revenue"` is included in the `valid` set, so the path where multiple names are invalid (and would yield multiple errors) is never exercised despite the test name and docstring claiming "one error per unknown name". 4. Check the production usage of `validate_names()` in `superset/mcp_service/dataset/tool/query_dataset.py:13-33`, where it validates requested columns, metrics, filter columns, and order_by fields; because the multi-unknown case is untested, a future regression in handling multiple invalid names could impact query validation without being caught by this test. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=e82ee3a710e84ec2a1c14249bac43db2&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=e82ee3a710e84ec2a1c14249bac43db2&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/utils/test_query_utils.py **Line:** 53:57 **Comment:** *Inconsistent Naming: The test name claims to verify behavior for multiple unknown names, but the input only contains one unknown value (`bogus_metric`) while `revenue` is valid. This leaves the actual multi-unknown path untested and can let regressions slip through; either rename the test to match its real scope or pass two invalid names and assert two errors. 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%2F41611&comment_hash=945a5d902b1c53d3e8069ca1be6aa8de6668bdd1f5e23ac42b694b8df4531c2c&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41611&comment_hash=945a5d902b1c53d3e8069ca1be6aa8de6668bdd1f5e23ac42b694b8df4531c2c&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]
