Fix: $gt/$lt bounds outside schema min/max incorrectly exclude boundary documents#8690
Conversation
…mping bug Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
…ema min/max Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
|
|
@copilot check if this test really fails without the fix, if yes show me the failing console output |
Yes, the test fails without the fix. Here's the console output: Document |
When a numeric query bound falls outside the schema's
minimum/maximum,getNumberIndexString()clamps it to the boundary value — producing the same index string as the boundary document. An exclusive scan ($gt/$lt) then skips that document even though it should match.Changes
src/query-planner.ts— After resolvingmatcherOptsfor a numeric index field, check ifstartKey < schema.minimumorendKey > schema.maximum. In those cases, promote the exclusive bound to inclusive, since clamping makes the boundary index string identical to the boundary document's. Bounds exactly atminimum/maximumare left exclusive as expected.test/unit/rx-storage-query-correctness.test.ts— AddedtestCorrectQueriescovering all four edge cases:$gtbelow min,$ltabove max,$gtexactly at min (must still exclude),$ltexactly at max (must still exclude).