Skip to content

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

test(agent): count scripted model calls and assert the empty completion is retried exactly once

M3gA-Minde1dc110aa626
diff --git a/crates/openhuman-core/src/agent/agent_tests.rs b/crates/openhuman-core/src/agent/agent_tests.rs
index f63660af3d..abe6f71a5f 100644
--- a/crates/openhuman-core/src/agent/agent_tests.rs
+++ b/crates/openhuman-core/src/agent/agent_tests.rs
@@ -44,12 +44,15 @@ use tinytools_agent::dialect::{NativeDialect, ToolDialect, XmlDialect};
/// When the queue is exhausted it returns a simple "done" text response.
struct ScriptedProvider {
responses: Mutex<Vec<ChatResponse>>,
+ /// Model calls made, including any answered by the exhausted-queue default.
+ calls: std::sync::atomic::AtomicUsize,
}
impl ScriptedProvider {
fn new(responses: Vec<ChatResponse>) -> Self {
Self {
responses: Mutex::new(responses),
+ calls: std::sync::atomic::AtomicUsize::new(0),
}
}
}
@@ -72,6 +75,7 @@ impl ChatModel<()> for ScriptedProvider {
_state: &(),
request: ModelRequest,
) -> tinyinference_llm::Result<ModelResponse> {
+ self.calls.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
let mut guard = self.responses.lock().unwrap();
let response = if guard.is_empty() {
ChatResponse {
diff --git a/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs b/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
index 16e0f386fb..aaf5e56aed 100644
--- a/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
+++ b/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
@@ -434,8 +434,9 @@ async fn turn_errors_on_empty_text_response() {
.await
.expect_err("an empty provider response must error");
// Both attempts were made: the original and the one retry.
- assert!(
- script.responses.lock().unwrap().is_empty(),
+ assert_eq!(
+ script.calls.load(std::sync::atomic::Ordering::SeqCst),
+ 2,
"the empty completion must be retried exactly once before erroring"
);
assert!(
@@ -462,8 +463,9 @@ async fn turn_errors_on_none_text_response() {
.turn("hi")
.await
.expect_err("a null-text provider response must error");
- assert!(
- script.responses.lock().unwrap().is_empty(),
+ assert_eq!(
+ script.calls.load(std::sync::atomic::Ordering::SeqCst),
+ 2,
"the empty completion must be retried exactly once before erroring"
);
assert!(