feat(search): add --snippet-max-length flag - #61
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
PR Summary by QodoAdd --snippet-max-length flag to search CLI and pass through to API
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo
1. Snippet test divide-by-zero
|
| def test_snippet_max_length(kn): | ||
| def avg_snippet(data): | ||
| lens = [len(r.get("snippet") or "") for r in results_of(data)] | ||
| return sum(lens) / len(lens) |
There was a problem hiding this comment.
1. Snippet test divide-by-zero 🐞 Bug ☼ Reliability
test_snippet_max_length computes an average as sum(lens)/len(lens) without guarding against an empty results list, which can raise ZeroDivisionError and fail the e2e suite with an unhandled exception.
Agent Prompt
## Issue description
`test_snippet_max_length` calculates an average snippet length by dividing by `len(lens)`. If the API returns zero results (an empty `results` list), this becomes a division by zero and the test errors out (not a clean assertion failure / skip).
## Issue Context
The e2e suite already has a pattern for handling vacuous assertions when search returns no results (`_non_empty_results` uses `pytest.skip`). The new snippet-length test should follow a similar approach or at least assert non-empty results before averaging.
## Fix Focus Areas
- tests/e2e/test_search.py[50-61]
### Suggested change
Update `avg_snippet()` to either:
- `assert results_of(data), "no results returned"` before computing the average, or
- `pytest.skip(...)` when results are empty (preferred if empty results are acceptable for live API variability).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Summary
--snippet-max-lengthtokeenable search. It maps to the API'ssnippet_max_lengthbody param (accepted range 180-10000; the API validates and returns a structured error with exit 1 on out-of-range values).Tests
Invalid parameter.test_snippet_max_length(loose comparative bounds, since caps overshoot ~10% per-fragment) andtest_snippet_max_length_out_of_range.test_search.pye2e file passes against the live API (25 passed).cargo clippyand release build pass.🤖 Generated with Claude Code