//! Single-use AC context registry (R-22). //! Filesystem-based: ~/.gsh/consumed/{context_id} use std::path::PathBuf; /// Tracks consumed AC context IDs on the filesystem. pub struct ConsumedRegistry { dir: PathBuf, } impl ConsumedRegistry { pub fn new(dir: PathBuf) -> Self { Self { dir } } /// Default registry location: ~/.gsh/consumed/ pub fn default_location() -> Self { let dir = dirs::home_dir() .map(|h| h.join(".gsh").join("consumed")) .unwrap_or_else(|| PathBuf::from("/tmp/.gsh/consumed")); Self { dir } } pub fn is_consumed(&self, context_id: &str) -> bool { self.dir.join(context_id).exists() } pub fn mark_consumed(&mut self, context_id: &str) { let _ = std::fs::create_dir_all(&self.dir); let _ = std::fs::write(self.dir.join(context_id), ""); } } #[cfg(test)] mod tests { use super::*; #[test] fn test_consume_and_check() { let dir = tempfile::tempdir().unwrap(); let mut reg = ConsumedRegistry::new(dir.path().to_path_buf()); assert!(!reg.is_consumed("ac-123")); reg.mark_consumed("ac-123"); assert!(reg.is_consumed("ac-123")); assert!(!reg.is_consumed("ac-456")); } }