|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +"""Regression tests for chat router private helper wiring.""" |
| 17 | + |
| 18 | +import ast |
| 19 | +import unittest |
| 20 | +from pathlib import Path |
| 21 | + |
| 22 | + |
| 23 | +CHAT_ROUTER_PATH = Path(__file__).resolve().parents[2] / "src" / "api" / "routers" / "chat.py" |
| 24 | + |
| 25 | + |
| 26 | +class ChatRouterPrivateHelperTests(unittest.TestCase): |
| 27 | + def test_called_create_helpers_are_defined(self) -> None: |
| 28 | + """Ensure refactors do not leave runtime-only missing helper errors behind.""" |
| 29 | + tree = ast.parse(CHAT_ROUTER_PATH.read_text()) |
| 30 | + defined_helpers = set() |
| 31 | + called_helpers = set() |
| 32 | + |
| 33 | + for node in ast.walk(tree): |
| 34 | + if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name.startswith("_create_"): |
| 35 | + defined_helpers.add(node.name) |
| 36 | + elif isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id.startswith("_create_"): |
| 37 | + called_helpers.add(node.func.id) |
| 38 | + |
| 39 | + self.assertLessEqual(called_helpers, defined_helpers) |
| 40 | + |
| 41 | + |
| 42 | +if __name__ == "__main__": |
| 43 | + unittest.main() |
0 commit comments