fix(db): avoid undefined enumerable keys in compare options#1552
fix(db): avoid undefined enumerable keys in compare options#1552v-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 (2)
📝 WalkthroughWalkthroughFixed ChangesString Collation Undefined Properties Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/db/tests/collection-auto-index.test.ts (1)
967-1011: ⚡ Quick winAdd a test for
locale/localeOptionswhenstringSortis omitted.Current cases miss the defaulted path where
defaultStringCollationincludeslocalebut notstringSort. That case should still include locale fields becausestringSortdefaults tolocale.✅ Suggested test addition
+ it(`should include locale fields when stringSort is omitted but locale values are provided`, () => { + const collection = createCollection<TestItem, string>({ + getKey: (item) => item.id, + defaultStringCollation: { + locale: `en-US`, + localeOptions: { sensitivity: `base` }, + }, + startSync: true, + sync: { + sync: ({ begin, commit, markReady }) => { + begin() + commit() + markReady() + }, + }, + }) + + const opts = collection.compareOptions + expect(opts.stringSort).toBe(`locale`) + expect(opts.locale).toBe(`en-US`) + expect(opts.localeOptions).toEqual({ sensitivity: `base` }) + })As per coding guidelines, "Always add unit tests that reproduce a bug before fixing it to ensure the bug is fixed and prevent regression."
🤖 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-auto-index.test.ts` around lines 967 - 1011, Add a new unit test in collection-auto-index.test.ts that constructs a collection via createCollection<TestItem, string> where defaultStringCollation provides locale and localeOptions but omits stringSort; assert that collection.compareOptions.stringSort equals "locale" (defaulted), and that compareOptions includes the locale and localeOptions keys with the expected values—use the same sync stub pattern as the other tests and reference createCollection, defaultStringCollation, and compareOptions to locate where to add the test.
🤖 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 `@packages/db/src/collection/index.ts`:
- Around line 999-1003: Compute the effective stringSort first and derive
localeMode from it instead of from options.stringSort; e.g., set a local
variable like stringSortEffective = options.stringSort ?? 'locale', then set
localeMode = stringSortEffective === 'locale' and return stringSort:
stringSortEffective while conditionally including locale and localeOptions based
on that localeMode (use the existing identifiers localeMode, options.locale,
options.localeOptions, and the returned stringSort).
---
Nitpick comments:
In `@packages/db/tests/collection-auto-index.test.ts`:
- Around line 967-1011: Add a new unit test in collection-auto-index.test.ts
that constructs a collection via createCollection<TestItem, string> where
defaultStringCollation provides locale and localeOptions but omits stringSort;
assert that collection.compareOptions.stringSort equals "locale" (defaulted),
and that compareOptions includes the locale and localeOptions keys with the
expected values—use the same sync stub pattern as the other tests and reference
createCollection, defaultStringCollation, and compareOptions to locate where to
add the test.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: dc1c5b52-815d-43f3-bc99-eee4bc6c2fed
📒 Files selected for processing (3)
.changeset/fix-compare-options-undefined-keys.mdpackages/db/src/collection/index.tspackages/db/tests/collection-auto-index.test.ts
🎯 Changes
buildCompareOptionsFromConfigassignedlocale: undefinedandlocaleOptions: undefinedas enumerable properties whenstringSort !== 'locale'. These extra keys causedeepEqualsinBaseIndex.matchesCompareOptionsto fail onObject.keyslength mismatch, preventing index matching and silently falling back to full scan.The fix conditionally spreads these properties so they only exist when they have actual values.
✅ Checklist
pnpm test:pr.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
Tests