use std::fs;
use std::path::Path;
use std::process::{Command, Output};
fn tsift_bin() -> Command {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_tsift-cli"));
cmd.env("OLLAMA_HOST", "http://127.0.0.1:1");
cmd
}
fn build_fixture(dir: &Path) {
fs::write(
dir.join("main.rs"),
r#"fn main() {
greet();
}
fn greet() {
helper();
}
fn helper() {}
"#,
)
.unwrap();
}
fn assert_ok(label: &str, output: &Output) {
assert!(
output.status.success(),
"core command `{label}` must succeed without tsift kg (exit {:?})\nstdout: {}\nstderr: {}",
output.status.code(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);
}
#[test]
fn core_commands_work_without_tsift_kg_and_create_no_graph_db() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path();
build_fixture(root);
let home = tempfile::tempdir().unwrap();
let graph_db = root.join(".tsift/graph.db");
let out = tsift_bin()
.args(["index", root.to_str().unwrap()])
.output()
.unwrap();
assert_ok("index", &out);
assert!(
!graph_db.exists(),
"indexing must not create .tsift/graph.db"
);
let out = tsift_bin()
.args(["status", root.to_str().unwrap()])
.output()
.unwrap();
assert_ok("status", &out);
let out = tsift_bin()
.args(["search", "--path", root.to_str().unwrap(), "greet"])
.output()
.unwrap();
assert_ok("search", &out);
let out = tsift_bin()
.args(["explain", "greet", root.to_str().unwrap()])
.output()
.unwrap();
assert_ok("explain", &out);
let out = tsift_bin()
.args(["graph", "greet", root.to_str().unwrap(), "--callees"])
.output()
.unwrap();
assert_ok("graph", &out);
let out = tsift_bin()
.args(["source-read", "main.rs", "--path", root.to_str().unwrap()])
.output()
.unwrap();
assert_ok("source-read", &out);
let notes = root.join("notes.md");
fs::write(¬es, "# notes\n\nsummarize the tsift session\n").unwrap();
let out = tsift_bin()
.args(["session-review", "--json", notes.to_str().unwrap()])
.env("HOME", home.path())
.output()
.unwrap();
assert_ok("session-review", &out);
assert!(
!graph_db.exists(),
"no core command may create .tsift/graph.db; found one at {}",
graph_db.display()
);
}