Skip to content

Fix: use independent fixtures in ClampsOverlappedPct test - #17416

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:fix/clamp-test-fixture
Jul 27, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:fix/clamp-test-fixture

Conversation

@xugangqiang

@xugangqiang xugangqiang commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

TestMergeByTokenSizeFromJSON_ClampsOverlappedPct reused a single items fixture across four calls to mergeByTokenSizeFromJSON.

mergeByTokenSizeFromJSON mutates its perItem argument in place and returns the same backing array (token.go: perItem[idx] = merged). As a result:

  • The 2nd and later calls merged already-merged chunks instead of the original input.
  • Because the returned slice aliases the input, later calls silently overwrote the earlier results (at100, at0, ...).
  • reflect.DeepEqual(at100, at150) was therefore vacuously true — the test was a false positive that never actually exercised the clamp. It would still pass even if the clamp were broken.

This is exactly the defect flagged in the review comment on PR #17396.

Fix

Add a clampOverlapFixture() factory and build a fresh fixture for every call, so that 150 / 1e300 / -5 / -1e300 are applied to the original input.

Verification

  • The test passes after the fix.
  • When the clamp logic was temporarily disabled, the test failed (panic at token.go:768 — the negative index produced by an out-of-range pct), proving the fixed test is no longer a false positive and can catch a clamp regression.

Scope

Test file only. No production code change (verified token.go is identical to upstream/main).

Refs: review comment on PR #17396.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The chunker overlap clamping test now creates fresh input for each mergeByTokenSizeFromJSON call and verifies equivalent results for oversized, negative, and extreme overlap percentages.

Changes

Overlap clamping test isolation

Layer / File(s) Summary
Fresh fixtures and expanded clamping coverage
internal/ingestion/component/chunker/token_batch1_test.go
Adds a per-invocation fixture and tests clamping equivalence for oversized and negative overlap values using independent inputs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

Fresh slices hop into the test,
Giant values face the clamp’s request.
Negative numbers join the race,
Equal results fall in place.
A bunny celebrates the case!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly matches the main change: using independent fixtures in the ClampsOverlappedPct test.
Description check ✅ Passed The description covers the problem, fix, verification, and scope, which satisfies the template's summary intent.

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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@internal/ingestion/component/chunker/token_batch1_test.go`:
- Around line 94-95: Update the first chunk’s Text fixture in the affected
token-batch test cases to contain just over 128 tokens, such as 130, instead of
100. Keep the second chunk and assertions unchanged so the fixture distinguishes
the clamped zero-overlap threshold from unclamped negative percentages.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a139274-0fc8-4c23-b6de-95f8c9e62ede

📥 Commits

Reviewing files that changed from the base of the PR and between a6a67c5 and 868acc8.

📒 Files selected for processing (1)
  • internal/ingestion/component/chunker/token_batch1_test.go

@xugangqiang xugangqiang added the ci Continue Integration label Jul 27, 2026
mergeByTokenSizeFromJSON mutates its perItem argument in place and returns
the same backing array (token.go). Reusing one fixture across the four calls
let later calls reprocess already-merged chunks and silently overwrite the
earlier results via aliasing, so reflect.DeepEqual was vacuously true - the
test passed without actually exercising the clamp (review comment on PR infiniflow#17396).

Build a fresh fixture per call. The first chunk now carries TKNums 130, just
above chunk_token_size 128, so both clamp directions are exercised: at pct=0
(threshold 128) the chunks stay split, while an unclamped negative pct raises
the threshold (e.g. -5 -> 134.4) and merges them - which would otherwise make
the lower-clamp assertions pass even if the clamp were removed (review:
coderabbitai on PR infiniflow#17416).

Verified the test now fails (negative-case assertions at
token_batch1_test.go:128/131; panic at token.go:768 for the upper case) when
the clamp is disabled, confirming it is no longer a false positive.
@xugangqiang
xugangqiang force-pushed the fix/clamp-test-fixture branch from 868acc8 to de8bb64 Compare July 27, 2026 07:09

@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)
internal/ingestion/component/chunker/token_batch1_test.go (1)

84-97: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove review-history references from the helper comment.

The PR/reviewer references on Lines 90 and 97 will go stale. Keep the current mutation and threshold rationale, but remove the historical attribution. As per coding guidelines, Go comments should describe the current runtime path rather than migration history.

Proposed cleanup
-// (see code review on PR `#17396`).
...
-// (review: coderabbitai on PR `#17416`).
🤖 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 `@internal/ingestion/component/chunker/token_batch1_test.go` around lines 84 -
97, Update the clampOverlapFixture comment to retain the explanation of per-call
slice freshness, mutation/aliasing behavior, and threshold coverage, while
removing all PR numbers, reviewer attributions, and other review-history
references. Keep the comment focused on the current runtime behavior and test
rationale.

Source: Coding guidelines

🤖 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 `@internal/ingestion/component/chunker/token_batch1_test.go`:
- Around line 84-97: Update the clampOverlapFixture comment to retain the
explanation of per-call slice freshness, mutation/aliasing behavior, and
threshold coverage, while removing all PR numbers, reviewer attributions, and
other review-history references. Keep the comment focused on the current runtime
behavior and test rationale.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5ec72e1d-5ebf-4402-8716-2174308d8637

📥 Commits

Reviewing files that changed from the base of the PR and between 868acc8 and de8bb64.

📒 Files selected for processing (1)
  • internal/ingestion/component/chunker/token_batch1_test.go

@xugangqiang

Copy link
Copy Markdown
Contributor Author

@yingfeng @yuzhichang @JinHai-CN Pls help to review.

@xugangqiang xugangqiang changed the title fix(test): use independent fixtures in ClampsOverlappedPct test Fix: use independent fixtures in ClampsOverlappedPct test Jul 27, 2026
@yuzhichang
yuzhichang merged commit 76acd49 into infiniflow:main Jul 27, 2026
3 checks passed
@xugangqiang
xugangqiang deleted the fix/clamp-test-fixture branch July 29, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants