use std::collections::HashMap;
use crate::types::SessionId;
#[derive(Debug, Default, Clone)]
pub struct EnrichmentState {
pub prev_failing: Option<u32>,
pub seen_comment_ids: std::collections::HashSet<i64>,
pub ci_reaction_sent: bool,
pub review_reaction_sent: bool,
}
pub type EnrichmentCache = HashMap<SessionId, EnrichmentState>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn new_comments_detected_correctly() {
let mut state = EnrichmentState::default();
let ids: Vec<i64> = vec![1, 2, 3];
let new_ids: Vec<i64> = ids.iter()
.filter(|id| !state.seen_comment_ids.contains(id))
.copied()
.collect();
assert_eq!(new_ids.len(), 3);
state.seen_comment_ids.extend(ids);
let ids2: Vec<i64> = vec![1, 2, 3, 4];
let new_ids2: Vec<i64> = ids2.iter()
.filter(|id| !state.seen_comment_ids.contains(id))
.copied()
.collect();
assert_eq!(new_ids2, vec![4]);
}
#[test]
fn ci_transition_detected() {
let mut state = EnrichmentState { prev_failing: Some(0), ..Default::default() };
let is_new_failure = (state.prev_failing == Some(0)) && 2 > 0;
assert!(is_new_failure);
state.prev_failing = Some(2);
let is_new_failure2 = (state.prev_failing == Some(0)) && 2 > 0;
assert!(!is_new_failure2);
}
}