#![allow(dead_code)]
use std::path::Path;
use rmcp::ServiceExt;
use rmcp::transport::child_process::TokioChildProcess;
use tokio::process::Command;
pub fn seed_default_tokenizer(data_dir: &Path) {
let fixture = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/tokenizer/tiny.json");
let dest_dir = data_dir.join("tokenizers").join("o200k");
std::fs::create_dir_all(&dest_dir).unwrap();
let dest = dest_dir.join("tokenizer.json");
std::fs::copy(&fixture, &dest).unwrap();
}
pub fn bin_path() -> std::path::PathBuf {
assert_cmd::cargo::cargo_bin("rover")
}
pub async fn make_summarizer_service(
db: &rover::storage::Db,
) -> std::sync::Arc<rover::summarizer::SummarizerService> {
let mut map: std::collections::HashMap<
String,
std::sync::Arc<dyn rover::summarizer::backend::SummarizerBackend>,
> = Default::default();
map.insert(
"default".into(),
std::sync::Arc::new(rover::summarizer::extractive::ExtractiveBackend::new(
"default",
rover::tokenizer::Tokenizer::O200k,
)),
);
let reg = std::sync::Arc::new(
rover::summarizer::registry::SummarizerRegistry::__test_construct(
map,
"default".into(),
Some("default".into()),
),
);
std::sync::Arc::new(rover::summarizer::SummarizerService::new(
db.clone(),
reg,
true,
))
}
pub async fn spawn_client(data_dir: &Path) -> rmcp::service::RunningService<rmcp::RoleClient, ()> {
let cfg_path = data_dir.join("rover.toml");
if !cfg_path.exists() {
std::fs::write(
&cfg_path,
"[robots]\nrespect = false\n\n[ssrf]\nlevel = \"loopback\"\n",
)
.unwrap();
}
let mut cmd = Command::new(bin_path());
cmd.arg("--config").arg(&cfg_path).arg("mcp");
cmd.env("ROVER_DATA_DIR", data_dir);
cmd.env("RUST_LOG", "info,rover=debug");
let proc = TokioChildProcess::new(cmd).expect("spawn rover mcp");
().serve(proc).await.expect("client handshake")
}
pub async fn spawn_client_with_config(
data_dir: &Path,
config_toml: &str,
) -> rmcp::service::RunningService<rmcp::RoleClient, ()> {
std::fs::write(data_dir.join("rover.toml"), config_toml).unwrap();
spawn_client(data_dir).await
}