From 8527f62034c8e81b3999d22dbb7281f2a53e78d7 Mon Sep 17 00:00:00 2001 From: leefer Date: Sun, 2 Aug 2026 08:49:57 +0800 Subject: [PATCH] fix: restore llm model validation dependency --- backend/llm/service.py | 1 + tests/test_llm_gateway.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/backend/llm/service.py b/backend/llm/service.py index 31da5b1..13e5c35 100644 --- a/backend/llm/service.py +++ b/backend/llm/service.py @@ -4,6 +4,7 @@ from datetime import datetime, timezone from typing import Any from urllib.parse import urlparse +from backend.bootstrap.config import validate_text from backend.features.screener.compiler import LLMCompilerError, test_llm_connection diff --git a/tests/test_llm_gateway.py b/tests/test_llm_gateway.py index 7e68769..7e7ff77 100644 --- a/tests/test_llm_gateway.py +++ b/tests/test_llm_gateway.py @@ -1,8 +1,10 @@ from __future__ import annotations import unittest +from unittest.mock import patch from backend.llm import LLMGateway, LLMGatewayError +from backend.llm.service import LLMServiceMixin class ProviderFailure(RuntimeError): @@ -113,6 +115,31 @@ class LLMGatewayTests(unittest.TestCase): with self.assertRaisesRegex(LLMGatewayError, "额度已用完"): gateway.call("mentor", "mentor-v1", lambda model: "unused", (ProviderFailure,)) + def test_saved_system_model_can_reach_the_connection_probe(self) -> None: + service = LLMServiceMixin() + service._system_credentials = { + "llm_models": [ + { + "id": "primary-model", + "name": "主模型", + "api_key": "secret", + "base_url": "https://model.example/v1", + "model": "model-name", + } + ] + } + service.llm_gateway = self.gateway() + expected = {"ok": True, "reply": "OK"} + with patch( + "backend.llm.service.test_llm_connection", return_value=expected + ) as connection_probe: + result = service.test_system_llm_profile("primary-model", {}) + + self.assertEqual(result, expected) + connection_probe.assert_called_once_with( + "secret", "https://model.example/v1", "model-name" + ) + if __name__ == "__main__": unittest.main()