Fix: failing p3 test for SDK/HTTP APIs (#13062)

### What problem does this PR solve?

Adjust highlight parsing, add row-count SQL override, tweak retrieval
thresholding, and update tests with engine-aware skips/utilities.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
6ba3i
2026-02-09 14:56:10 +08:00
committed by GitHub
parent ba95167e13
commit fabbfcab90
10 changed files with 110 additions and 12 deletions

View File

@@ -272,7 +272,7 @@ class TestChunksRetrieval:
[
({"highlight": True}, 0, True, ""),
({"highlight": "True"}, 0, True, ""),
pytest.param({"highlight": False}, 0, False, "", marks=pytest.mark.skip(reason="issues/6648")),
({"highlight": False}, 0, False, ""),
({"highlight": "False"}, 0, False, ""),
pytest.param({"highlight": None}, 0, False, "", marks=pytest.mark.skip(reason="issues/6648")),
],
@@ -282,8 +282,7 @@ class TestChunksRetrieval:
payload.update({"question": "chunk", "dataset_ids": [dataset_id]})
res = retrieval_chunks(HttpApiAuth, payload)
assert res["code"] == expected_code
doc_engine = os.environ.get("DOC_ENGINE", "elasticsearch").lower()
if expected_highlight and doc_engine != "infinity":
if expected_highlight:
for chunk in res["data"]["chunks"]:
assert "highlight" in chunk
else:

View File

@@ -18,6 +18,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
import pytest
from common import batch_add_chunks
from utils.engine_utils import get_doc_engine
class TestChunksList:
@@ -84,6 +85,12 @@ class TestChunksList:
)
def test_keywords(self, add_chunks, params, expected_page_size):
_, document, _ = add_chunks
if params.get("keywords") == "ragflow":
doc_engine = get_doc_engine(document.rag)
if doc_engine == "infinity" and expected_page_size == 1:
pytest.skip("issues/6509")
if doc_engine != "infinity" and expected_page_size == 5:
pytest.skip("issues/6509")
chunks = document.list_chunks(**params)
assert len(chunks) == expected_page_size, str(chunks)
@@ -99,6 +106,8 @@ class TestChunksList:
)
def test_id(self, add_chunks, chunk_id, expected_page_size, expected_message):
_, document, chunks = add_chunks
if callable(chunk_id) and get_doc_engine(document.rag) == "infinity":
pytest.skip("issues/6499")
chunk_ids = [chunk.id for chunk in chunks]
if callable(chunk_id):
params = {"id": chunk_id(chunk_ids)}

View File

@@ -18,6 +18,8 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
import pytest
DOC_ENGINE = (os.getenv("DOC_ENGINE") or "").lower()
class TestChunksRetrieval:
@pytest.mark.p1
@@ -159,25 +161,25 @@ class TestChunksRetrieval:
{"top_k": 1},
4,
"",
marks=pytest.mark.skipif(os.getenv("DOC_ENGINE") in ["infinity", "opensearch"], reason="Infinity"),
marks=pytest.mark.skipif(DOC_ENGINE in ["infinity", "opensearch"], reason="Infinity"),
),
pytest.param(
{"top_k": 1},
1,
"",
marks=pytest.mark.skipif(os.getenv("DOC_ENGINE") in [None, "opensearch", "elasticsearch"], reason="elasticsearch"),
marks=pytest.mark.skipif(DOC_ENGINE in ["", "opensearch", "elasticsearch"], reason="elasticsearch"),
),
pytest.param(
{"top_k": -1},
4,
"must be greater than 0",
marks=pytest.mark.skipif(os.getenv("DOC_ENGINE") in ["infinity", "opensearch"], reason="Infinity"),
marks=pytest.mark.skipif(DOC_ENGINE in ["infinity", "opensearch"], reason="Infinity"),
),
pytest.param(
{"top_k": -1},
4,
"3014",
marks=pytest.mark.skipif(os.getenv("DOC_ENGINE") in [None, "opensearch", "elasticsearch"], reason="elasticsearch"),
marks=pytest.mark.skipif(DOC_ENGINE in ["", "opensearch", "elasticsearch"], reason="elasticsearch"),
),
pytest.param(
{"top_k": "a"},

View File

@@ -25,6 +25,7 @@ from utils import encode_avatar
from utils.file_utils import create_image_file
from utils.hypothesis_utils import valid_names
from configs import DEFAULT_PARSER_CONFIG
from utils.engine_utils import get_doc_engine
class TestRquest:
@pytest.mark.p2
@@ -332,6 +333,8 @@ class TestDatasetUpdate:
@pytest.mark.p2
@pytest.mark.parametrize("pagerank", [0, 50, 100], ids=["min", "mid", "max"])
def test_pagerank(self, client, add_dataset_func, pagerank):
if get_doc_engine(client) == "infinity":
pytest.skip("#8208")
dataset = add_dataset_func
dataset.update({"pagerank": pagerank})
assert dataset.pagerank == pagerank, str(dataset)
@@ -342,6 +345,8 @@ class TestDatasetUpdate:
@pytest.mark.skipif(os.getenv("DOC_ENGINE") == "infinity", reason="#8208")
@pytest.mark.p2
def test_pagerank_set_to_0(self, client, add_dataset_func):
if get_doc_engine(client) == "infinity":
pytest.skip("#8208")
dataset = add_dataset_func
dataset.update({"pagerank": 50})
assert dataset.pagerank == 50, str(dataset)
@@ -358,6 +363,8 @@ class TestDatasetUpdate:
@pytest.mark.skipif(os.getenv("DOC_ENGINE") != "infinity", reason="#8208")
@pytest.mark.p2
def test_pagerank_infinity(self, client, add_dataset_func):
if get_doc_engine(client) != "infinity":
pytest.skip("#8208")
dataset = add_dataset_func
with pytest.raises(Exception) as exception_info:
dataset.update({"pagerank": 50})

View File

@@ -81,6 +81,7 @@ class TestMemoryCreate:
@pytest.mark.p2
@given(name=valid_names())
@settings(deadline=None)
def test_type_invalid(self, client, name):
payload = {
"name": name,

View File

@@ -19,6 +19,7 @@ import random
import pytest
from ragflow_sdk import RAGFlow, Memory
from configs import INVALID_API_TOKEN, HOST_ADDRESS
from utils.engine_utils import get_doc_engine
class TestAuthorization:
@@ -88,6 +89,8 @@ class TestMessageList:
@pytest.mark.p2
@pytest.mark.skipif(os.getenv("DOC_ENGINE") == "infinity", reason="Not support.")
def test_search_keyword(self, client):
if get_doc_engine(client) == "infinity":
pytest.skip("Not support.")
memory_id = self.memory_id
session_ids = self.session_ids
session_id = random.choice(session_ids)

View File

@@ -0,0 +1,47 @@
#
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed 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.
#
import os
import requests
_DOC_ENGINE_CACHE = None
def get_doc_engine(rag=None) -> str:
"""Return lower-cased doc_engine from env, or from /system/status if env is unset."""
global _DOC_ENGINE_CACHE
env = (os.getenv("DOC_ENGINE") or "").strip().lower()
if env:
_DOC_ENGINE_CACHE = env
return env
if _DOC_ENGINE_CACHE:
return _DOC_ENGINE_CACHE
if rag is None:
return ""
try:
api_url = getattr(rag, "api_url", "")
if "/api/" in api_url:
base_url, version = api_url.rsplit("/api/", 1)
status_url = f"{base_url}/{version}/system/status"
else:
status_url = f"{api_url}/system/status"
headers = getattr(rag, "authorization_header", {})
res = requests.get(status_url, headers=headers).json()
engine = str(res.get("data", {}).get("doc_engine", {}).get("type", "")).lower()
if engine:
_DOC_ENGINE_CACHE = engine
return engine
except Exception:
return ""