Skip to content

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

test(ci): tighten session and nudge assertions

Steven Enamakeld239666dfbb8
diff --git a/crates/openhuman-core/src/agent/agent_turn_loop_nudge_tests.rs b/crates/openhuman-core/src/agent/agent_turn_loop_nudge_tests.rs
index 4852575c1a..79a8e1dfc2 100644
--- a/crates/openhuman-core/src/agent/agent_turn_loop_nudge_tests.rs
+++ b/crates/openhuman-core/src/agent/agent_turn_loop_nudge_tests.rs
@@ -7,6 +7,8 @@ use tinyinference_llm::message::Message;
const NUDGE: &str =
"The last call failed validation. Correct its schema or arguments once before trying again.";
+const FAILED_TOOL_RESULT_WITH_NUDGE: &str =
+ "{\"status_code\": 422}\n\n[harness note]\nThe last call failed validation. Correct its schema or arguments once before trying again.";
/// A native-tool-calling model that replays scripted responses and records the
/// messages of every request it receives.
@@ -89,7 +91,10 @@ fn call(id: &str, name: &str) -> ChatResponse {
}
fn nudge_count(messages: &[Message]) -> usize {
- messages.iter().filter(|m| m.text().contains(NUDGE)).count()
+ messages
+ .iter()
+ .filter(|m| matches!(m, Message::Tool(_)) && m.text() == FAILED_TOOL_RESULT_WITH_NUDGE)
+ .count()
}
async fn run_turn(
@@ -145,9 +150,7 @@ async fn validation_nudge_reaches_the_retry_but_is_not_committed() {
assert_eq!(requests.len(), 2, "one failing call, then the retry");
assert!(
- requests[1]
- .last()
- .is_some_and(|message| message.text().contains(NUDGE)),
+ matches!(requests[1].last(), Some(message) if matches!(message, Message::Tool(_)) && message.text() == FAILED_TOOL_RESULT_WITH_NUDGE),
"the retry request must end with the nudge, got {:?}",
requests[1].last()
);
@@ -195,9 +198,7 @@ async fn a_second_validation_failure_rearms_the_nudge() {
assert_eq!(requests.iter().map(|r| nudge_count(r)).collect::<Vec<_>>(), [0, 1, 1],
"each failure nudges exactly the request that follows it; a consumed nudge is not carried over");
assert!(
- requests[2]
- .last()
- .is_some_and(|message| message.text().contains(NUDGE)),
+ matches!(requests[2].last(), Some(message) if matches!(message, Message::Tool(_)) && message.text() == FAILED_TOOL_RESULT_WITH_NUDGE),
"the re-armed nudge must end the request after the second failure"
);
assert_eq!(
diff --git a/crates/openhuman-embed/tests/attached_tools.rs b/crates/openhuman-embed/tests/attached_tools.rs
index abeec4ae7a..2d9a64b6e4 100644
--- a/crates/openhuman-embed/tests/attached_tools.rs
+++ b/crates/openhuman-embed/tests/attached_tools.rs
@@ -209,6 +209,21 @@ fn attached_tools_survive_clones_and_session_resume() {
if index == 3 {
assert!(messages.iter().any(|m| m["role"] == "user"
&& m["content"].as_str().unwrap_or("").contains("third user")));
+ assert!(
+ !messages.iter().any(|m| {
+ let content = m["content"].as_str().unwrap_or("");
+ content.contains("first user") || content.contains("second user")
+ }),
+ "a new session must not inherit the continuing session's history"
+ );
+ }
+ if index == 2 {
+ assert!(
+ !messages.iter().any(|m| {
+ m["content"].as_str().unwrap_or("").contains("first user")
+ }),
+ "a new session must start without the continuing session's history"
+ );
}
}
})
diff --git a/tests/in_process/agent_prompt_comprehension_e2e.rs b/tests/in_process/agent_prompt_comprehension_e2e.rs
index 601a22033c..09f14277b5 100644
--- a/tests/in_process/agent_prompt_comprehension_e2e.rs
+++ b/tests/in_process/agent_prompt_comprehension_e2e.rs
@@ -45,7 +45,6 @@ static AGENT_DEF_REGISTRY_INIT: OnceLock<()> = OnceLock::new();
static SCRIPTED: OnceLock<Mutex<std::collections::VecDeque<Value>>> = OnceLock::new();
static CAPTURED: OnceLock<Mutex<Vec<Value>>> = OnceLock::new();
-static SCRIPTED_UPSTREAM: OnceLock<SocketAddr> = OnceLock::new();
fn scripted() -> std::sync::MutexGuard<'static, std::collections::VecDeque<Value>> {
lock_or_recover(SCRIPTED.get_or_init(Default::default))
@@ -313,33 +312,6 @@ async fn serve_on_ephemeral(
(addr, handle)
}
-fn scripted_upstream_addr() -> SocketAddr {
- *SCRIPTED_UPSTREAM.get_or_init(|| {
- ensure_rpc_auth();
- let (addr_tx, addr_rx) = std::sync::mpsc::sync_channel(1);
- std::thread::Builder::new()
- .name("prompt-scripted-upstream".into())
- .spawn(move || {
- let runtime = tokio::runtime::Builder::new_current_thread()
- .enable_all()
- .build()
- .expect("build scripted upstream runtime");
- runtime.block_on(async move {
- let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
- .await
- .expect("bind scripted upstream");
- addr_tx.send(listener.local_addr().expect("scripted upstream addr"))
- .expect("report scripted upstream addr");
- axum::serve(listener, scripted_upstream_router())
- .await
- .expect("serve scripted upstream");
- });
- })
- .expect("spawn scripted upstream");
- addr_rx.recv().expect("scripted upstream startup")
- })
-}
-
async fn post_json_rpc(rpc_base: &str, id: i64, method: &str, params: Value) -> Value {
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(180))
@@ -499,7 +471,7 @@ async fn boot_stack(extra_config: &str) -> Stack {
EnvVarGuard::unset("VITE_BACKEND_URL"),
];
- let mock_addr = scripted_upstream_addr();
+ let (mock_addr, mock_join) = serve_on_ephemeral(scripted_upstream_router()).await;
let mock_origin = format!("http://{mock_addr}");
write_min_config(&openhuman_home, &mock_origin, extra_config);
write_min_config(
@@ -525,7 +497,7 @@ async fn boot_stack(extra_config: &str) -> Stack {
rpc_base,
_guards: guards,
_tmp: tmp,
- joins: vec![rpc_join],
+ joins: vec![mock_join, rpc_join],
}
}