Skip to content

Commit 3a46fea

Browse files
committed
Merge pull request 'Fix #47: enable code-search by default in terraphim_grep' (#50) from task/47-impl into main
2 parents d5b6ecd + 047c934 commit 3a46fea

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

crates/terraphim_grep/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
4141
clap = { version = "4", features = ["derive"] }
4242

4343
[features]
44-
default = ["llm"]
44+
# `code-search` ships in the default set so a plain `cargo build`/`cargo install`
45+
# produces a grep that actually searches file contents. Without it, `search_code`
46+
# compiles to a no-op stub that returns no matches (see hybrid_searcher.rs).
47+
default = ["llm", "code-search"]
4548
llm = ["dep:terraphim_service"]
4649
code-search = ["dep:fff-search"]
4750
# Enable OpenRouter provider support (required for live OpenRouter tests against free models)

crates/terraphim_grep/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ terraphim_grep = { path = "../terraphim_grep" }
2929
| Feature | Default | Description |
3030
|---------------|---------|----------------------------------------------------|
3131
| `llm` | Yes | Enable LLM integration via `terraphim_service` |
32-
| `code-search` | No | Enable `fff-search` code retrieval backend |
32+
| `code-search` | Yes | Enable `fff-search` code retrieval backend |
3333
| `openrouter` | No | Enable OpenRouter provider for live LLM tests |
3434

35+
> **Note:** `code-search` is enabled by default so the tool greps file contents out of
36+
> the box. If you build with `--no-default-features` and omit `code-search`, file-content
37+
> search is disabled and every query returns no matches; the binary logs a warning on the
38+
> first search to make this obvious.
39+
3540
## Usage
3641

3742
### Library

crates/terraphim_grep/src/hybrid_searcher.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,18 @@ impl HybridSearcher {
361361
#[cfg(not(feature = "code-search"))]
362362
{
363363
let _ = (query, limit, search_path);
364+
// `code-search` is a default feature, so reaching here means the binary was
365+
// built with `--no-default-features` (or a custom set omitting it). Returning
366+
// an empty Vec silently makes every query look like "0 results" with no
367+
// explanation -- warn once so the cause is obvious rather than mysterious.
368+
static WARNED: std::sync::Once = std::sync::Once::new();
369+
WARNED.call_once(|| {
370+
tracing::warn!(
371+
"terraphim-grep was built without the `code-search` feature; \
372+
file-content search is disabled and every query returns no matches. \
373+
Rebuild with `--features code-search` (the default) to enable grep."
374+
);
375+
});
364376
Ok(vec![])
365377
}
366378
}
@@ -417,6 +429,51 @@ mod tests {
417429
assert_eq!(results.total_results(), 2);
418430
}
419431

432+
/// Regression for #47: a default build (which now enables `code-search`) must grep
433+
/// file contents over a populated directory and return matches. Before the fix the
434+
/// `code-search` feature was off by default, so `search_code` compiled to a no-op stub
435+
/// and this exact scenario silently produced zero chunks.
436+
#[cfg(feature = "code-search")]
437+
#[tokio::test]
438+
async fn default_build_greps_populated_directory() {
439+
let tmp = tempfile::TempDir::new().expect("tempdir");
440+
std::fs::write(
441+
tmp.path().join("alpha.rs"),
442+
"fn configure_pipeline() { /* pipeline setup */ }\n",
443+
)
444+
.unwrap();
445+
std::fs::write(
446+
tmp.path().join("beta.rs"),
447+
"fn run_pipeline() { configure_pipeline(); }\n",
448+
)
449+
.unwrap();
450+
451+
let searcher = HybridSearcher::new(
452+
"test-role".to_string(),
453+
terraphim_types::Thesaurus::new("t".to_string()),
454+
)
455+
.expect("build hybrid searcher")
456+
.with_search_path(tmp.path().to_path_buf());
457+
458+
let results = searcher
459+
.search(
460+
"pipeline",
461+
&GrepOptions {
462+
haystack: Haystack::Code,
463+
max_results: 50,
464+
..GrepOptions::default()
465+
},
466+
)
467+
.await
468+
.expect("search should succeed");
469+
470+
assert!(
471+
!results.code_results.is_empty(),
472+
"default build must return file-content matches over {:?}, got none",
473+
tmp.path()
474+
);
475+
}
476+
420477
fn chunk(source: &str, content: &str, score: f64) -> RetrievedChunk {
421478
RetrievedChunk {
422479
content: content.to_string(),

0 commit comments

Comments
 (0)