fix: assign backend label per code path in vouch search CLI#53
Conversation
The search command assigned a single backend variable after deciding which path ran, then stamped it on every result. Substring fallback hits were mislabelled as fts5 when FTS5 returned an empty list instead of raising. Restructured the branches so backend is set only when the path that produced the hits is known. Also updates the stale docstring from 'FTS5 search over claims, pages, and entities' to reflect the current multi-backend search surface. Fixes vouchdev#52
📝 WalkthroughWalkthroughDocstring updated to describe the lookup flow as “embedding → fts5 → substring”, CHANGELOG Unreleased “Fixed” entry added documenting backend-labeling correction, and two CLI tests added verifying per-hit backend labels for FTS5 and substring fallback. ChangesSearch docstring, changelog, and CLI tests
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)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@CHANGELOG.md`:
- Around line 9-12: The CHANGELOG.md has duplicate "### Fixed" headings in the
same release section; remove the second "### Fixed" heading and merge its
bullet(s) into the first "### Fixed" list so there is only one "### Fixed"
heading under the [Unreleased] section, preserving both bullets (including the
`vouch search` CLI fix and the stale docstring note) in that single list.
🪄 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 Plus
Run ID: dba45bf0-6b49-4132-b009-7c5a07889a85
📒 Files selected for processing (2)
CHANGELOG.mdsrc/vouch/cli.py
| ### Fixed | ||
| - Fix `vouch search` CLI: assign backend label per code path so substring fallback results are no longer mislabelled as `fts5`; update stale docstring to reflect multi-backend search surface (#52). | ||
|
|
||
| ### Fixed |
There was a problem hiding this comment.
Remove duplicate ### Fixed heading.
The [Unreleased] section contains two ### Fixed headings (lines 9 and 12). According to Keep a Changelog format, there should be only one heading per section type per release. Merge both bullet points under a single ### Fixed heading.
📝 Proposed fix
## [Unreleased]
### Fixed
- Fix `vouch search` CLI: assign backend label per code path so substring fallback results are no longer mislabelled as `fts5`; update stale docstring to reflect multi-backend search surface (`#52`).
-
-### Fixed
- Bundle import rejects tar members whose path escapes `kb_dir`
(CVE-2007-4559, `#9`). Previously a crafted `.tar.gz` with a member📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ### Fixed | |
| - Fix `vouch search` CLI: assign backend label per code path so substring fallback results are no longer mislabelled as `fts5`; update stale docstring to reflect multi-backend search surface (#52). | |
| ### Fixed | |
| ### Fixed | |
| - Fix `vouch search` CLI: assign backend label per code path so substring fallback results are no longer mislabelled as `fts5`; update stale docstring to reflect multi-backend search surface (`#52`). | |
| - Bundle import rejects tar members whose path escapes `kb_dir` | |
| (CVE-2007-4559, `#9`). Previously a crafted `.tar.gz` with a member |
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 12-12: Multiple headings with the same content
(MD024, no-duplicate-heading)
🤖 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 `@CHANGELOG.md` around lines 9 - 12, The CHANGELOG.md has duplicate "### Fixed"
headings in the same release section; remove the second "### Fixed" heading and
merge its bullet(s) into the first "### Fixed" list so there is only one "###
Fixed" heading under the [Unreleased] section, preserving both bullets
(including the `vouch search` CLI fix and the stale docstring note) in that
single list.
|
Thanks for this — the docstring update is a nice catch. One thing I want to double-check on the code change: the new Could you share the exact command + state where you saw Also: a small test would be great — anything that asserts The docstring fix should land either way 🙏 |
You're right — I re-read it and the label assignment is equivalent in I'll update the PR to keep only the docstring fix and drop the branch Apologies for the noise on the logic change. |
The branch restructure was equivalent to the original and did not fix a real bug. Revert to the original control flow; keep only the docstring update from FTS5-only to multi-backend description. Fixes vouchdev#52
|
Updated — reverted the logic change, kept only the docstring fix. |
…l tests Revert the control-flow restructure (equivalent to original, no real bug). Keep only the docstring update from 'FTS5 search' to 'Search claims, pages, and entities (embedding -> fts5 -> substring)'. Add two tests asserting vouch search prints the correct backend label: - test_search_fts5_backend_label: FTS5 hit -> (fts5) - test_search_substring_backend_label: state.db absent -> (substring) Fixes vouchdev#52
|
Updated — reverted the logic change as you pointed out, it was
All 110 tests pass. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_cli.py (1)
114-117: ⚡ Quick winDecouple fallback trigger from DB-file internals.
On Line 114, forcing fallback by deleting
state.dbis brittle and tied to storage layout. Prefer monkeypatching the FTS5 call to raise so this test validates behavior, not implementation details.Proposed test-hardening diff
def test_search_substring_backend_label( store: KBStore, monkeypatch: pytest.MonkeyPatch ) -> None: @@ - # Remove state.db so FTS5 raises and substring fallback runs - state_db = store.kb_dir / "state.db" - if state_db.exists(): - state_db.unlink() + # Force FTS5 to fail so substring fallback runs + from vouch import search as search_mod + monkeypatch.setattr( + search_mod, + "_search_fts5", + lambda *_args, **_kwargs: (_ for _ in ()).throw(RuntimeError("forced fts5 failure")), + )🤖 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 `@tests/test_cli.py` around lines 114 - 117, Replace the brittle deletion of state.db with a targeted monkeypatch that makes the FTS5 query raise: remove the state_db unlink block and instead in tests/test_cli.py monkeypatch sqlite3.Connection.execute (or sqlite3.Cursor.execute) used by the KB/search code (or the specific method on the store object if present) to raise sqlite3.OperationalError when the SQL contains FTS5-specific text (e.g., "fts5", "MATCH" or "virtual fts5"), so the test triggers the substring fallback path without touching store.kb_dir/state.db; use the existing test's store fixture to scope the monkeypatch and restore normal behavior for other queries.
🤖 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.
Nitpick comments:
In `@tests/test_cli.py`:
- Around line 114-117: Replace the brittle deletion of state.db with a targeted
monkeypatch that makes the FTS5 query raise: remove the state_db unlink block
and instead in tests/test_cli.py monkeypatch sqlite3.Connection.execute (or
sqlite3.Cursor.execute) used by the KB/search code (or the specific method on
the store object if present) to raise sqlite3.OperationalError when the SQL
contains FTS5-specific text (e.g., "fts5", "MATCH" or "virtual fts5"), so the
test triggers the substring fallback path without touching
store.kb_dir/state.db; use the existing test's store fixture to scope the
monkeypatch and restore normal behavior for other queries.
|
LGTM! |
fix: assign backend label per code path in vouch search CLI
Yes boss🫡 |
Problem
The
searchcommand docstring read:This is stale — the search layer now supports embedding, FTS5,
substring, and hybrid backends. The docstring misleads users about
what the command actually does.
Fix
Update the docstring to reflect the current multi-backend search
surface:
Tests
108 tests pass, 4 deselected.
Fixes #52
Summary by CodeRabbit