Repository navigation
test(mcp): cover filter and request validation rejection branches - #898
Draft
vishal-bala wants to merge 2 commits into
Draft
vishal-bala wants to merge 2 commits into
vishal-bala wants to merge 2 commits into
Conversation
Parametrised tables for the MCP structured-filter parser, the locked-filter escape backstop, search and upsert request validation, and check_operator_misuse. Folds the existing single-case rejection tests into those tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Relabels a backstop row by the check that refuses it, drops a duplicate row, folds the empty return_fields and no-server-side-embedding tests into tables, and tightens the latter's match so the two embedding errors are told apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #898 +/- ##
==========================================
+ Coverage 81.24% 81.55% +0.31%
==========================================
Files 121 121
Lines 15145 15145
Branches 2661 2661
==========================================
+ Hits 12304 12351 +47
+ Misses 2201 2166 -35
+ Partials 640 628 -12
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The MCP server's input-validation layer takes untrusted input from agents, and several of its rejection branches had no test. Among them were three refusals in the backstop that stops a caller's filter escaping a locked tenant filter. If any of those guards were deleted, the unit suite would still pass. This PR covers them, along with the matching branches in the structured-filter parser, search and upsert request validation, and
check_operator_misuse.Changes
One table of invalid inputs per module
tests/unit/test_mcp/test_filters.py:test_parse_filter_rejects_malformed_structured_filtersis one table of malformed filters. It covers a non-object filter, two logical keys,notwrapping an array, a non-object logical child, an empty field, a missing op or value, a vector field, unknown operators per field type, empty, non-string, non-numeric and bool values, and a scalar whereinneeds a list. Each row asserts its own error message. The five older single-case rejection tests are folded in as rows.], an unclosed range and an escaped]inside a range. None of them has a top-level|, so only the depth, bracket and range-span checks can refuse them. An older row whose label claimed a stray closer is relabelled by the check that actually refuses it, and a row that duplicated its branch is dropped.test_parse_filter_renders_each_operatorpins the rendered string for tagneandlike, textneandlike, and numericeq,neandlte. The twolikerows check that query syntax is escaped and the*wildcard stays live.tests/unit/test_mcp/test_search_tool_unit.py:test_search_records_rejects_invalid_request_argumentscoverslimitabovemax_limit, a non-listreturn_fields, non-string and empty entries, and the existing limit, offset, unknown-field, vector-field and empty-list cases.tests/unit/test_mcp/test_upsert_tool_unit.py: the request-shape table gains an invalidid_fieldand a non-boolskip_embedding_if_present. A new two-row test covers both errors raised when the server has no embedding support. Itsmatch=strings tell the two errors apart, which the oldermatch="embedding"did not.tests/unit/test_filter.py:test_comparing_a_field_to_a_field_raiseschecks that==and!=between twoTag,TextorGeofields raise.AI Assistance
Claude Code (claude-opus-5-5): tests, pre-PR review and description.
Reviewer Brief
Start here:
tests/unit/test_mcp/test_filters.py,test_merge_locked_filter_refuses_a_caller_rendering_that_could_escape. Its four new rows are the only tests of the backstop's depth, bracket and range-span refusals; every other row there is refused by the top-level|check.Where it could fail
tests/unit/test_mcp/test_filters.py(renders_each_operator): the taglikerow pins@category:{sci\-fi*}. Taglikestill leaves|live, which is the known, deferred tag-widening issue. No row here has a|, so none certifies that behaviour.redisvl/mcp/tools/search.py_reject_escapable_filter(pre-existing, not changed here): a raw caller rendering that ends in one unpaired\is accepted. That backslash then escapes the merge's closing paren. No DSL operator renders that shape today. It is reported separately and deliberately not pinned in this PR.Not verified: behaviour against a live Redis; nothing here builds a query that reaches Redis. Cluster and API-key paths are not touched.
Beyond CI: source is unchanged, so every new test passes on the base by construction. Instead, 17 mutations were each run against the new tests, and every one fails at least one row. Each mutation either replaces a guard's condition with
False(depth < 0, the stray-]branch,limit > max_limit,return_fieldslist and entry checks,id_field,skip_embedding_if_presenttype and no-embedding checks,check_operator_misuse, five parser guards) or removes something: the backslash skip in_find_unescaped, the unclosed-range refusal, or thelikeescaper. With coverage,redisvl/mcp/filters.pygoes from 82% to 99% under the unit suite. The one missed line, 224, is unreachable because both list helpers reject an empty list first.Reviewed
830e89c2· Claude Code (claude-opus-5-5) · lenses: correctness, security, design, tests, docs (Redis behaviour not run: no query construction changes)