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 token limit saturation and exact comparison
Steven Enamakel47b98e9784ed
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rsindex c64453fa54..12c748d749 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rs@@ -225,11 +225,9 @@ impl OpenHumanBudgetGate {return None;}};- for hit in verdict- .hits- .iter()- // Every hit is worth a line: a warning, or the refusal about to be- // returned.+ for hit in verdict.hits.iter()+ // Every hit is worth a line: a warning, or the refusal about to be+ // returned.{log::warn!("[tinyagents][budget] budget `{}` for {} at ${:.4}/{:?} usd, {}/{:?} tokens (exceeded={})",diff --git a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate_tests.rsindex 174f937fea..d507c5610e 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate_tests.rs@@ -220,8 +220,12 @@ fn a_refusing_budget_refuses_the_agent_over_it() {assert!(refusal.starts_with("BUDGET_EXCEEDED:"), "{refusal}");assert!(refusal.contains("planner cap"), "{refusal}");assert!(- gate.check_budgets_against(&estimate_for("orchestrator"), &gate.live_budgets(), &tracker)- .is_none(),+ gate.check_budgets_against(+ &estimate_for("orchestrator"),+ &gate.live_budgets(),+ &tracker+ )+ .is_none(),"the cap matches only the planner");}diff --git a/crates/openhuman-core/src/platform/cost/budget_tests.rs b/crates/openhuman-core/src/platform/cost/budget_tests.rsindex 973f8b4771..9c2f29129f 100644--- a/crates/openhuman-core/src/platform/cost/budget_tests.rs+++ b/crates/openhuman-core/src/platform/cost/budget_tests.rs@@ -284,3 +284,35 @@ action = "refuse"assert!((b.warn_fraction - 0.8).abs() < f64::EPSILON);assert!(toml::from_str::<crate::config::CostConfig>("[[budgets]]\nmax_usdd = 1\n").is_err());}++#[test]+fn token_limits_compare_exactly_and_totals_saturate() {+ let scope = UsageScope::default();+ let mut huge = spend(10, "m", None, None, 0.0);+ huge.usage.input_tokens = u64::MAX;+ huge.usage.output_tokens = u64::MAX;+ let mut limit = policy(+ BudgetScope::Global,+ BudgetPeriod::Month,+ 1e9,+ BudgetAction::Refuse,+ );+ limit.max_usd = None;+ limit.max_tokens = Some(u64::MAX);+ // Two saturating records reach the limit instead of wrapping under it.+ let verdict = evaluate(+ &[limit.clone()],+ &[huge.clone(), huge],+ call("m", &scope),+ now(),+ );+ assert!(verdict.refusal().is_some(), "{verdict:?}");++ // 2^53 - 1 tokens against a 2^53 limit: equal as f64, not as integers.+ let mut near = spend(10, "m", None, None, 0.0);+ near.usage.input_tokens = (1u64 << 53) - 1;+ near.usage.output_tokens = 0;+ limit.max_tokens = Some(1u64 << 53);+ let verdict = evaluate(&[limit], &[near], call("m", &scope), now());+ assert!(verdict.refusal().is_none(), "{verdict:?}");+}