Test: release Go-proxy RESTful contract tests verified passing in Go mode (#17468)

### Summary

Aligns Go and Python error codes/messages so both backends honor the
same RESTful API contract, removing implementation-specific error leaks
(MySQL errors, `ValueError`, `AttributeError`, Gin validator format) in
favor of clean business error codes.

**Chat list** — invalid `orderby` now returns code 101 (was: raw Python
`AttributeError` code 100); invalid `page`/`page_size` values fall back
to defaults (was: raw `ValueError`/`ProgrammingError` code 100).

**Dataset create/update/delete** — adds UUID validation (101),
extra-field rejection (101), duplicate-id detection (101), content-type
/ JSON-syntax / object-shape checks (101), and "lacks permission" for
nonexistent datasets (IDOR). Create auto-deduplicates dataset names.
Pagerank updates tolerate a missing ES index. List response includes
`parser_config` and `pagerank`.

**Session list/update** — adds filtering, sorting, and pagination
support. Empty payloads are valid no-ops. Authorization errors map to
code 109.

**Chunk list** — doc object uses Python key names (`chunk_count`,
`dataset_id`, `chunk_method`, run text status). Add validates list
element types.

**Document update** — adds `chunk_method` alias, pydantic-style Field
error messages, metadata index auto-create with refresh, and "These
documents do not belong to dataset" messages. List validates
`metadata_condition` and reports ownership errors for unmatched name/id
filters.

**Search completion** — `kb_ids` ownership failure returns code 102
instead of 109.

Released 31 contract tests from `GO_ONLY_SKIPS` (all verified passing on
both Go and Python backends with real LLM keys).
This commit is contained in:
euvre
2026-07-30 19:58:49 +08:00
committed by GitHub
parent 75ac8cec2e
commit 8fc20dd9ca
53 changed files with 1138 additions and 426 deletions

View File

@@ -38,77 +38,42 @@ GO_ONLY_SKIPS = {
"test_cancel_missing_task_sets_cancel_contract",
},
"Go validation or response contract does not match the established API contract": {
"test_chat_list_page_and_page_size_contract",
"test_chat_list_sorting_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_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",
# Go CreateDataset does not accept parser_config in the request body.
"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_parser_config_bugfix_contract",
"test_dataset_create_content_type_and_payload_bad_contract",
"test_dataset_create_parser_config_invalid_contract",
"test_dataset_create_parser_config_defaults_and_extra_fields_contract",
"test_dataset_list_query_contract_matrix",
"test_dataset_delete_contract_matrix",
# "test_memory_update_invalid_name",
# "test_memory_crud_cycle",
# "test_messages_add_list_recent_content_update_forget",
# "test_message_status_validation_requires_boolean",
# "test_message_search_route_contract",
# "test_memory_crud_and_config",
# "test_messages_list_and_search_validation_contracts",
# "test_message_update_forget_and_content_error_contracts",
"test_dataset_create_embedding_model_contract",
# Empty path (e.g. /chats//sessions) triggers a 405/404 framework
# response in Go rather than the Python contract's code-100 envelope.
"test_session_create_validation_and_deleted_chat_contract",
"test_session_delete_basic_scenarios",
"test_session_list_filter_and_deleted_chat_contract",
"test_session_list_page_and_sort_contract",
"test_session_update_name_and_param_contract",
"test_session_update_requires_auth_and_invalid_target_contract",
"test_chat_completion_validation_errors",
"test_chat_completion_nonstream_with_session",
"test_chat_completion_nonstream_with_chat_without_session",
"test_chat_completion_nonstream_without_chat",
"test_chat_completion_stream_events",
"test_search_completion_sse_shape_when_kb_ids_provided",
"test_system_tokens_auth_and_crud",
# --- exposed after meta_fields skip guard removal ---
# Go response data omits the parser_config key that the contract asserts.
"test_documents_update_parser_config_contract",
},
"Go ingestion pipeline does not complete document parsing within the test timeout": {
# Chunk add requires an embedding model call; document update/delete
# touches ES/Infinity indices that are only created during parsing.
# Without a working Go ingestion pipeline, these indices never exist.
"test_chunk_add_keyword_question_and_tag_contract",
"test_chunk_add_repeated_and_deleted_document_contract",
"test_chunk_concurrent_add_contract",
"test_documents_list_default_concurrent_and_filters_contract",
"test_documents_list_error_and_sorting_contract",
"test_documents_update_patch_and_delete",
"test_documents_update_name_contract",
"test_documents_update_chunk_method_contract",
"test_documents_update_meta_fields_contract",
"test_documents_update_invalid_field_and_guard_contract",
"test_documents_update_parser_config_contract",
"test_documents_metadata_batch_update_contract",
"test_documents_metadata_update_path",
"test_documents_delete_contract_matrix",
"test_documents_delete_invalid_dataset_partial_duplicate_repeat_and_cross_dataset",
"test_documents_delete_concurrent_and_bulk_contract",
"test_documents_download_requires_auth_and_invalid_id_contract",
},
"Go LLM setup cannot exercise the configured model": {
"test_related_questions_contract",
},
"Go ingestion pipeline does not complete document parsing within the test timeout": {
"test_chat_list_concurrent_and_dataset_delete_contract",
"test_chat_create_dataset_ids_contract",
"test_chat_create_llm_contract",
@@ -127,11 +92,9 @@ GO_ONLY_SKIPS = {
"test_retrieval_document_ids_and_metadata_condition_contract",
"test_retrieval_rerank_unknown_contract",
"test_retrieval_concurrent_contract",
"test_documents_parse_and_stop",
"test_documents_parse_contract_matrix",
"test_documents_parse_invalid_dataset_partial_duplicate_and_repeated",
"test_documents_parse_chunks_and_scaled_bulk_contract",
"test_documents_stop_parse_requires_auth",
"test_documents_stop_parse_contract_matrix",
"test_documents_stop_parse_invalid_dataset_partial_and_scaled_concurrency",
"test_documents_table_parser_chat_patterns",

View File

@@ -365,15 +365,15 @@ def test_chat_list_page_and_page_size_contract(rest_client, clear_chats):
("page two", {"page": 2, "page_size": 2}, 0, lambda total: min(max(total - 2, 0), 2), ""),
("page three", {"page": 3, "page_size": 2}, 0, lambda total: min(max(total - 4, 0), 2), ""),
("page string", {"page": "3", "page_size": 2}, 0, lambda total: min(max(total - 4, 0), 2), ""),
("page negative", {"page": -1, "page_size": 2}, 100, None, "ProgrammingError(1064"),
("page alpha", {"page": "a", "page_size": 2}, 100, None, "ValueError(\"invalid literal for int() with base 10: 'a'\")"),
("page negative", {"page": -1, "page_size": 2}, 0, lambda total: total, ""),
("page alpha", {"page": "a", "page_size": 2}, 0, lambda total: total, ""),
("page_size none", {"page_size": None}, 0, lambda total: total, ""),
("page_size zero", {"page_size": 0}, 0, lambda total: total, ""),
("page_size one", {"page_size": 1}, 0, lambda total: total, ""),
("page_size six", {"page_size": 6}, 0, lambda total: total, ""),
("page_size string", {"page_size": "1"}, 0, lambda total: total, ""),
("page_size negative", {"page_size": -1}, 0, lambda total: total, ""),
("page_size alpha", {"page_size": "a"}, 100, None, "ValueError(\"invalid literal for int() with base 10: 'a'\")"),
("page_size alpha", {"page_size": "a"}, 0, lambda total: total, ""),
]
for scenario_name, params, expected_code, expected_count_fn, expected_message in cases:
@@ -403,7 +403,7 @@ def test_chat_list_sorting_contract(rest_client, clear_chats):
("orderby create", {"orderby": "create_time"}, 0, descending_names, ""),
("orderby update", {"orderby": "update_time"}, 0, descending_names, ""),
("orderby name ascending", {"orderby": "name", "desc": "False"}, 0, ascending_names, ""),
("orderby unknown", {"orderby": "unknown"}, 100, None, "AttributeError(\"type object 'Dialog' has no attribute 'unknown'\")"),
("orderby unknown", {"orderby": "unknown"}, 101, None, "invalid orderby field"),
("desc none", {"desc": None}, 0, descending_names, ""),
("desc true", {"desc": "true"}, 0, descending_names, ""),
("desc True", {"desc": "True"}, 0, descending_names, ""),

View File

@@ -200,7 +200,7 @@ def test_chunk_add_keyword_question_and_tag_contract(rest_client, create_documen
[
({"content": "chunk test", "important_keywords": ["a", "b", "c"]}, 0, ""),
({"content": "chunk test", "important_keywords": [""]}, 0, ""),
({"content": "chunk test", "important_keywords": [1]}, 100, "TypeError('sequence item 0: expected str instance, int found')"),
({"content": "chunk test", "important_keywords": [1]}, 102, "`important_keywords` must be a list of strings"),
({"content": "chunk test", "important_keywords": ["a", "a"]}, 0, ""),
({"content": "chunk test", "important_keywords": "abc"}, 102, "`important_keywords` is required to be a list"),
({"content": "chunk test", "important_keywords": 123}, 102, "`important_keywords` is required to be a list"),
@@ -211,7 +211,7 @@ def test_chunk_add_keyword_question_and_tag_contract(rest_client, create_documen
[
({"content": "chunk test", "questions": ["a", "b", "c"]}, 0, ""),
({"content": "chunk test", "questions": [""]}, 0, ""),
({"content": "chunk test", "questions": [1]}, 100, "TypeError('sequence item 0: expected str instance, int found')"),
({"content": "chunk test", "questions": [1]}, 102, "`questions` must be a list of strings"),
({"content": "chunk test", "questions": ["a", "a"]}, 0, ""),
({"content": "chunk test", "questions": "abc"}, 102, "`questions` is required to be a list"),
({"content": "chunk test", "questions": 123}, 102, "`questions` is required to be a list"),

View File

@@ -289,36 +289,36 @@ def test_documents_list_error_and_sorting_contract(rest_client, create_dataset,
"orderby invalid",
f"/datasets/{dataset_id}/documents",
{"orderby": "unknown"},
100,
"Document' has no attribute 'unknown'",
101,
"invalid orderby field",
),
(
"page invalid number",
f"/datasets/{dataset_id}/documents",
{"page": -1, "page_size": 2},
100,
"1064",
0,
"",
),
(
"page invalid type",
f"/datasets/{dataset_id}/documents",
{"page": "a", "page_size": 2},
100,
"invalid literal for int()",
0,
"",
),
(
"page_size invalid number",
f"/datasets/{dataset_id}/documents",
{"page_size": -1},
100,
"1064",
0,
"",
),
(
"page_size invalid type",
f"/datasets/{dataset_id}/documents",
{"page_size": "a"},
100,
"invalid literal for int()",
0,
"",
),
]
for case_name, path, params, expected_code, expected_message in error_cases:
@@ -547,7 +547,7 @@ def test_documents_update_name_contract(rest_client, create_dataset, tmp_path):
("new_name.txt", 0, ""),
(long_name, 0, ""),
(0, 102, "Field: <name> - Message: <Input should be a valid string> - Value: <0>"),
(None, 100, "AttributeError('NoneType' object has no attribute 'encode')"),
(None, 102, "Field: <name> - Message: <Input should be a valid string> - Value: <None>"),
("", 101, "The extension of file can't be changed"),
("ragflow_test_upload_0", 101, "The extension of file can't be changed"),
("ragflow_test_upload_1.txt", 102, "Duplicated document name in the same dataset."),

View File

@@ -101,7 +101,7 @@ def test_search_update_invalid_search_id(rest_client):
assert res.status_code == 200
payload = res.json()
assert payload["code"] == 109, payload
assert "no authorization" in payload["message"], payload
assert "no authorization" in payload["message"].lower(), payload
@pytest.mark.p2

View File

@@ -146,7 +146,7 @@ def test_session_create_validation_and_deleted_chat_contract(rest_client, create
assert invalid_chat_res.status_code == 200
invalid_chat_payload = invalid_chat_res.json()
assert invalid_chat_payload["code"] == 109, invalid_chat_payload
assert invalid_chat_payload["message"] == "no authorization", invalid_chat_payload
assert invalid_chat_payload["message"].lower().strip().rstrip(".") == "no authorization", invalid_chat_payload
for scenario_name, payload in (
("valid", {"name": "valid_name"}),
@@ -194,7 +194,7 @@ def test_session_create_validation_and_deleted_chat_contract(rest_client, create
assert create_after_delete.status_code == 200
create_after_delete_payload = create_after_delete.json()
assert create_after_delete_payload["code"] == 109, create_after_delete_payload
assert create_after_delete_payload["message"] == "no authorization", create_after_delete_payload
assert create_after_delete_payload["message"].lower().strip().rstrip(".") == "no authorization", create_after_delete_payload
@pytest.mark.p2
@@ -234,7 +234,7 @@ def test_session_delete_requires_auth_and_invalid_target_contract(rest_client, c
assert invalid_chat_res.status_code == 200
invalid_chat_payload = invalid_chat_res.json()
assert invalid_chat_payload["code"] == 109, invalid_chat_payload
assert invalid_chat_payload["message"] == "no authorization", invalid_chat_payload
assert invalid_chat_payload["message"].lower().strip().rstrip(".") == "no authorization", invalid_chat_payload
@pytest.mark.p2
@@ -242,7 +242,7 @@ def test_session_delete_basic_scenarios(rest_client, create_chat):
cases = [
("none payload", None, 0, 5, {}),
("invalid only", {"ids": ["invalid_id"]}, 102, 5, "The chat doesn't own the session invalid_id"),
("not json", "not json", 100, 5, "<BadRequest '400: Bad Request'>"),
("not json", "not json", 101, 5, "Malformed JSON syntax: Missing commas/brackets or invalid encoding"),
("single id", lambda sessions: {"ids": [sessions[0]["id"]]}, 0, 4, True),
("all ids", lambda sessions: {"ids": [session["id"] for session in sessions]}, 0, 0, True),
("delete all", {"delete_all": True}, 0, 0, True),
@@ -394,7 +394,7 @@ def test_session_list_filter_and_deleted_chat_contract(rest_client, create_chat)
assert invalid_chat_res.status_code == 200
invalid_chat_payload = invalid_chat_res.json()
assert invalid_chat_payload["code"] == 109, invalid_chat_payload
assert invalid_chat_payload["message"] == "no authorization", invalid_chat_payload
assert invalid_chat_payload["message"].lower().strip().rstrip(".") == "no authorization", invalid_chat_payload
delete_chat_res = rest_client.delete("/chats", json={"ids": [chat_id]})
assert delete_chat_res.status_code == 200
@@ -405,7 +405,7 @@ def test_session_list_filter_and_deleted_chat_contract(rest_client, create_chat)
assert deleted_list_res.status_code == 200
deleted_list_payload = deleted_list_res.json()
assert deleted_list_payload["code"] == 109, deleted_list_payload
assert deleted_list_payload["message"] == "no authorization", deleted_list_payload
assert deleted_list_payload["message"].lower().strip().rstrip(".") == "no authorization", deleted_list_payload
@pytest.mark.p2
@@ -420,14 +420,14 @@ def test_session_list_page_and_sort_contract(rest_client, create_chat):
("page two", {"page": 2, "page_size": 2}, 0, 2, ""),
("page three", {"page": 3, "page_size": 2}, 0, 1, ""),
("page string", {"page": "3", "page_size": 2}, 0, 1, ""),
("page negative", {"page": -1, "page_size": 2}, 100, 0, "ProgrammingError(1064"),
("page alpha", {"page": "a", "page_size": 2}, 100, 0, "ValueError(\"invalid literal for int() with base 10: 'a'\")"),
("page negative", {"page": -1, "page_size": 2}, 0, 2, ""),
("page alpha", {"page": "a", "page_size": 2}, 0, 2, ""),
("page_size none", {"page_size": None}, 0, 5, ""),
("page_size zero", {"page_size": 0}, 0, 0, ""),
("page_size one", {"page_size": 1}, 0, 1, ""),
("page_size six", {"page_size": 6}, 0, 5, ""),
("page_size negative", {"page_size": -1}, 0, 5, ""),
("page_size alpha", {"page_size": "a"}, 100, 0, "ValueError(\"invalid literal for int() with base 10: 'a'\")"),
("page_size alpha", {"page_size": "a"}, 0, 5, ""),
]
for scenario_name, params, expected_code, expected_count, expected_message in page_cases:
res = rest_client.get(f"/chats/{chat_id}/sessions", params=params)
@@ -444,7 +444,7 @@ def test_session_list_page_and_sort_contract(rest_client, create_chat):
("orderby create", {"orderby": "create_time", "page_size": 30}, "create_time", True, descending_names, ""),
("orderby update", {"orderby": "update_time", "page_size": 30}, "update_time", True, descending_names, ""),
("orderby name ascending", {"orderby": "name", "desc": "False", "page_size": 30}, "name", False, created_names, ""),
("orderby unknown", {"orderby": "unknown", "page_size": 30}, None, None, None, "AttributeError(\"type object 'Conversation' has no attribute 'unknown'\")"),
("orderby unknown", {"orderby": "unknown", "page_size": 30}, None, None, None, "invalid orderby field"),
("desc none", {"desc": None, "page_size": 30}, "create_time", True, descending_names, ""),
("desc true", {"desc": "true", "page_size": 30}, "create_time", True, descending_names, ""),
("desc True", {"desc": "True", "page_size": 30}, "create_time", True, descending_names, ""),
@@ -457,7 +457,7 @@ def test_session_list_page_and_sort_contract(rest_client, create_chat):
res = rest_client.get(f"/chats/{chat_id}/sessions", params=params)
assert res.status_code == 200, (scenario_name, res.text)
payload = res.json()
expected_code = 0 if expected_names is not None else 100
expected_code = 0 if expected_names is not None else 101
assert payload["code"] == expected_code, (scenario_name, payload)
if expected_code == 0:
assert is_sorted(payload["data"], field, descending), (scenario_name, payload)
@@ -498,7 +498,7 @@ def test_session_update_requires_auth_and_invalid_target_contract(rest_client, c
assert invalid_chat_res.status_code == 200
invalid_chat_payload = invalid_chat_res.json()
assert invalid_chat_payload["code"] == 109, invalid_chat_payload
assert invalid_chat_payload["message"] == "no authorization", invalid_chat_payload
assert invalid_chat_payload["message"].lower().strip().rstrip(".") == "no authorization", invalid_chat_payload
empty_session_res = rest_client.patch(f"/chats/{chat_id}/sessions/", json={"name": "x"})
assert empty_session_res.status_code == 200
@@ -552,7 +552,7 @@ def test_session_update_name_and_param_contract(rest_client, create_chat):
assert update_after_delete_res.status_code == 200
update_after_delete_payload = update_after_delete_res.json()
assert update_after_delete_payload["code"] == 109, update_after_delete_payload
assert update_after_delete_payload["message"] == "no authorization", update_after_delete_payload
assert update_after_delete_payload["message"].lower().strip().rstrip(".") == "no authorization", update_after_delete_payload
@pytest.mark.p2
@@ -602,7 +602,8 @@ def test_related_questions_compatibility_requires_auth(rest_client_noauth):
assert res.status_code == 200
payload = res.json()
if IS_GO_PROXY:
assert_auth_error(payload, "invalid token")
assert payload["code"] == 102, payload
assert payload["message"] == "Authorization is not valid!", payload
else:
assert payload["code"] == 102, payload
assert payload["message"].strip() in {
@@ -759,4 +760,4 @@ def test_chat_completion_validation_errors(rest_client, create_chat):
assert invalid_chat.status_code == 200
invalid_chat_payload = invalid_chat.json()
assert invalid_chat_payload["code"] == 109, invalid_chat_payload
assert "no authorization" in invalid_chat_payload["message"], invalid_chat_payload
assert "no authorization" in invalid_chat_payload["message"].lower(), invalid_chat_payload