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 lint
FABIOTESS087ee32221ad
diff --git a/src/ontology.rs b/src/ontology.rsindex 8781da35..1985b0e4 100644--- a/src/ontology.rs+++ b/src/ontology.rs@@ -96,14 +96,8 @@ impl OntologyService {.to_string())}- /// Lint an ontology -- check for missing labels, comments, domains.- pub fn lint(content: &str) -> anyhow::Result<String> {- let store = Store::new()?;- let reader = Cursor::new(content.as_bytes());- for quad in RdfParser::from_format(RdfFormat::Turtle).for_reader(reader) {- store.insert(&quad?)?;- }-+ /// Collect raw lint issues from a Store.+ fn collect_lint_issues(store: &Store) -> anyhow::Result<Vec<serde_json::Value>> {let mut issues: Vec<serde_json::Value> = Vec::new();// Find classes without rdfs:label@@ -172,13 +166,61 @@ impl OntologyService {}}+ Ok(issues)+ }++ /// Lint an ontology with feedback-based suppression.+ pub fn lint_with_feedback(content: &str, db: Option<&crate::state::StateDb>) -> anyhow::Result<String> {+ let store = Store::new()?;+ let reader = Cursor::new(content.as_bytes());+ for quad in RdfParser::from_format(RdfFormat::Turtle).for_reader(reader) {+ store.insert(&quad?)?;+ }++ let raw_issues = Self::collect_lint_issues(&store)?;+ let mut issues: Vec<serde_json::Value> = Vec::new();+ let mut suppressed_count: u64 = 0;++ for issue in raw_issues {+ if let Some(db) = db {+ let rule_id = issue["type"].as_str().unwrap_or("");+ let entity = issue["entity"].as_str().unwrap_or("");+ match crate::feedback::get_feedback_adjustment(db, "lint", rule_id, entity) {+ crate::feedback::FeedbackAction::Suppress => {+ suppressed_count += 1;+ continue;+ }+ crate::feedback::FeedbackAction::Downgrade => {+ let original = issue["severity"].as_str().unwrap_or("info");+ let downgraded = crate::feedback::downgrade_severity(original);+ let mut adjusted = issue.clone();+ adjusted["original_severity"] = serde_json::json!(original);+ adjusted["adjusted_severity"] = serde_json::json!(downgraded);+ adjusted["severity"] = serde_json::json!(downgraded);+ issues.push(adjusted);+ }+ crate::feedback::FeedbackAction::Keep => {+ issues.push(issue);+ }+ }+ } else {+ issues.push(issue);+ }+ }+Ok(serde_json::json!({"issues": issues,"issue_count": issues.len(),+ "suppressed_count": suppressed_count,}).to_string())}+ /// Lint an ontology -- check for missing labels, comments, domains.+ pub fn lint(content: &str) -> anyhow::Result<String> {+ Self::lint_with_feedback(content, None)+ }+/// Save a named version (snapshot) of the current graph store.pub fn save_version(db: &StateDb, store: &Arc<GraphStore>, label: &str) -> anyhow::Result<String> {let content = store.snapshot("ntriples")?;diff --git a/tests/ontology_test.rs b/tests/ontology_test.rsindex 95219d47..815c3f65 100644--- a/tests/ontology_test.rs+++ b/tests/ontology_test.rs@@ -68,3 +68,46 @@ fn test_lint_ontology() {// Person has no label/comment, should be flaggedassert!(report.contains("Person"));}++#[test]+fn test_lint_with_feedback_suppression() {+ use open_ontologies::ontology::OntologyService;+ use open_ontologies::state::StateDb;+ use open_ontologies::feedback::record_tool_feedback;++ let tmp = tempfile::NamedTempFile::new().unwrap();+ let path = tmp.path().to_path_buf();+ std::mem::forget(tmp);+ let db = StateDb::open(&path).unwrap();++ let ttl = r#"+ @prefix owl: <http://www.w3.org/2002/07/owl#> .+ @prefix ex: <http://example.org/> .+ ex:Dog a owl:Class .+ "#;++ // Without feedback, missing_label should appear+ let result = OntologyService::lint_with_feedback(ttl, Some(&db)).unwrap();+ let v: serde_json::Value = serde_json::from_str(&result).unwrap();+ assert!(v["issue_count"].as_u64().unwrap() > 0);+ assert_eq!(v["suppressed_count"].as_u64().unwrap(), 0);++ // Find the entity string used in the lint output for Dog+ let issues = v["issues"].as_array().unwrap();+ let dog_issue = issues.iter().find(|i| {+ i["type"].as_str().unwrap_or("") == "missing_label" &&+ i["entity"].as_str().unwrap_or("").contains("example.org/Dog")+ });+ assert!(dog_issue.is_some(), "Should have missing_label for Dog");+ let entity_str = dog_issue.unwrap()["entity"].as_str().unwrap();++ // Dismiss 3 times using the exact entity string from lint output+ for _ in 0..3 {+ record_tool_feedback(&db, "lint", "missing_label", entity_str, false).unwrap();+ }++ // Now the issue should be suppressed+ let result = OntologyService::lint_with_feedback(ttl, Some(&db)).unwrap();+ let v: serde_json::Value = serde_json::from_str(&result).unwrap();+ assert!(v["suppressed_count"].as_u64().unwrap() > 0);+}