Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Tests: fix failling http in CI (#13301)

Idriss Sbaaoui9d78d3ddb128
diff --git a/api/apps/sdk/doc.py b/api/apps/sdk/doc.py
index 3f0295e569..513a01c4c1 100644
--- a/api/apps/sdk/doc.py
+++ b/api/apps/sdk/doc.py
@@ -809,6 +809,10 @@ async def delete(tenant_id, dataset_id):
return get_result()
+DOC_STOP_PARSING_INVALID_STATE_MESSAGE = "Can't stop parsing document that has not started or already completed"
+DOC_STOP_PARSING_INVALID_STATE_ERROR_CODE = "DOC_STOP_PARSING_INVALID_STATE"
+
+
@manager.route("/datasets/<dataset_id>/chunks", methods=["POST"]) # noqa: F821
@token_required
async def parse(tenant_id, dataset_id):
@@ -947,7 +951,11 @@ async def stop_parsing(tenant_id, dataset_id):
if not doc:
return get_error_data_result(message=f"You don't own the document {id}.")
if doc[0].run != TaskStatus.RUNNING.value :
- return get_error_data_result("Can't stop parsing document that has not started or already completed")
+ return construct_json_result(
+ code=RetCode.DATA_ERROR,
+ message=DOC_STOP_PARSING_INVALID_STATE_MESSAGE,
+ data={"error_code": DOC_STOP_PARSING_INVALID_STATE_ERROR_CODE},
+ )
# Send cancellation signal via Redis to stop background task
cancel_all_task_of(id)
info = {"run": "2", "progress": 0, "chunk_num": 0}
diff --git a/test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py b/test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py
index b1fe88f931..635d09b555 100644
--- a/test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py
+++ b/test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py
@@ -592,7 +592,12 @@ class TestDocRoutesUnit:
res = _run(module.parse.__wrapped__("tenant-1", "ds-1"))
assert "don't own the document" in res["message"]
- monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc(progress=0.5)])
+ monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc(run=module.TaskStatus.RUNNING.value)])
+ monkeypatch.setattr(
+ module.DocumentService,
+ "update_by_id",
+ lambda *_args, **_kwargs: (_ for _ in ()).throw(AssertionError("update_by_id must not be called for running docs")),
+ )
res = _run(module.parse.__wrapped__("tenant-1", "ds-1"))
assert "currently being processed" in res["message"]
@@ -631,11 +636,23 @@ class TestDocRoutesUnit:
res = _run(module.stop_parsing.__wrapped__("tenant-1", "ds-1"))
assert "don't own the document" in res["message"]
- monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc(progress=1)])
+ monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc(run=module.TaskStatus.DONE.value)])
+ monkeypatch.setattr(
+ module,
+ "cancel_all_task_of",
+ lambda *_args, **_kwargs: (_ for _ in ()).throw(AssertionError("cancel_all_task_of must not be called for non-running docs")),
+ )
+ monkeypatch.setattr(
+ module.DocumentService,
+ "update_by_id",
+ lambda *_args, **_kwargs: (_ for _ in ()).throw(AssertionError("update_by_id must not be called for non-running docs")),
+ )
res = _run(module.stop_parsing.__wrapped__("tenant-1", "ds-1"))
- assert "progress at 0 or 1" in res["message"]
+ assert res["code"] == module.RetCode.DATA_ERROR
+ assert res["data"]["error_code"] == module.DOC_STOP_PARSING_INVALID_STATE_ERROR_CODE
+ assert res["message"] == module.DOC_STOP_PARSING_INVALID_STATE_MESSAGE
- monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc(progress=0.3)])
+ monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc(run=module.TaskStatus.RUNNING.value)])
monkeypatch.setattr(module, "cancel_all_task_of", lambda *_args, **_kwargs: None)
monkeypatch.setattr(module.DocumentService, "update_by_id", lambda *_args, **_kwargs: True)
_patch_docstore(monkeypatch, module, delete=lambda *_args, **_kwargs: None)
@@ -651,7 +668,7 @@ class TestDocRoutesUnit:
assert "Duplicate document ids" in res["message"]
monkeypatch.setattr(module, "check_duplicate_ids", lambda ids, _kind: (ids, []))
- monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc(progress=0.3)])
+ monkeypatch.setattr(module.DocumentService, "query", lambda **_kwargs: [_DummyDoc(run=module.TaskStatus.RUNNING.value)])
res = _run(module.stop_parsing.__wrapped__("tenant-1", "ds-1"))
assert res["code"] == 0