Skip to content

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

test(storage): add import tests for tinybox, tinyconnectors, tinyjuice and tinywallet

Steven Enamakel51197c9c1411
diff --git a/crates/openhuman-core/src/modules/storage_import_tinybox_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinybox_tests.rs
new file mode 100644
index 0000000000..53c46765b7
--- /dev/null
+++ b/crates/openhuman-core/src/modules/storage_import_tinybox_tests.rs
@@ -0,0 +1,120 @@
+use super::*;
+use sha2::Digest;
+use tinystoragedrivers::{MemoryStorage, Precondition, Scope, StorageBackend};
+
+fn scoped() -> ScopedStorage {
+ MemoryStorage::new()
+ .for_scope(&Scope::new("module:tinybox@local").unwrap())
+ .unwrap()
+}
+
+const INDEX: &str = r#"{"jails":{"j1":{"id":"j1","label":"build","dir":"/w/jails/j1","backend_at_create":"landlock","created_at_unix":10,"updated_at_unix":20,"notes":"keep"}}}"#;
+
+fn legacy_workspace() -> tempfile::TempDir {
+ let dir = tempfile::tempdir().unwrap();
+ let base = dir.path().join(BASE_DIR);
+ std::fs::create_dir_all(base.join("j1")).unwrap();
+ std::fs::write(base.join(INDEX_FILE), INDEX).unwrap();
+ dir
+}
+
+#[tokio::test]
+async fn the_jail_index_moves_into_one_document_with_the_same_shape() {
+ let legacy = legacy_workspace();
+ let scoped = scoped();
+ let outcome = import_into(&scoped, &legacy.path().join(BASE_DIR))
+ .await
+ .unwrap();
+ assert_eq!(outcome, Outcome::Imported { written: true });
+ let stored = scoped
+ .documents()
+ .get(JAIL_INDEX_COLLECTION, "jails")
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(stored.doc, serde_json::from_str::<Value>(INDEX).unwrap());
+}
+
+#[tokio::test]
+async fn the_legacy_index_is_left_untouched() {
+ let legacy = legacy_workspace();
+ let file = legacy.path().join(BASE_DIR).join(INDEX_FILE);
+ let before = sha2::Sha256::digest(std::fs::read(&file).unwrap());
+ import_into(&scoped(), &legacy.path().join(BASE_DIR))
+ .await
+ .unwrap();
+ assert_eq!(sha2::Sha256::digest(std::fs::read(&file).unwrap()), before);
+}
+
+#[tokio::test]
+async fn an_index_the_module_already_wrote_is_kept_and_a_rerun_is_a_noop() {
+ let legacy = legacy_workspace();
+ let base = legacy.path().join(BASE_DIR);
+ let scoped = scoped();
+ scoped
+ .documents()
+ .ensure_collection(&CollectionSpec::new(JAIL_INDEX_COLLECTION))
+ .await
+ .unwrap();
+ scoped
+ .documents()
+ .put(
+ JAIL_INDEX_COLLECTION,
+ "jails",
+ json!({"jails": {}}),
+ Precondition::Absent,
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ import_into(&scoped, &base).await.unwrap(),
+ Outcome::Imported { written: false }
+ );
+ let stored = scoped
+ .documents()
+ .get(JAIL_INDEX_COLLECTION, "jails")
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(stored.doc, json!({"jails": {}}));
+ assert_eq!(
+ import_into(&scoped, &base).await.unwrap(),
+ Outcome::AlreadyDone
+ );
+}
+
+#[tokio::test]
+async fn a_workspace_without_an_index_writes_no_marker() {
+ let empty = tempfile::tempdir().unwrap();
+ let scoped = scoped();
+ assert_eq!(
+ import_into(&scoped, &empty.path().join(BASE_DIR))
+ .await
+ .unwrap(),
+ Outcome::NoSource
+ );
+ let legacy = legacy_workspace();
+ assert_eq!(
+ import_into(&scoped, &legacy.path().join(BASE_DIR))
+ .await
+ .unwrap(),
+ Outcome::Imported { written: true }
+ );
+}
+
+#[tokio::test]
+async fn an_index_that_is_not_a_json_object_is_skipped_not_retried_forever() {
+ let dir = tempfile::tempdir().unwrap();
+ let base = dir.path().join(BASE_DIR);
+ std::fs::create_dir_all(&base).unwrap();
+ std::fs::write(base.join(INDEX_FILE), "[1, 2]").unwrap();
+ let scoped = scoped();
+ assert_eq!(
+ import_into(&scoped, &base).await.unwrap(),
+ Outcome::Imported { written: false }
+ );
+ assert_eq!(
+ import_into(&scoped, &base).await.unwrap(),
+ Outcome::AlreadyDone
+ );
+}
diff --git a/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs
new file mode 100644
index 0000000000..9c7b049596
--- /dev/null
+++ b/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs
@@ -0,0 +1,240 @@
+use super::*;
+use sha2::Digest;
+use tinystoragedrivers::{MemoryStorage, Precondition, Scope, StorageBackend};
+
+fn scoped() -> ScopedStorage {
+ MemoryStorage::new()
+ .for_scope(&Scope::new("module:tinyconnectors@local").unwrap())
+ .unwrap()
+}
+
+/// A state directory as the pre-storage module left it.
+fn legacy_state() -> tempfile::TempDir {
+ let dir = tempfile::tempdir().unwrap();
+ let prefs = dir.path().join(PREFS_DIR);
+ let triggers = dir.path().join(TRIGGERS_DIR);
+ std::fs::create_dir_all(&prefs).unwrap();
+ std::fs::create_dir_all(&triggers).unwrap();
+ std::fs::write(
+ prefs.join("gmail.json"),
+ r#"{"allow_write":false,"allow_delete":false}"#,
+ )
+ .unwrap();
+ std::fs::write(prefs.join("slack.json"), "true").unwrap();
+ std::fs::write(prefs.join("broken.json"), "{not json").unwrap();
+ std::fs::write(prefs.join("note.txt"), "ignored").unwrap();
+ std::fs::write(
+ triggers.join("2026-10-12.jsonl"),
+ concat!(
+ r#"{"receivedAtMs":1,"toolkit":"gmail","trigger":"NEW","metadataId":"a","metadataUuid":"u","payload":{}}"#,
+ "\n",
+ "not json at all\n",
+ "\n",
+ r#"{"receivedAtMs":2,"toolkit":"gmail","trigger":"NEW","metadataId":"b","metadataUuid":"v","payload":{"k":1}}"#,
+ "\n",
+ ),
+ )
+ .unwrap();
+ std::fs::write(
+ triggers.join("2026-10-13.jsonl"),
+ concat!(
+ r#"{"receivedAtMs":3,"toolkit":"slack","trigger":"MSG","metadataId":"c","metadataUuid":"w","payload":{}}"#,
+ "\n"
+ ),
+ )
+ .unwrap();
+ std::fs::write(triggers.join("README.jsonl"), "{}\n").unwrap();
+ dir
+}
+
+fn tree_digest(root: &Path) -> Vec<(String, Vec<u8>)> {
+ let mut out = Vec::new();
+ for dir in [PREFS_DIR, TRIGGERS_DIR] {
+ let mut names: Vec<_> = std::fs::read_dir(root.join(dir))
+ .unwrap()
+ .map(|entry| entry.unwrap().path())
+ .collect();
+ names.sort();
+ for path in names {
+ let bytes = std::fs::read(&path).unwrap();
+ out.push((
+ path.display().to_string(),
+ sha2::Sha256::digest(bytes).to_vec(),
+ ));
+ }
+ }
+ out
+}
+
+#[tokio::test]
+async fn preferences_and_the_trigger_archive_move_into_the_modules_storage() {
+ let legacy = legacy_state();
+ let scoped = scoped();
+ let outcome = import_into(&scoped, legacy.path()).await.unwrap();
+ // gmail + slack; the corrupt preference, the non-day archive name and the
+ // unparsable archive line are skipped.
+ assert_eq!(
+ outcome,
+ Outcome::Imported {
+ prefs: 2,
+ triggers: 3,
+ skipped: 3
+ }
+ );
+
+ let docs = scoped.documents();
+ let gmail = docs.get(PREFS_COLLECTION, "gmail").await.unwrap().unwrap();
+ assert_eq!(
+ gmail.doc,
+ json!({"value": {"allow_write": false, "allow_delete": false}})
+ );
+ let slack = docs.get(PREFS_COLLECTION, "slack").await.unwrap().unwrap();
+ assert_eq!(slack.doc, json!({"value": true}));
+ assert!(docs
+ .get(PREFS_COLLECTION, "broken")
+ .await
+ .unwrap()
+ .is_none());
+
+ let streams = scoped.streams();
+ let first = streams
+ .read_window("triggers/2026-10-12", 0, 10)
+ .await
+ .unwrap();
+ assert_eq!(first.len(), 2);
+ assert_eq!(first[0].value["metadataId"], "a");
+ assert_eq!(first[1].value["payload"], json!({"k": 1}));
+ let second = streams
+ .read_window("triggers/2026-10-13", 0, 10)
+ .await
+ .unwrap();
+ assert_eq!(second.len(), 1);
+ assert_eq!(second[0].value["toolkit"], "slack");
+ assert!(streams.len("triggers/README").await.unwrap() == 0);
+}
+
+#[tokio::test]
+async fn the_legacy_files_are_left_untouched() {
+ let legacy = legacy_state();
+ let before = tree_digest(legacy.path());
+ import_into(&scoped(), legacy.path()).await.unwrap();
+ assert_eq!(tree_digest(legacy.path()), before);
+}
+
+#[tokio::test]
+async fn a_second_run_is_a_noop_even_after_the_module_changed_the_data() {
+ let legacy = legacy_state();
+ let scoped = scoped();
+ import_into(&scoped, legacy.path()).await.unwrap();
+ // The user later deletes a preference; the untouched file must not bring
+ // it back.
+ scoped
+ .documents()
+ .delete(PREFS_COLLECTION, "gmail", Precondition::None)
+ .await
+ .unwrap();
+ assert_eq!(
+ import_into(&scoped, legacy.path()).await.unwrap(),
+ Outcome::AlreadyDone
+ );
+ assert!(scoped
+ .documents()
+ .get(PREFS_COLLECTION, "gmail")
+ .await
+ .unwrap()
+ .is_none());
+}
+
+#[tokio::test]
+async fn records_the_module_already_wrote_are_never_replaced_or_duplicated() {
+ let legacy = legacy_state();
+ let scoped = scoped();
+ scoped
+ .documents()
+ .put(
+ PREFS_COLLECTION,
+ "gmail",
+ json!({"value": {"allow_write": true}}),
+ Precondition::Absent,
+ )
+ .await
+ .unwrap();
+ scoped
+ .streams()
+ .append("triggers/2026-10-12", json!({"metadataId": "live"}))
+ .await
+ .unwrap();
+
+ let outcome = import_into(&scoped, legacy.path()).await.unwrap();
+ assert_eq!(
+ outcome,
+ Outcome::Imported {
+ prefs: 1,
+ triggers: 1,
+ skipped: 3
+ }
+ );
+ let gmail = scoped
+ .documents()
+ .get(PREFS_COLLECTION, "gmail")
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(gmail.doc, json!({"value": {"allow_write": true}}));
+ let day = scoped
+ .streams()
+ .read_window("triggers/2026-10-12", 0, 10)
+ .await
+ .unwrap();
+ assert_eq!(day.len(), 1);
+ assert_eq!(day[0].value["metadataId"], "live");
+}
+
+#[tokio::test]
+async fn a_state_directory_without_legacy_files_writes_no_marker() {
+ let empty = tempfile::tempdir().unwrap();
+ let scoped = scoped();
+ assert_eq!(
+ import_into(&scoped, empty.path()).await.unwrap(),
+ Outcome::NoSource
+ );
+ // Files that show up later (an older build still running) are still taken.
+ let legacy = legacy_state();
+ assert!(matches!(
+ import_into(&scoped, legacy.path()).await.unwrap(),
+ Outcome::Imported { .. }
+ ));
+}
+
+#[tokio::test]
+async fn an_unreadable_preference_file_is_retried_instead_of_marked_done() {
+ let legacy = legacy_state();
+ // Invalid UTF-8 cannot be read as text: an I/O failure, not corrupt JSON.
+ std::fs::write(
+ legacy.path().join(PREFS_DIR).join("bad.json"),
+ [0xff, 0xfe, 0xfd],
+ )
+ .unwrap();
+ let scoped = scoped();
+ assert!(import_into(&scoped, legacy.path()).await.is_err());
+ assert!(scoped
+ .documents()
+ .get(PREFS_COLLECTION, "gmail")
+ .await
+ .unwrap()
+ .is_none());
+
+ std::fs::remove_file(legacy.path().join(PREFS_DIR).join("bad.json")).unwrap();
+ assert!(matches!(
+ import_into(&scoped, legacy.path()).await.unwrap(),
+ Outcome::Imported { prefs: 2, .. }
+ ));
+}
+
+#[test]
+fn only_calendar_days_name_an_archive_stream() {
+ assert!(is_day("2026-10-13"));
+ for name in ["2026-1-13", "20261013", "2026-10-1x", "README", "2026-10-130", ""] {
+ assert!(!is_day(name), "{name}");
+ }
+}
diff --git a/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs
new file mode 100644
index 0000000000..5df28a0036
--- /dev/null
+++ b/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs
@@ -0,0 +1,197 @@
+use super::*;
+use std::time::Duration;
+use tinystoragedrivers::{MemoryStorage, Scope, StorageBackend};
+
+const FRESH: &str = "00112233445566778899aabbccddeeff";
+const OLD: &str = "ffeeddccbbaa99887766554433221100";
+const UPPER: &str = "ABCDEF0123456789ABCDEF0123456789";
+
+fn scoped() -> ScopedStorage {
+ MemoryStorage::new()
+ .for_scope(&Scope::new("module:tinyjuice@local").unwrap())
+ .unwrap()
+}
+
+fn set_age(path: &Path, age: Duration) {
+ let file = std::fs::File::options().write(true).open(path).unwrap();
+ file.set_modified(SystemTime::now() - age).unwrap();
+}
+
+/// A CCR directory as the pre-storage tier left it: a fresh original, one older
+/// than any sensible TTL, and files that are not CCR tokens.
+fn legacy_root() -> tempfile::TempDir {
+ let dir = tempfile::tempdir().unwrap();
+ std::fs::write(dir.path().join(FRESH), "fresh original\nline two").unwrap();
+ set_age(&dir.path().join(FRESH), Duration::from_secs(60));
+ std::fs::write(dir.path().join(OLD), "stale original").unwrap();
+ set_age(&dir.path().join(OLD), Duration::from_secs(7200));
+ std::fs::write(dir.path().join(UPPER), "upper-case token").unwrap();
+ std::fs::write(dir.path().join("notes.txt"), "not a token").unwrap();
+ std::fs::write(
+ dir.path().join("deadbeefdeadbeefdeadbeefdeadbeef"),
+ [0xff, 0xfe, 0x00],
+ )
+ .unwrap();
+ std::fs::create_dir(dir.path().join("0123456789abcdef0123456789abcdef")).unwrap();
+ dir
+}
+
+async fn read(scoped: &ScopedStorage, token: &str) -> Option<String> {
+ scoped
+ .blobs()
+ .get(&format!("{CCR_BLOB_PREFIX}{token}"))
+ .await
+ .unwrap()
+ .map(|blob| String::from_utf8(blob.bytes).unwrap())
+}
+
+#[tokio::test]
+async fn originals_within_their_ttl_move_into_the_modules_blobs() {
+ let legacy = legacy_root();
+ let scoped = scoped();
+ let outcome = import_into(
+ &scoped,
+ legacy.path(),
+ Some(Duration::from_secs(3600)),
+ SystemTime::now(),
+ )
+ .await
+ .unwrap();
+ // fresh and the upper-case token are written; the old one is expired; the
+ // note, the binary file and the directory are skipped.
+ assert_eq!(
+ outcome,
+ Outcome::Imported {
+ imported: 2,
+ expired: 1,
+ skipped: 3
+ }
+ );
+ assert_eq!(
+ read(&scoped, FRESH).await.as_deref(),
+ Some("fresh original\nline two")
+ );
+ assert!(read(&scoped, OLD).await.is_none());
+ // The module mints lowercase tokens, so that is the key it will look up.
+ assert_eq!(
+ read(&scoped, &UPPER.to_ascii_lowercase()).await.as_deref(),
+ Some("upper-case token")
+ );
+}
+
+#[tokio::test]
+async fn an_imported_original_expires_with_the_time_it_had_left() {
+ let legacy = legacy_root();
+ let scoped = scoped();
+ import_into(
+ &scoped,
+ legacy.path(),
+ Some(Duration::from_secs(3600)),
+ SystemTime::now(),
+ )
+ .await
+ .unwrap();
+ let meta = scoped
+ .blobs()
+ .head(&format!("{CCR_BLOB_PREFIX}{FRESH}"))
+ .await
+ .unwrap()
+ .expect("imported");
+ assert!(meta.expires_at.is_some(), "a TTL carries over as an expiry");
+}
+
+#[tokio::test]
+async fn without_a_ttl_every_readable_original_is_kept() {
+ let legacy = legacy_root();
+ let scoped = scoped();
+ let outcome = import_into(&scoped, legacy.path(), None, SystemTime::now())
+ .await
+ .unwrap();
+ assert_eq!(
+ outcome,
+ Outcome::Imported {
+ imported: 3,
+ expired: 0,
+ skipped: 3
+ }
+ );
+ assert_eq!(read(&scoped, OLD).await.as_deref(), Some("stale original"));
+}
+
+#[tokio::test]
+async fn the_legacy_files_are_left_in_place() {
+ let legacy = legacy_root();
+ import_into(&scoped(), legacy.path(), None, SystemTime::now())
+ .await
+ .unwrap();
+ assert_eq!(
+ std::fs::read_to_string(legacy.path().join(FRESH)).unwrap(),
+ "fresh original\nline two"
+ );
+ assert!(legacy.path().join(OLD).exists());
+}
+
+#[tokio::test]
+async fn a_second_run_is_a_noop_and_a_blob_already_stored_is_kept() {
+ let legacy = legacy_root();
+ let scoped = scoped();
+ scoped
+ .blobs()
+ .put(
+ &format!("{CCR_BLOB_PREFIX}{FRESH}"),
+ b"written by the module".to_vec(),
+ None,
+ )
+ .await
+ .unwrap();
+ let first = import_into(&scoped, legacy.path(), None, SystemTime::now())
+ .await
+ .unwrap();
+ assert_eq!(
+ first,
+ Outcome::Imported {
+ imported: 2,
+ expired: 0,
+ skipped: 4
+ }
+ );
+ assert_eq!(
+ read(&scoped, FRESH).await.as_deref(),
+ Some("written by the module")
+ );
+ assert_eq!(
+ import_into(&scoped, legacy.path(), None, SystemTime::now())
+ .await
+ .unwrap(),
+ Outcome::AlreadyDone
+ );
+}
+
+#[tokio::test]
+async fn a_missing_directory_writes_no_marker() {
+ let dir = tempfile::tempdir().unwrap();
+ let missing = dir.path().join("ccr");
+ let scoped = scoped();
+ assert_eq!(
+ import_into(&scoped, &missing, None, SystemTime::now())
+ .await
+ .unwrap(),
+ Outcome::NoSource
+ );
+ std::fs::create_dir(&missing).unwrap();
+ std::fs::write(missing.join(FRESH), "late").unwrap();
+ assert!(matches!(
+ import_into(&scoped, &missing, None, SystemTime::now())
+ .await
+ .unwrap(),
+ Outcome::Imported { imported: 1, .. }
+ ));
+}
+
+#[test]
+fn only_hex_tokens_of_the_hash_length_are_ccr_names() {
+ assert!(is_token(FRESH));
+ for name in ["", "abc", "zz112233445566778899aabbccddeeff", "../etc/passwd"] {
+ assert!(!is_token(name), "{name}");
+ }
+}
diff --git a/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs
new file mode 100644
index 0000000000..a34fe1a012
--- /dev/null
+++ b/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs
@@ -0,0 +1,148 @@
+use super::*;
+use sha2::Digest;
+use tinystoragedrivers::{MemoryStorage, Scope, StorageBackend};
+
+fn scoped() -> ScopedStorage {
+ MemoryStorage::new()
+ .for_scope(&Scope::new("module:tinywallet@local").unwrap())
+ .unwrap()
+}
+
+fn record(id: &str, status: &str) -> String {
+ format!(
+ r#"{{"id":"{id}","url":"https://api.example/x","asset":"0xusdc","amountAtomic":2500,"amountDisplay":"0.002500 USDC","recipient":"0xpayee","network":"eip155:8453","txSignature":null,"status":"{status}","timestamp":"2026-10-12T10:00:00Z"}}"#
+ )
+}
+
+/// A workspace as the pre-storage ledger left it: a payment that changed status
+/// appears twice under one id.
+fn legacy_workspace() -> tempfile::TempDir {
+ let dir = tempfile::tempdir().unwrap();
+ let file = dir.path().join(LEDGER_FILE);
+ std::fs::create_dir_all(file.parent().unwrap()).unwrap();
+ std::fs::write(
+ &file,
+ format!(
+ "{}\n{}\n\ngarbage line\n{}\n",
+ record("p1", "pending"),
+ record("p2", "settled"),
+ record("p1", "settled")
+ ),
+ )
+ .unwrap();
+ dir
+}
+
+fn digest(path: &Path) -> Vec<u8> {
+ sha2::Sha256::digest(std::fs::read(path).unwrap()).to_vec()
+}
+
+#[tokio::test]
+async fn the_payment_history_moves_into_the_modules_stream_in_order() {
+ let legacy = legacy_workspace();
+ let scoped = scoped();
+ let outcome = import_into(&scoped, legacy.path()).await.unwrap();
+ assert_eq!(
+ outcome,
+ Outcome::Imported {
+ payments: 3,
+ skipped: 1
+ }
+ );
+ let stored = scoped
+ .streams()
+ .read_window(PAYMENTS_STREAM, 0, 10)
+ .await
+ .unwrap();
+ let seen: Vec<_> = stored
+ .iter()
+ .map(|entry| {
+ (
+ entry.value["id"].as_str().unwrap().to_owned(),
+ entry.value["status"].as_str().unwrap().to_owned(),
+ )
+ })
+ .collect();
+ assert_eq!(
+ seen,
+ [("p1", "pending"), ("p2", "settled"), ("p1", "settled")]
+ .map(|(id, status)| (id.to_owned(), status.to_owned()))
+ );
+ // The amounts survive field for field, which is what the budget sums.
+ assert_eq!(stored[1].value["amountAtomic"], 2500);
+}
+
+#[tokio::test]
+async fn the_legacy_ledger_is_left_untouched() {
+ let legacy = legacy_workspace();
+ let file = legacy.path().join(LEDGER_FILE);
+ let before = digest(&file);
+ import_into(&scoped(), legacy.path()).await.unwrap();
+ assert_eq!(digest(&file), before);
+}
+
+#[tokio::test]
+async fn a_second_run_does_not_repeat_the_history() {
+ let legacy = legacy_workspace();
+ let scoped = scoped();
+ import_into(&scoped, legacy.path()).await.unwrap();
+ assert_eq!(
+ import_into(&scoped, legacy.path()).await.unwrap(),
+ Outcome::AlreadyDone
+ );
+ assert_eq!(scoped.streams().len(PAYMENTS_STREAM).await.unwrap(), 3);
+}
+
+#[tokio::test]
+async fn a_stream_the_module_already_wrote_is_not_preceded_by_old_records() {
+ let legacy = legacy_workspace();
+ let scoped = scoped();
+ scoped
+ .streams()
+ .append(PAYMENTS_STREAM, serde_json::from_str(&record("live", "settled")).unwrap())
+ .await
+ .unwrap();
+ assert_eq!(
+ import_into(&scoped, legacy.path()).await.unwrap(),
+ Outcome::Imported {
+ payments: 0,
+ skipped: 1
+ }
+ );
+ assert_eq!(scoped.streams().len(PAYMENTS_STREAM).await.unwrap(), 1);
+}
+
+#[tokio::test]
+async fn a_workspace_without_a_ledger_writes_no_marker() {
+ let empty = tempfile::tempdir().unwrap();
+ let scoped = scoped();
+ assert_eq!(
+ import_into(&scoped, empty.path()).await.unwrap(),
+ Outcome::NoSource
+ );
+ let legacy = legacy_workspace();
+ assert!(matches!(
+ import_into(&scoped, legacy.path()).await.unwrap(),
+ Outcome::Imported { .. }
+ ));
+}
+
+#[tokio::test]
+async fn an_unreadable_ledger_is_retried_instead_of_marked_done() {
+ let dir = tempfile::tempdir().unwrap();
+ let file = dir.path().join(LEDGER_FILE);
+ std::fs::create_dir_all(file.parent().unwrap()).unwrap();
+ std::fs::write(&file, [0xff, 0xfe]).unwrap();
+ let scoped = scoped();
+ assert!(import_into(&scoped, dir.path()).await.is_err());
+ assert_eq!(scoped.streams().len(PAYMENTS_STREAM).await.unwrap(), 0);
+
+ std::fs::write(&file, format!("{}\n", record("p1", "settled"))).unwrap();
+ assert_eq!(
+ import_into(&scoped, dir.path()).await.unwrap(),
+ Outcome::Imported {
+ payments: 1,
+ skipped: 0
+ }
+ );
+}