Copilot commented on code in PR #41698:
URL: https://github.com/apache/superset/pull/41698#discussion_r3537775023
##########
tests/unit_tests/mcp_service/utils/test_token_utils.py:
##########
@@ -677,3 +677,42 @@ def test_progressive_truncation(self) -> None:
assert isinstance(result, dict)
assert result["id"] == 1 # Scalar fields preserved
assert len(notes) > 0
+
+ def test_large_dashboard_respects_default_max_list_items(self) -> None:
+ """Regression test for the Medialab large-dashboard report.
+
+ A dashboard with 463 charts and 48 native_filters should have
+ native_filters (48 items) left untouched under the new default cap
+ of 100, while charts (463 items) is truncated to 100 — a clear
+ improvement over the old flat 30-item cap, which truncated both.
+ """
+ response = {
+ "id": 1,
+ "dashboard_title": "x" * 2000, # forces Phase 2 to trigger
+ "charts": [{"id": i, "slice_name": f"chart_{i}"} for i in
range(463)],
+ "native_filters": [{"id": i, "name": f"filter_{i}"} for i in
range(48)],
+ }
+ result, was_truncated, notes = truncate_oversized_response(response,
3000)
+ assert was_truncated is True
+ assert isinstance(result, dict)
+ assert len(result["charts"]) == 100
+ assert len(result["native_filters"]) == 48
+ assert any("charts" in n and "463" in n for n in notes)
+ assert not any("native_filters" in n for n in notes)
+
+ def test_large_dashboard_respects_custom_max_list_items(self) -> None:
+ """A custom max_list_items should truncate both fields to that cap."""
+ response = {
Review Comment:
The test docstring says the custom `max_list_items` “should truncate both
fields”, but the assertions verify `native_filters` is *not* truncated when
it’s under the cap. This mismatch makes the test intent unclear and could
mislead future changes.
##########
superset/mcp_service/middleware.py:
##########
@@ -1451,6 +1457,7 @@ def create_response_size_guard_middleware() ->
ResponseSizeGuardMiddleware | Non
config.get("warn_threshold_pct", DEFAULT_WARN_THRESHOLD_PCT)
),
excluded_tools=config.get("excluded_tools"),
+ max_list_items=int(config.get("max_list_items",
DEFAULT_MAX_LIST_ITEMS)),
)
Review Comment:
`create_response_size_guard_middleware()` casts `max_list_items` with
`int(...)`. If an operator sets `MCP_RESPONSE_SIZE_CONFIG['max_list_items'] =
None` (or otherwise falsy), this will raise `TypeError` and prevent the
middleware from being created. Using the default when the config value is
missing/None avoids this startup-time failure mode.
##########
superset/mcp_service/middleware.py:
##########
@@ -1182,13 +1184,15 @@ def __init__(
token_limit: int = DEFAULT_TOKEN_LIMIT,
warn_threshold_pct: int = DEFAULT_WARN_THRESHOLD_PCT,
excluded_tools: list[str] | str | None = None,
+ max_list_items: int = DEFAULT_MAX_LIST_ITEMS,
) -> None:
self.token_limit = token_limit
self.warn_threshold_pct = warn_threshold_pct
self.warn_threshold = int(token_limit * warn_threshold_pct / 100)
if isinstance(excluded_tools, str):
excluded_tools = [excluded_tools]
self.excluded_tools = set(excluded_tools or [])
+ self.max_list_items = max_list_items
Review Comment:
`max_list_items` can be configured via `MCP_RESPONSE_SIZE_CONFIG`. If it’s
set to 0 or a negative number, Phase 2 list truncation will behave unexpectedly
(e.g. `list[:-1]` for -1) and the truncation note will report a nonsensical
cap. Clamping to a minimum of 1 here avoids surprising runtime behavior from a
simple config mistake.
--
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]