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(session_host): cover juice-off turn wiring end to end
Steven Enamakelaf9649bc1c8e
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_juice_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_juice_tests.rsindex 2be1cc2e93..52cc0ed8f1 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session_juice_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_juice_tests.rs@@ -226,3 +226,98 @@ async fn resumed_juice_snapshot_does_not_add_live_repl_declarations() {"an empty frozen transcript must not gain Juice declarations from the live catalog");}++/// `[components] juice = false` end to end through a turn's wiring: the+/// session builds its tool-output middleware with compaction and the summary+/// stage off, the tinyjuice module is never claimed, and a large compressible+/// tool result enters the transcript uncompressed.+#[tokio::test]+async fn juice_off_turn_loads_no_module_and_passes_tool_output_through() {+ use crate::agent::tinyagents::middleware::tool_output::ToolOutputMiddleware;+ use tinyagents_harness::context::{RunConfig, RunContext};+ use tinyagents_harness::middleware::{Middleware, ToolInvocationIdentity};++ crate::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()+ .expect("builtin definitions");+ let tmp = tempfile::tempdir().expect("tempdir");+ let mut config = crate::config::Config {+ workspace_dir: tmp.path().join("workspace"),+ action_dir: tmp.path().join("workspace"),+ config_path: tmp.path().join("config.toml"),+ modules: crate::config::schema::ModulesConfig {+ enabled: true,+ allow_download: false,+ ..Default::default()+ },+ ..Default::default()+ };+ std::fs::create_dir_all(&config.workspace_dir).expect("workspace");+ config.context.compaction_enabled = true;+ config.tokenjuice.router_enabled = true;+ assert!(config.components.set("juice", false));++ let mut host = crate::agent::OpenHumanSessionHost::from_config_for_agent(&config, "summarizer")+ .expect("summarizer session");+ host.ensure_runtime_session().expect("runtime session");+ let context_mw = host+ .runtime_state+ .lock()+ .expect("runtime state")+ .context_middleware+ .clone()+ .expect("context middleware");+ assert!(+ !context_mw.tokenjuice_compaction_enabled,+ "juice off must switch tool-output compaction off"+ );+ assert!(+ context_mw.payload_summarizer.is_none(),+ "juice off must drop the summary stage"+ );++ // Run the middleware exactly as the turn would, on a result that+ // compaction would otherwise rewrite (a large uniform JSON array).+ let rows: Vec<serde_json::Value> = (0..200)+ .map(|i| serde_json::json!({"id": i, "name": format!("row-{i}"), "status": "ok"}))+ .collect();+ let payload = serde_json::to_string(&rows).expect("payload");+ assert!(payload.len() >= config.tokenjuice.min_bytes_to_compress);+ let mw = ToolOutputMiddleware {+ budget_bytes: 1_000_000,+ payload_summarizer: context_mw.payload_summarizer.clone(),+ artifact_store: None,+ tokenjuice_compaction_enabled: context_mw.tokenjuice_compaction_enabled,+ tokenjuice_compression: context_mw.tokenjuice_compression,+ runtime_config: context_mw.runtime_config.clone(),+ tool_policies: Default::default(),+ artifact_reads: Default::default(),+ focus_by_call: Default::default(),+ summary_focus_tools: Default::default(),+ raw_fetches: Default::default(),+ file_reads: Default::default(),+ };+ let mut ctx = RunContext::new(+ RunConfig::new("juice-off-turn"),+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),+ );+ let mut result = tinytools::ToolResult::success(&payload);+ mw.after_tool(+ &mut ctx,+ &(),+ &ToolInvocationIdentity::new(+ tinyagents_harness::ids::CallId::new("juice-off-1"),+ "some_other_tool",+ ),+ &mut result,+ )+ .await+ .expect("after_tool");+ assert_eq!(result.output(), payload, "tool output must pass through");++ // The module was never asked for: the refusal is typed and nothing was+ // downloaded (downloads are off, so a claim would have ended in Failed).+ let err = crate::modules::ensure_loaded_within(&config, "tinyjuice", None)+ .await+ .unwrap_err();+ assert_eq!(err, crate::modules::LoadError::Disabled("juice"));+}diff --git a/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs b/crates/openhuman-core/src/config/schema/load_components_migration_tests.rsindex c4817cdddb..37769adcfa 100644--- a/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs+++ b/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs@@ -106,8 +106,16 @@ fn legacy_tokenjuice_router_off_maps_to_components_juice() {#[test]fn tokenjuice_router_on_or_absent_keeps_juice_on() {- assert!(migrated("[tokenjuice]\nrouter_enabled = true\n", None).components.juice);- assert!(migrated("[tokenjuice]\nccr_enabled = false\n", None).components.juice);+ assert!(+ migrated("[tokenjuice]\nrouter_enabled = true\n", None)+ .components+ .juice+ );+ assert!(+ migrated("[tokenjuice]\nccr_enabled = false\n", None)+ .components+ .juice+ );}#[test]diff --git a/crates/openhuman-core/src/inference/tokenjuice/savings.rs b/crates/openhuman-core/src/inference/tokenjuice/savings.rsindex 8ad3118f2d..594825ddd7 100644--- a/crates/openhuman-core/src/inference/tokenjuice/savings.rs+++ b/crates/openhuman-core/src/inference/tokenjuice/savings.rs@@ -68,7 +68,12 @@ fn request(original_tokens: u64,compacted_tokens: u64,) -> Option<RecordSavingsRequest> {- request_for(attribution_model(), compressor, original_tokens, compacted_tokens)+ request_for(+ attribution_model(),+ compressor,+ original_tokens,+ compacted_tokens,+ )}/// [`request`] for an explicit attribution `model`.diff --git a/crates/openhuman-core/src/inference/tokenjuice/savings_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/savings_tests.rsindex 133f2d67b9..e5cd1a8f0e 100644--- a/crates/openhuman-core/src/inference/tokenjuice/savings_tests.rs+++ b/crates/openhuman-core/src/inference/tokenjuice/savings_tests.rs@@ -37,8 +37,18 @@ fn host_pricing_over_module_math_reproduces_the_old_totals() {// (model, compressor, original, compacted)let events: [(&str, CompressorKind, u64, u64); 5] = [- ("claude-sonnet-4-6", CompressorKind::SmartCrusher, 2000, 1000),- ("claude-sonnet-4-6", CompressorKind::SmartCrusher, 10000, 2500),+ (+ "claude-sonnet-4-6",+ CompressorKind::SmartCrusher,+ 2000,+ 1000,+ ),+ (+ "claude-sonnet-4-6",+ CompressorKind::SmartCrusher,+ 10000,+ 2500,+ ),("claude-sonnet-4-6", CompressorKind::TextCrusher, 5000, 5000),("no-such-model-xyz", CompressorKind::TextCrusher, 4000, 1000),("claude-sonnet-4-6", CompressorKind::TextCrusher, 800, 900),@@ -69,7 +79,10 @@ fn host_pricing_over_module_math_reproduces_the_old_totals() {}// Old totals: 3 shrinking events (equal and expanded are ignored).- assert_eq!((total.0, total.1, total.2, total.3), (3, 16000, 4500, 11500));+ assert_eq!(+ (total.0, total.1, total.2, total.3),+ (3, 16000, 4500, 11500)+ );// (1000 + 7500) tokens priced at $3 / 1M; the unpriced model adds none.assert!((total.4 - 0.0255).abs() < 1e-12, "cost {}", total.4);@@ -81,5 +94,8 @@ fn host_pricing_over_module_math_reproduces_the_old_totals() {let smart = by_compressor[CompressorKind::SmartCrusher.as_str()];assert_eq!((smart.0, smart.1), (2, 8500));assert!((smart.2 - 0.0255).abs() < 1e-12);- assert_eq!(by_compressor[CompressorKind::TextCrusher.as_str()], (1, 3000, 0.0));+ assert_eq!(+ by_compressor[CompressorKind::TextCrusher.as_str()],+ (1, 3000, 0.0)+ );}