Spaces:
Sleeping

p4r5kpftnp-cmd Claude Opus 4.7 commited on
Commit
1c701bb
·
1 Parent(s): beba93c

Fuzz retriever query handling (fix missing input guards)

Browse files

Adds tests/test_retriever_fuzz.py covering MathLibRetriever.retrieve and
__init__ across degenerate inputs (empty, whitespace, 5000-char, special
chars, Lean unicode, None, non-string) and index-dir failure modes
(missing, garbage). Heavy deps (HuggingFaceEmbeddings, FAISS,
HuggingFaceCrossEncoder) are mocked before the module is imported so the
suite is hermetic.

Bug found and fixed:
- retrieve(None) (and any non-string) was silently passed to the LangChain
retriever where it surfaced as an opaque error far from the call site.
Now raises TypeError up front.
- Empty/whitespace queries fell through to the embedding model which
returns noisy near-neighbours; they now short-circuit to [].
- Unbounded query length could pin the embedder; capped at 2000 chars.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

2 files changed +254
Files changed (2)
src/retriever.py+24
tests/test_retriever_fuzz.pyAdded+230