Skip to content

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

fix(tokenjuice): correct test expectations for token budget handling

Steven Enamakel1d6ae34dea6d
diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rs
index c1b8e4c12c..1a29727996 100644
--- a/crates/openhuman-core/src/core/runtime/context.rs
+++ b/crates/openhuman-core/src/core/runtime/context.rs
@@ -574,6 +574,17 @@ impl CoreContext {
})
}
+ /// Test-only constructor with the given `[components]` switches.
+ #[cfg(test)]
+ pub(crate) fn for_test_with_components(
+ components: crate::core::runtime::ComponentSet,
+ ) -> Arc<CoreContext> {
+ let base = Self::for_test(crate::core::runtime::DomainSet::full(), None);
+ let mut ctx = Arc::try_unwrap(base).unwrap_or_else(|_| unreachable!("fresh Arc"));
+ ctx.components = components;
+ Arc::new(ctx)
+ }
+
/// Test-only constructor that carries an embedder-supplied config, so a
/// cross-module test can exercise the `load_config_with_timeout()` read
/// path (which prefers [`CoreContext::current_embedder_config`]) without a
diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/mod_tests.rs
index 29778e34f0..7bada5dc74 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/mod_tests.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/mod_tests.rs
@@ -319,3 +319,34 @@ async fn released_queries_keep_cached_originals_in_the_module_and_accept_artifac
assert!(markdown.contains("hello"));
assert!(!markdown.contains("secret_script"));
}
+
+// ── [components] juice ────────────────────────────────────────────────
+
+fn juice_off() -> crate::config::Config {
+ let mut config = crate::config::Config::default();
+ config.components.juice = false;
+ config
+}
+
+#[test]
+fn juice_off_drops_handles_summaries_and_companion_tools() {
+ let on = crate::config::Config::default();
+ assert!(enabled(&on));
+ assert!(repl_handle_active(&on));
+ assert!(!companion_tool_names("orchestrator", &on).is_empty());
+
+ let off = juice_off();
+ assert!(!enabled(&off));
+ assert!(!repl_handle_active(&off));
+ assert!(!summarizes_tool_output("orchestrator", &off));
+ assert!(companion_tool_names("orchestrator", &off).is_empty());
+}
+
+#[tokio::test]
+async fn juice_off_install_never_touches_the_module() {
+ install_from_config(&juice_off()).await.expect("no-op");
+ assert_eq!(
+ crate::modules::state_of("tinyjuice"),
+ crate::modules::types::ModuleState::Available
+ );
+}
diff --git a/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
index 59af0c51f4..0facfcd61a 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
@@ -170,3 +170,43 @@ fn compress_declares_explicit_as_an_enum_of_the_accepted_kinds() {
— note `plain_text`, not serde's `plainText`"
);
}
+
+// ── [components] juice = false ────────────────────────────────────────
+
+#[tokio::test]
+async fn every_tokenjuice_method_answers_component_disabled_when_juice_is_off() {
+ let mut set = crate::core::runtime::ComponentSet::all();
+ set.juice = false;
+ let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(set);
+ let handlers: [fn(Map<String, Value>) -> ControllerFuture; 8] = [
+ handle_detect,
+ handle_compress,
+ handle_cache_stats,
+ handle_retrieve,
+ handle_settings_get,
+ handle_settings_update,
+ handle_savings_stats,
+ handle_savings_reset,
+ ];
+ crate::core::runtime::context::CoreContext::scope(ctx, async {
+ for handler in handlers {
+ let err = handler(Map::new()).await.unwrap_err();
+ let decoded = crate::core::StructuredRpcError::decode(&err).expect("typed error");
+ assert_eq!(decoded.message, "COMPONENT_DISABLED:juice");
+ }
+ })
+ .await;
+}
+
+#[tokio::test]
+async fn tokenjuice_methods_are_not_gated_when_juice_is_on() {
+ let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(
+ crate::core::runtime::ComponentSet::all(),
+ );
+ crate::core::runtime::context::CoreContext::scope(ctx, async {
+ // Gate passes; the handler then fails on its own missing param.
+ let err = handle_detect(Map::new()).await.unwrap_err();
+ assert!(!err.contains("COMPONENT_DISABLED"), "{err}");
+ })
+ .await;
+}
diff --git a/crates/openhuman-core/src/modules/ops_components_tests.rs b/crates/openhuman-core/src/modules/ops_components_tests.rs
index fb457303ad..0cf4c0b191 100644
--- a/crates/openhuman-core/src/modules/ops_components_tests.rs
+++ b/crates/openhuman-core/src/modules/ops_components_tests.rs
@@ -70,3 +70,16 @@ async fn a_disabled_hosting_component_never_loads_the_tinyhosts_module() {
let status = statuses.iter().find(|s| s.id == "tinyhosts").unwrap();
assert_eq!(status.state, ModuleState::Disabled);
}
+
+#[tokio::test]
+async fn juice_off_refuses_tinyjuice_before_download_or_load() {
+ let config = config_without("juice");
+ let err = ensure_loaded_within(&config, "tinyjuice", None)
+ .await
+ .unwrap_err();
+ assert_eq!(err, LoadError::Disabled("juice"));
+ assert_eq!(state_of("tinyjuice"), ModuleState::Available);
+ let statuses = list(&config);
+ let status = statuses.iter().find(|s| s.id == "tinyjuice").unwrap();
+ assert_eq!(status.state, ModuleState::Disabled);
+}
diff --git a/crates/openhuman-core/src/tools/ops_tests_repl_tools_tests.rs b/crates/openhuman-core/src/tools/ops_tests_repl_tools_tests.rs
index 5db3e7bb21..c6d6235a19 100644
--- a/crates/openhuman-core/src/tools/ops_tests_repl_tools_tests.rs
+++ b/crates/openhuman-core/src/tools/ops_tests_repl_tools_tests.rs
@@ -83,3 +83,22 @@ fn repl_tools_belong_to_the_inference_family_and_are_read_only() {
assert!(tool.is_concurrency_safe(&serde_json::json!({})));
}
}
+
+#[test]
+fn juice_off_registers_no_juice_or_recovery_tools() {
+ let tmp = TempDir::new().unwrap();
+ let mut cfg = test_config(&tmp);
+ cfg.components.juice = false;
+ let names = tool_names(&registry_for(&tmp, &cfg));
+ for absent in tinyjuice_bus::tools::REPL_TOOLS
+ .iter()
+ .chain([
+ &tinyjuice_bus::tools::RETRIEVE,
+ &tinyjuice_bus::tools::LEGACY_RETRIEVE,
+ ])
+ {
+ assert!(!names.iter().any(|n| n == absent), "`{absent}` registered");
+ }
+ // Unchanged elsewhere: the rest of the registry is still there.
+ assert!(names.iter().any(|n| n == "current_time"));
+}