Skip to content

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

test: tighten scratch dir and budget month assertions

Steven Enamakel6223afae849a
diff --git a/crates/openhuman-core/src/security/policy/enforcement_scratch_dir_tests_tests.rs b/crates/openhuman-core/src/security/policy/enforcement_scratch_dir_tests_tests.rs
index e035b52399..f9298a4b2f 100644
--- a/crates/openhuman-core/src/security/policy/enforcement_scratch_dir_tests_tests.rs
+++ b/crates/openhuman-core/src/security/policy/enforcement_scratch_dir_tests_tests.rs
@@ -52,11 +52,10 @@ fn saas_policy_skips_the_shared_projects_and_scratch_grants() {
"/tmp/openhuman must not be granted in SaaS"
);
+ let scratch_available = ensure_openhuman_scratch_dir().is_some();
let single = roots(false);
assert!(single.contains(&projects));
- // The scratch dir is only granted when it can be created safely (not a
- // symlink, hardenable permissions); that is host state, not policy.
- if ensure_openhuman_scratch_dir().is_some() {
- assert!(single.contains(&scratch));
- }
+ // Granted exactly when the dir can be created safely (not a symlink,
+ // hardenable permissions): an unsafe path must not be granted.
+ assert_eq!(single.contains(&scratch), scratch_available);
}
diff --git a/tests/cost_report_e2e.rs b/tests/cost_report_e2e.rs
index 92422e343b..eae53aba51 100644
--- a/tests/cost_report_e2e.rs
+++ b/tests/cost_report_e2e.rs
@@ -8,7 +8,7 @@
use std::sync::Arc;
-use chrono::{Duration, Utc};
+use chrono::{Datelike, Duration, Utc};
use openhuman_core::agent::tinyagents::host::OpenHumanBudgetGate;
use openhuman_core::config::Config;
use openhuman_core::core::invoke::{default_state, invoke_method};
@@ -61,12 +61,20 @@ async fn cost_reports_group_the_ledger_and_a_refuse_budget_stops_the_call() {
// Seed the ledger, oldest first.
// Milliseconds apart, so the ledger stays inside the current budget month
// even at a month boundary.
+ let month_start = Utc::now()
+ .date_naive()
+ .with_day(1)
+ .expect("first of the month")
+ .and_hms_opt(0, 0, 0)
+ .expect("midnight")
+ .and_utc();
let start = Utc::now() - Duration::milliseconds(CALLS.len() as i64 + 1);
for (i, (model, thread, input, cached, cost_usd)) in CALLS.iter().enumerate() {
let mut usage = TokenUsage::new(*model, *input, 10, 0.0, 0.0);
usage.cached_input_tokens = *cached;
usage.cost_usd = *cost_usd;
- usage.timestamp = start + Duration::milliseconds(i as i64);
+ // Never before the budget month's start (UTC midnight on the 1st).
+ usage.timestamp = (start + Duration::milliseconds(i as i64)).max(month_start);
usage.scope.thread_id = Some((*thread).to_string());
usage.scope.agent_id = Some("orchestrator".to_string());
tracker.record_usage_unconditional(usage).expect("record");