Skip to content

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

test(subagent-host): add test module for driver adapter

Steven Enamakel6637e0a58dc5
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
index 26c8944690..bb0a72dbbe 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
@@ -470,3 +470,7 @@ fn cost_source_of(charged: Option<&ChargedAmount>) -> tinyagents_harness::cost::
None => tinyagents_harness::cost::CostSource::Unknown,
}
}
+
+#[cfg(test)]
+#[path = "driver_adapter_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter_tests.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter_tests.rs
new file mode 100644
index 0000000000..ec29f125ea
--- /dev/null
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter_tests.rs
@@ -0,0 +1,164 @@
+use super::*;
+
+fn key() -> SubagentTaskKey {
+ SubagentTaskKey {
+ root_run_id: "root".into(),
+ parent_run_id: "parent".into(),
+ thread_id: Some("thread".into()),
+ task_id: "task".into(),
+ }
+}
+
+fn cause(class: &str, operation: &str, summary: &str) -> tinyagents_harness::no_progress::ClassifiedStopCause {
+ tinyagents_harness::no_progress::ClassifiedStopCause {
+ class: class.into(),
+ operation: operation.into(),
+ summary: summary.into(),
+ }
+}
+
+fn neutral_outcome(status: SubagentOutcomeKind) -> SubagentOutcome {
+ let mut outcome = SubagentOutcome::cancelled("task");
+ outcome.status = status;
+ outcome.output = "durable winner".into();
+ outcome.extensions.insert("agent_id".into(), serde_json::json!("winner"));
+ outcome.extensions.insert("elapsed_ms".into(), serde_json::json!(0));
+ outcome.extensions.insert(
+ "failure_cause".into(),
+ serde_json::json!({
+ "class": "not_found",
+ "operation": "file_read",
+ "summary": "path was not found",
+ }),
+ );
+ serde_json::from_slice(&serde_json::to_vec(&outcome).unwrap()).unwrap()
+}
+
+fn host_outcome(
+ failure_cause: Option<tinyagents_harness::no_progress::ClassifiedStopCause>,
+ status: SubagentRunStatus,
+) -> SubagentRunOutcome {
+ SubagentRunOutcome {
+ task_id: "task".into(),
+ agent_id: "cached-agent".into(),
+ output: "cached local result".into(),
+ iterations: 3,
+ failure_cause,
+ elapsed: std::time::Duration::from_millis(10),
+ mode: crate::agent::subagent_host::SubagentMode::Typed,
+ status,
+ final_history: Vec::new(),
+ usage: SubagentUsage::default(),
+ artifact_paths: Vec::new(),
+ persistence_disposition: SubagentPersistenceDisposition::TerminalInserted,
+ }
+}
+
+fn project(
+ outcome: SubagentOutcome,
+ host: Option<SubagentRunOutcome>,
+ disposition: SubagentPersistenceDisposition,
+ persistence: &OpenHumanPersistence,
+) -> SubagentRunOutcome {
+ outcome_to_host(
+ SubagentRunResult::new(outcome, disposition),
+ host,
+ persistence,
+ &key(),
+ "fallback-agent",
+ )
+}
+
+#[test]
+fn durable_winner_cause_is_restored_without_a_host_cache() {
+ let directory = tempfile::tempdir().unwrap();
+ let persistence = OpenHumanPersistence::new(directory.path().join("checkpoints"));
+ let outcome = neutral_outcome(SubagentOutcomeKind::Incomplete(SubagentIncomplete::new(
+ "path was not found",
+ )));
+
+ let projected = project(outcome, None, SubagentPersistenceDisposition::TerminalExisting, &persistence);
+
+ assert_eq!(
+ projected.failure_cause,
+ Some(cause("not_found", "file_read", "path was not found"))
+ );
+ assert_eq!(projected.output, "durable winner");
+}
+
+#[test]
+fn a_losing_cached_cause_cannot_replace_the_durable_winner_cause() {
+ let directory = tempfile::tempdir().unwrap();
+ let persistence = OpenHumanPersistence::new(directory.path().join("checkpoints"));
+ let outcome = neutral_outcome(SubagentOutcomeKind::Incomplete(SubagentIncomplete::new(
+ "path was not found",
+ )));
+ let loser = host_outcome(
+ Some(cause("permission", "shell", "loser was denied")),
+ SubagentRunStatus::Incomplete {
+ reason: "loser was denied".into(),
+ },
+ );
+
+ let projected = project(
+ outcome,
+ Some(loser),
+ SubagentPersistenceDisposition::TerminalExisting,
+ &persistence,
+ );
+
+ assert_eq!(
+ projected.failure_cause,
+ Some(cause("not_found", "file_read", "path was not found"))
+ );
+ assert_eq!(projected.output, "durable winner");
+}
+
+#[test]
+fn ordinary_host_projection_keeps_the_winning_cause() {
+ let directory = tempfile::tempdir().unwrap();
+ let persistence = OpenHumanPersistence::new(directory.path().join("checkpoints"));
+ let winner_cause = cause("permission", "shell", "permission denied");
+ let outcome = neutral_outcome(SubagentOutcomeKind::Incomplete(SubagentIncomplete::new(
+ "permission denied",
+ )));
+ let host = host_outcome(
+ Some(winner_cause.clone()),
+ SubagentRunStatus::Incomplete {
+ reason: "permission denied".into(),
+ },
+ );
+
+ let projected = project(
+ outcome,
+ Some(host),
+ SubagentPersistenceDisposition::TerminalInserted,
+ &persistence,
+ );
+
+ assert_eq!(projected.failure_cause, Some(winner_cause));
+}
+
+#[test]
+fn non_incomplete_winners_discard_stale_typed_causes() {
+ let directory = tempfile::tempdir().unwrap();
+ let persistence = OpenHumanPersistence::new(directory.path().join("checkpoints"));
+ let statuses = [
+ SubagentOutcomeKind::Completed,
+ SubagentOutcomeKind::AwaitingInput(SubagentPause {
+ reason: "question".into(),
+ resume: SubagentResume::default(),
+ }),
+ SubagentOutcomeKind::Cancelled,
+ ];
+
+ for status in statuses {
+ let projected = project(
+ neutral_outcome(status),
+ None,
+ SubagentPersistenceDisposition::TerminalExisting,
+ &persistence,
+ );
+ assert_eq!(projected.failure_cause, None);
+ }
+}