tests: improve RAGFlow coverage based on Codecov report (#13200)

### What problem does this PR solve?

Codecov’s coverage report shows that several RAGFlow code paths are
currently untested or under-tested. This makes it easier for regressions
to slip in during refactors and feature work.
This PR adds targeted automated tests to cover the files and branches
highlighted by Codecov, improving confidence in core behavior while
keeping runtime functionality unchanged.

### Type of change

- [x] Other (please describe): Test coverage improvement (adds/extends
unit and integration tests to address Codecov-reported gaps)
This commit is contained in:
6ba3i
2026-02-25 19:12:11 +08:00
committed by GitHub
parent 2a5ddf064d
commit 38011f2c16
56 changed files with 11453 additions and 17 deletions

View File

@@ -13,6 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import importlib.util
import sys
from pathlib import Path
from types import ModuleType
import pytest
from common import plugin_llm_tools
from configs import INVALID_API_TOKEN
@@ -40,3 +45,54 @@ class TestPluginTools:
res = plugin_llm_tools(WebApiAuth)
assert res["code"] == 0, res
assert isinstance(res["data"], list), res
class _DummyManager:
def route(self, *_args, **_kwargs):
def decorator(func):
return func
return decorator
def _load_plugin_app(monkeypatch):
repo_root = Path(__file__).resolve().parents[4]
common_pkg = ModuleType("common")
common_pkg.__path__ = [str(repo_root / "common")]
monkeypatch.setitem(sys.modules, "common", common_pkg)
stub_apps = ModuleType("api.apps")
stub_apps.login_required = lambda func: func
monkeypatch.setitem(sys.modules, "api.apps", stub_apps)
stub_plugin = ModuleType("agent.plugin")
class _StubGlobalPluginManager:
@staticmethod
def get_llm_tools():
return []
stub_plugin.GlobalPluginManager = _StubGlobalPluginManager
monkeypatch.setitem(sys.modules, "agent.plugin", stub_plugin)
module_path = Path(__file__).resolve().parents[4] / "api" / "apps" / "plugin_app.py"
spec = importlib.util.spec_from_file_location("test_plugin_app_unit", module_path)
module = importlib.util.module_from_spec(spec)
module.manager = _DummyManager()
spec.loader.exec_module(module)
return module
@pytest.mark.p2
def test_llm_tools_metadata_shape_unit(monkeypatch):
module = _load_plugin_app(monkeypatch)
class _DummyTool:
def get_metadata(self):
return {"name": "dummy", "description": "test"}
monkeypatch.setattr(module.GlobalPluginManager, "get_llm_tools", staticmethod(lambda: [_DummyTool()]))
res = module.llm_tools()
assert res["code"] == 0
assert isinstance(res["data"], list)
assert res["data"][0]["name"] == "dummy"
assert res["data"][0]["description"] == "test"