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(tinyagents): add budget gate host tests
Steven Enamakel3eaa76775bc6
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 1a5b22f0be..174f937fea 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@@ -215,12 +215,12 @@ fn a_refusing_budget_refuses_the_agent_over_it() {let (_tmp, tracker) = ledger_with(2.0, "planner");let gate = budgeted_gate(crate::config::BudgetAction::Refuse);let refusal = gate- .check_budgets_against(&estimate_for("planner"), &tracker)+ .check_budgets_against(&estimate_for("planner"), &gate.live_budgets(), &tracker).expect("planner is over its cap");assert!(refusal.starts_with("BUDGET_EXCEEDED:"), "{refusal}");assert!(refusal.contains("planner cap"), "{refusal}");assert!(- gate.check_budgets_against(&estimate_for("orchestrator"), &tracker)+ gate.check_budgets_against(&estimate_for("orchestrator"), &gate.live_budgets(), &tracker).is_none(),"the cap matches only the planner");@@ -231,7 +231,7 @@ fn a_warning_budget_never_refuses() {let (_tmp, tracker) = ledger_with(2.0, "planner");let gate = budgeted_gate(crate::config::BudgetAction::Warn);assert!(gate- .check_budgets_against(&estimate_for("planner"), &tracker)+ .check_budgets_against(&estimate_for("planner"), &gate.live_budgets(), &tracker).is_none());}@@ -241,3 +241,63 @@ async fn without_budgets_acquire_is_unchanged() {assert!(gate.check_budgets(&estimate_for("planner")).is_none());assert!(gate.acquire(&estimate_for("planner")).await.is_ok());}++#[test]+fn budgets_are_re_read_from_the_session_config_file() {+ // Built with no budgets; the file on disk now holds a refusing one.+ let tmp = tempfile::tempdir().unwrap();+ let config_path = tmp.path().join("config.toml");+ std::fs::write(+ &config_path,+ r#"+[[cost.budgets]]+name = "live cap"+scope = "agent"+match = "planner"+max_usd = 1.0+action = "refuse"+"#,+ )+ .unwrap();+ let config = Config {+ config_path,+ ..Config::default()+ };+ let gate = OpenHumanBudgetGate::new(Arc::new(config));+ let policies = gate.live_budgets();+ assert_eq!(policies.len(), 1);+ let (_ledger, tracker) = ledger_with(2.0, "planner");+ let refusal = gate+ .check_budgets_against(&estimate_for("planner"), &policies, &tracker)+ .expect("the live budget refuses");+ assert!(refusal.contains("live cap"), "{refusal}");+}++#[test]+fn a_missing_config_file_keeps_the_session_budgets() {+ let gate = budgeted_gate(crate::config::BudgetAction::Refuse);+ assert_eq!(gate.live_budgets().len(), 1);+}++#[test]+fn a_call_is_checked_against_its_own_model() {+ let (_tmp, tracker) = ledger_with(2.0, "planner");+ let mut config = Config::default();+ config.cost.budgets = vec![crate::config::BudgetPolicy {+ name: Some("model cap".into()),+ scope: crate::config::BudgetScope::Model,+ matches: Some("m".into()),+ period: crate::config::BudgetPeriod::Month,+ max_usd: Some(1.0),+ max_tokens: None,+ warn_fraction: 0.8,+ action: crate::config::BudgetAction::Refuse,+ }];+ let gate = OpenHumanBudgetGate::new(Arc::new(config));+ // Another call left a different model in the shared attribution.+ *gate.last_model.write() = "other".into();+ let policies = gate.live_budgets();+ assert!(gate+ .check_budgets_against(&estimate_for("planner"), &policies, &tracker)+ .is_some());+}