use sqlitegraph::backend::GraphBackend;
use sqlitegraph::backend::NodeSpec;
use sqlitegraph::backend::native::v3::V3Backend;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== V3 OPEN ROUNDTRIP TEST ===\n");
let temp_dir = tempfile::tempdir()?;
let db_path = temp_dir.path().join("test.db");
println!("STEP 1: Creating database with 10,000 nodes...");
let backend = V3Backend::create(&db_path)?;
for i in 0..10_000 {
backend.insert_node(NodeSpec {
kind: "TestKind".to_string(),
name: format!("node_{:05}", i),
file_path: None,
data: serde_json::json!({"value": i}),
})?;
}
backend.flush_to_disk()?;
drop(backend);
println!(" ✓ Created and flushed");
let index_path = db_path.with_extension("v3index");
assert!(index_path.exists(), "Index file should exist after flush");
let index_size = std::fs::metadata(&index_path)?.len();
println!(
" ✓ Index file created: {:.2} KB",
index_size as f64 / 1024.0
);
println!("\nSTEP 2: Reopening database...");
let backend = V3Backend::open(&db_path)?;
println!(" ✓ Database opened");
println!("\nSTEP 3: Verifying index functionality...");
use sqlitegraph::SnapshotId;
let snapshot_id = SnapshotId(0);
let results = backend.query_nodes_by_name_pattern(snapshot_id, "node_04200")?;
assert_eq!(results.len(), 1, "Should find exactly one node");
println!(" ✓ Name index working: found node_04200");
for i in [0, 100, 1000, 5000, 9999] {
let name = format!("node_{:05}", i);
let results = backend.query_nodes_by_name_pattern(snapshot_id, &name)?;
assert_eq!(
results.len(),
1,
"Should find exactly one node for {}",
name
);
}
println!(" ✓ Multiple name lookups working correctly");
println!("\n=== ALL TESTS PASSED ===");
Ok(())
}