fix(db): skip deletes for unsent keys in filterDuplicateInserts#1551
fix(db): skip deletes for unsent keys in filterDuplicateInserts#1551v-anton wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesDelete Guard Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/db/tests/collection-subscriber-duplicate-inserts.test.ts (1)
457-508: ⚡ Quick winAdd an explicit empty-batch/empty-set corner-case test in this block.
The new tests reproduce the bug well, but this added suite still misses an explicit
changes = []+sentKeys = new Set()case.As per coding guidelines, `**/*.test.{ts,tsx,js}`: "Test corner cases including: empty arrays/sets, single-element collections, undefined vs null values, resolved promises, async race conditions, and limit/offset edge cases".Proposed test addition
describe(`filterDuplicateInserts`, () => { + it(`should return empty output for empty changes and empty sentKeys`, () => { + const sentKeys = new Set<string | number>() + const changes: Array<ChangeMessage<TestItem, string>> = [] + + const result = filterDuplicateInserts(changes, sentKeys) + + expect(result).toEqual([]) + expect(sentKeys.size).toBe(0) + }) + it(`should skip deletes for keys never sent to D2`, () => {🤖 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 `@packages/db/tests/collection-subscriber-duplicate-inserts.test.ts` around lines 457 - 508, Add a corner-case unit test for filterDuplicateInserts that covers an empty changes array and an empty sentKeys set: create changes = [] and sentKeys = new Set(), call filterDuplicateInserts(changes, sentKeys), and assert the result is an empty array and sentKeys remains empty (or unchanged). Place this test in the existing describe(`filterDuplicateInserts`) block alongside the other it(...) cases so it validates the empty-batch/empty-set path for the filterDuplicateInserts function.
🤖 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 `@packages/db/tests/collection-subscriber-duplicate-inserts.test.ts`:
- Around line 457-508: Add a corner-case unit test for filterDuplicateInserts
that covers an empty changes array and an empty sentKeys set: create changes =
[] and sentKeys = new Set(), call filterDuplicateInserts(changes, sentKeys), and
assert the result is an empty array and sentKeys remains empty (or unchanged).
Place this test in the existing describe(`filterDuplicateInserts`) block
alongside the other it(...) cases so it validates the empty-batch/empty-set path
for the filterDuplicateInserts function.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b5ed8e11-d4d5-4876-8783-a230926a8d39
📒 Files selected for processing (3)
.changeset/fix-ghost-delete-sentkeys.mdpackages/db/src/query/live/utils.tspackages/db/tests/collection-subscriber-duplicate-inserts.test.ts
🎯 Changes
filterDuplicateInsertsforwarded delete changes for keys never present insentKeys. When SSE delivers deletes for items filtered out by thewhereclause, the spurious -1 multiplicity corrupts D2's TopKState window.The fix checks the return value of
sentKeys.delete()— iffalse, the key was never sent, so the delete is skipped.✅ Checklist
pnpm test:pr.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
Tests