Skip to content

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

refactor(core): move test-only context constructors into a support module

Steven Enamakel3e4b5419c659
diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rs
index b8c75f9f7a..99295591b1 100644
--- a/crates/openhuman-core/src/core/runtime/context.rs
+++ b/crates/openhuman-core/src/core/runtime/context.rs
@@ -551,81 +551,6 @@ impl CoreContext {
pub fn propagate<F: Future>(fut: F) -> impl Future<Output = F::Output> {
super::spawn::carry(fut)
}
-
- /// Test-only constructor: build a context with an explicit
- /// [`DomainSet`](crate::core::runtime::DomainSet) and optional workspace, so
- /// cross-module tests (e.g. `core::all`'s registry filter) can exercise the
- /// ambient DomainSet gate without going through the full [`CoreContext::init`]
- /// boot sequence.
- #[cfg(test)]
- pub(crate) fn for_test(
- domains: crate::core::runtime::DomainSet,
- workspace_dir: Option<std::path::PathBuf>,
- ) -> Arc<CoreContext> {
- Arc::new(CoreContext {
- host_kind: HostKind::Cli,
- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {
- workspace_dir,
- }))),
- domains,
- tool_groups: Default::default(),
- components: Default::default(),
- embedder_config: None,
- user_skill_roots: true,
- backend_transport: None,
- turn_origin: None,
- channel_thread: None,
- session_agent: None,
- profile: None,
- agent: Default::default(),
- bare: false,
- })
- }
-
- /// Test-only: given `[components]` switches.
- #[cfg(test)]
- pub(crate) fn for_test_with_components(c: crate::core::runtime::ComponentSet) -> Arc<Self> {
- let mut ctx = Arc::try_unwrap(Self::for_test(super::DomainSet::full(), None))
- .ok()
- .unwrap();
- ctx.components = c;
- 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
- /// full boot or a racy on-disk `config.toml`.
- ///
- /// Distinct from [`CoreContext::for_test`] — which always sets
- /// `embedder_config: None` — so the ~30 existing `for_test` call sites are
- /// unaffected. The workspace binding is anchored to the config's
- /// `workspace_dir`, matching how [`CoreContext::init`] wires an
- /// embedder-supplied config.
- #[cfg(test)]
- pub(crate) fn for_test_with_config(
- domains: crate::core::runtime::DomainSet,
- config: crate::config::Config,
- ) -> Arc<CoreContext> {
- Arc::new(CoreContext {
- host_kind: HostKind::Cli,
- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {
- workspace_dir: Some(config.workspace_dir.clone()),
- }))),
- domains,
- tool_groups: Default::default(),
- components: Default::default(),
- embedder_config: Some(config),
- user_skill_roots: true,
- backend_transport: None,
- turn_origin: None,
- channel_thread: None,
- session_agent: None,
- profile: None,
- agent: Default::default(),
- bare: false,
- })
- }
}
/// Initialize the workspace-bound stores and report the memory engine.
@@ -757,6 +682,10 @@ mod agent_parts;
mod overlay;
pub use overlay::ContextOverlay;
+#[cfg(test)]
+#[path = "context_test_support.rs"]
+mod test_support;
+
#[cfg(test)]
#[path = "context_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/core/runtime/context_test_support.rs b/crates/openhuman-core/src/core/runtime/context_test_support.rs
new file mode 100644
index 0000000000..7c36f45fd6
--- /dev/null
+++ b/crates/openhuman-core/src/core/runtime/context_test_support.rs
@@ -0,0 +1,78 @@
+//! Test-only constructors for [`CoreContext`]: a context with an explicit domain
+//! set, workspace or embedder config, without the full [`CoreContext::init`] boot.
+
+use super::*;
+
+impl CoreContext {
+ /// Test-only constructor: build a context with an explicit
+ /// [`DomainSet`](crate::core::runtime::DomainSet) and optional workspace, so
+ /// cross-module tests (e.g. `core::all`'s registry filter) can exercise the
+ /// ambient DomainSet gate without going through the full [`CoreContext::init`]
+ /// boot sequence.
+ pub(crate) fn for_test(
+ domains: crate::core::runtime::DomainSet,
+ workspace_dir: Option<std::path::PathBuf>,
+ ) -> Arc<CoreContext> {
+ Arc::new(CoreContext {
+ host_kind: HostKind::Cli,
+ workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {
+ workspace_dir,
+ }))),
+ domains,
+ tool_groups: Default::default(),
+ components: Default::default(),
+ embedder_config: None,
+ user_skill_roots: true,
+ backend_transport: None,
+ turn_origin: None,
+ channel_thread: None,
+ session_agent: None,
+ profile: None,
+ agent: Default::default(),
+ bare: false,
+ })
+ }
+
+ /// Test-only: given `[components]` switches.
+ pub(crate) fn for_test_with_components(c: crate::core::runtime::ComponentSet) -> Arc<Self> {
+ let mut ctx = Arc::try_unwrap(Self::for_test(super::DomainSet::full(), None))
+ .ok()
+ .unwrap();
+ ctx.components = c;
+ 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
+ /// full boot or a racy on-disk `config.toml`.
+ ///
+ /// Distinct from [`CoreContext::for_test`] — which always sets
+ /// `embedder_config: None` — so the ~30 existing `for_test` call sites are
+ /// unaffected. The workspace binding is anchored to the config's
+ /// `workspace_dir`, matching how [`CoreContext::init`] wires an
+ /// embedder-supplied config.
+ pub(crate) fn for_test_with_config(
+ domains: crate::core::runtime::DomainSet,
+ config: crate::config::Config,
+ ) -> Arc<CoreContext> {
+ Arc::new(CoreContext {
+ host_kind: HostKind::Cli,
+ workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {
+ workspace_dir: Some(config.workspace_dir.clone()),
+ }))),
+ domains,
+ tool_groups: Default::default(),
+ components: Default::default(),
+ embedder_config: Some(config),
+ user_skill_roots: true,
+ backend_transport: None,
+ turn_origin: None,
+ channel_thread: None,
+ session_agent: None,
+ profile: None,
+ agent: Default::default(),
+ bare: false,
+ })
+ }
+}