Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(cost): add coverage for global cost tracking and subagent tenant isolation

Steven Enamakel70467cb787c9
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
index de96a77e9c..d76555e51d 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
@@ -293,9 +293,11 @@ async fn unscoped_async_spawn_refuses_before_persisting_a_running_session() {
)
.await
.expect("tool dispatch reports a refusal as a tool outcome");
+ // An unscoped SaaS call fails closed on the store itself, so nothing was
+ // persisted either way.
let sessions = SubagentSessionStore::new(workspace.path().to_path_buf())
.load()
- .unwrap();
+ .unwrap_or_default();
assert!(
result.is_error,
"unscoped spawn must not report accepted: {}",
diff --git a/crates/openhuman-core/src/platform/cost/global_tests.rs b/crates/openhuman-core/src/platform/cost/global_tests.rs
index baa574abd0..b394277016 100644
--- a/crates/openhuman-core/src/platform/cost/global_tests.rs
+++ b/crates/openhuman-core/src/platform/cost/global_tests.rs
@@ -187,6 +187,7 @@ fn rebind_global_moves_recording_to_the_new_workspace() {
cfg.enabled = true;
rebind_global(cfg.clone(), before_login.path());
+ let first = try_global().expect("rebind installs a tracker");
record_provider_usage(MODEL_A, &make_usage(10, 5, 0.1));
rebind_global(cfg.clone(), after_login.path());
@@ -194,13 +195,9 @@ fn rebind_global_moves_recording_to_the_new_workspace() {
assert_eq!(bound.workspace_dir(), after_login.path());
record_provider_usage(MODEL_B, &make_usage(20, 10, 0.2));
- let ledger = |dir: &TempDir| {
- std::fs::read_to_string(dir.path().join("state").join("costs.jsonl")).unwrap_or_default()
- };
- assert!(ledger(&before_login).contains(MODEL_A));
- assert!(!ledger(&before_login).contains(MODEL_B));
- assert!(ledger(&after_login).contains(MODEL_B));
- assert!(!ledger(&after_login).contains(MODEL_A));
+ // Each workspace keeps its own ledger.
+ assert_eq!(records_for_model(&first, MODEL_A).len(), 1);
+ assert!(records_for_model(&first, MODEL_B).is_empty());
assert_eq!(records_for_model(&bound, MODEL_B).len(), 1);
assert!(records_for_model(&bound, MODEL_A).is_empty());
diff --git a/crates/openhuman-core/src/platform/cost/tracker_tests.rs b/crates/openhuman-core/src/platform/cost/tracker_tests.rs
index cbf31d306d..2b842ed9e7 100644
--- a/crates/openhuman-core/src/platform/cost/tracker_tests.rs
+++ b/crates/openhuman-core/src/platform/cost/tracker_tests.rs
@@ -357,13 +357,16 @@ fn get_dashboard_budget_status_warning_and_exceeded() {
monthly_limit_usd: 100.0,
..Default::default()
};
- let tracker = CostTracker::new(config.clone(), tmp.path()).unwrap();
+ let tracker = CostTracker::new(config, tmp.path()).unwrap();
let warn_dash = tracker.get_dashboard("USD", 0.8, 0.95).unwrap();
assert_eq!(warn_dash.budget_status, BudgetStatus::Warning);
- write_raw_record(tmp.path(), &dated_record("s1", MANAGED_MODEL, 15.0, today));
- let tracker2 = CostTracker::new(config, tmp.path()).unwrap();
- let alert_dash = tracker2.get_dashboard("USD", 0.8, 0.95).unwrap();
+ // The legacy ledger is imported once, so the next spend goes through the
+ // tracker like any other.
+ tracker
+ .record_usage_unconditional(dated_record("s1", MANAGED_MODEL, 15.0, today).usage)
+ .unwrap();
+ let alert_dash = tracker.get_dashboard("USD", 0.8, 0.95).unwrap();
assert_eq!(alert_dash.budget_status, BudgetStatus::Exceeded);
assert!((alert_dash.budget_utilization - 1.0).abs() < f64::EPSILON);
}