Skip to content

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

test(cost): cover cache report attribution and filter rejection

Steven Enamakel82d52c6f41a3
diff --git a/crates/openhuman-core/src/platform/cost/report_tests.rs b/crates/openhuman-core/src/platform/cost/report_tests.rs
index 7648d72d29..0213d9bb93 100644
--- a/crates/openhuman-core/src/platform/cost/report_tests.rs
+++ b/crates/openhuman-core/src/platform/cost/report_tests.rs
@@ -289,7 +289,16 @@ fn an_estimated_cost_lands_in_estimated_usd_not_charged() {
#[test]
fn embedding_batches_stay_out_of_the_cache_report() {
let (from, to) = window();
- let mut embedding = record((2, 9), "voyage/voyage-3", Some("t1"), None, 5000, 0, 0.0, false);
+ let mut embedding = record(
+ (2, 9),
+ "voyage/voyage-3",
+ Some("t1"),
+ None,
+ 5000,
+ 0,
+ 0.0,
+ false,
+ );
embedding.usage.scope.origin = Some(EMBEDDING_ORIGIN.into());
let mut records = sample();
records.push(embedding);
@@ -303,7 +312,16 @@ fn embedding_batches_stay_out_of_the_cache_report() {
fn a_provider_switch_in_a_thread_is_not_a_cold_call() {
let (from, to) = window();
let first = record((2, 9), "model/a", Some("t9"), Some("x"), 1000, 0, 0.1, true);
- let mut second = record((2, 10), "model/a", Some("t9"), Some("x"), 1000, 0, 0.1, true);
+ let mut second = record(
+ (2, 10),
+ "model/a",
+ Some("t9"),
+ Some("x"),
+ 1000,
+ 0,
+ 0.1,
+ true,
+ );
second.usage.scope.provider = Some("openrouter".into());
let report = build_cache_report(&[first, second], from, to, &ReportFilter::default());
assert_eq!(report.cold_calls, 0, "{:?}", report.calls);
diff --git a/tests/raw_coverage/billing_cost_e2e.rs b/tests/raw_coverage/billing_cost_e2e.rs
index 7e340395fd..89d5770257 100644
--- a/tests/raw_coverage/billing_cost_e2e.rs
+++ b/tests/raw_coverage/billing_cost_e2e.rs
@@ -670,6 +670,26 @@ alert_threshold = 0.9
Some(3),
"one cache row per seeded call: {cache}"
);
+ // The seeded records predate attribution: no thread, so no call can be a
+ // repeat, none is cold, and nothing was read from the cache.
+ assert_eq!(cache.get("cold_calls").and_then(Value::as_u64), Some(0), "{cache}");
+ assert_eq!(cache.get("cache_hit_ratio").and_then(Value::as_f64), Some(0.0), "{cache}");
+ assert_eq!(cache.get("cached_input_tokens").and_then(Value::as_u64), Some(0), "{cache}");
+ assert!(
+ cache
+ .get("uncached_premium_usd")
+ .and_then(Value::as_f64)
+ .is_some_and(|p| p >= 0.0),
+ "{cache}"
+ );
+ let misspelt = harness
+ .call(
+ 59,
+ "openhuman.cost_cache_report",
+ json!({ "filter": { "threadId": "t1" } }),
+ )
+ .await;
+ assert_error(&misspelt, "cost_cache_report with a misspelt filter key");
// The wire spelling is `groupBy`; anything the schema does not declare is
// refused rather than silently ignored.