use asobi::model::EntityInput;
use asobi::storage::libsql::db;
use tempfile::tempdir;
fn set_db(path: &std::path::Path) {
unsafe { std::env::set_var(db::ENV_DATABASE_URL, path.to_str().unwrap()) };
}
async fn seed(conn: &libsql::Connection, name: &str) {
db::create_entities(
conn,
vec![EntityInput {
name: name.to_string(),
entity_type: "project".to_string(),
observations: vec!["precious".to_string()],
}],
)
.await
.unwrap();
}
#[tokio::test]
async fn bench_env_var_isolates_real_graph() {
let dir = tempdir().unwrap();
let real_db = dir.path().join("real.db");
let scratch_db = dir.path().join("scratch.db");
set_db(&real_db);
{
let (_db, conn) = db::init_db().await.unwrap();
seed(&conn, "keep-me").await;
}
set_db(&scratch_db);
{
let (_db, conn) = db::init_db().await.unwrap();
seed(&conn, "bench-entity").await;
db::reset(&conn).await.unwrap();
}
set_db(&real_db);
let (_db, conn) = db::init_db().await.unwrap();
let graph = db::open_nodes(&conn, vec!["keep-me".to_string()])
.await
.unwrap();
assert_eq!(graph.entities.len(), 1, "bench reset wiped the real graph");
assert_eq!(graph.entities[0].name, "keep-me");
}