Skip to content

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

test(refactor): move env overlay context tests to dedicated file

Steven Enamakelf0e4aefc4889
diff --git a/crates/openhuman-core/src/config/schema/load_env_overlay_context_tests.rs b/crates/openhuman-core/src/config/schema/load_env_overlay_context_tests.rs
new file mode 100644
index 0000000000..046b8a5466
--- /dev/null
+++ b/crates/openhuman-core/src/config/schema/load_env_overlay_context_tests.rs
@@ -0,0 +1,83 @@
+use super::*;
+
+#[test]
+fn env_overlay_context_tool_result_budget_env_suppresses_legacy_migration() {
+ // If the env var is *present*, the `agent.tool_result_budget_bytes`
+ // migration must NOT run — even when the explicit env value equals
+ // the default. This protects users who explicitly set the env to
+ // the default.
+ let default_budget = crate::agent::context::DEFAULT_TOOL_RESULT_BUDGET_BYTES;
+ let mut cfg = Config::default();
+ cfg.context.tool_result_budget_bytes = default_budget;
+ cfg.agent.tool_result_budget_bytes = 999_999;
+
+ cfg.apply_env_overlay_with(&HashMapEnv::new().with(
+ "OPENHUMAN_CONTEXT_TOOL_RESULT_BUDGET_BYTES",
+ &default_budget.to_string(),
+ ));
+ assert_eq!(
+ cfg.context.tool_result_budget_bytes, default_budget,
+ "env presence must suppress the legacy agent→context copy"
+ );
+}
+
+#[test]
+fn env_overlay_compaction_default_on_and_switch() {
+ // Default is on: large results become a stats line, a head and a handle
+ // the REPL tools query.
+ assert!(Config::default().context.compaction_enabled);
+ assert!(Config::default().tokenjuice.router_enabled);
+ assert!(Config::default().tokenjuice.repl_handle_enabled);
+
+ // `OPENHUMAN_COMPACTION=0` opts out; `=1` keeps it on.
+ let mut cfg = Config::default();
+ cfg.apply_env_overlay_with(&HashMapEnv::new().with("OPENHUMAN_COMPACTION", "0"));
+ assert!(!cfg.context.compaction_enabled);
+ assert!(!crate::inference::tokenjuice::repl_handle_active(&cfg));
+ let mut cfg = Config::default();
+ cfg.apply_env_overlay_with(&HashMapEnv::new().with("OPENHUMAN_COMPACTION", "1"));
+ assert!(cfg.context.compaction_enabled);
+
+ // Truthy re-enables; the namespaced alias works too.
+ let mut cfg = Config::default();
+ cfg.context.compaction_enabled = false;
+ cfg.apply_env_overlay_with(
+ &HashMapEnv::new().with("OPENHUMAN_CONTEXT_COMPACTION_ENABLED", "on"),
+ );
+ assert!(cfg.context.compaction_enabled);
+
+ // Garbage is ignored (leaves the prior value untouched).
+ let mut cfg = Config::default();
+ cfg.context.compaction_enabled = true;
+ cfg.apply_env_overlay_with(&HashMapEnv::new().with("OPENHUMAN_COMPACTION", "maybe"));
+ assert!(cfg.context.compaction_enabled);
+}
+
+#[test]
+fn env_overlay_context_tool_result_budget_legacy_migration_when_env_absent() {
+ // Env absent, context at default, agent customised → agent value copies forward.
+ let default_budget = crate::agent::context::DEFAULT_TOOL_RESULT_BUDGET_BYTES;
+ let mut cfg = Config::default();
+ cfg.context.tool_result_budget_bytes = default_budget;
+ cfg.agent.tool_result_budget_bytes = 777_777;
+
+ cfg.apply_env_overlay_with(&HashMapEnv::new());
+ assert_eq!(cfg.context.tool_result_budget_bytes, 777_777);
+}
+
+#[test]
+fn env_overlay_context_tool_result_budget_env_wins_over_legacy_migration() {
+ // Env present with a non-default value, and agent also customised.
+ // The env value must apply; the legacy agent→context copy must NOT
+ // overwrite it.
+ let mut cfg = Config::default();
+ cfg.agent.tool_result_budget_bytes = 111_111;
+
+ cfg.apply_env_overlay_with(
+ &HashMapEnv::new().with("OPENHUMAN_CONTEXT_TOOL_RESULT_BUDGET_BYTES", "222222"),
+ );
+ assert_eq!(
+ cfg.context.tool_result_budget_bytes, 222_222,
+ "env value wins; legacy migration suppressed"
+ );
+}
diff --git a/crates/openhuman-core/src/config/schema/load_env_overlay_tests.rs b/crates/openhuman-core/src/config/schema/load_env_overlay_tests.rs
index 0208ede8ff..6752330e10 100644
--- a/crates/openhuman-core/src/config/schema/load_env_overlay_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load_env_overlay_tests.rs
@@ -552,88 +552,6 @@ fn env_overlay_dictation_activation_mode_only_toggle_or_push() {
);
}
-#[test]
-fn env_overlay_context_tool_result_budget_env_suppresses_legacy_migration() {
- // If the env var is *present*, the `agent.tool_result_budget_bytes`
- // migration must NOT run — even when the explicit env value equals
- // the default. This protects users who explicitly set the env to
- // the default.
- let default_budget = crate::agent::context::DEFAULT_TOOL_RESULT_BUDGET_BYTES;
- let mut cfg = Config::default();
- cfg.context.tool_result_budget_bytes = default_budget;
- cfg.agent.tool_result_budget_bytes = 999_999;
-
- cfg.apply_env_overlay_with(&HashMapEnv::new().with(
- "OPENHUMAN_CONTEXT_TOOL_RESULT_BUDGET_BYTES",
- &default_budget.to_string(),
- ));
- assert_eq!(
- cfg.context.tool_result_budget_bytes, default_budget,
- "env presence must suppress the legacy agent→context copy"
- );
-}
-
-#[test]
-fn env_overlay_compaction_default_on_and_switch() {
- // Default is on: large results become a stats line, a head and a handle
- // the REPL tools query.
- assert!(Config::default().context.compaction_enabled);
- assert!(Config::default().tokenjuice.router_enabled);
- assert!(Config::default().tokenjuice.repl_handle_enabled);
-
- // `OPENHUMAN_COMPACTION=0` opts out; `=1` keeps it on.
- let mut cfg = Config::default();
- cfg.apply_env_overlay_with(&HashMapEnv::new().with("OPENHUMAN_COMPACTION", "0"));
- assert!(!cfg.context.compaction_enabled);
- assert!(!crate::inference::tokenjuice::repl_handle_active(&cfg));
- let mut cfg = Config::default();
- cfg.apply_env_overlay_with(&HashMapEnv::new().with("OPENHUMAN_COMPACTION", "1"));
- assert!(cfg.context.compaction_enabled);
-
- // Truthy re-enables; the namespaced alias works too.
- let mut cfg = Config::default();
- cfg.context.compaction_enabled = false;
- cfg.apply_env_overlay_with(
- &HashMapEnv::new().with("OPENHUMAN_CONTEXT_COMPACTION_ENABLED", "on"),
- );
- assert!(cfg.context.compaction_enabled);
-
- // Garbage is ignored (leaves the prior value untouched).
- let mut cfg = Config::default();
- cfg.context.compaction_enabled = true;
- cfg.apply_env_overlay_with(&HashMapEnv::new().with("OPENHUMAN_COMPACTION", "maybe"));
- assert!(cfg.context.compaction_enabled);
-}
-
-#[test]
-fn env_overlay_context_tool_result_budget_legacy_migration_when_env_absent() {
- // Env absent, context at default, agent customised → agent value copies forward.
- let default_budget = crate::agent::context::DEFAULT_TOOL_RESULT_BUDGET_BYTES;
- let mut cfg = Config::default();
- cfg.context.tool_result_budget_bytes = default_budget;
- cfg.agent.tool_result_budget_bytes = 777_777;
-
- cfg.apply_env_overlay_with(&HashMapEnv::new());
- assert_eq!(cfg.context.tool_result_budget_bytes, 777_777);
-}
-
-#[test]
-fn env_overlay_context_tool_result_budget_env_wins_over_legacy_migration() {
- // Env present with a non-default value, and agent also customised.
- // The env value must apply; the legacy agent→context copy must NOT
- // overwrite it.
- let mut cfg = Config::default();
- cfg.agent.tool_result_budget_bytes = 111_111;
-
- cfg.apply_env_overlay_with(
- &HashMapEnv::new().with("OPENHUMAN_CONTEXT_TOOL_RESULT_BUDGET_BYTES", "222222"),
- );
- assert_eq!(
- cfg.context.tool_result_budget_bytes, 222_222,
- "env value wins; legacy migration suppressed"
- );
-}
-
#[test]
fn env_overlay_auto_update_interval_parses_u32() {
let mut cfg = Config::default();
diff --git a/crates/openhuman-core/src/config/schema/load_tests.rs b/crates/openhuman-core/src/config/schema/load_tests.rs
index 53e221f027..b04cb82c33 100644
--- a/crates/openhuman-core/src/config/schema/load_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load_tests.rs
@@ -106,6 +106,8 @@ mod active_user_and_dirs_tests;
mod backup_tests;
#[path = "load_corruption_recovery_tests.rs"]
mod corruption_recovery_tests;
+#[path = "load_env_overlay_context_tests.rs"]
+mod env_overlay_context_tests;
#[path = "load_env_overlay_tests.rs"]
mod env_overlay_tests;
#[path = "load_migration_tests.rs"]