mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-22 07:31:05 +08:00
Add Go service/handler tests for API contract parity (#16905)
This commit is contained in:
@@ -38,30 +38,27 @@ GO_ONLY_SKIPS = {
|
||||
"test_cancel_missing_task_sets_cancel_contract",
|
||||
},
|
||||
"Go validation or response contract does not match the established API contract": {
|
||||
"test_chat_create_name_validation",
|
||||
"test_chat_duplicate_name_validation",
|
||||
"test_chat_create_additional_guards_contract",
|
||||
"test_chat_list_default_get_and_separate_lookup_contract",
|
||||
"test_chat_list_page_and_page_size_contract",
|
||||
"test_chat_list_sorting_contract",
|
||||
"test_chat_create_prompt_contract",
|
||||
"test_chat_update_name_contract",
|
||||
"test_chat_update_mapping_and_validation_branches_p2",
|
||||
"test_dataset_update_name_and_case_insensitive_contract",
|
||||
"test_dataset_update_embedding_model_format_contract",
|
||||
"test_dataset_update_parser_config_valid_matrix_contract",
|
||||
"test_dataset_update_parser_config_with_chunk_method_change_contract",
|
||||
"test_dataset_update_pagerank_contract",
|
||||
"test_dataset_update_pagerank_set_to_zero_contract",
|
||||
"test_dataset_update_content_type_and_payload_contract",
|
||||
"test_dataset_update_identifier_validation_contract",
|
||||
"test_dataset_update_parser_config_defaults_contract",
|
||||
"test_dataset_update_parser_config_invalid_contract",
|
||||
"test_dataset_update_field_unset_and_unsupported_contract",
|
||||
"test_dataset_update_name_invalid_and_duplicate_contract",
|
||||
"test_dataset_create_name_and_case_insensitive_contract",
|
||||
# Updating with `{"parser_config": {}}` / `None` is a valid no-op in Go (handled by
|
||||
# ParserConfigProvided). But the final GET asserts the stored parser_config equals Python's
|
||||
# DEFAULT_PARSER_CONFIG, which embeds a CI-specific tenant `llm_id` and a richer `graphrag` /
|
||||
# `parent_child` structure than Go's common.GetParserConfig produces. Exact equality is a
|
||||
# Python/CI-specific contract, not a meaningful Go behavior difference.
|
||||
"test_dataset_update_parser_config_defaults_contract",
|
||||
"test_dataset_create_parser_config_different_chunk_methods_contract",
|
||||
"test_dataset_create_parser_config_missing_raptor_and_graphrag",
|
||||
"test_dataset_create_embedding_model_contract",
|
||||
"test_dataset_create_embedding_model_format_contract",
|
||||
"test_dataset_create_parser_config_bugfix_contract",
|
||||
"test_dataset_create_content_type_and_payload_bad_contract",
|
||||
"test_dataset_create_parser_config_invalid_contract",
|
||||
@@ -76,8 +73,6 @@ GO_ONLY_SKIPS = {
|
||||
"test_memory_crud_and_config",
|
||||
"test_messages_list_and_search_validation_contracts",
|
||||
"test_message_update_forget_and_content_error_contracts",
|
||||
"test_search_create_invalid_name",
|
||||
"test_search_update_invalid_search_id",
|
||||
"test_session_create_validation_and_deleted_chat_contract",
|
||||
"test_session_delete_basic_scenarios",
|
||||
"test_session_list_filter_and_deleted_chat_contract",
|
||||
|
||||
@@ -150,9 +150,7 @@ def _load_list_datasets_module(monkeypatch, *, kbs, parsing_status_by_kb):
|
||||
monkeypatch,
|
||||
"api.db.services.user_service",
|
||||
TenantService=SimpleNamespace(
|
||||
get_joined_tenants_by_user_id=lambda user_id: [
|
||||
{"tenant_id": "tenant-1"}
|
||||
],
|
||||
get_joined_tenants_by_user_id=lambda user_id: [{"tenant_id": "tenant-1"}],
|
||||
),
|
||||
UserService=SimpleNamespace(get_by_ids=lambda ids: []),
|
||||
UserTenantService=SimpleNamespace(),
|
||||
@@ -173,13 +171,9 @@ def _load_list_datasets_module(monkeypatch, *, kbs, parsing_status_by_kb):
|
||||
|
||||
repo_root = Path(__file__).resolve().parents[5]
|
||||
module_path = repo_root / "api" / "apps" / "services" / "dataset_api_service.py"
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"test_dataset_api_service_list_datasets_module", module_path
|
||||
)
|
||||
spec = importlib.util.spec_from_file_location("test_dataset_api_service_list_datasets_module", module_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
monkeypatch.setitem(
|
||||
sys.modules, "test_dataset_api_service_list_datasets_module", module
|
||||
)
|
||||
monkeypatch.setitem(sys.modules, "test_dataset_api_service_list_datasets_module", module)
|
||||
spec.loader.exec_module(module)
|
||||
return module, parsing_status_mock, get_list_mock
|
||||
|
||||
@@ -343,4 +337,4 @@ def test_list_datasets_with_include_parsing_status_missing_kb_gets_empty_dict(mo
|
||||
by_id = {r["id"]: r for r in payload["data"]}
|
||||
assert by_id["kb-a"]["parsing_status"]["unstart_count"] == 1
|
||||
assert by_id["kb-b"]["parsing_status"] == {}
|
||||
parsing_status_mock.assert_called_once()
|
||||
parsing_status_mock.assert_called_once()
|
||||
|
||||
@@ -83,15 +83,9 @@ def test_chunk_shape_helper_recognises_chunk_payloads(monkeypatch):
|
||||
"""A response that is chunk-shaped (list, or dict with non-empty results/chunks)
|
||||
is classified as chunked regardless of which payload was sent."""
|
||||
module = _load_docling_parser(monkeypatch)
|
||||
assert module.DoclingParser._looks_like_chunk_response(
|
||||
[{"text": "chunk-1"}]
|
||||
) is True
|
||||
assert module.DoclingParser._looks_like_chunk_response(
|
||||
{"results": [{"text": "chunk-1"}, {"text": "chunk-2"}]}
|
||||
) is True
|
||||
assert module.DoclingParser._looks_like_chunk_response(
|
||||
{"chunks": [{"text": "chunk-1"}]}
|
||||
) is True
|
||||
assert module.DoclingParser._looks_like_chunk_response([{"text": "chunk-1"}]) is True
|
||||
assert module.DoclingParser._looks_like_chunk_response({"results": [{"text": "chunk-1"}, {"text": "chunk-2"}]}) is True
|
||||
assert module.DoclingParser._looks_like_chunk_response({"chunks": [{"text": "chunk-1"}]}) is True
|
||||
|
||||
|
||||
@pytest.mark.p2
|
||||
@@ -164,4 +158,4 @@ def test_remote_chunked_request_with_ignored_flag_does_not_log_success(monkeypat
|
||||
assert sections == [("real content", "")]
|
||||
flat = " ".join(record.getMessage() for record in caplog.records)
|
||||
assert "Successfully used native chunking" not in flat
|
||||
assert "Server ignored chunking request" in flat
|
||||
assert "Server ignored chunking request" in flat
|
||||
|
||||
Reference in New Issue
Block a user