1use rustc_hash::FxHashMap;
18use serde::Deserialize;
19
20#[derive(Debug, Clone, Deserialize, Default)]
24pub struct ContextConfig {
25 #[serde(default)]
31 pub files: FxHashMap<String, String>,
32
33 pub session: Option<String>,
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43 use crate::serde_yaml;
44
45 #[test]
46 fn test_context_config_default() {
47 let config = ContextConfig::default();
48 assert!(config.files.is_empty());
49 assert!(config.session.is_none());
50 }
51
52 #[test]
53 fn test_context_config_deserialize_empty() {
54 let yaml = "";
55 let config: ContextConfig = serde_yaml::from_str(yaml).unwrap_or_default();
56 assert!(config.files.is_empty());
57 }
58
59 #[test]
60 fn test_context_config_deserialize_files() {
61 let yaml = r#"
62files:
63 brand: ./context/brand.md
64 persona: ./context/persona.json
65"#;
66 let config: ContextConfig = serde_yaml::from_str(yaml).unwrap();
67 assert_eq!(config.files.len(), 2);
68 assert_eq!(
69 config.files.get("brand"),
70 Some(&"./context/brand.md".to_string())
71 );
72 assert_eq!(
73 config.files.get("persona"),
74 Some(&"./context/persona.json".to_string())
75 );
76 }
77
78 #[test]
79 fn test_context_config_deserialize_session() {
80 let yaml = r#"
81session: .nika/sessions/prev.json
82"#;
83 let config: ContextConfig = serde_yaml::from_str(yaml).unwrap();
84 assert_eq!(config.session, Some(".nika/sessions/prev.json".to_string()));
85 }
86
87 #[test]
88 fn test_context_config_deserialize_full() {
89 let yaml = r#"
90files:
91 brand: ./context/brand.md
92 examples: ./context/*.md
93session: .nika/sessions/prev.json
94"#;
95 let config: ContextConfig = serde_yaml::from_str(yaml).unwrap();
96 assert_eq!(config.files.len(), 2);
97 assert!(config.files.contains_key("brand"));
98 assert!(config.files.contains_key("examples"));
99 assert!(config.session.is_some());
100 }
101
102 #[test]
103 fn test_context_config_glob_pattern() {
104 let yaml = r#"
105files:
106 examples: ./context/*.md
107"#;
108 let config: ContextConfig = serde_yaml::from_str(yaml).unwrap();
109 assert!(config.files.get("examples").unwrap().contains('*'));
110 }
111}