bito-code-review[bot] commented on code in PR #36767: URL: https://github.com/apache/superset/pull/36767#discussion_r2635045379
########## tests/unit_tests/extensions/test_types.py: ########## @@ -0,0 +1,248 @@ +# 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 extension configuration and manifest Pydantic models.""" + +import pytest +from pydantic import ValidationError +from superset_core.extensions.types import ( + ContributionConfig, + ExtensionConfig, + ExtensionConfigBackend, + ExtensionConfigFrontend, + Manifest, + ManifestBackend, + ModuleFederationConfig, +) + +# ============================================================================= +# ExtensionConfig (extension.json) tests +# ============================================================================= + + +def test_extension_config_minimal(): + """Test ExtensionConfig with minimal required fields.""" + config = ExtensionConfig.model_validate( + { + "id": "my-extension", + "name": "My Extension", + } + ) + assert config.id == "my-extension" + assert config.name == "My Extension" + assert config.version == "0.0.0" + assert config.dependencies == [] + assert config.permissions == [] + assert config.frontend is None + assert config.backend is None + + +def test_extension_config_full(): + """Test ExtensionConfig with all fields populated.""" + config = ExtensionConfig.model_validate( + { + "id": "query_insights", + "name": "Query Insights", + "version": "1.0.0", + "license": "Apache-2.0", + "description": "A query insights extension", + "dependencies": ["other-extension"], + "permissions": ["can_read", "can_view"], + "frontend": { + "contributions": { + "views": { + "sqllab.panels": [ + {"id": "query_insights.main", "name": "Query Insights"} + ] + } + }, + "moduleFederation": {"exposes": ["./index"]}, + }, + "backend": { + "entryPoints": ["query_insights.entrypoint"], + "files": ["backend/src/query_insights/**/*.py"], + }, + } + ) + assert config.id == "query_insights" + assert config.name == "Query Insights" + assert config.version == "1.0.0" + assert config.license == "Apache-2.0" + assert config.description == "A query insights extension" + assert config.dependencies == ["other-extension"] + assert config.permissions == ["can_read", "can_view"] + assert config.frontend is not None + assert config.frontend.moduleFederation.exposes == ["./index"] + assert config.backend is not None + assert config.backend.entryPoints == ["query_insights.entrypoint"] + assert config.backend.files == ["backend/src/query_insights/**/*.py"] + + +def test_extension_config_missing_id(): + """Test ExtensionConfig raises error when id is missing.""" + with pytest.raises(ValidationError) as exc_info: + ExtensionConfig.model_validate({"name": "My Extension"}) + assert "id" in str(exc_info.value) + + +def test_extension_config_missing_name(): + """Test ExtensionConfig raises error when name is missing.""" + with pytest.raises(ValidationError) as exc_info: + ExtensionConfig.model_validate({"id": "my-extension"}) + assert "name" in str(exc_info.value) + + +def test_extension_config_empty_id(): + """Test ExtensionConfig raises error when id is empty.""" + with pytest.raises(ValidationError) as exc_info: + ExtensionConfig.model_validate({"id": "", "name": "My Extension"}) + assert "id" in str(exc_info.value) + + +def test_extension_config_invalid_version(): + """Test ExtensionConfig raises error for invalid version format.""" + with pytest.raises(ValidationError) as exc_info: + ExtensionConfig.model_validate( + {"id": "my-extension", "name": "My Extension", "version": "invalid"} + ) + assert "version" in str(exc_info.value) + + +def test_extension_config_valid_versions(): + """Test ExtensionConfig accepts valid semantic versions.""" + for version in ["1.0.0", "0.1.0", "10.20.30", "1.0.0-beta"]: + config = ExtensionConfig.model_validate( + {"id": "my-extension", "name": "My Extension", "version": version} + ) + assert config.version == version Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Version validation mismatch</b></div> <div id="fix"> The test for valid versions includes '1.0.0-beta', but the Pydantic pattern for version only allows major.minor.patch format without pre-release identifiers. This will cause the test to fail unexpectedly. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ``` --- a/tests/unit_tests/extensions/test_types.py +++ b/tests/unit_tests/extensions/test_types.py @@ -125,7 +125,7 @@ def test_extension_config_invalid_version(): def test_extension_config_valid_versions(): """Test ExtensionConfig accepts valid semantic versions.""" - for version in ["1.0.0", "0.1.0", "10.20.30", "1.0.0-beta"]: + for version in ["1.0.0", "0.1.0", "10.20.30"]: config = ExtensionConfig.model_validate( {"id": "my-extension", "name": "My Extension", "version": version} ) assert config.version == version ``` </div> </details> </div> <small><i>Code Review Run #44297a</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- 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]
