Skip to content

Commit db19655

Browse files
committed
test(grep): prove insufficient KG preservation
1 parent aada68a commit db19655

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

crates/terraphim_grep/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Query
113113
├── Sufficient ──→ Return chunks (SearchOnly)
114114
├── NeedsSynthesis ──→ RLM fallback (if LLM configured)
115115
├── NeedsExpansion ──→ RLM fallback with additional chunks
116-
└── Insufficient ──→ Return empty (RlmInsufficient)
116+
└── Insufficient ──→ Preserve retrieved chunks + KG metadata (RlmInsufficient)
117117
```
118118

119119
## Key Types

crates/terraphim_grep/src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl TerraphimGrep {
336336
mod tests {
337337
use super::*;
338338
#[cfg(feature = "code-search")]
339-
use terraphim_types::Thesaurus;
339+
use terraphim_types::{NormalizedTerm, NormalizedTermValue, Thesaurus};
340340

341341
#[test]
342342
fn test_grep_options_default() {
@@ -454,7 +454,13 @@ mod tests {
454454
let path = tmp.path().join("only_match.rs");
455455
std::fs::write(&path, "fn unique_target() { /* unique_target */ }\n").unwrap();
456456

457-
let hybrid = HybridSearcher::new("test-role".to_string(), Thesaurus::new("t".to_string()))
457+
let mut thesaurus = Thesaurus::new("t".to_string());
458+
let concept_key = NormalizedTermValue::from("unique_target");
459+
let concept = NormalizedTerm::new(1, concept_key.clone())
460+
.with_display_value("unique_target".to_string());
461+
thesaurus.insert(concept_key, concept);
462+
463+
let hybrid = HybridSearcher::new("test-role".to_string(), thesaurus)
458464
.expect("build hybrid searcher")
459465
.with_search_path(tmp.path().to_path_buf());
460466
let grep = TerraphimGrep::new(Arc::new(hybrid), Arc::new(SufficiencyJudge::default()));
@@ -490,6 +496,14 @@ mod tests {
490496
result.concepts.len(),
491497
"stats.kg_hits must equal concepts.len() when concepts are retained"
492498
);
499+
assert!(result.stats.kg_hits > 0, "fixture must produce a KG hit");
500+
assert!(
501+
result
502+
.concepts
503+
.iter()
504+
.any(|concept| concept.name == "unique_target"),
505+
"the known KG concept must survive the RlmInsufficient branch"
506+
);
493507
}
494508

495509
/// The RLM prompt for `include_answer` must embed the `AnswerSignature`

0 commit comments

Comments
 (0)