haz-domain 0.2.0

Shared domain types for the haz task runner (identifiers, paths, errors).
Documentation
//! Cache-related workspace settings.
//!
//! Carries the hash-algorithm choice that participates in the
//! content-addressing schema (`CACHE-002`) plus the `clean`
//! sub-mapping holding workspace-level thresholds for
//! `haz cache clean` (`CFG-034`, `CFG-035`).

use crate::settings::cache_clean::CacheCleanSettings;

/// Which hash function participates in cache-key derivation.
///
/// First-class variants for the two specification-recognised
/// values; future hash functions would add new variants here.
/// `Default::default()` returns [`HashAlgo::Blake3`], matching
/// the `CFG-027` default.
///
/// # Examples
///
/// ```
/// use haz_domain::settings::cache::HashAlgo;
///
/// assert_eq!(HashAlgo::default(), HashAlgo::Blake3);
/// assert_ne!(HashAlgo::Blake3, HashAlgo::Sha256);
/// ```
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub enum HashAlgo {
    /// BLAKE3 (`hash_function_id = 0x00`).
    #[default]
    Blake3,
    /// SHA-256 (`hash_function_id = 0x01`).
    Sha256,
}

/// Workspace-wide cache settings.
///
/// `Default::default()` yields the `CFG-027` default
/// ([`HashAlgo::Blake3`]) plus a defaulted [`CacheCleanSettings`]
/// (both thresholds absent per `CFG-034` / `CFG-035`); an absent
/// `cache` mapping in `workspace.yml` is equivalent to this
/// default.
///
/// # Examples
///
/// ```
/// use haz_domain::settings::cache::{CacheSettings, HashAlgo};
///
/// let cs = CacheSettings::default();
/// assert_eq!(cs.hash, HashAlgo::Blake3);
/// assert!(cs.clean.max_age.is_none());
/// assert!(cs.clean.max_size.is_none());
/// ```
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct CacheSettings {
    /// Hash function used in cache-key derivation (`CACHE-002`).
    pub hash: HashAlgo,
    /// Workspace-level defaults for `haz cache clean` thresholds
    /// (`CFG-034`, `CFG-035`).
    pub clean: CacheCleanSettings,
}

#[cfg(test)]
mod tests {
    use crate::settings::cache::{CacheSettings, HashAlgo};

    #[test]
    fn hash_algo_default_is_blake3() {
        assert_eq!(HashAlgo::default(), HashAlgo::Blake3);
    }

    #[test]
    fn hash_algo_variants_are_distinct() {
        assert_ne!(HashAlgo::Blake3, HashAlgo::Sha256);
    }

    #[test]
    fn cache_settings_default_uses_blake3() {
        assert_eq!(CacheSettings::default().hash, HashAlgo::Blake3);
    }

    #[test]
    fn cache_settings_carry_chosen_algo() {
        let cs = CacheSettings {
            hash: HashAlgo::Sha256,
            ..CacheSettings::default()
        };
        assert_eq!(cs.hash, HashAlgo::Sha256);
    }
}