Skip to content

Commit fb79bfb

Browse files
committed
test(source_roots): verify add_custom_root deduplication and lexicographical sorting
1 parent d6a225f commit fb79bfb

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎crates/lore-core/src/source_roots.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,28 @@ mod tests {
423423
remove_custom_root(&conn, &registry, "claude-code", &with_trailing).unwrap();
424424
assert!(custom_roots(&conn, "claude-code").unwrap().is_empty());
425425
}
426+
427+
#[test]
428+
fn add_custom_root_deduplicates_and_sorts_multiple_directories() {
429+
let conn = crate::storage::open_in_memory().unwrap();
430+
let registry = AdapterRegistry::v0();
431+
let dir = tempfile::tempdir().unwrap();
432+
433+
let sub_b = dir.path().join("b_dir");
434+
let sub_a = dir.path().join("a_dir");
435+
std::fs::create_dir_all(&sub_b).unwrap();
436+
std::fs::create_dir_all(&sub_a).unwrap();
437+
438+
// Add in reverse order
439+
add_custom_root(&conn, &registry, "claude-code", sub_b.to_str().unwrap()).unwrap();
440+
add_custom_root(&conn, &registry, "claude-code", sub_a.to_str().unwrap()).unwrap();
441+
442+
// Add duplicate
443+
add_custom_root(&conn, &registry, "claude-code", sub_b.to_str().unwrap()).unwrap();
444+
445+
let roots = custom_roots(&conn, "claude-code").unwrap();
446+
assert_eq!(roots.len(), 2);
447+
assert_eq!(roots[0], std::fs::canonicalize(&sub_a).unwrap());
448+
assert_eq!(roots[1], std::fs::canonicalize(&sub_b).unwrap());
449+
}
426450
}

0 commit comments

Comments
 (0)