codeant-ai-for-open-source[bot] commented on code in PR #41299: URL: https://github.com/apache/superset/pull/41299#discussion_r3456266519
########## tests/unit_tests/test_check_secret_key.py: ########## @@ -0,0 +1,64 @@ +# 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 SupersetAppInitializer.check_secret_key.""" + +from unittest.mock import MagicMock, patch + +import pytest + +from superset.constants import CHANGE_ME_SECRET_KEY +from superset.initialization import SupersetAppInitializer + + +def _make_initializer(secret_key, *, debug=False, testing=False): Review Comment: **Suggestion:** Add explicit type annotations for all parameters and the return type on this helper function to satisfy the fully-typed new Python code rule. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This is a newly added Python helper function, and it omits type annotations for its parameters and return value. The custom rule requires new Python code to be fully typed, so this is a real violation. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=85133ddab5f14ef3b293df8202a29f54&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=85133ddab5f14ef3b293df8202a29f54&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/test_check_secret_key.py **Line:** 27:27 **Comment:** *Custom Rule: Add explicit type annotations for all parameters and the return type on this helper function to satisfy the fully-typed new Python code rule. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41299&comment_hash=4eac4a3b5cbeab2d32be2350f248e5735845721ebac925861cb2ed1691ee6954&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41299&comment_hash=4eac4a3b5cbeab2d32be2350f248e5735845721ebac925861cb2ed1691ee6954&reaction=dislike'>👎</a> ########## tests/unit_tests/test_check_secret_key.py: ########## @@ -0,0 +1,64 @@ +# 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 SupersetAppInitializer.check_secret_key.""" + +from unittest.mock import MagicMock, patch + +import pytest + +from superset.constants import CHANGE_ME_SECRET_KEY +from superset.initialization import SupersetAppInitializer + + +def _make_initializer(secret_key, *, debug=False, testing=False): + """Build a bare initializer with just the attributes check_secret_key needs.""" + init = object.__new__(SupersetAppInitializer) + init.config = {"SECRET_KEY": secret_key} + app = MagicMock() + app.debug = debug + app.config = {"TESTING": testing} + init.superset_app = app + return init + + [email protected]("secret_key", ["", None, CHANGE_ME_SECRET_KEY]) +def test_check_secret_key_refuses_to_start_when_insecure(secret_key): + """An empty/missing or placeholder key fails closed in non-debug mode.""" + initializer = _make_initializer(secret_key) + with patch("superset.initialization.is_test", return_value=False): + with pytest.raises(SystemExit): + initializer.check_secret_key() + + [email protected]("secret_key", ["", None, CHANGE_ME_SECRET_KEY]) +def test_check_secret_key_warns_but_starts_in_debug(secret_key): + """In debug/testing mode an insecure key warns but does not exit.""" + initializer = _make_initializer(secret_key, debug=True) + with patch("superset.initialization.is_test", return_value=False): + # Should not raise SystemExit. + initializer.check_secret_key() + + +def test_check_secret_key_accepts_strong_key(): + """A non-empty, non-placeholder key starts without warning or exit.""" Review Comment: **Suggestion:** Add an explicit `-> None` return type annotation to this new test function to keep new Python code fully typed. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This newly added function has no return type annotation. Since the custom rule requires new Python functions to be fully typed, the suggestion identifies a real violation. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=316d3f1bce9f4b85b70ffd534d3398ae&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=316d3f1bce9f4b85b70ffd534d3398ae&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/test_check_secret_key.py **Line:** 57:57 **Comment:** *Custom Rule: Add an explicit `-> None` return type annotation to this new test function to keep new Python code fully typed. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41299&comment_hash=679f55789111a4b4a7c062a8fa3c9b66c91d5a2baf44a0863b07aa0f8cd361d6&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41299&comment_hash=679f55789111a4b4a7c062a8fa3c9b66c91d5a2baf44a0863b07aa0f8cd361d6&reaction=dislike'>👎</a> ########## tests/unit_tests/test_check_secret_key.py: ########## @@ -0,0 +1,64 @@ +# 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 SupersetAppInitializer.check_secret_key.""" + +from unittest.mock import MagicMock, patch + +import pytest + +from superset.constants import CHANGE_ME_SECRET_KEY +from superset.initialization import SupersetAppInitializer + + +def _make_initializer(secret_key, *, debug=False, testing=False): + """Build a bare initializer with just the attributes check_secret_key needs.""" + init = object.__new__(SupersetAppInitializer) + init.config = {"SECRET_KEY": secret_key} + app = MagicMock() + app.debug = debug + app.config = {"TESTING": testing} + init.superset_app = app + return init + + [email protected]("secret_key", ["", None, CHANGE_ME_SECRET_KEY]) +def test_check_secret_key_refuses_to_start_when_insecure(secret_key): Review Comment: **Suggestion:** Add a type annotation for `secret_key` and an explicit `-> None` return annotation for this new test function. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This newly added test function has an untyped parameter and no return annotation. The rule explicitly requires new Python functions to be fully typed, so the violation is present. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9807a1516bf348649a034f641cbd33ae&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9807a1516bf348649a034f641cbd33ae&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/test_check_secret_key.py **Line:** 39:39 **Comment:** *Custom Rule: Add a type annotation for `secret_key` and an explicit `-> None` return annotation for this new test function. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41299&comment_hash=e5fd6488950c6a58d20e83c3db3fd9d50449982f112311b81d0eb3f90be2b293&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41299&comment_hash=e5fd6488950c6a58d20e83c3db3fd9d50449982f112311b81d0eb3f90be2b293&reaction=dislike'>👎</a> ########## tests/unit_tests/test_check_secret_key.py: ########## @@ -0,0 +1,64 @@ +# 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 SupersetAppInitializer.check_secret_key.""" + +from unittest.mock import MagicMock, patch + +import pytest + +from superset.constants import CHANGE_ME_SECRET_KEY +from superset.initialization import SupersetAppInitializer + + +def _make_initializer(secret_key, *, debug=False, testing=False): + """Build a bare initializer with just the attributes check_secret_key needs.""" + init = object.__new__(SupersetAppInitializer) + init.config = {"SECRET_KEY": secret_key} + app = MagicMock() + app.debug = debug + app.config = {"TESTING": testing} + init.superset_app = app + return init + + [email protected]("secret_key", ["", None, CHANGE_ME_SECRET_KEY]) +def test_check_secret_key_refuses_to_start_when_insecure(secret_key): + """An empty/missing or placeholder key fails closed in non-debug mode.""" + initializer = _make_initializer(secret_key) + with patch("superset.initialization.is_test", return_value=False): + with pytest.raises(SystemExit): + initializer.check_secret_key() + + [email protected]("secret_key", ["", None, CHANGE_ME_SECRET_KEY]) +def test_check_secret_key_warns_but_starts_in_debug(secret_key): Review Comment: **Suggestion:** Add a type annotation for `secret_key` and an explicit `-> None` return annotation for this new test function. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This is a new Python test function without type annotations on its parameter or its return type. That directly violates the fully-typed new Python code rule. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0cbae0040b404d168f727a8ed1d45053&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0cbae0040b404d168f727a8ed1d45053&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** tests/unit_tests/test_check_secret_key.py **Line:** 48:48 **Comment:** *Custom Rule: Add a type annotation for `secret_key` and an explicit `-> None` return annotation for this new test function. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41299&comment_hash=7e706f940c1a5b8e4f8e91d9afbf871e5bc5f14275910814cce49eaf9d1be150&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41299&comment_hash=7e706f940c1a5b8e4f8e91d9afbf871e5bc5f14275910814cce49eaf9d1be150&reaction=dislike'>👎</a> -- 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]
