bito-code-review[bot] commented on code in PR #40652: URL: https://github.com/apache/superset/pull/40652#discussion_r3337935090
########## tests/unit_tests/views/health_version_test.py: ########## @@ -0,0 +1,72 @@ +# 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 ``/version`` endpoint and ``EXPOSE_VERSION_INFO`` gating.""" + +from typing import Any + +from pytest_mock import MockerFixture + +FULL_METADATA = { + "version_string": "1.2.3", + "version_sha": "abcd1234", + "full_sha": "abcd1234ef567890", + "build_number": "42", + "branch_name": "master", +} + + +def test_version_exposes_full_metadata_by_default( + client: Any, + mocker: MockerFixture, +) -> None: + """With EXPOSE_VERSION_INFO True (default) the full metadata is returned.""" + mocker.patch( + "superset.utils.version.get_version_metadata", + return_value=dict(FULL_METADATA), + ) + client.application.config["EXPOSE_VERSION_INFO"] = True + + response = client.get("/version") + assert response.status_code == 200 + + body = response.get_json() + assert body["version_string"] == "1.2.3" + assert body["version_sha"] == "abcd1234" + assert body["full_sha"] == "abcd1234ef567890" + assert body["branch_name"] == "master" + Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Missing build_number assertion</b></div> <div id="fix"> The positive test case asserts `version_string`, `version_sha`, `full_sha`, and `branch_name` but does not assert `build_number`. Since the mock data includes `"build_number": "42"` and the endpoint exposes all fields when `EXPOSE_VERSION_INFO` is True, this assertion should be added to complete test coverage. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ``` --- a/tests/unit_tests/views/health_version_test.py +++ b/tests/unit_tests/views/health_version_test.py @@ -48,6 +48,7 @@ def test_version_exposes_full_metadata_by_default( assert body["full_sha"] == "abcd1234ef567890" assert body["branch_name"] == "master" assert body["build_number"] == "42" + def test_version_redacts_details_when_flag_disabled( client: Any, ``` </div> </details> </div> <small><i>Code Review Run #fabd4a</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]
