Go: fix warnings (#17738)

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-08-03 21:30:01 +08:00
committed by GitHub
parent d357eea8ef
commit 86021932ae
103 changed files with 437 additions and 439 deletions

View File

@@ -45,7 +45,7 @@ def test_document_download_by_id_invalid_id_contract(rest_client):
assert res.status_code == 200
payload = res.json()
assert payload["code"] == 102, payload
assert payload["message"] == "Document not found!", payload
assert payload["message"] == "document not found", payload
@pytest.mark.p2
@@ -62,4 +62,4 @@ def test_document_artifact_rejects_unsafe_filename(rest_client):
assert res.status_code == 200
payload = res.json()
assert payload["code"] == 102, payload
assert payload["message"] == "Invalid file type.", payload
assert payload["message"] == "invalid file type", payload

View File

@@ -690,12 +690,12 @@ def test_documents_update_invalid_field_and_guard_contract(rest_client, create_d
first_document_id = uploaded_docs[0]["id"]
strict_guard_cases = [
({"chunk_count": 1}, 102, "Can't change `chunk_count`."),
({"token_count": 1}, 102, "Can't change `token_count`."),
({"chunk_count": 100}, 102, "Can't change `chunk_count`."),
({"token_count": 100}, 102, "Can't change `token_count`."),
({"chunk_count": 1}, 102, "can't change `chunk_count`"),
({"token_count": 1}, 102, "can't change `token_count`"),
({"chunk_count": 100}, 102, "can't change `chunk_count`"),
({"token_count": 100}, 102, "can't change `token_count`"),
({"progress": 2.0}, 102, "Field: <progress> - Message: <Input should be less than or equal to 1> - Value: <2.0>"),
({"progress": 1.0}, 102, "Can't change `progress`."),
({"progress": 1.0}, 102, "can't change `progress`"),
({"meta_fields": []}, 102, "Field: <meta_fields> - Message: <Input should be a valid dictionary> - Value: <[]>"),
]
for payload, expected_code, expected_message in strict_guard_cases:
@@ -1491,14 +1491,14 @@ def test_documents_download_requires_auth_and_invalid_id_contract(rest_client, c
assert invalid_doc_res.status_code == 200
invalid_doc_payload = invalid_doc_res.json()
assert invalid_doc_payload["code"] == 102, invalid_doc_payload
assert invalid_doc_payload["message"] == "Document not found!", invalid_doc_payload
assert invalid_doc_payload["message"] == "document not found", invalid_doc_payload
invalid_dataset_path = tmp_path / "invalid_dataset_download.txt"
invalid_dataset_res = _download_document_to_file(rest_client, "invalid_dataset_id", document_id, invalid_dataset_path)
assert invalid_dataset_res.status_code == 200
invalid_dataset_payload = invalid_dataset_res.json()
assert invalid_dataset_payload["code"] == 102, invalid_dataset_payload
assert invalid_dataset_payload["message"] == "Document not found!", invalid_dataset_payload
assert invalid_dataset_payload["message"] == "document not found", invalid_dataset_payload
@pytest.mark.p2

View File

@@ -221,7 +221,7 @@ class TestDocumentsUpdated:
@pytest.mark.parametrize(
"payload, expected_code, expected_message",
[
({"chunk_count": 1}, 102, "Can't change `chunk_count`."),
({"chunk_count": 1}, 102, "can't change `chunk_count`"),
pytest.param(
{"create_date": "Fri, 14 Mar 2025 16:53:42 GMT"},
102,
@@ -270,7 +270,7 @@ class TestDocumentsUpdated:
"The input parameters are invalid.",
marks=pytest.mark.skip(reason="issues/6104"),
),
pytest.param({"progress": 1.0}, 102, "Can't change `progress`."),
pytest.param({"progress": 1.0}, 102, "can't change `progress`"),
pytest.param(
{"progress_msg": "ragflow_test"},
102,
@@ -301,7 +301,7 @@ class TestDocumentsUpdated:
"The input parameters are invalid.",
marks=pytest.mark.skip(reason="issues/6104"),
),
({"token_count": 1}, 102, "Can't change `token_count`."),
({"token_count": 1}, 102, "can't change `token_count`"),
pytest.param(
{"type": "ragflow_test"},
102,
@@ -339,10 +339,10 @@ class TestDocumentsUpdated:
@pytest.mark.parametrize(
"payload, expected_code, expected_message",
[
({"chunk_count": 100}, 102, "Can't change `chunk_count`."),
({"token_count": 100}, 102, "Can't change `token_count`."),
({"chunk_count": 100}, 102, "can't change `chunk_count`"),
({"token_count": 100}, 102, "can't change `token_count`"),
({"progress": 2.0}, 102, "Field: <progress> - Message: <Input should be less than or equal to 1> - Value: <2.0>"),
({"progress": 1.0}, 102, "Can't change `progress`."),
({"progress": 1.0}, 102, "can't change `progress`"),
({"meta_fields": []}, 102, "Field: <meta_fields> - Message: <Input should be a valid dictionary> - Value: <[]>"),
],
)

View File

@@ -148,7 +148,7 @@ class TestDocumentsUpdated:
@pytest.mark.parametrize(
"payload, expected_message",
[
({"chunk_count": 1}, "Can't change `chunk_count`"),
({"chunk_count": 1}, "can't change `chunk_count`"),
pytest.param(
{"create_date": "Fri, 14 Mar 2025 16:53:42 GMT"},
"The input parameters are invalid",
@@ -189,7 +189,7 @@ class TestDocumentsUpdated:
"The input parameters are invalid",
marks=pytest.mark.skip(reason="issues/6104"),
),
({"progress": 1.0}, "Can't change `progress`"),
({"progress": 1.0}, "can't change `progress`"),
pytest.param(
{"progress_msg": "ragflow_test"},
"The input parameters are invalid",
@@ -215,7 +215,7 @@ class TestDocumentsUpdated:
"The input parameters are invalid",
marks=pytest.mark.skip(reason="issues/6104"),
),
({"token_count": 1}, "Can't change `token_count`"),
({"token_count": 1}, "can't change `token_count`"),
pytest.param(
{"type": "ragflow_test"},
"The input parameters are invalid",
@@ -245,7 +245,7 @@ class TestDocumentsUpdated:
@pytest.mark.parametrize(
"payload, expected_message",
[
({"chunk_count": 1}, "Can't change `chunk_count`"),
({"chunk_count": 1}, "can't change `chunk_count`"),
],
)
def test_immutable_fields_chunk_count(self, add_documents, payload, expected_message):
@@ -260,7 +260,7 @@ class TestDocumentsUpdated:
@pytest.mark.parametrize(
"payload, expected_message",
[
({"token_count": 9999}, "Can't change `token_count`"), # Attempt to change immutable field
({"token_count": 9999}, "can't change `token_count`"), # Attempt to change immutable field
],
)
def test_immutable_fields_token_count(self, add_documents, payload, expected_message):
@@ -275,7 +275,7 @@ class TestDocumentsUpdated:
@pytest.mark.parametrize(
"payload, expected_message",
[
({"progress": 0.5}, "Can't change `progress`"), # Attempt to change immutable field
({"progress": 0.5}, "can't change `progress`"), # Attempt to change immutable field
({"progress": 1.5}, "Field: <progress> - Message: <Input should be less than or equal to 1> - Value: <1.5>"), # Attempt to change immutable field
],
)

View File

@@ -335,7 +335,7 @@ class TestDocumentMetadataUnit:
def test_get_route_not_found_success_and_exception_unit(self, document_app_module, monkeypatch):
module = document_app_module
# Cross-tenant access is denied -> "Document not found!" (no ID enumeration).
# Cross-tenant access is denied -> "document not found" (no ID enumeration).
# Stub get_by_id to a valid document so the test can only pass via the
# accessible() early return; if that check ever regresses, the route would
# proceed and the assertions below would no longer match.
@@ -353,7 +353,7 @@ class TestDocumentMetadataUnit:
)
res = _run(module.get("doc1"))
assert res["code"] == RetCode.DATA_ERROR
assert "Document not found!" in res["message"]
assert "document not found" in res["message"]
assert accessible_calls == [("doc1", "user-1")]
# From here on the user is authorized; exercise the original branches.
@@ -362,7 +362,7 @@ class TestDocumentMetadataUnit:
monkeypatch.setattr(module.DocumentService, "get_by_id", lambda _doc_id: (False, None))
res = _run(module.get("doc1"))
assert res["code"] == RetCode.DATA_ERROR
assert "Document not found!" in res["message"]
assert "document not found" in res["message"]
async def fake_thread_pool_exec(*_args, **_kwargs):
return b"blob-data"
@@ -396,7 +396,7 @@ class TestDocumentMetadataUnit:
module = document_app_module
monkeypatch.setattr(module, "request", _DummyRequest(args={"ext": "abc"}))
# Cross-tenant access is denied -> "Document not found!" (no ID enumeration).
# Cross-tenant access is denied -> "document not found" (no ID enumeration).
accessible_calls = []
def fake_accessible_denied(doc_id, user_id):
@@ -406,7 +406,7 @@ class TestDocumentMetadataUnit:
monkeypatch.setattr(module.DocumentService, "accessible", fake_accessible_denied)
res = _run(module.download_attachment(attachment_id="att1"))
assert res["code"] == RetCode.DATA_ERROR
assert "Document not found!" in res["message"]
assert "document not found" in res["message"]
assert accessible_calls == [("att1", "user-1")]
# From here on the user is authorized; exercise the original branches.
@@ -447,7 +447,7 @@ class TestDocumentMetadataUnit:
res = _run(module.download_document("doc1"))
assert res["code"] == RetCode.DATA_ERROR
assert "Document not found!" in res["message"]
assert "document not found" in res["message"]
def test_dataset_document_download_rejects_other_tenant_unit(self, document_rest_api_module, monkeypatch):
module = document_rest_api_module
@@ -456,7 +456,7 @@ class TestDocumentMetadataUnit:
res = _run(module.download("kb1", "doc1"))
assert res["code"] == RetCode.DATA_ERROR
assert "Document not found!" in res["message"]
assert "document not found" in res["message"]
@pytest.mark.p2
def test_get_document_image_content_type_from_object_extension_unit(self, document_app_module, monkeypatch):

View File

@@ -204,7 +204,7 @@ class TestAttachmentDownloadMissingBlob:
"""Regression for #15502: missing-blob → structured 4xx, not HTTP 500."""
def test_empty_blob_returns_not_found(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Storage returns None (orphaned metadata) → 'Document not found!' 4xx,
"""Storage returns None (orphaned metadata) → 'document not found' 4xx,
not a TypeError 500 from make_response(None)."""
module = _load_agent_api(monkeypatch, storage_get=lambda *_a, **_k: None)
result = asyncio.run(module.download_attachment(tenant_id="t1", attachment_id="orphan"))

View File

@@ -107,7 +107,7 @@ def test_validate_immutable_fields_chunk_count_mismatch():
doc.progress = 0.5
error_msg, error_code = validate_immutable_fields(update_doc_req, doc)
assert error_msg == "Can't change `chunk_count`."
assert error_msg == "can't change `chunk_count`"
assert error_code == RetCode.DATA_ERROR
@@ -120,7 +120,7 @@ def test_validate_immutable_fields_token_count_mismatch():
doc.progress = 0.5
error_msg, error_code = validate_immutable_fields(update_doc_req, doc)
assert error_msg == "Can't change `token_count`."
assert error_msg == "can't change `token_count`"
assert error_code == RetCode.DATA_ERROR
@@ -133,7 +133,7 @@ def test_validate_immutable_fields_progress_mismatch():
doc.progress = 0.5
error_msg, error_code = validate_immutable_fields(update_doc_req, doc)
assert error_msg == "Can't change `progress`."
assert error_msg == "can't change `progress`"
assert error_code == RetCode.DATA_ERROR
@@ -185,7 +185,7 @@ def test_validate_immutable_fields_zero_values_must_match():
doc.progress = 0.5
error_msg, error_code = validate_immutable_fields(update_doc_req, doc)
assert error_msg == "Can't change `chunk_count`."
assert error_msg == "can't change `chunk_count`"
assert error_code == RetCode.DATA_ERROR
@@ -198,7 +198,7 @@ def test_validate_immutable_fields_zero_token_count_mismatch_when_chunk_count_ma
doc.progress = 0.0
error_msg, error_code = validate_immutable_fields(update_doc_req, doc)
assert error_msg == "Can't change `token_count`."
assert error_msg == "can't change `token_count`"
assert error_code == RetCode.DATA_ERROR
@@ -211,7 +211,7 @@ def test_validate_immutable_fields_zero_progress_mismatch_when_counts_match():
doc.progress = 0.5
error_msg, error_code = validate_immutable_fields(update_doc_req, doc)
assert error_msg == "Can't change `progress`."
assert error_msg == "can't change `progress`"
assert error_code == RetCode.DATA_ERROR