|
1 | | -use crate::core; |
2 | | -use crate::review; |
3 | | - |
4 | | -pub(super) fn apply_feedback_accept( |
5 | | - store: &mut review::FeedbackStore, |
6 | | - comments: &[core::Comment], |
7 | | -) -> usize { |
8 | | - let mut updated = 0; |
9 | | - for comment in comments { |
10 | | - let is_new = store.accept.insert(comment.id.clone()); |
11 | | - if is_new { |
12 | | - updated += 1; |
13 | | - let key = review::classify_comment_type(comment).as_str().to_string(); |
14 | | - let stats = store.by_comment_type.entry(key).or_default(); |
15 | | - stats.accepted = stats.accepted.saturating_add(1); |
16 | | - let file_patterns = review::derive_file_patterns(&comment.file_path); |
17 | | - store.record_feedback_patterns(&comment.category.to_string(), &file_patterns, true); |
18 | | - } |
19 | | - store.suppress.remove(&comment.id); |
20 | | - } |
21 | | - updated |
22 | | -} |
23 | | - |
24 | | -pub(super) fn apply_feedback_reject( |
25 | | - store: &mut review::FeedbackStore, |
26 | | - comments: &[core::Comment], |
27 | | -) -> usize { |
28 | | - let mut updated = 0; |
29 | | - for comment in comments { |
30 | | - let is_new = store.suppress.insert(comment.id.clone()); |
31 | | - if is_new { |
32 | | - updated += 1; |
33 | | - let key = review::classify_comment_type(comment).as_str().to_string(); |
34 | | - let stats = store.by_comment_type.entry(key).or_default(); |
35 | | - stats.rejected = stats.rejected.saturating_add(1); |
36 | | - let file_patterns = review::derive_file_patterns(&comment.file_path); |
37 | | - store.record_feedback_patterns(&comment.category.to_string(), &file_patterns, false); |
38 | | - } |
39 | | - store.accept.remove(&comment.id); |
40 | | - } |
41 | | - updated |
42 | | -} |
43 | | - |
44 | | -#[cfg(test)] |
45 | | -mod tests { |
46 | | - use super::*; |
47 | | - use std::path::PathBuf; |
48 | | - |
49 | | - #[test] |
50 | | - fn test_feedback_stats_not_double_counted() { |
51 | | - let mut store = review::FeedbackStore::default(); |
52 | | - let comment = core::Comment { |
53 | | - id: "cmt_dup".to_string(), |
54 | | - file_path: PathBuf::from("test.rs"), |
55 | | - line_number: 1, |
56 | | - content: "test".to_string(), |
57 | | - rule_id: None, |
58 | | - severity: core::comment::Severity::Warning, |
59 | | - category: core::comment::Category::Bug, |
60 | | - suggestion: None, |
61 | | - confidence: 0.8, |
62 | | - code_suggestion: None, |
63 | | - tags: vec![], |
64 | | - fix_effort: core::comment::FixEffort::Low, |
65 | | - feedback: None, |
66 | | - }; |
67 | | - |
68 | | - let comments = vec![comment]; |
69 | | - |
70 | | - for _ in 0..2 { |
71 | | - apply_feedback_accept(&mut store, &comments); |
72 | | - } |
73 | | - |
74 | | - let key = review::classify_comment_type(&comments[0]) |
75 | | - .as_str() |
76 | | - .to_string(); |
77 | | - let stats = &store.by_comment_type[&key]; |
78 | | - assert_eq!( |
79 | | - stats.accepted, 1, |
80 | | - "Stats should only count 1 acceptance, not 2 (double-counting bug)" |
81 | | - ); |
82 | | - assert_eq!(store.by_category["Bug"].accepted, 1); |
83 | | - assert_eq!(store.by_file_pattern["*.rs"].accepted, 1); |
84 | | - assert_eq!(store.by_category_file_pattern["Bug|*.rs"].accepted, 1); |
85 | | - } |
86 | | -} |
| 1 | +#[path = "apply/accept.rs"] |
| 2 | +mod accept; |
| 3 | +#[path = "apply/reject.rs"] |
| 4 | +mod reject; |
| 5 | +#[path = "apply/stats.rs"] |
| 6 | +mod stats; |
| 7 | + |
| 8 | +pub(super) use accept::apply_feedback_accept; |
| 9 | +pub(super) use reject::apply_feedback_reject; |
0 commit comments