//! Authored-case validation infrastructure for metal2vulkan. //! //! Harvesting, manifests, observations, and translation A/B are deliberately separate. Nothing in //! this crate infers execution inputs or repairs a manifest. pub mod ab; pub mod air; pub mod candidate; pub mod case; pub mod check; pub mod executor_contract; pub mod hash; pub mod index; pub mod jsonl; pub mod library_module; pub mod literal; pub mod metal; pub mod normalize; pub mod observation; pub mod observation_contract; pub mod requirement; pub mod review; pub mod source; pub mod store; pub mod translation_audit; pub mod triage; use std::fs; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicU64, Ordering}; static SCRATCH_COUNTER: AtomicU64 = AtomicU64::new(0); pub struct ScratchDir { path: PathBuf, } impl ScratchDir { pub fn new(purpose: &str) -> Result { let safe: String = purpose .chars() .map(|ch| { if ch.is_ascii_alphanumeric() || matches!(ch, '-' | '_') { ch } else { '_' } }) .collect(); loop { let serial = SCRATCH_COUNTER.fetch_add(1, Ordering::Relaxed); let path = std::env::temp_dir().join(format!( "metal2vulkan-validation-{}-{serial}-{safe}", std::process::id() )); match fs::create_dir(&path) { Ok(()) => return Ok(Self { path }), Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue, Err(error) => return Err(format!("create {}: {error}", path.display())), } } } pub fn path(&self) -> &Path { &self.path } } impl Drop for ScratchDir { fn drop(&mut self) { let _ = fs::remove_dir_all(&self.path); } } #[cfg(test)] mod tests { use super::*; #[test] fn scratch_directory_is_removed_on_drop() { let path = { let scratch = ScratchDir::new("cleanup-test").unwrap(); let path = scratch.path().to_path_buf(); fs::write(path.join("file"), b"temporary").unwrap(); path }; assert!(!path.exists()); } #[test] fn scratch_directory_skips_a_stale_process_serial() { let serial = SCRATCH_COUNTER.load(Ordering::Relaxed); let stale = std::env::temp_dir().join(format!( "metal2vulkan-validation-{}-{serial}-stale-serial-test", std::process::id() )); fs::create_dir(&stale).unwrap(); let scratch = ScratchDir::new("stale-serial-test").unwrap(); assert_ne!(scratch.path(), stale); fs::remove_dir(&stale).unwrap(); } }