Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

feat: add lint-feedback and enforce-feedback CLI subcommands with integration tests

FABIOTESS20e351fe9163
diff --git a/src/main.rs b/src/main.rs
index 269d1f6f..5e7ad92c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -206,6 +206,38 @@ enum Commands {
reject: bool,
},
+ // ─── Feedback ────────────────────────────────────────────────
+ /// Accept or dismiss a lint issue
+ LintFeedback {
+ /// Lint rule ID (e.g. "missing_label", "missing_comment")
+ #[arg(long)]
+ rule_id: String,
+ /// Entity IRI that triggered the issue
+ #[arg(long)]
+ entity: String,
+ /// Accept the issue as valid
+ #[arg(long, default_value_t = false)]
+ accept: bool,
+ /// Dismiss/ignore the issue
+ #[arg(long, default_value_t = false)]
+ dismiss: bool,
+ },
+ /// Accept or dismiss an enforce violation
+ EnforceFeedback {
+ /// Enforce rule ID (e.g. "orphan_class", "missing_domain")
+ #[arg(long)]
+ rule_id: String,
+ /// Entity IRI that triggered the violation
+ #[arg(long)]
+ entity: String,
+ /// Accept the violation as valid
+ #[arg(long, default_value_t = false)]
+ accept: bool,
+ /// Dismiss/override the violation
+ #[arg(long, default_value_t = false)]
+ dismiss: bool,
+ },
+
// ─── Clinical ─────────────────────────────────────────────────
/// Look up clinical terminology crosswalk
Crosswalk {
@@ -398,6 +430,7 @@ async fn main() -> anyhow::Result<()> {
}
Commands::Lint { input } => {
use open_ontologies::ontology::OntologyService;
+ let (db, _graph) = setup(&cli.data_dir)?;
let content = if input == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)?;
@@ -405,7 +438,7 @@ async fn main() -> anyhow::Result<()> {
} else {
std::fs::read_to_string(&input)?
};
- let result = OntologyService::lint(&content).unwrap_or_else(|e| format!(r#"{{"error":"{}"}}"#, e));
+ let result = OntologyService::lint_with_feedback(&content, Some(&db)).unwrap_or_else(|e| format!(r#"{{"error":"{}"}}"#, e));
if cli.pretty {
if let Ok(v) = serde_json::from_str::<serde_json::Value>(&result) {
println!("{}", serde_json::to_string_pretty(&v).unwrap());
@@ -747,8 +780,8 @@ async fn main() -> anyhow::Result<()> {
}
Commands::Enforce { pack } => {
let (db, graph) = setup(&cli.data_dir)?;
- let enforcer = open_ontologies::enforce::Enforcer::new(db, graph);
- let result = enforcer.enforce(&pack)
+ let enforcer = open_ontologies::enforce::Enforcer::new(db.clone(), graph);
+ let result = enforcer.enforce_with_feedback(&pack, Some(&db))
.unwrap_or_else(|e| format!(r#"{{"error":"{}"}}"#, e));
if cli.pretty {
if let Ok(v) = serde_json::from_str::<serde_json::Value>(&result) {
@@ -900,6 +933,36 @@ async fn main() -> anyhow::Result<()> {
println!("{}", result);
}
}
+ Commands::LintFeedback { rule_id, entity, accept, dismiss } => {
+ let (db, _graph) = setup(&cli.data_dir)?;
+ let accepted = accept || !dismiss;
+ let result = open_ontologies::feedback::record_tool_feedback(&db, "lint", &rule_id, &entity, accepted)
+ .unwrap_or_else(|e| format!(r#"{{"error":"{}"}}"#, e));
+ if cli.pretty {
+ if let Ok(v) = serde_json::from_str::<serde_json::Value>(&result) {
+ println!("{}", serde_json::to_string_pretty(&v).unwrap());
+ } else {
+ println!("{}", result);
+ }
+ } else {
+ println!("{}", result);
+ }
+ }
+ Commands::EnforceFeedback { rule_id, entity, accept, dismiss } => {
+ let (db, _graph) = setup(&cli.data_dir)?;
+ let accepted = accept || !dismiss;
+ let result = open_ontologies::feedback::record_tool_feedback(&db, "enforce", &rule_id, &entity, accepted)
+ .unwrap_or_else(|e| format!(r#"{{"error":"{}"}}"#, e));
+ if cli.pretty {
+ if let Ok(v) = serde_json::from_str::<serde_json::Value>(&result) {
+ println!("{}", serde_json::to_string_pretty(&v).unwrap());
+ } else {
+ println!("{}", result);
+ }
+ } else {
+ println!("{}", result);
+ }
+ }
}
Ok(())
diff --git a/tests/cli_test.rs b/tests/cli_test.rs
index 9ce0d8d4..9bf403d9 100644
--- a/tests/cli_test.rs
+++ b/tests/cli_test.rs
@@ -223,3 +223,72 @@ fn test_cli_align_feedback() {
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(stdout.contains("ok"));
}
+
+#[test]
+fn test_cli_lint_feedback() {
+ let dir = tempfile::tempdir().unwrap();
+ let out = oo_isolated(&dir)
+ .args(["lint-feedback", "--rule-id", "missing_label", "--entity", "<http://example.org/Dog>", "--dismiss"])
+ .output().unwrap();
+ assert!(out.status.success(), "stderr: {}", String::from_utf8_lossy(&out.stderr));
+ let stdout = String::from_utf8_lossy(&out.stdout);
+ assert!(stdout.contains("ok"));
+ assert!(stdout.contains("lint"));
+}
+
+#[test]
+fn test_cli_enforce_feedback() {
+ let dir = tempfile::tempdir().unwrap();
+ let out = oo_isolated(&dir)
+ .args(["enforce-feedback", "--rule-id", "orphan_class", "--entity", "<http://example.org/Thing>", "--accept"])
+ .output().unwrap();
+ assert!(out.status.success(), "stderr: {}", String::from_utf8_lossy(&out.stderr));
+ let stdout = String::from_utf8_lossy(&out.stdout);
+ assert!(stdout.contains("ok"));
+ assert!(stdout.contains("enforce"));
+}
+
+#[test]
+fn test_cli_lint_suppression_end_to_end() {
+ let dir = tempfile::tempdir().unwrap();
+ let ttl_path = dir.path().join("test.ttl");
+ std::fs::write(&ttl_path, r#"
+ @prefix owl: <http://www.w3.org/2002/07/owl#> .
+ @prefix ex: <http://example.org/> .
+ ex:Dog a owl:Class .
+ "#).unwrap();
+
+ // Lint should report issues initially
+ let out = oo_isolated(&dir)
+ .args(["lint", ttl_path.to_str().unwrap()])
+ .output().unwrap();
+ assert!(out.status.success());
+ let stdout = String::from_utf8_lossy(&out.stdout);
+ let v: serde_json::Value = serde_json::from_str(&stdout.trim()).unwrap();
+
+ // Find the entity string for missing_label on 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 exact entity string from lint output
+ for _ in 0..3 {
+ let out = oo_isolated(&dir)
+ .args(["lint-feedback", "--rule-id", "missing_label", "--entity", entity_str, "--dismiss"])
+ .output().unwrap();
+ assert!(out.status.success());
+ }
+
+ // Lint should now show suppressed_count > 0
+ let out = oo_isolated(&dir)
+ .args(["lint", ttl_path.to_str().unwrap()])
+ .output().unwrap();
+ assert!(out.status.success());
+ let stdout = String::from_utf8_lossy(&out.stdout);
+ let v: serde_json::Value = serde_json::from_str(&stdout.trim()).unwrap();
+ assert!(v["suppressed_count"].as_u64().unwrap() > 0, "suppressed_count should be > 0 after 3 dismissals");
+}