@@ -187,6 +187,13 @@ mod tests {
187187 use std:: io:: Write ;
188188 use tempfile:: TempDir ;
189189
190+ #[ test]
191+ fn test_new_creates_empty_graph ( ) {
192+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
193+ let kg = KnowledgeGraph :: new ( temp_dir. path ( ) . to_path_buf ( ) ) ;
194+ assert_eq ! ( kg. concept_count( ) , 0 ) ;
195+ }
196+
190197 #[ test]
191198 fn test_knowledge_graph_loading ( ) {
192199 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
@@ -257,4 +264,36 @@ mod tests {
257264 assert ! ( kg. are_related( "auth_module" , "security_handler" ) ) ;
258265 assert ! ( !kg. are_related( "auth_module" , "ui_component" ) ) ;
259266 }
267+
268+ #[ test]
269+ fn test_group_by_concept_buckets_modules ( ) {
270+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
271+ let kg_dir = temp_dir. path ( ) . join ( "kg" ) ;
272+ std:: fs:: create_dir ( & kg_dir) . unwrap ( ) ;
273+
274+ let mut auth_file = std:: fs:: File :: create ( kg_dir. join ( "Authentication.md" ) ) . unwrap ( ) ;
275+ writeln ! ( auth_file, "# Authentication" ) . unwrap ( ) ;
276+ writeln ! ( auth_file, "synonyms:: auth, login" ) . unwrap ( ) ;
277+
278+ let mut kg = KnowledgeGraph :: new ( kg_dir. clone ( ) ) ;
279+ kg. load_from_directory ( & kg_dir) . unwrap ( ) ;
280+
281+ let modules = vec ! [
282+ "service::auth_handler" . to_string( ) ,
283+ "service::login_manager" . to_string( ) ,
284+ "service::unrelated_utils" . to_string( ) ,
285+ ] ;
286+ let groups = kg. group_by_concept ( & modules) ;
287+
288+ assert ! (
289+ groups. contains_key( "Authentication" ) ,
290+ "auth modules must be grouped"
291+ ) ;
292+ assert_eq ! ( groups[ "Authentication" ] . len( ) , 2 ) ;
293+ assert ! (
294+ groups. contains_key( "uncategorized" ) ,
295+ "unmatched modules go to uncategorized"
296+ ) ;
297+ assert_eq ! ( groups[ "uncategorized" ] . len( ) , 1 ) ;
298+ }
260299}
0 commit comments