The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(cost): cover set-aside ledgers and bad utf-8 lines
Steven Enamakel67b647d1cc51
diff --git a/crates/openhuman-core/src/agent/artifacts/store_documents_tests.rs b/crates/openhuman-core/src/agent/artifacts/store_documents_tests.rsindex 8079edbf30..e51d5506c9 100644--- a/crates/openhuman-core/src/agent/artifacts/store_documents_tests.rs+++ b/crates/openhuman-core/src/agent/artifacts/store_documents_tests.rs@@ -90,6 +90,13 @@ fn the_legacy_files_are_imported_without_overwriting() {std::fs::create_dir_all(&bad).unwrap();std::fs::write(bad.join("meta.json"), "{nope").unwrap();std::fs::create_dir_all(dir.path().join("empty")).unwrap();+ // A copy under another folder name is not the record.+ let copy = dir.path().join("copy-of-a");+ std::fs::create_dir_all(©).unwrap();+ let mut stray = meta("a", 1, Some("t"));+ stray.title = "stray".into();+ std::fs::write(copy.join("meta.json"), serde_json::to_string(&stray).unwrap()).unwrap();+ std::fs::write(copy.join("args.json"), r#"{"x":5}"#).unwrap();let docs = docs_in(&MemoryStorage::new(), "local");// A record and arguments written before the import are not overwritten.diff --git a/crates/openhuman-core/src/platform/cost/tracker_documents_tests.rs b/crates/openhuman-core/src/platform/cost/tracker_documents_tests.rsindex 9ccdb49b38..bd5893ead1 100644--- a/crates/openhuman-core/src/platform/cost/tracker_documents_tests.rs+++ b/crates/openhuman-core/src/platform/cost/tracker_documents_tests.rs@@ -93,19 +93,31 @@ fn a_legacy_import_skips_ids_already_stored_or_repeated() {}#[test]-fn a_failed_rename_fails_the_import_and_a_retry_creates_nothing_twice() {+fn an_earlier_set_aside_ledger_is_kept_and_bad_utf8_lines_are_skipped() {let dir = tempfile::tempdir().unwrap();let path = dir.path().join("costs.jsonl");let rec = record("a/model", 0.5, 30);- std::fs::write(&path, format!("{}\n", serde_json::to_string(&rec).unwrap())).unwrap();- // A non-empty directory where the rename target goes blocks the rename.- let blocker = dir.path().join("costs.jsonl.migrated");- std::fs::create_dir_all(blocker.join("x")).unwrap();+ let mut raw = b"\xff\xfe not utf-8\n".to_vec();+ raw.extend_from_slice(serde_json::to_string(&rec).unwrap().as_bytes());+ raw.push(b'\n');+ std::fs::write(&path, raw).unwrap();+ let earlier = dir.path().join("costs.jsonl.migrated");+ std::fs::write(&earlier, "earlier").unwrap();+let docs = docs_in(&MemoryStorage::new(), "local");- assert!(docs.import_legacy(&path).is_err());- assert!(path.exists(), "the ledger stays for a retry");- std::fs::remove_dir_all(&blocker).unwrap();- assert_eq!(docs.import_legacy(&path).unwrap(), 0);- assert_eq!(docs.all().unwrap().len(), 1);+ assert_eq!(docs.import_legacy(&path).unwrap(), 1);assert!(!path.exists());+ assert_eq!(std::fs::read_to_string(&earlier).unwrap(), "earlier");+ assert!(dir.path().join("costs.jsonl.migrated.1").exists());+}++#[test]+fn a_ledger_another_core_already_set_aside_counts_as_done() {+ let dir = tempfile::tempdir().unwrap();+ let path = dir.path().join("costs.jsonl");+ assert!(set_aside(&path).is_ok());+ // An unreadable ledger (here a directory) fails the import instead.+ std::fs::create_dir_all(&path).unwrap();+ let docs = docs_in(&MemoryStorage::new(), "local");+ assert!(docs.import_legacy(&path).is_err());}