mirror of
https://github.com/apache/superset.git
synced 2026-04-18 07:35:09 +00:00
feat(mcp): dynamic feature availability via menus and feature flags (#37964)
This commit is contained in:
60
tests/unit_tests/mcp_service/system/test_system_utils.py
Normal file
60
tests/unit_tests/mcp_service/system/test_system_utils.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# 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 system-level utility functions."""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from superset.mcp_service.system.system_utils import calculate_feature_availability
|
||||
|
||||
|
||||
def test_calculate_feature_availability_returns_menus():
|
||||
"""Test that accessible menus are returned."""
|
||||
mock_sm = MagicMock()
|
||||
mock_sm.user_view_menu_names.return_value = {
|
||||
"SQL Lab",
|
||||
"Dashboards",
|
||||
"Charts",
|
||||
}
|
||||
|
||||
with patch("superset.security_manager", mock_sm):
|
||||
result = calculate_feature_availability({}, {}, {})
|
||||
|
||||
assert result.accessible_menus == ["Charts", "Dashboards", "SQL Lab"]
|
||||
mock_sm.user_view_menu_names.assert_called_once_with("menu_access")
|
||||
|
||||
|
||||
def test_calculate_feature_availability_empty_when_no_context():
|
||||
"""Test graceful fallback when security manager is unavailable."""
|
||||
broken_sm = MagicMock()
|
||||
broken_sm.user_view_menu_names.side_effect = RuntimeError("no ctx")
|
||||
|
||||
with patch("superset.security_manager", broken_sm):
|
||||
result = calculate_feature_availability({}, {}, {})
|
||||
|
||||
assert result.accessible_menus == []
|
||||
|
||||
|
||||
def test_calculate_feature_availability_menus_sorted():
|
||||
"""Test that accessible menus are returned in sorted order."""
|
||||
mock_sm = MagicMock()
|
||||
mock_sm.user_view_menu_names.return_value = {"Zzz", "Aaa", "Mmm"}
|
||||
|
||||
with patch("superset.security_manager", mock_sm):
|
||||
result = calculate_feature_availability({}, {}, {})
|
||||
|
||||
assert result.accessible_menus == ["Aaa", "Mmm", "Zzz"]
|
||||
@@ -60,6 +60,7 @@ def _make_instance_info(**kwargs):
|
||||
from superset.mcp_service.system.schemas import (
|
||||
DashboardBreakdown,
|
||||
DatabaseBreakdown,
|
||||
FeatureAvailability,
|
||||
InstanceSummary,
|
||||
PopularContent,
|
||||
RecentActivity,
|
||||
@@ -93,6 +94,7 @@ def _make_instance_info(**kwargs):
|
||||
),
|
||||
"database_breakdown": DatabaseBreakdown(by_type={}),
|
||||
"popular_content": PopularContent(top_tags=[], top_creators=[]),
|
||||
"feature_availability": FeatureAvailability(),
|
||||
"timestamp": datetime.now(timezone.utc),
|
||||
}
|
||||
defaults.update(kwargs)
|
||||
|
||||
@@ -55,6 +55,15 @@ def test_get_default_instructions_with_enterprise_branding():
|
||||
assert "execute_sql" in instructions
|
||||
|
||||
|
||||
def test_get_default_instructions_mentions_feature_availability():
|
||||
"""Test that instructions direct LLMs to get_instance_info for features."""
|
||||
instructions = get_default_instructions()
|
||||
|
||||
assert "get_instance_info" in instructions
|
||||
assert "Feature Availability" in instructions
|
||||
assert "accessible menus" in instructions
|
||||
|
||||
|
||||
def test_init_fastmcp_server_with_default_app_name():
|
||||
"""Test that default APP_NAME produces Superset branding."""
|
||||
# Mock Flask app config with default APP_NAME
|
||||
|
||||
Reference in New Issue
Block a user