KeiSeiKit-1.0/_primitives/_rust/kei-graph-check/tests/integration.rs
Parfii-bot 19ee220e0a feat(primitives): 4 Rust crates for deep-sleep — conflict-scan, refactor-engine, graph-check, store
- kei-conflict-scan: rules/hooks/blocks/orphans/CP detection (6 tests)
- kei-refactor-engine: plan-mode + advisory patch format, zero-conflict guarantee (5 tests)
- kei-graph-check: wikilinks/handoffs/block-refs validator (4 tests)
- kei-store: trait + 5 backends (filesystem/github/forgejo/gitea prod, s3 stub) (8 tests)

1916 LOC Rust total; all files <200 LOC; 23/23 tests pass.
2026-04-22 08:28:22 +08:00

75 lines
2.1 KiB
Rust

//! Integration tests for kei-graph-check.
use std::fs;
use std::path::{Path, PathBuf};
use tempfile::TempDir;
fn bin() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_kei-graph-check"))
}
fn write(root: &Path, rel: &str, body: &str) {
let full = root.join(rel);
if let Some(parent) = full.parent() {
fs::create_dir_all(parent).unwrap();
}
fs::write(full, body).unwrap();
}
#[test]
fn clean_graph_exits_zero() {
let tmp = TempDir::new().unwrap();
write(tmp.path(), "a.md", "see [[b]]");
write(tmp.path(), "b.md", "hello");
let out = std::process::Command::new(bin())
.args(["--path"])
.arg(tmp.path())
.output()
.unwrap();
assert!(out.status.success(), "stderr: {}", String::from_utf8_lossy(&out.stderr));
}
#[test]
fn broken_wikilink_exits_two() {
let tmp = TempDir::new().unwrap();
write(tmp.path(), "a.md", "see [[ghost]]");
let out = std::process::Command::new(bin())
.args(["--path"])
.arg(tmp.path())
.output()
.unwrap();
assert_eq!(out.status.code(), Some(2));
}
#[test]
fn patch_removal_breaks_graph() {
let tmp = TempDir::new().unwrap();
write(tmp.path(), "a.md", "see [[b]]");
write(tmp.path(), "b.md", "hello");
let patch = tmp.path().join("p.patch");
fs::write(&patch, "# removed: b.md\n").unwrap();
let out = std::process::Command::new(bin())
.args(["--path"])
.arg(tmp.path())
.args(["--after-diff"])
.arg(&patch)
.output()
.unwrap();
assert_eq!(out.status.code(), Some(2));
}
#[test]
fn json_output_schema() {
let tmp = TempDir::new().unwrap();
write(tmp.path(), "a.md", "see [[ghost]]");
let out = std::process::Command::new(bin())
.args(["--path"])
.arg(tmp.path())
.arg("--json")
.output()
.unwrap();
let v: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap();
assert_eq!(v["broken_count"], 1);
assert_eq!(v["broken"][0]["kind"], "wikilink");
assert_eq!(v["broken"][0]["target"], "ghost");
}