feat: add explicit search backend selection#58
Conversation
Refs #55 Adds --backend choices for everything, fd, and rg-files, resolves the default backend with Windows-first behavior, and routes search execution through a backend dispatch layer. Windows default remains Everything/es.exe. Non-Windows requires explicit --backend fd or --backend rg-files. Stats, JSON output, and search logs now include the selected backend name.
Refs #55 Adds focused backend tests for default resolution, missing backend errors, dispatch to existing Everything functions, fd/rg-files command construction, timeout handling, and backend fields in stats/JSON/log output.
Refs #55 Documents explicit backend selection, clarifies search JSON output and backend stats, and adds Compatibility Notes guidance for backend-related PRs.
- validate_everything_backend() raises BackendConfigError instead of surfacing a raw FileNotFoundError from subprocess.run - call it from backend_search() before invoking es_search / es_search_multi_path - README: list fd and ripgrep as optional tools, clarify that the Everything/es.exe restriction is on the backend (not on se as a whole), and note that --backend fd / rg-files can be explicitly opted into on Windows - test: cover BackendConfigError when get_es_path() points at a missing file
Review feedback addressed (force-pushed
|
| Optional | Note |
|---|---|
| fd | --backend fd でファイル名/パス検索(POSIX 系の主用途。Windows でも明示指定可) |
| ripgrep | --backend rg-files で rg --files + Python 正規表現フィルタ |
3. Wording: Everything restriction is on the backend, not on se
Before:
Everything は Windows 専用です。他の OS では動作しません。
After:
Everything /
es.exebackend は Windows 専用です。Linux/POSIX 系では--backend fdまたは--backend rg-filesを明示指定してください。
Backend selection section now also explicitly states that --backend fd / --backend rg-files can be opted into on Windows (PATH の fd.exe / rg.exe) for smoke / portable fallback, while the default backend is unchanged.
Verification (re-run after da505e0)
python -m pytest -q→ 37 passed (+1 new test, 0 regressions)python src/se.py --check --json→ok: trueon Windowspython src/se.py --literal -n 3 py→everythingdefault unchangedpython src/se.py --backend fd --literal -n 5 py→ rc 0, results returnedpython src/se.py --backend rg-files --literal -n 5 py→ rc 0, results returnedpython src/se.py --backend fd --max-seconds 0.0001 --literal -p "C:/Users" py --stats→[se] backend=fd ... timed_out=True, rc 0 (partial-results convention preserved)python -c "...patched get_es_path -> missing path..."→BackendConfigError: se: es.exe not found at C:\does-not-exist\es.exe. Run \se --doctor` or set es_path in ~/.serc.`- NDA banned-term scan on the repo → clean
git diff --check→ clean
Out of scope (deferred to #56)
--backend plocate/--backend arch-linux- plocate → fd automatic fallback
--install-hintflag- backend-aware
--check(Linux probing, install-hint surfacing)
These were drafted locally, reviewed, and intentionally not included in this PR per the review recommendation to keep #55 a clean backend-selector layer.
- move backend resolution after --expand-only output so Linux/POSIX can run se -e without --backend - allow validate_everything_backend() to accept PATH-resolved es.exe values via shutil.which - add regression tests for both review findings
Follow-up review fixes addressed (
|
- _search_fd / _search_rg_files: raise BackendConfigError instead of sys.exit(1) when the underlying tool exits non-zero with stderr, so cmd_search owns exit code, stats, and log emission consistently - backend_search everything single-path branch: use _remaining_timeout instead of inline (deadline - time.monotonic()), so an exhausted budget fails before spawning es.exe (matches fd / rg-files paths) - tests: cover both helper failure paths and the early-exhausted budget case for the everything single-path branch
Layer-responsibility fixes (
|
Refs #55
Depends on #57 (repo hygiene docs/templates already merged).
Summary
Adds the explicit
--backendselector layer for the #55 MVP:everything— existing Windows / Everything /es.exebackendfd— filename/path backend viafdrg-files—rg --filesplus Python regex filteringThis PR intentionally does not add
plocate,arch-linux, automatic backend detection, or fallback behavior. Those remain for #56 follow-up PRs.Compatibility Notes
se query→ Everything /es.exe.--backendnow fails closed with exit2and a hint to use--backend fdor--backend rg-files.--statsnow includesbackend=<name>."backend": "...".--logentries now include"backend": "...".124.-f/--fzfremains disabled in non-interactive mode.Implementation split
feat: add explicit backend dispatch_backend_invoke(argv, timeout)seam only_backend_streamyettest: cover explicit backend selectiontests/test_backend.pydocs: document backend selector compatibilityVerification
python -m py_compile src/se.pypython -m pytest tests/test_cli.py tests/test_backend.py -q→ 36 passedpowershell.exe ... .\src\se.cmd --check --json→ok: truepython src/se.py se.py -n 3 --stats→backend=everything, rc 0python src/se.py --backend fd --literal -n 3 se.py --stats→ rc 0python src/se.py --backend rg-files --literal -n 3 se.py --json→ JSON includesbackend: rg-files