Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(storage): wire up snapshot import test module

Steven Enamakel95ceca45fe54
diff --git a/crates/openhuman-core/src/storage/import/snapshot.rs b/crates/openhuman-core/src/storage/import/snapshot.rs
index 6da02fcd83..a6f1c253c2 100644
--- a/crates/openhuman-core/src/storage/import/snapshot.rs
+++ b/crates/openhuman-core/src/storage/import/snapshot.rs
@@ -103,3 +103,7 @@ fn companion(path: &Path, suffix: &str) -> PathBuf {
name.push(suffix);
PathBuf::from(name)
}
+
+#[cfg(test)]
+#[path = "snapshot_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/storage/import/snapshot_tests.rs b/crates/openhuman-core/src/storage/import/snapshot_tests.rs
new file mode 100644
index 0000000000..3488c91f88
--- /dev/null
+++ b/crates/openhuman-core/src/storage/import/snapshot_tests.rs
@@ -0,0 +1,20 @@
+use super::*;
+
+#[test]
+fn snapshot_sees_uncheckpointed_wal_writes_and_leaves_source_intact() {
+ let src_dir = tempfile::tempdir().unwrap();
+ let path = src_dir.path().join("legacy.db");
+ let conn = rusqlite::Connection::open(&path).unwrap();
+ conn.pragma_update(None, "journal_mode", "WAL").unwrap();
+ conn.pragma_update(None, "wal_autocheckpoint", 0).unwrap();
+ conn.execute("CREATE TABLE t (v TEXT)", []).unwrap();
+ conn.execute("INSERT INTO t VALUES ('in-wal')", []).unwrap();
+
+ let snap = Snapshot::of(&path, "state/legacy.db").unwrap();
+ let copy = rusqlite::Connection::open(snap.db()).unwrap();
+ let v: String = copy.query_row("SELECT v FROM t", [], |r| r.get(0)).unwrap();
+ assert_eq!(v, "in-wal");
+ // The live source still answers and was not modified by the snapshot.
+ let n: i64 = conn.query_row("SELECT COUNT(*) FROM t", [], |r| r.get(0)).unwrap();
+ assert_eq!(n, 1);
+}