arcanalytics commented on code in PR #44337: URL: https://github.com/apache/superset/pull/44337#discussion_r4037404936
########## tests/unit_tests/mcp_service/dataset/tool/test_delete_dataset.py: ########## @@ -0,0 +1,336 @@ +# 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 the delete_dataset MCP tool. + +Run through the async MCP Client (not direct calls); auth is mocked via the +autouse mock_auth fixture, matching the other dataset tool test files. +""" + +from collections.abc import Iterator +from unittest.mock import Mock, patch + +import pytest +from fastmcp import Client + +from superset.mcp_service.app import mcp + +_RESOLVE = "superset.mcp_service.dataset.tool.delete_dataset.resolve_dataset" +_COUNT = "superset.mcp_service.dataset.tool.delete_dataset._count_affected_objects" +_RUN = "superset.commands.dataset.delete.DeleteDatasetCommand.run" +_VALIDATE = "superset.commands.dataset.delete.DeleteDatasetCommand.validate" +_FLAG = "superset.mcp_service.dataset.tool.delete_dataset.is_feature_enabled" + + [email protected] +def mcp_server() -> object: + """Provide the FastMCP app instance under test.""" + return mcp + + [email protected](autouse=True) +def mock_auth() -> Iterator[Mock]: + """Authenticate every tool call as a mock admin user.""" + with patch("superset.mcp_service.auth.get_user_from_request") as mock_get_user: + # The tool validates the command (lookup + editorship) before counting + # dependents; default it to a pass so tests that patch run() alone keep + # working. The permission test re-patches it to raise. + with patch(_VALIDATE): + mock_user = Mock() Review Comment: All six findings on this model shared one root cause, so `00085fe2a73` removes the cause rather than patching each site. The model claimed to reconstruct the cohort as of a past date while reading current-state sources, which is why every round surfaced another input that was not historical. Since a flight cuts exactly once and the freshness gate makes it cut only when data is complete, that as-of machinery was buying reproducibility the model caveat already disclaimed. It is gone, and the description now says plainly that the cohort is a snapshot taken at cut time, made durable by writing once rather than by being replayable. The enrolment query is 216 lines shorter. Specifically: - Qualification gates on `is_winback_eligible`, the governed flag that already covers fraud, ban, current-subscriber and consent. That closes the missing fraud check and removes the hand-rolled ban and consent CTEs. - The freshness gate now covers `warehouse_internal.page_events`, the source the dormancy rule reads that it had missed, using a bounded seven-day lookback so the watermark scan stays cheap. - The MRR window inconsistency is gone: there is no per-day MRR read left, only peak value ever, with current-subscriber status coming from the governed flag. - `last_billing_country` is read at cut time and the description no longer claims otherwise. - Arm assignment applies `abs()` outside `mod()`, so a fingerprint of INT64_MIN cannot fail the build. Verified on prod: run one enrolled 1,424,343 users, an identical second run added 0, and all rows are distinct users. Delivery output is unchanged at 124,152 churned and 1,014,899 lapsed rows, because the users this removes were previously enrolled and then suppressed, so they never shipped. -- 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]
