//! Lint through the CLI: `run lint.* ` gives the engine's answer and fixes the note. mod common; use common::{empty_vault, note, read_file, run}; use notescraft_engine::{Registry, Session, register_core}; use serde_json::{Value, json}; const MESSY: &str = "# A\n\n### B\n\ntext with gaps\n"; fn engine(root: &std::path::Path, id: &str, params: &Value) -> Value { let mut registry = Registry::new(); register_core(&mut registry).expect("register"); let mut session = Session::open_read_only(root).expect("open"); registry.run(id, &mut session, params).expect("engine run") } #[test] fn check_matches_the_engine_and_fix_all_safe_cleans_the_note() { let root = empty_vault("lint-cli"); note(&root, "messy.md", MESSY); let params = json!({ "path": "messy.md" }); let checked = run(&root, &["--json", "run", "lint.check", ¶ms.to_string()]); assert_eq!(checked.code, 0, "{}", checked.stderr); assert_eq!(checked.result(), engine(&root, "lint.check", ¶ms)); let fixed = run(&root, &["--json", "run", "lint.fix_all_safe", ¶ms.to_string()]); assert_eq!(fixed.code, 0, "{}", fixed.stderr); assert_eq!(read_file(&root, "messy.md"), "# A\n\n## B\n\ntext with gaps\n"); let stale = run(&root, &["--json", "run", "lint.fix", &json!({ "path": "messy.md", "key": "heading-increment:0000000000000000" }).to_string()]); assert_eq!(stale.code, 1); assert!(stale.stdout.contains("stale"), "{}", stale.stdout); }