The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(transcript-view): move subagent anchor tests to dedicated file
Steven Enamakel5a9a71204fdd
diff --git a/crates/openhuman-core/src/flows/ops_migration_and_side_effect_tests.rs b/crates/openhuman-core/src/flows/ops_migration_and_side_effect_tests.rsindex 8fe4840cec..4a1d3b4878 100644--- a/crates/openhuman-core/src/flows/ops_migration_and_side_effect_tests.rs+++ b/crates/openhuman-core/src/flows/ops_migration_and_side_effect_tests.rs@@ -605,3 +605,95 @@ async fn draft_promote_of_invalid_graph_is_rejected_and_keeps_the_draft() {// The draft survives a failed promote so the user can fix it.assert!(flows_draft_get(&config, &draft.id).is_ok());}++/// Regression for #6540: a graph whose *node* omits `name` must report which+/// object is at fault, not a bare `missing field \`name\``.+///+/// The bare message is worse than uninformative here, because the one reading+/// it cannot even rule out the obvious candidate: every field of+/// `WorkflowGraph` is `#[serde(default)]`, so the top-level `name` can never be+/// the cause — yet an authoring agent that assumes it is will re-send the same+/// graph until it exhausts its iteration cap. That is exactly what happened+/// live: six identical retries, 392k input tokens, no workflow created.+#[test]+fn migrate_and_deserialize_graph_names_the_node_that_is_missing_a_field() {+ let missing_node_name = json!({+ "name": "top-level name is present and is NOT the problem",+ "nodes": [+ { "id": "start", "kind": "trigger", "name": "Trigger" },+ { "id": "nameless", "kind": "trigger" }+ ]+ });++ let err = migrate_and_deserialize_graph(missing_node_name)+ .expect_err("a node without `name` must not deserialize");++ // The path is the point of the fix: `nodes[1]` is the second node, and+ // naming it is what distinguishes this from the two other required `name`+ // fields reachable from one graph (`Port::name`, `WorkflowInput::name`).+ assert!(+ err.contains("nodes[1]"),+ "error must name the offending node's path, got: {err}"+ );+ // ...and the original serde detail must survive the wrapping, or the fix+ // would have traded one unactionable message for another.+ assert!(+ err.contains("missing field") && err.contains("name"),+ "error must still say which field is missing, got: {err}"+ );+}++/// The premise of the test above: a graph with no top-level `name` at all+/// deserializes fine. If this ever starts failing, `missing field \`name\``+/// becomes genuinely ambiguous and the path in the message matters more, not+/// less.+#[test]+fn migrate_and_deserialize_graph_accepts_a_graph_with_no_top_level_name() {+ let no_top_level_name = json!({+ "nodes": [ { "id": "start", "kind": "trigger", "name": "Trigger" } ]+ });++ let graph = migrate_and_deserialize_graph(no_top_level_name)+ .expect("top-level `name` is #[serde(default)] and must not be required");+ assert_eq!(+ graph.name, "",+ "absent top-level name must default to empty"+ );+}++/// Regression for the misattribution case raised in review on #6545: when the+/// graph's own fields are at fault *and* a node is independently invalid, the+/// error must not be pinned on the node.+///+/// Locating by "first member that fails on its own" is only sound once the+/// top level is known good — otherwise it turns a correct vague message into a+/// confident wrong one, which is worse than what this PR set out to fix.+#[test]+fn migrate_and_deserialize_graph_does_not_blame_a_node_for_a_top_level_fault() {+ let top_level_fault = json!({+ // Wrong type, not missing: `name` is `String`, so this fails the graph+ // parse on its own account.+ "name": 123,+ "nodes": [+ // Independently invalid too — the bait for the member scan.+ { "id": "nameless", "kind": "trigger" }+ ]+ });++ let err = migrate_and_deserialize_graph(top_level_fault)+ .expect_err("a non-string top-level `name` must not deserialize");++ // Assert what must NOT be claimed. Comparing the rendered string to the+ // bare serde message would pass for the wrong reason: the two messages can+ // coincide without the failing path being the same one.+ assert!(+ !err.contains("nodes["),+ "a top-level fault must not be attributed to a node, got: {err}"+ );+ assert!(+ err.contains("name"),+ "error should still name the offending field, got: {err}"+ );+}++// The member scan covers four arrays, and until now only `nodes` was everdiff --git a/crates/openhuman-core/src/flows/ops_migration_tests.rs b/crates/openhuman-core/src/flows/ops_migration_tests.rsnew file mode 100644index 0000000000..f10f0a9cdd--- /dev/null+++ b/crates/openhuman-core/src/flows/ops_migration_tests.rs@@ -0,0 +1,40 @@+use super::*;++/// Regression cases for migration errors that identify the invalid collection+/// member rather than reporting an ambiguous top-level deserialization error.+#[test]+fn migrate_and_deserialize_graph_names_the_member_in_inputs_agents_and_edges() {+ let bad_input = json!({ "inputs": [{ "type": "string" }] });+ let err = migrate_and_deserialize_graph(bad_input).expect_err("input without `name`");+ assert!(err.starts_with("inputs[0]: "), "got: {err}");++ let bad_agent = json!({ "agents": [{ "name": "no id" }] });+ let err = migrate_and_deserialize_graph(bad_agent).expect_err("agent without `id`");+ assert!(err.starts_with("agents[0]: "), "got: {err}");++ let bad_edge = json!({ "edges": [{ "from_port": "main" }] });+ let err = migrate_and_deserialize_graph(bad_edge).expect_err("edge without endpoints");+ assert!(err.starts_with("edges[0]: "), "got: {err}");+}++#[test]+fn migrate_and_deserialize_graph_falls_back_when_no_member_is_at_fault() {+ let err = migrate_and_deserialize_graph(json!({+ "name": "valid",+ "nodes": "this is not an array"+ }))+ .expect_err("a non-array `nodes` must not deserialize");++ assert!(!err.contains("nodes["), "got: {err}");+ assert!(err.contains("invalid type"), "got: {err}");+}++#[test]+fn migrate_and_deserialize_graph_reports_a_non_object_graph_without_inventing_a_location() {+ let err = migrate_and_deserialize_graph(json!("this is a string, not a workflow graph"))+ .expect_err("a non-object graph must not deserialize");++ assert!(!err.contains('['), "got: {err}");+ assert!(!err.contains(": invalid") || !err.starts_with("name"), "got: {err}");+ assert!(err.contains("invalid type"), "got: {err}");+}diff --git a/crates/openhuman-core/src/flows/ops_tests.rs b/crates/openhuman-core/src/flows/ops_tests.rsindex f722f9a9e2..5a47947eab 100644--- a/crates/openhuman-core/src/flows/ops_tests.rs+++ b/crates/openhuman-core/src/flows/ops_tests.rs@@ -712,6 +712,9 @@ mod engine_compatibility_tests;mod inference_gate_tests;#[path = "ops_migration_and_side_effect_tests.rs"]mod migration_and_side_effect_tests;+#[cfg(test)]+#[path = "ops_migration_tests.rs"]+mod migration_tests;#[path = "ops_resume_checkpoint_tests.rs"]mod resume_checkpoint_tests;#[path = "ops_run_lifecycle_tests.rs"]diff --git a/crates/openhuman-core/src/threads/transcript_view/mod.rs b/crates/openhuman-core/src/threads/transcript_view/mod.rsindex 0a63c9a591..cbe7ca1666 100644--- a/crates/openhuman-core/src/threads/transcript_view/mod.rs+++ b/crates/openhuman-core/src/threads/transcript_view/mod.rs@@ -103,3 +103,6 @@ fn parse_cursor(cursor: Option<&str>) -> usize {#[cfg(test)]#[path = "transcript_view_tests.rs"]mod tests;+#[cfg(test)]+#[path = "transcript_subagent_anchor_tests.rs"]+mod subagent_anchor_tests;diff --git a/crates/openhuman-core/src/threads/transcript_view/transcript_subagent_anchor_tests.rs b/crates/openhuman-core/src/threads/transcript_view/transcript_subagent_anchor_tests.rsnew file mode 100644index 0000000000..05eb9d16f7--- /dev/null+++ b/crates/openhuman-core/src/threads/transcript_view/transcript_subagent_anchor_tests.rs@@ -0,0 +1,42 @@+use super::project::project_thread;+use super::tests::write_raw;+use super::types::DisplayItem;+use tempfile::TempDir;++#[test]+fn subagent_anchors_to_parent_turn_by_spawn_timestamp() {+ let dir = TempDir::new().unwrap();+ let root_stem = "800_orchestrator";+ let thread_id = "thr_anchor";+ let t1 = chrono::DateTime::from_timestamp(1_000_000, 0).unwrap().to_rfc3339();+ let t2 = chrono::DateTime::from_timestamp(2_000_000, 0).unwrap().to_rfc3339();+ let root_body = vec![+ r#"{"role":"user","content":"one","request_id":"req-1"}"#.to_string(),+ format!(r#"{{"role":"assistant","content":"a1","provider":"anthropic","model":"m","usage":{{"input":1,"output":1,"cached_input":0,"cost_usd":0.0}},"ts":"{t1}","iteration":1,"request_id":"req-1"}}"#),+ r#"{"role":"user","content":"two","request_id":"req-2"}"#.to_string(),+ format!(r#"{{"role":"assistant","content":"a2","provider":"anthropic","model":"m","usage":{{"input":1,"output":1,"cached_input":0,"cost_usd":0.0}},"ts":"{t2}","iteration":1,"request_id":"req-2"}}"#),+ ];+ let root_refs: Vec<&str> = root_body.iter().map(String::as_str).collect();+ write_raw(dir.path(), root_stem, thread_id, &root_refs);+ write_raw(dir.path(), &format!("{root_stem}__999950_coder"), thread_id, &[r#"{"role":"assistant","content":"coder work"}"#]);+ write_raw(dir.path(), &format!("{root_stem}__1000050_planner"), thread_id, &[r#"{"role":"assistant","content":"planner work"}"#]);++ let mut anchors: Vec<(String, Option<String>)> = project_thread(dir.path(), thread_id)+ .expect("project thread")+ .items+ .iter()+ .filter_map(|item| match item {+ DisplayItem::Subagent { request_id, items, .. } => items.iter().find_map(|inner| match inner {+ DisplayItem::AssistantMessage { content, .. } => Some((content.clone(), request_id.clone())),+ _ => None,+ }),+ _ => None,+ })+ .collect();+ anchors.sort();++ assert_eq!(anchors, vec![+ ("coder work".to_string(), Some("req-1".to_string())),+ ("planner work".to_string(), Some("req-2".to_string())),+ ]);+}diff --git a/crates/openhuman-core/src/threads/transcript_view/transcript_view_tests.rs b/crates/openhuman-core/src/threads/transcript_view/transcript_view_tests.rsindex 0dafa5026b..1e881053e6 100644--- a/crates/openhuman-core/src/threads/transcript_view/transcript_view_tests.rs+++ b/crates/openhuman-core/src/threads/transcript_view/transcript_view_tests.rs@@ -18,7 +18,7 @@ fn meta_line(thread_id: &str) -> String {/// Write a raw JSONL transcript (meta header + given body lines) into/// `session_raw/{stem}.jsonl` and return the path.-fn write_raw(workspace: &Path, stem: &str, thread_id: &str, body: &[&str]) -> PathBuf {+pub(super) fn write_raw(workspace: &Path, stem: &str, thread_id: &str, body: &[&str]) -> PathBuf {let path = transcript::resolve_keyed_transcript_path(workspace, stem).expect("resolve");write_raw_at(&path, thread_id, body);path@@ -662,80 +662,6 @@ fn append_transcript_turn_projects_full_display_shape() {assert_eq!(assistants[1].3.as_deref(), Some("req-1"));assert!(!assistants[1].4, "final answer is not interim");}--#[test]-fn subagent_anchors_to_parent_turn_by_spawn_timestamp() {- let dir = TempDir::new().unwrap();- let root_stem = "800_orchestrator";- let thread_id = "thr_anchor";-- let t1 = chrono::DateTime::from_timestamp(1_000_000, 0)- .unwrap()- .to_rfc3339();- let t2 = chrono::DateTime::from_timestamp(2_000_000, 0)- .unwrap()- .to_rfc3339();-- // Two turns: req-1 (assistant ts t1), req-2 (assistant ts t2).- let root_body = vec![- r#"{"role":"user","content":"one","request_id":"req-1"}"#.to_string(),- format!(- r#"{{"role":"assistant","content":"a1","provider":"anthropic","model":"m","usage":{{"input":1,"output":1,"cached_input":0,"cost_usd":0.0}},"ts":"{t1}","iteration":1,"request_id":"req-1"}}"#- ),- r#"{"role":"user","content":"two","request_id":"req-2"}"#.to_string(),- format!(- r#"{{"role":"assistant","content":"a2","provider":"anthropic","model":"m","usage":{{"input":1,"output":1,"cached_input":0,"cost_usd":0.0}},"ts":"{t2}","iteration":1,"request_id":"req-2"}}"#- ),- ];- let root_refs: Vec<&str> = root_body.iter().map(String::as_str).collect();- write_raw(dir.path(), root_stem, thread_id, &root_refs);-- // Sub-agent stems encode the spawn unix timestamp: coder spawned during- // turn 1 (1_000_050), planner during turn 2 (2_000_050).- write_raw(- dir.path(),- &format!("{root_stem}__1000050_coder"),- thread_id,- &[r#"{"role":"assistant","content":"coder work"}"#],- );- write_raw(- dir.path(),- &format!("{root_stem}__2000050_planner"),- thread_id,- &[r#"{"role":"assistant","content":"planner work"}"#],- );-- let projected = project_thread(dir.path(), thread_id).expect("project thread");- // The seeded sub-agent files share the `orchestrator` meta agent name, so- // key the anchoring by each sub-agent's inner work content instead of `id`.- let mut anchors: Vec<(String, Option<String>)> = projected- .items- .iter()- .filter_map(|i| match i {- DisplayItem::Subagent {- request_id, items, ..- } => {- let marker = items.iter().find_map(|inner| match inner {- DisplayItem::AssistantMessage { content, .. } => Some(content.clone()),- _ => None,- })?;- Some((marker, request_id.clone()))- }- _ => None,- })- .collect();- anchors.sort();-- assert_eq!(- anchors,- vec![- ("coder work".to_string(), Some("req-1".to_string())),- ("planner work".to_string(), Some("req-2".to_string())),- ],- "each sub-agent anchors to the turn active at its spawn time"- );-}-#[test]fn get_page_missing_thread_is_empty_not_error() {let dir = TempDir::new().unwrap();