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 model switches and estimated cost sources
Steven Enamakel5b1a98124baa
diff --git a/crates/openhuman-core/src/platform/cost/report.rs b/crates/openhuman-core/src/platform/cost/report.rsindex 6a4e32d8ff..a70e0acf3e 100644--- a/crates/openhuman-core/src/platform/cost/report.rs+++ b/crates/openhuman-core/src/platform/cost/report.rs@@ -305,11 +305,7 @@ pub fn build_cache_report(let cached = usage.cached_input_tokens.min(usage.input_tokens);let thread = usage.scope.thread_id.clone();let repeat = thread.as_ref().is_some_and(|t| {- !caches_seen.insert((- t.clone(),- usage.model.clone(),- usage.scope.agent_id.clone(),- ))+ !caches_seen.insert((t.clone(), usage.model.clone(), usage.scope.agent_id.clone()))});let cold = repeat && cached == 0 && usage.input_tokens > 0;if cold {diff --git a/crates/openhuman-core/src/platform/cost/report_tests.rs b/crates/openhuman-core/src/platform/cost/report_tests.rsindex 8b3cec7d50..bb86e34909 100644--- a/crates/openhuman-core/src/platform/cost/report_tests.rs+++ b/crates/openhuman-core/src/platform/cost/report_tests.rs@@ -238,3 +238,50 @@ fn cache_report_prices_the_uncached_premium_for_known_models() {None => assert_eq!(report.uncached_premium_usd, 0.0),}}++#[test]+fn a_model_switch_in_a_thread_is_not_a_cold_call() {+ let (from, to) = window();+ let records = vec![+ record((2, 9), "model/a", Some("t9"), Some("x"), 1000, 0, 0.1, true),+ // First call on another model: its cache could not have been warm.+ record(+ (2, 10),+ "model/b",+ Some("t9"),+ Some("x"),+ 1000,+ 0,+ 0.1,+ true,+ ),+ // Same model again, still nothing cached: genuinely cold.+ record(+ (2, 11),+ "model/b",+ Some("t9"),+ Some("x"),+ 1000,+ 0,+ 0.1,+ true,+ ),+ ];+ let report = build_cache_report(&records, from, to, &ReportFilter::default());+ assert_eq!(report.cold_calls, 1);+ assert_eq!(+ report.calls.iter().map(|c| c.cold).collect::<Vec<_>>(),+ vec![false, false, true]+ );+}++#[test]+fn an_estimated_cost_lands_in_estimated_usd_not_charged() {+ use crate::inference::provider::BilledUsage;+ let estimated = BilledUsage::from_counts(100, 10).with_estimated_usd(0.25);+ let usage = crate::platform::cost::global::build_token_usage("model/a", &estimated).unwrap();+ assert_eq!(usage.cost_source, CostSource::Estimated);+ let charged = BilledUsage::from_counts(100, 10).with_charged_usd(0.25);+ let usage = crate::platform::cost::global::build_token_usage("model/a", &charged).unwrap();+ assert_eq!(usage.cost_source, CostSource::ProviderCharged);+}