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(inference): add test module and update global cost tests
Steven Enamakel77824d7c63a7
diff --git a/crates/openhuman-core/src/inference/ops.rs b/crates/openhuman-core/src/inference/ops.rsindex d40811d6b6..3ea548af4d 100644--- a/crates/openhuman-core/src/inference/ops.rs+++ b/crates/openhuman-core/src/inference/ops.rs@@ -19,3 +19,7 @@ pub use status::{inference_diagnostics, inference_prompt, inference_status, inference_summarize,inference_test_provider_model, inference_vision_prompt,};++#[cfg(test)]+#[path = "ops_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/inference/ops/status.rs b/crates/openhuman-core/src/inference/ops/status.rsindex 54bc2913c1..10b692bdf2 100644--- a/crates/openhuman-core/src/inference/ops/status.rs+++ b/crates/openhuman-core/src/inference/ops/status.rs@@ -188,6 +188,3 @@ pub async fn inference_diagnostics(config: &Config) -> Result<Outcome<Value>, Stresult}-#[cfg(test)]-#[path = "../ops_tests.rs"]-mod tests;diff --git a/crates/openhuman-core/src/platform/cost/global_tests.rs b/crates/openhuman-core/src/platform/cost/global_tests.rsindex 96123d9091..d98b732007 100644--- a/crates/openhuman-core/src/platform/cost/global_tests.rs+++ b/crates/openhuman-core/src/platform/cost/global_tests.rs@@ -102,6 +102,85 @@ fn record_provider_usage_persists_through_the_global_tracker() {assert!((usage.cost_usd - 0.5).abs() < f64::EPSILON);}+#[test]+fn native_usage_round_trip_preserves_submicro_usd_and_charge_state_in_cost_rows() {+ let _lock = tracker_test_lock();+ let tracker = global_tracker();+ const REPORTED_MODEL: &str = "test-model/submicro-reported";+ const FREE_MODEL: &str = "test-model/submicro-free";+ const UNKNOWN_MODEL: &str = "test-model/submicro-unknown";+ const ESTIMATED_MODEL: &str = "test-model/submicro-estimated";++ let billed = BilledUsage::from_counts(4, 2).with_charged_usd(0.00000042);+ let response = tinyinference_llm::model::response_to_model_response(+ &tinyinference_llm::model::ChatResponse {+ usage: Some(billed),+ ..Default::default()+ },+ &tinyinference_llm::model::ModelRequest::default(),+ );+ let recovered = tinyinference_llm::usage::usage_info_from_response(&response)+ .expect("provider usage survives response conversion");+ assert_eq!(recovered.charged_amount_usd.to_bits(), billed.charged_amount_usd.to_bits());+ assert!(recovered.charge_reported);+ assert!(!recovered.cost_is_estimate);+ record_provider_usage(&DispatchCtx::ambient(), REPORTED_MODEL, &recovered);++ let free = tinyinference_llm::usage::usage_info_from_response(+ &tinyinference_llm::model::response_to_model_response(+ &tinyinference_llm::model::ChatResponse {+ usage: Some(BilledUsage::from_counts(4, 2).with_charged_usd(0.0)),+ ..Default::default()+ },+ &tinyinference_llm::model::ModelRequest::default(),+ ),+ )+ .expect("reported free usage survives conversion");+ assert_eq!(free.charged_amount_usd, 0.0);+ assert!(free.charge_reported);+ record_provider_usage(&DispatchCtx::ambient(), FREE_MODEL, &free);++ let unknown = tinyinference_llm::usage::usage_info_from_response(+ &tinyinference_llm::model::response_to_model_response(+ &tinyinference_llm::model::ChatResponse {+ usage: Some(BilledUsage::from_counts(4, 2)),+ ..Default::default()+ },+ &tinyinference_llm::model::ModelRequest::default(),+ ),+ )+ .expect("token usage survives conversion");+ assert!(!unknown.charge_reported);+ assert!(!unknown.cost_is_estimate);+ record_provider_usage(&DispatchCtx::ambient(), UNKNOWN_MODEL, &unknown);++ record_provider_usage(+ &DispatchCtx::ambient(),+ ESTIMATED_MODEL,+ &BilledUsage::from_counts(4, 2).with_estimated_usd(0.00000037),+ );++ let row = |model: &str| {+ records_for_model(&tracker, model)+ .into_iter()+ .next()+ .expect("cost row persisted")+ .usage+ };+ let reported_row = row(REPORTED_MODEL);+ assert_eq!(reported_row.cost_usd.to_bits(), 0.00000042_f64.to_bits());+ assert_eq!(reported_row.cost_source, CostSource::ProviderCharged);+ let free_row = row(FREE_MODEL);+ assert_eq!(free_row.cost_usd, 0.0);+ assert_eq!(free_row.cost_source, CostSource::ProviderCharged);+ let unknown_row = row(UNKNOWN_MODEL);+ assert_eq!(unknown_row.cost_usd, 0.0);+ assert_eq!(unknown_row.cost_source, CostSource::Unknown);+ let estimated_row = row(ESTIMATED_MODEL);+ assert_eq!(estimated_row.cost_usd.to_bits(), 0.00000037_f64.to_bits());+ assert_eq!(estimated_row.cost_source, CostSource::Estimated);+}+#[test]fn record_provider_usage_skips_all_zero_payload() {// Serialised against every other test that touches the process-global