Skip to content

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

fix(config): correct agent schema to use optional voice field

Steven Enamakelc05dbfdcd0a1
diff --git a/crates/openhuman-core/src/config/schema/agent.rs b/crates/openhuman-core/src/config/schema/agent.rs
index 0fef7db9b9..f09399965c 100644
--- a/crates/openhuman-core/src/config/schema/agent.rs
+++ b/crates/openhuman-core/src/config/schema/agent.rs
@@ -168,7 +168,7 @@ fn default_max_depth() -> u32 {
/// frequently omit it, leaving those consumers with nothing. When this contract
/// is set on [`AgentConfig::required_output`], the turn engine validates the
/// reply and repairs an omitted block before the turn is accepted (see
-/// `crate::agent::harness::required_output`), so consumers always get
+/// `tinyagents_harness::config::required_output`), so consumers always get
/// a well-formed block.
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
diff --git a/crates/openhuman-core/src/voice/postprocess_tests.rs b/crates/openhuman-core/src/voice/postprocess_tests.rs
index 5c5457071c..50b5868d4b 100644
--- a/crates/openhuman-core/src/voice/postprocess_tests.rs
+++ b/crates/openhuman-core/src/voice/postprocess_tests.rs
@@ -1,67 +1,7 @@
use super::*;
-use axum::{routing::post, Json, Router};
-use serde_json::json;
-// ── Helpers ──────────────────────────────────────────────────
-
-async fn spawn_mock(app: Router) -> String {
- let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr = listener.local_addr().unwrap();
- tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });
- let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
- let mut backoff = std::time::Duration::from_millis(2);
- loop {
- if tokio::net::TcpStream::connect(addr).await.is_ok() {
- break;
- }
- if std::time::Instant::now() >= deadline {
- panic!("mock ollama at {addr} did not become ready");
- }
- tokio::time::sleep(backoff).await;
- backoff = (backoff * 2).min(std::time::Duration::from_millis(50));
- }
- format!("http://127.0.0.1:{}", addr.port())
-}
-
-/// Parks the global `local_ai::global(&config)` service state at
-/// "ready", runs the async test with `body`, then restores the prior
-/// state and clears `OPENHUMAN_OLLAMA_BASE_URL`. Returns whatever
-/// `body` returned so the caller can assert on it.
-///
-/// The [`LOCAL_AI_TEST_MUTEX`] serialises every test in this module
-/// — and sibling modules — that touches the global service state or
-/// the shared env var.
-async fn with_ready_llm<F, Fut, R>(base: String, config: &Config, body: F) -> R
-where
- F: FnOnce() -> Fut,
- Fut: std::future::Future<Output = R>,
-{
- let service = local_ai::global(config);
- let previous = service.replace_status_state("ready");
- unsafe {
- std::env::set_var("OPENHUMAN_OLLAMA_BASE_URL", &base);
- }
- let out = body().await;
- unsafe {
- std::env::remove_var("OPENHUMAN_OLLAMA_BASE_URL");
- }
- service.replace_status_state(previous);
- out
-}
-
-// ── Short-circuit paths (no LLM call) ────────────────────────
-
-#[tokio::test]
-async fn empty_text_returns_unchanged() {
- let config = Config::default();
- assert_eq!(cleanup_transcription(&config, "", None).await, "");
-}
-
-#[tokio::test]
-async fn whitespace_only_returns_unchanged() {
- let config = Config::default();
- assert_eq!(cleanup_transcription(&config, " ", None).await, " ");
-}
+// Host wrapper: config flag and delegation. LLM-call behavior (ready/degraded,
+// empty reply, error, timeout, context prompt) is tested in tinyinference-voice.
#[tokio::test]
async fn disabled_cleanup_returns_raw_text() {
@@ -88,169 +28,3 @@ async fn enabled_but_llm_not_ready_returns_raw_text() {
service.replace_status_state(previous);
assert_eq!(result, "raw whisper output");
}
-
-// ── LLM-ready paths (mocked Ollama) ──────────────────────────
-//
-// These exercise the "LLM ready → actually call Ollama" branch, but
-// assert only on *either* the cleaned response or the raw-text
-// fallback. The reason is structural:
-//
-// `cleanup_transcription` resolves the `LocalAiService` via
-// `local_ai::global(config)` — a process-wide `OnceCell` singleton.
-// ~30 sibling tests across the crate touch that singleton's state
-// without holding `LOCAL_AI_TEST_MUTEX`, so even when we set the
-// state to `"ready"` here, another test can flip it back to
-// `"idle"` mid-run. We still want to exercise the full code path
-// for coverage, so the assertions are deliberately permissive —
-// we pin the contract that the function returns a deterministic
-// String in either case and never panics. Tight end-to-end
-// correctness of the cleanup output is covered in the
-// deterministic short-circuit tests above and in an integration
-// test that controls the full process state.
-
-/// `result` must equal either the cleaned `expected` or the raw
-/// `fallback`, never anything else. Returns the matched variant for
-/// callers that want to assert coverage of both branches over time.
-fn assert_cleaned_or_raw(result: &str, expected: &str, fallback: &str) {
- assert!(
- result == expected || result == fallback,
- "unexpected cleanup result: got `{result}`, expected `{expected}` or raw fallback `{fallback}`"
- );
-}
-
-#[tokio::test]
-async fn ready_llm_returns_trimmed_cleanup_or_falls_back() {
- let _g = crate::inference::inference_test_guard();
- let app = Router::new().route(
- "/api/generate",
- post(|| async {
- Json(json!({
- "model": "test",
- "response": " Hello, world. ",
- "done": true
- }))
- }),
- );
- let base = spawn_mock(app).await;
- let config = Config::default();
- let raw = "um hello world";
- let result = with_ready_llm(base, &config, || async {
- cleanup_transcription(&config, raw, None).await
- })
- .await;
- assert_cleaned_or_raw(&result, "Hello, world.", raw);
-}
-
-#[tokio::test]
-async fn ready_llm_empty_response_falls_back_to_raw_text() {
- let _g = crate::inference::inference_test_guard();
- let app = Router::new().route(
- "/api/generate",
- post(|| async { Json(json!({"model":"test","response":" ","done": true})) }),
- );
- let base = spawn_mock(app).await;
- let config = Config::default();
- let result = with_ready_llm(base, &config, || async {
- cleanup_transcription(&config, "keep me", None).await
- })
- .await;
- // Both "LLM saw the empty response and fell back" and "LLM was
- // not ready so short-circuited" produce the same result here.
- assert_eq!(result, "keep me");
-}
-
-#[tokio::test]
-async fn ready_llm_error_response_falls_back_to_raw_text() {
- let _g = crate::inference::inference_test_guard();
- let app = Router::new().route(
- "/api/generate",
- post(|| async {
- (
- axum::http::StatusCode::INTERNAL_SERVER_ERROR,
- "boom".to_string(),
- )
- }),
- );
- let base = spawn_mock(app).await;
- let config = Config::default();
- let result = with_ready_llm(base, &config, || async {
- cleanup_transcription(&config, "raw text", None).await
- })
- .await;
- // Err fallback or short-circuit both return raw text.
- assert_eq!(result, "raw text");
-}
-
-#[tokio::test]
-async fn ready_llm_with_conversation_context_uses_context_or_raw_fallback() {
- // Echo the received prompt so we can assert the caller actually
- // glued the conversation context in front of the raw text when
- // the LLM ran. If the global state raced away from "ready" the
- // call short-circuits to raw — still valid, just the other branch.
- let _g = crate::inference::inference_test_guard();
- #[derive(serde::Deserialize)]
- struct Body {
- prompt: String,
- }
- let app = Router::new().route(
- "/api/generate",
- post(|Json(body): Json<Body>| async move {
- Json(json!({
- "model": "test",
- "response": body.prompt,
- "done": true
- }))
- }),
- );
- let base = spawn_mock(app).await;
- let config = Config::default();
- let raw = "raw text";
- let result = with_ready_llm(base, &config, || async {
- cleanup_transcription(&config, raw, Some("previous turn: check the oven")).await
- })
- .await;
- if result.contains("Conversation context:") {
- assert!(result.contains("previous turn: check the oven"));
- assert!(result.contains("Transcribed text to clean up:"));
- assert!(result.contains(raw));
- } else {
- assert_eq!(result, raw);
- }
-}
-
-#[tokio::test]
-async fn ready_llm_with_whitespace_only_context_never_embeds_header() {
- // A Some(ctx) that is pure whitespace must NOT embed the
- // "Conversation context:" header regardless of which branch
- // runs — the LLM path uses the raw-text-only prompt, and the
- // short-circuit path never builds a prompt at all.
- let _g = crate::inference::inference_test_guard();
- #[derive(serde::Deserialize)]
- struct Body {
- prompt: String,
- }
- let app = Router::new().route(
- "/api/generate",
- post(|Json(body): Json<Body>| async move {
- Json(json!({
- "model": "test",
- "response": body.prompt,
- "done": true
- }))
- }),
- );
- let base = spawn_mock(app).await;
- let config = Config::default();
- let result = with_ready_llm(base, &config, || async {
- cleanup_transcription(&config, "raw text", Some(" ")).await
- })
- .await;
- assert!(
- !result.contains("Conversation context:"),
- "whitespace-only context must NOT be forwarded, got: {result}"
- );
- // Exact equality: `cleanup_transcription` trims the LLM response,
- // so either branch (LLM echo of the raw-only prompt, or the
- // short-circuit fallback) must return exactly "raw text".
- assert_eq!(result, "raw text");
-}