@@ -404,76 +404,6 @@ fn resolve_convention_store_path_for_feedback(config: &config::Config) -> Option
404404 dirs:: data_local_dir ( ) . map ( |d| d. join ( "diffscope" ) . join ( "conventions.json" ) )
405405}
406406
407- #[ cfg( test) ]
408- mod tests {
409- use super :: * ;
410-
411- #[ test]
412- fn test_select_discussion_comment_empty_comments ( ) {
413- // Should return an error, not panic
414- let result = select_discussion_comment ( & [ ] , None , None ) ;
415- assert ! ( result. is_err( ) ) ;
416- }
417-
418- #[ test]
419- fn test_select_discussion_comment_defaults_to_first ( ) {
420- let comment = core:: Comment {
421- id : "cmt_1" . to_string ( ) ,
422- file_path : PathBuf :: from ( "test.rs" ) ,
423- line_number : 1 ,
424- content : "test" . to_string ( ) ,
425- rule_id : None ,
426- severity : core:: comment:: Severity :: Info ,
427- category : core:: comment:: Category :: BestPractice ,
428- suggestion : None ,
429- confidence : 0.8 ,
430- code_suggestion : None ,
431- tags : vec ! [ ] ,
432- fix_effort : core:: comment:: FixEffort :: Low ,
433- feedback : None ,
434- } ;
435- let result = select_discussion_comment ( & [ comment. clone ( ) ] , None , None ) . unwrap ( ) ;
436- assert_eq ! ( result. id, "cmt_1" ) ;
437- }
438-
439- #[ test]
440- fn test_feedback_stats_not_double_counted ( ) {
441- // Simulate accepting the same comment twice — stats should only increment once
442- let mut store = review:: FeedbackStore :: default ( ) ;
443- let comment = core:: Comment {
444- id : "cmt_dup" . to_string ( ) ,
445- file_path : PathBuf :: from ( "test.rs" ) ,
446- line_number : 1 ,
447- content : "test" . to_string ( ) ,
448- rule_id : None ,
449- severity : core:: comment:: Severity :: Warning ,
450- category : core:: comment:: Category :: Bug ,
451- suggestion : None ,
452- confidence : 0.8 ,
453- code_suggestion : None ,
454- tags : vec ! [ ] ,
455- fix_effort : core:: comment:: FixEffort :: Low ,
456- feedback : None ,
457- } ;
458-
459- let comments = vec ! [ comment] ;
460-
461- // Accept the same batch of comments twice
462- for _ in 0 ..2 {
463- apply_feedback_accept ( & mut store, & comments) ;
464- }
465-
466- let key = review:: classify_comment_type ( & comments[ 0 ] )
467- . as_str ( )
468- . to_string ( ) ;
469- let stats = & store. by_comment_type [ & key] ;
470- assert_eq ! (
471- stats. accepted, 1 ,
472- "Stats should only count 1 acceptance, not 2 (double-counting bug)"
473- ) ;
474- }
475- }
476-
477407fn load_discussion_thread ( path : Option < & std:: path:: Path > , comment_id : & str ) -> DiscussionThread {
478408 let Some ( path) = path else {
479409 return DiscussionThread {
@@ -567,3 +497,73 @@ async fn answer_discussion_question(
567497 let response = adapter. complete ( request) . await ?;
568498 Ok ( response. content )
569499}
500+
501+ #[ cfg( test) ]
502+ mod tests {
503+ use super :: * ;
504+
505+ #[ test]
506+ fn test_select_discussion_comment_empty_comments ( ) {
507+ // Should return an error, not panic
508+ let result = select_discussion_comment ( & [ ] , None , None ) ;
509+ assert ! ( result. is_err( ) ) ;
510+ }
511+
512+ #[ test]
513+ fn test_select_discussion_comment_defaults_to_first ( ) {
514+ let comment = core:: Comment {
515+ id : "cmt_1" . to_string ( ) ,
516+ file_path : PathBuf :: from ( "test.rs" ) ,
517+ line_number : 1 ,
518+ content : "test" . to_string ( ) ,
519+ rule_id : None ,
520+ severity : core:: comment:: Severity :: Info ,
521+ category : core:: comment:: Category :: BestPractice ,
522+ suggestion : None ,
523+ confidence : 0.8 ,
524+ code_suggestion : None ,
525+ tags : vec ! [ ] ,
526+ fix_effort : core:: comment:: FixEffort :: Low ,
527+ feedback : None ,
528+ } ;
529+ let result = select_discussion_comment ( std:: slice:: from_ref ( & comment) , None , None ) . unwrap ( ) ;
530+ assert_eq ! ( result. id, "cmt_1" ) ;
531+ }
532+
533+ #[ test]
534+ fn test_feedback_stats_not_double_counted ( ) {
535+ // Simulate accepting the same comment twice — stats should only increment once
536+ let mut store = review:: FeedbackStore :: default ( ) ;
537+ let comment = core:: Comment {
538+ id : "cmt_dup" . to_string ( ) ,
539+ file_path : PathBuf :: from ( "test.rs" ) ,
540+ line_number : 1 ,
541+ content : "test" . to_string ( ) ,
542+ rule_id : None ,
543+ severity : core:: comment:: Severity :: Warning ,
544+ category : core:: comment:: Category :: Bug ,
545+ suggestion : None ,
546+ confidence : 0.8 ,
547+ code_suggestion : None ,
548+ tags : vec ! [ ] ,
549+ fix_effort : core:: comment:: FixEffort :: Low ,
550+ feedback : None ,
551+ } ;
552+
553+ let comments = vec ! [ comment] ;
554+
555+ // Accept the same batch of comments twice
556+ for _ in 0 ..2 {
557+ apply_feedback_accept ( & mut store, & comments) ;
558+ }
559+
560+ let key = review:: classify_comment_type ( & comments[ 0 ] )
561+ . as_str ( )
562+ . to_string ( ) ;
563+ let stats = & store. by_comment_type [ & key] ;
564+ assert_eq ! (
565+ stats. accepted, 1 ,
566+ "Stats should only count 1 acceptance, not 2 (double-counting bug)"
567+ ) ;
568+ }
569+ }
0 commit comments