Skip to content

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

chore: files changed crates/openhuman-embed/tests/README.md,crates/openhuman-embed/tests/public_api.

Steven Enamakel4f9014fc5d3f
diff --git a/crates/openhuman-embed/tests/README.md b/crates/openhuman-embed/tests/README.md
index 88fdee5328..381e54f020 100644
--- a/crates/openhuman-embed/tests/README.md
+++ b/crates/openhuman-embed/tests/README.md
@@ -27,6 +27,8 @@ recorded on the wrong server.
| File | What it proves |
| --- | --- |
| [`common/mod.rs`](common/mod.rs) | Shared helpers: `runtime()`, `offline_config()`, `provider(reply)`, `stub_backend()`, `chat_completion`, `tool_call_completion`, and request inspectors (`chat_requests`, `tool_names`, `tool_results`). |
+| [`facades.rs`](facades.rs) | The runtime-free curated facades (`artifacts`, `chat_surface`, `identity`, `config` helpers, `modules`), the compile-status constants and `schema_for_rpc_method`. |
+| [`seams_runtime.rs`](seams_runtime.rs) | A controller extension is invokable after a real `build()`, a `live_policy` is applied after boot, and hooks are removed on drop while the extension outlives the runtime. |
| [`harness_embed.rs`](harness_embed.rs) | A `Harness` runs a real turn with no transport and no background services, routes it to the mock provider, and binds nothing. |
| [`runtime_agents.rs`](runtime_agents.rs) | Several agents on one runtime keep their own provider, access tier, skills, MCP servers and working directory, and the runtime's API key reaches a mocked managed backend as a bearer. |
| [`session_store.rs`](session_store.rs) | On a `Stateless` workspace with `InMemorySessionStores`, transcripts, journal and run status land in the store per agent, a reopened agent resumes from the store, and nothing durable is written to the scratch directory. |
diff --git a/crates/openhuman-embed/tests/facades.rs b/crates/openhuman-embed/tests/facades.rs
new file mode 100644
index 0000000000..195c2ba8e7
--- /dev/null
+++ b/crates/openhuman-embed/tests/facades.rs
@@ -0,0 +1,157 @@
+//! Behaviour of the curated facades a host reaches without a runtime:
+//! `artifacts`, `chat_surface`, `identity`, `config` helpers, `modules`, and
+//! the compile-status constants. No runtime is built, so these share a process.
+
+use std::time::Duration;
+
+use openhuman_embed::artifacts::{
+ create_artifact, finalize_artifact, resolve_ready_file, ArtifactKind, ArtifactStatus, FileRoots,
+};
+use openhuman_embed::chat_surface::{
+ publish_web_channel_event, subscribe_web_channel_events, WebChannelEvent,
+};
+use openhuman_embed::identity::{peek_credential_user_identity, UserIdentity};
+
+#[tokio::test]
+async fn an_artifact_resolves_only_once_ready_and_only_under_its_roots() {
+ let workspace = tempfile::tempdir().expect("workspace");
+ let files = tempfile::tempdir().expect("files");
+ let roots = FileRoots::new(files.path());
+
+ let (meta, path) = create_artifact(
+ workspace.path(),
+ roots.clone(),
+ ArtifactKind::Document,
+ "Facade note",
+ "md",
+ )
+ .await
+ .expect("artifact reserved");
+ assert!(path.starts_with(files.path()), "{}", path.display());
+
+ let pending = resolve_ready_file(workspace.path(), &roots, &meta.id)
+ .await
+ .expect_err("a pending artifact does not resolve");
+ assert!(pending.contains("not ready"), "{pending}");
+
+ tokio::fs::write(&path, b"hello").await.expect("write file");
+ let ready = finalize_artifact(workspace.path(), &meta.id, 5)
+ .await
+ .expect("finalized");
+ assert_eq!(ready.status, ArtifactStatus::Ready);
+ let resolved = resolve_ready_file(workspace.path(), &roots, &meta.id)
+ .await
+ .expect("ready artifact resolves");
+ assert_eq!(resolved, path);
+
+ // A host that trusts a different folder must not resolve the same record.
+ let elsewhere = tempfile::tempdir().expect("elsewhere");
+ assert!(
+ resolve_ready_file(
+ workspace.path(),
+ &FileRoots::new(elsewhere.path()),
+ &meta.id
+ )
+ .await
+ .is_err(),
+ "a file outside the trusted roots is refused"
+ );
+
+ tokio::fs::remove_file(&path).await.expect("remove file");
+ let missing = resolve_ready_file(workspace.path(), &roots, &meta.id)
+ .await
+ .expect_err("a deleted file is reported");
+ assert!(missing.contains("file missing"), "{missing}");
+
+ assert!(
+ resolve_ready_file(workspace.path(), &roots, "no-such-artifact")
+ .await
+ .is_err()
+ );
+}
+
+#[tokio::test]
+async fn web_channel_events_reach_a_subscriber_with_a_timestamp() {
+ let mut events = subscribe_web_channel_events();
+ publish_web_channel_event(WebChannelEvent {
+ event: "facade_probe".into(),
+ thread_id: "thread-facade".into(),
+ ..WebChannelEvent::default()
+ });
+ let received = loop {
+ let event = tokio::time::timeout(Duration::from_secs(5), events.recv())
+ .await
+ .expect("an event arrives")
+ .expect("bus open");
+ if event.event == "facade_probe" {
+ break event;
+ }
+ };
+ assert_eq!(received.thread_id, "thread-facade");
+ assert!(received.ts.is_some(), "the publisher stamps ts");
+}
+
+#[test]
+fn identity_is_empty_when_nobody_is_signed_in() {
+ assert!(peek_credential_user_identity().is_none());
+ assert!(UserIdentity::default().is_empty());
+ assert!(!UserIdentity {
+ id: Some("u1".into()),
+ ..UserIdentity::default()
+ }
+ .is_empty());
+}
+
+#[test]
+fn the_active_user_marker_reads_back_from_a_root() {
+ use openhuman_embed::config::read_active_user_id;
+
+ let root = tempfile::tempdir().expect("root");
+ assert_eq!(read_active_user_id(root.path()), None, "no marker yet");
+
+ std::fs::write(
+ root.path().join("active_user.toml"),
+ "user_id = \"u-facade\"\n",
+ )
+ .expect("write marker");
+ assert_eq!(
+ read_active_user_id(root.path()).as_deref(),
+ Some("u-facade")
+ );
+}
+
+#[test]
+fn compile_status_constants_are_the_cores_and_usable_in_const_context() {
+ // Hosts assert these at compile time (`const _: () = assert!(..)`), so they
+ // must stay `const bool`s. Embed's own cargo features do not mirror the
+ // core's (the default set comes from `openhuman-core/default`), so the
+ // value is compared with the core's, not with a `cfg!`.
+ const HTTP: bool = openhuman_embed::HTTP_SERVER_COMPILED_IN;
+ const VOICE: bool = openhuman_embed::VOICE_COMPILED_IN;
+ assert_eq!(
+ HTTP,
+ openhuman_core::core::http_server_status::HTTP_SERVER_COMPILED_IN
+ );
+ assert_eq!(VOICE, openhuman_core::voice::VOICE_COMPILED_IN);
+}
+
+#[test]
+fn schema_lookup_finds_a_builtin_method_and_rejects_an_unknown_one() {
+ let schema = openhuman_embed::schema_for_rpc_method("openhuman.config_get_runtime_flags")
+ .expect("built-in controller is registered");
+ assert_eq!(schema.namespace, "config");
+ assert_eq!(schema.function, "get_runtime_flags");
+ assert!(openhuman_embed::schema_for_rpc_method("openhuman.no_such_method").is_none());
+}
+
+#[cfg(feature = "modules")]
+#[test]
+fn the_bundled_releases_dir_is_set_once() {
+ use openhuman_embed::modules::{browser, set_bundled_releases_dir};
+
+ assert!(!browser::MODULE_ID.is_empty());
+ let first = std::path::PathBuf::from("/nonexistent/embed-facade-first");
+ let second = std::path::PathBuf::from("/nonexistent/embed-facade-second");
+ assert!(set_bundled_releases_dir(first).is_ok());
+ assert_eq!(set_bundled_releases_dir(second.clone()), Err(second));
+}
diff --git a/crates/openhuman-embed/tests/public_api.rs b/crates/openhuman-embed/tests/public_api.rs
index fc0156fe61..1d09e095a1 100644
--- a/crates/openhuman-embed/tests/public_api.rs
+++ b/crates/openhuman-embed/tests/public_api.rs
@@ -200,3 +200,40 @@ fn exposes_the_channels_contract() {
let _ = ChannelError::UnknownAgent("x".into());
let _ = ChannelError::Invalid("x".into());
}
+
+#[test]
+fn exposes_the_curated_facades_and_compile_status() {
+ use openhuman_embed::artifacts::{self, ArtifactKind, FileRoots};
+ use openhuman_embed::chat_surface::{self, WebChannelEvent};
+ use openhuman_embed::config::{self, RuntimeFlags};
+ use openhuman_embed::identity::{self, UserIdentity};
+ use openhuman_embed::{ControllerSchema, HTTP_SERVER_COMPILED_IN, VOICE_COMPILED_IN};
+
+ // Signatures, pinned by coercion to a function pointer.
+ let _: fn(&std::path::Path) -> Option<String> = config::read_active_user_id;
+ let _: fn() -> anyhow::Result<std::path::PathBuf> = config::default_root_openhuman_dir;
+ let _: fn() -> Option<UserIdentity> = identity::peek_credential_user_identity;
+ let _: fn(&str) -> Option<ControllerSchema> = openhuman_embed::schema_for_rpc_method;
+ let _: fn(WebChannelEvent) = chat_surface::publish_web_channel_event;
+ let _ = chat_surface::subscribe_web_channel_events;
+ let _ = chat_surface::register_approval_surface_subscriber;
+ let _ = chat_surface::register_artifact_surface_subscriber;
+ let _ = artifacts::resolve_ready_file;
+ let _ = FileRoots::new("/tmp/embed-public-api").with_trusted([]);
+ let _ = ArtifactKind::Document;
+ let _ = RuntimeFlags {
+ browser_allow_all: false,
+ log_prompts: false,
+ };
+
+ const _: bool = HTTP_SERVER_COMPILED_IN;
+ const _: bool = VOICE_COMPILED_IN;
+}
+
+#[cfg(feature = "modules")]
+#[test]
+fn exposes_the_module_configuration_facade() {
+ let _: fn(std::path::PathBuf) -> Result<(), std::path::PathBuf> =
+ openhuman_embed::modules::set_bundled_releases_dir;
+ let _: &str = openhuman_embed::modules::browser::MODULE_ID;
+}
diff --git a/crates/openhuman-embed/tests/seams_runtime.rs b/crates/openhuman-embed/tests/seams_runtime.rs
new file mode 100644
index 0000000000..dd8c7cbef3
--- /dev/null
+++ b/crates/openhuman-embed/tests/seams_runtime.rs
@@ -0,0 +1,115 @@
+//! Builder seams after a real `build()`: a controller extension is invokable
+//! through the runtime, a live policy is applied once the core has booted, and
+//! the documented drop behaviour holds (hooks removed; the registry, which has
+//! no removal, keeps the extension).
+//!
+//! One test, one runtime: a runtime claims a process-wide slot.
+
+mod common;
+
+use std::sync::Arc;
+
+use common::{offline_config, runtime, stub_backend};
+use openhuman_core::core::all::{ControllerFuture, RegisteredController};
+use openhuman_core::core::ControllerSchema;
+use openhuman_embed::seams::{ControllerExtension, DomainGroup, PostTurnHook, SecurityPolicy};
+use openhuman_embed::{schema_for_rpc_method, Runtime, Workspace};
+use serde_json::{json, Map, Value};
+
+const METHOD: &str = "openhuman.embed_seam_probe_ping";
+const POLICY_MARKER: u32 = 4242;
+
+fn ping(_params: Map<String, Value>) -> ControllerFuture {
+ Box::pin(async { Ok(json!({ "pong": true })) })
+}
+
+fn extension() -> ControllerExtension {
+ ControllerExtension {
+ group: DomainGroup::Platform,
+ controllers: vec![RegisteredController {
+ schema: ControllerSchema {
+ namespace: "embed_seam_probe",
+ function: "ping",
+ description: "Seam probe.",
+ inputs: vec![],
+ outputs: vec![],
+ },
+ handler: ping,
+ }],
+ namespaces: &[("embed_seam_probe", "Embed seam probe.")],
+ }
+}
+
+struct ProbeHook;
+
+#[async_trait::async_trait]
+impl PostTurnHook for ProbeHook {
+ fn name(&self) -> &str {
+ "embed-seam-runtime-hook"
+ }
+ async fn on_turn_complete(
+ &self,
+ _ctx: &openhuman_embed::seams::TurnContext,
+ ) -> anyhow::Result<()> {
+ Ok(())
+ }
+}
+
+fn hook_installed() -> bool {
+ openhuman_core::agent::hooks::embedder_post_turn_hooks()
+ .iter()
+ .any(|hook| hook.name() == "embed-seam-runtime-hook")
+}
+
+#[test]
+fn seams_are_live_after_build_and_unwound_on_drop() {
+ let tokio = runtime();
+ tokio.block_on(async {
+ tokio::spawn(async {
+ assert!(
+ schema_for_rpc_method(METHOD).is_none(),
+ "not registered yet"
+ );
+ let backend = stub_backend().await;
+
+ let mut policy = SecurityPolicy::default();
+ policy.max_actions_per_hour = POLICY_MARKER;
+
+ let runtime = Runtime::builder()
+ .config(offline_config())
+ .workspace(Workspace::Ephemeral)
+ .backend_url(backend.uri())
+ .controller_extension(extension())
+ .post_turn_hook(Arc::new(ProbeHook))
+ .live_policy(Arc::new(policy))
+ .build()
+ .await
+ .expect("runtime builds");
+
+ let reply = runtime
+ .core_runtime()
+ .invoke(METHOD, json!({}))
+ .await
+ .expect("the extension's method is invokable after build");
+ assert_eq!(reply, json!({ "pong": true }));
+ assert!(schema_for_rpc_method(METHOD).is_some());
+ assert!(hook_installed(), "hook installed while the runtime lives");
+
+ let live = openhuman_core::security::live_policy::current()
+ .expect("a live policy is installed after build");
+ assert_eq!(
+ live.max_actions_per_hour, POLICY_MARKER,
+ "the builder's policy replaced the one the core booted with"
+ );
+
+ drop(runtime);
+ assert!(!hook_installed(), "hook removed when the runtime drops");
+ assert!(
+ schema_for_rpc_method(METHOD).is_some(),
+ "the registry has no removal: the extension outlives the runtime"
+ );
+ })
+ .await
+ .expect("test task");
+ });
+}
diff --git a/crates/openhuman-rpc/tests/host_cli.rs b/crates/openhuman-rpc/tests/host_cli.rs
index d750637961..1a5f2167d3 100644
--- a/crates/openhuman-rpc/tests/host_cli.rs
+++ b/crates/openhuman-rpc/tests/host_cli.rs
@@ -10,7 +10,8 @@ fn cli_host_runs_help_and_returns_ok() {
std::thread::Builder::new()
.stack_size(64 * 1024 * 1024)
.spawn(|| {
- openhuman_rpc::host::cli(&["--help".to_string()]).expect("--help dispatches and exits Ok");
+ openhuman_rpc::host::cli(&["--help".to_string()])
+ .expect("--help dispatches and exits Ok");
openhuman_rpc::host::cli(&["http_host".to_string(), "--help".to_string()])
.expect("the http_host namespace extension is registered");
})