#![cfg(all(feature = "v2_experimental", feature = "v2_dev_tdd"))]
use sqlitegraph::backend::native::{
GraphFile, NativeResult, node_store::NodeStore, v2::node_record_v2::NodeRecordV2,
};
use tempfile::tempdir;
#[test]
fn test_direct_rebuild_v2_index_capture() -> NativeResult<()> {
let temp_dir =
tempdir().map_err(|e| sqlitegraph::backend::native::NativeBackendError::Io(e))?;
let db_path = temp_dir.path().join("test.db");
let mut graph_file = GraphFile::create(&db_path)?;
let node_id_1 = 1i64;
let node_record_v2_1 = NodeRecordV2::new(
node_id_1,
"test".to_string(),
"test_node".to_string(),
serde_json::json!({}),
);
let buffer_1 = node_record_v2_1.serialize();
println!(
"DEBUG: Manually created V2 node record buffer: {:?}",
&buffer_1[..buffer_1.len().min(16)]
);
let node_data_offset = graph_file.header().node_data_offset as u64;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::Write;
graph_file.file.seek(SeekFrom::Start(node_data_offset))?;
graph_file.file.write_all(&buffer_1)?;
graph_file.file.flush()?;
let mut node_store = NodeStore::new(&mut graph_file);
println!("DEBUG: About to call rebuild_v2_index...");
let result = node_store.rebuild_v2_index(&mut graph_file)?;
println!("DEBUG: rebuild_v2_index completed, found {} nodes", result);
Ok(())
}