fix(api): validate immutable document fields when value is zero (#16309)

This commit is contained in:
Harsh Kashyap
2026-06-25 16:59:12 +05:30
committed by GitHub
parent 66d86154ab
commit 8d3c3f868c
2 changed files with 56 additions and 3 deletions

View File

@@ -175,6 +175,59 @@ def test_validate_immutable_fields_none_values():
assert error_code is None
@pytest.mark.p2
def test_validate_immutable_fields_zero_values_must_match():
"""Regression: falsy zero values must still be validated, not skipped."""
update_doc_req = UpdateDocumentReq(chunk_count=0, token_count=0, progress=0.0)
doc = Mock()
doc.chunk_num = 10
doc.token_num = 100
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_code == RetCode.DATA_ERROR
@pytest.mark.p2
def test_validate_immutable_fields_zero_token_count_mismatch_when_chunk_count_matches():
update_doc_req = UpdateDocumentReq(chunk_count=0, token_count=0, progress=0.0)
doc = Mock()
doc.chunk_num = 0
doc.token_num = 100
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_code == RetCode.DATA_ERROR
@pytest.mark.p2
def test_validate_immutable_fields_zero_progress_mismatch_when_counts_match():
update_doc_req = UpdateDocumentReq(chunk_count=0, token_count=0, progress=0.0)
doc = Mock()
doc.chunk_num = 0
doc.token_num = 0
doc.progress = 0.5
error_msg, error_code = validate_immutable_fields(update_doc_req, doc)
assert error_msg == "Can't change `progress`."
assert error_code == RetCode.DATA_ERROR
@pytest.mark.p2
def test_validate_immutable_fields_zero_values_matching_doc():
update_doc_req = UpdateDocumentReq(chunk_count=0, token_count=0, progress=0.0)
doc = Mock()
doc.chunk_num = 0
doc.token_num = 0
doc.progress = 0.0
error_msg, error_code = validate_immutable_fields(update_doc_req, doc)
assert error_msg is None
assert error_code is None
def test_validate_document_name_valid():
"""Test valid document name update."""
req_doc_name = "new_document.pdf"