use serde::{Deserialize, Serialize};
fn default_confirm_threshold() -> String {
"external_untrusted".to_owned()
}
fn default_disclose_threshold() -> String {
"local_untrusted".to_owned()
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct ConsentGateConfig {
pub enabled: bool,
#[serde(default = "default_confirm_threshold")]
pub confirm_threshold: String,
#[serde(default = "default_disclose_threshold")]
pub disclose_threshold: String,
pub audit_all: bool,
}
impl Default for ConsentGateConfig {
fn default() -> Self {
Self {
enabled: true,
confirm_threshold: default_confirm_threshold(),
disclose_threshold: default_disclose_threshold(),
audit_all: true,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_match_spec() {
let cfg = ConsentGateConfig::default();
assert!(cfg.enabled);
assert_eq!(cfg.confirm_threshold, "external_untrusted");
assert_eq!(cfg.disclose_threshold, "local_untrusted");
assert!(cfg.audit_all);
}
#[test]
fn deserializes_from_empty_table() {
let cfg: ConsentGateConfig = toml::from_str("").unwrap();
assert!(cfg.enabled);
assert_eq!(cfg.confirm_threshold, "external_untrusted");
assert_eq!(cfg.disclose_threshold, "local_untrusted");
}
#[test]
fn deserializes_explicit_values() {
let cfg: ConsentGateConfig = toml::from_str(
"enabled = false\nconfirm_threshold = \"local_untrusted\"\naudit_all = false\n",
)
.unwrap();
assert!(!cfg.enabled);
assert_eq!(cfg.confirm_threshold, "local_untrusted");
assert!(!cfg.audit_all);
}
}