Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.
Rust ai-nativedescription-logicsformal-verificationinfrastructure-as-codeisabelle-languageknowledge-graphleanlean4mcpmcp-serverontologyowlowl2reasoningrustshaclsparqltheorem-proving
feat: integrate feedback suppression into enforce
FABIOTESSe59c79fc291c
diff --git a/src/enforce.rs b/src/enforce.rsindex 933557bd..0136339b 100644--- a/src/enforce.rs+++ b/src/enforce.rs@@ -16,6 +16,11 @@ impl Enforcer {/// Run enforcement for a rule pack. Built-in packs: "generic", "boro", "value_partition"./// Custom rules stored in SQLite are also checked for the given pack name.pub fn enforce(&self, rule_pack: &str) -> anyhow::Result<String> {+ self.enforce_with_feedback(rule_pack, None)+ }++ /// Run enforcement with optional feedback-based suppression.+ pub fn enforce_with_feedback(&self, rule_pack: &str, feedback_db: Option<&StateDb>) -> anyhow::Result<String> {let mut violations = Vec::new();let mut total_rules = 0u32;let mut passed_rules = 0u32;@@ -30,6 +35,37 @@ impl Enforcer {// Also run custom rules for this packself.run_custom_rules(rule_pack, &mut violations, &mut total_rules, &mut passed_rules);+ // Apply feedback adjustments+ let mut filtered_violations: Vec<serde_json::Value> = Vec::new();+ let mut suppressed_count: u64 = 0;++ for violation in violations {+ if let Some(db) = feedback_db {+ let rule = violation["rule"].as_str().unwrap_or("");+ let entity = violation["entity"].as_str().unwrap_or("");+ match crate::feedback::get_feedback_adjustment(db, "enforce", rule, entity) {+ crate::feedback::FeedbackAction::Suppress => {+ suppressed_count += 1;+ continue;+ }+ crate::feedback::FeedbackAction::Downgrade => {+ let original = violation["severity"].as_str().unwrap_or("info");+ let downgraded = crate::feedback::downgrade_severity(original);+ let mut adjusted = violation.clone();+ adjusted["original_severity"] = serde_json::json!(original);+ adjusted["adjusted_severity"] = serde_json::json!(downgraded);+ adjusted["severity"] = serde_json::json!(downgraded);+ filtered_violations.push(adjusted);+ }+ crate::feedback::FeedbackAction::Keep => {+ filtered_violations.push(violation);+ }+ }+ } else {+ filtered_violations.push(violation);+ }+ }+let compliance = if total_rules > 0 {passed_rules as f64 / total_rules as f64} else {@@ -38,10 +74,11 @@ impl Enforcer {let result = serde_json::json!({"rule_pack": rule_pack,- "violations": violations,+ "violations": filtered_violations,"total_rules": total_rules,"passed_rules": passed_rules,"compliance": compliance,+ "suppressed_count": suppressed_count,});Ok(result.to_string())diff --git a/tests/enforce_test.rs b/tests/enforce_test.rsindex bb343fee..5b3c8d89 100644--- a/tests/enforce_test.rs+++ b/tests/enforce_test.rs@@ -1,4 +1,5 @@use open_ontologies::enforce::Enforcer;+use open_ontologies::feedback::record_tool_feedback;use open_ontologies::graph::GraphStore;use open_ontologies::state::StateDb;use std::sync::Arc;@@ -182,3 +183,54 @@ fn test_enforce_compliance_score() {let score = parsed["compliance"].as_f64().unwrap();assert!(score >= 0.0 && score <= 1.0);}++#[test]+fn test_enforce_with_feedback_suppression() {+ let tmp = NamedTempFile::new().unwrap();+ let path = tmp.path().to_path_buf();+ std::mem::forget(tmp);+ let db = StateDb::open(&path).unwrap();+ let graph = Arc::new(GraphStore::new());++ // Load a class with no label (triggers missing_label rule in generic pack)+ graph+ .load_turtle(+ r#"+ @prefix owl: <http://www.w3.org/2002/07/owl#> .+ @prefix ex: <http://example.org/> .+ ex:Dog a owl:Class .+ "#,+ None,+ )+ .unwrap();++ let enforcer = Enforcer::new(db.clone(), graph.clone());++ // Without feedback, violations should appear+ let result = enforcer.enforce_with_feedback("generic", Some(&db)).unwrap();+ let v: serde_json::Value = serde_json::from_str(&result).unwrap();+ let violations = v["violations"].as_array().unwrap();+ assert!(violations.len() > 0);+ assert_eq!(v["suppressed_count"].as_u64().unwrap(), 0);++ // Find the entity string for the missing_label violation on Dog+ let dog_violation = violations.iter().find(|v| {+ v["rule"].as_str().unwrap_or("") == "missing_label"+ && v["entity"].as_str().unwrap_or("").contains("example.org/Dog")+ });+ assert!(+ dog_violation.is_some(),+ "Should have missing_label violation for Dog"+ );+ let entity_str = dog_violation.unwrap()["entity"].as_str().unwrap();++ // Dismiss 3 times using exact entity string+ for _ in 0..3 {+ record_tool_feedback(&db, "enforce", "missing_label", entity_str, false).unwrap();+ }++ // Now that violation should be suppressed+ let result = enforcer.enforce_with_feedback("generic", Some(&db)).unwrap();+ let v: serde_json::Value = serde_json::from_str(&result).unwrap();+ assert!(v["suppressed_count"].as_u64().unwrap() > 0);+}