Skip to content

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

Merged
wangq8 merged 4 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/doc-immutable-fields-zero-guard
Jun 25, 2026
Merged

wangq8 merged 4 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/doc-immutable-fields-zero-guard

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator

Summary

  • fix validate_immutable_fields() to use explicit is not None checks for chunk_count, token_count, and progress
  • add regression tests for zero-valued immutable fields

Problem

Submitting chunk_count=0, token_count=0, or progress=0.0 bypassed the immutability guard because the function used truthiness checks. That allowed clients to attempt direct updates to immutable document metadata with valid zero values.

Test plan

  • .v/bin/pytest test/unit_test/api/utils/test_doc_validation.py -q -k immutable → 11 passed
  • .v/bin/ruff check api/utils/validation_utils.py test/unit_test/api/utils/test_doc_validation.py

Use explicit None checks for chunk_count, token_count, and progress so
falsy but valid values still run the immutability guard.
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Jun 24, 2026
@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Friendly follow-up: this PR is non-draft and mergeable with a focused immutability-guard fix plus regression tests for zero-valued fields.

Validated locally:

.v/bin/pytest test/unit_test/api/utils/test_doc_validation.py -q -k immutable → 11 passed

Could a maintainer please add the ci label when possible so the full workflow can run?

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a8d9642e-879d-429d-a40e-1876f4a5833d

📥 Commits

Reviewing files that changed from the base of the PR and between 1da103a and 6fba08b.

📒 Files selected for processing (1)
  • test/unit_test/api/utils/test_doc_validation.py

📝 Walkthrough

Walkthrough

validate_immutable_fields now uses is not None checks for chunk_count, token_count, and progress. New regression tests cover zero-valued mismatch and match cases.

Changes

Falsy-value immutability fix and regression tests

Layer / File(s) Summary
Non-None guards and zero-value regressions
api/utils/validation_utils.py, test/unit_test/api/utils/test_doc_validation.py
validate_immutable_fields now validates falsy-but-specified chunk_count, token_count, and progress values, and four regression tests cover mismatched zero values and matching zero values.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 A zero hopped in, quiet and small,
Yet now it gets checked, one and all.
is not None keeps watch at the gate,
And falsy values no longer skate.
The bunny nods: “Yep, that’s the rule!” 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description covers summary, problem, and tests, but it omits the required Type of change section. Add the Type of change checklist and select the appropriate category; the rest of the description is already sufficient.
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the bug fix and mentions the zero-value immutability issue.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/unit_test/api/utils/test_doc_validation.py (1)

178-202: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add isolated mismatch tests for token_count and progress.

The new mismatch test exits on chunk_count first, so regressions in zero-value checks for token_count/progress could still slip through. Add focused cases where earlier fields match and each later field mismatches independently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit_test/api/utils/test_doc_validation.py` around lines 178 - 202, The
new zero-value regression coverage in
test_validate_immutable_fields_zero_values_must_match only exercises the first
failing field, so it can miss similar bugs in validate_immutable_fields for
later fields. Add separate isolated tests in
test_validate_immutable_fields_zero_values_must_match coverage where chunk_count
matches but token_count mismatches, and another where chunk_count and
token_count match but progress mismatches. Use UpdateDocumentReq, Mock, and
validate_immutable_fields to verify each case returns the expected
RetCode.DATA_ERROR and the corresponding immutable-field message.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/unit_test/api/utils/test_doc_validation.py`:
- Around line 178-202: The new zero-value regression coverage in
test_validate_immutable_fields_zero_values_must_match only exercises the first
failing field, so it can miss similar bugs in validate_immutable_fields for
later fields. Add separate isolated tests in
test_validate_immutable_fields_zero_values_must_match coverage where chunk_count
matches but token_count mismatches, and another where chunk_count and
token_count match but progress mismatches. Use UpdateDocumentReq, Mock, and
validate_immutable_fields to verify each case returns the expected
RetCode.DATA_ERROR and the corresponding immutable-field message.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f55863a2-77b6-427d-bced-d4108031f34a

📥 Commits

Reviewing files that changed from the base of the PR and between 9a91564 and 1da103a.

📒 Files selected for processing (2)
  • api/utils/validation_utils.py
  • test/unit_test/api/utils/test_doc_validation.py

@wangq8 wangq8 added the ci Continue Integration label Jun 25, 2026
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (1dfc240) to head (33c99c4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16309   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants