Skip to content

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

refactor(web_chat): move error copy tests to separate module

Steven Enamakel07700687081d
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
index 6e2e2e30c5..620d244099 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
@@ -50,10 +50,10 @@ use persistence::{persist_delivery_reply, persist_then_announce};
use super::background_completions;
use super::busy_guard::is_busy;
#[cfg(test)]
-use super::busy_guard::{busy, clear_busy_for_thread, TurnBusy};
+use super::busy_guard::{TurnBusy, busy, clear_busy_for_thread};
use super::completion_notice::build_undelivered_notice;
use super::completion_owners;
-use super::delivery_drain::{run_drain, DrainFence, DrainOutcome, RECOVERY_BUSY_POLL};
+use super::delivery_drain::{DrainFence, DrainOutcome, RECOVERY_BUSY_POLL, run_drain};
use crate::core::runtime::CoreContext;
/// Coalesce completions landing within this window into one delivery turn.
@@ -669,8 +669,8 @@ async fn run_system_turn_on_thread(
Ok(response) => crate::web_chat::presentation::deliver_response_single_bubble(
ctx, "system", &thread_id, &run_id, response, None,
),
- Err(error) => {
- crate::web_chat::publish_web_channel_event(crate::web_chat::WebChannelEvent::ChatError {
+ Err(error) => crate::web_chat::publish_web_channel_event(
+ crate::web_chat::WebChannelEvent::ChatError {
context: crate::web_chat::channel_event::event_context(
"system",
thread_id.clone(),
@@ -686,8 +686,8 @@ async fn run_system_turn_on_thread(
copy_key: None,
copy_params: None,
guardrail: None,
- })
- }
+ },
+ ),
},
)
}
diff --git a/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs
index bb98341203..342340a383 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs
@@ -9,7 +9,6 @@
use super::*;
use crate::agent::triage::evaluator::{ArmError, classify_error};
-use crate::web_chat::WebChannelEvent;
use regex::Regex;
/// `(case, input, error_type, source, retryable, retry_after_ms, provider,
@@ -701,211 +700,6 @@ fn loop_guard_halt_summaries_are_byte_identical() {
/// `(case, copy_key, copy_params as literal JSON)` for the same 37 inputs as
/// [`EXPECTED`], in the same order. One key per table row.
-const EXPECTED_COPY_KEYS: &[(&str, &str, &str)] = &[
- (
- "codex_expired",
- "chat_error.codex_session_expired",
- r#"{"provider":"openai_codex"}"#,
- ),
- ("session_expired", "chat_error.session_expired", "null"),
- (
- "local_session_managed",
- "chat_error.local_session_managed_unavailable",
- "null",
- ),
- ("action_budget", "chat_error.action_budget", "null"),
- ("max_iterations", "chat_error.max_iterations", "null"),
- ("turn_timeout_marker", "chat_error.turn_timeout", "null"),
- ("turn_timeout_harness", "chat_error.turn_timeout", "null"),
- ("empty_response", "chat_error.empty_response", "null"),
- (
- "chat_template",
- "chat_error.chat_template_rejected",
- r#"{"provider":"openai"}"#,
- ),
- (
- "rate_limited_transient",
- "chat_error.rate_limited",
- r#"{"provider":"openrouter","retry_after_secs":30}"#,
- ),
- (
- "rate_limited_business",
- "chat_error.rate_limited_billing",
- r#"{"provider":"openai"}"#,
- ),
- ("timeout", "chat_error.timeout", "null"),
- (
- "auth_error",
- "chat_error.auth_error",
- r#"{"provider":"openai"}"#,
- ),
- (
- "budget_402",
- "chat_error.budget_exhausted",
- r#"{"provider":"openai"}"#,
- ),
- ("budget_phrase", "chat_error.budget_exhausted", "null"),
- (
- "budget_phrase_provider_source",
- "chat_error.budget_exhausted",
- r#"{"provider":"openrouter"}"#,
- ),
- (
- "provider_5xx",
- "chat_error.provider_unavailable",
- r#"{"provider":"anthropic"}"#,
- ),
- ("context_overflow", "chat_error.context_overflow", "null"),
- (
- "config_rejection",
- "chat_error.model_unavailable",
- r#"{"provider":"openai"}"#,
- ),
- ("model_unavailable", "chat_error.model_unavailable", "null"),
- ("model_transient", "chat_error.provider_unavailable", "null"),
- ("vision", "chat_error.capability_unsupported", "null"),
- (
- "malformed_history_byo",
- "chat_error.malformed_history",
- r#"{"provider":"openai"}"#,
- ),
- (
- "request_rejected_4xx",
- "chat_error.request_rejected",
- r#"{"provider":"someprovider"}"#,
- ),
- ("network", "chat_error.network", "null"),
- (
- "transient_529",
- "chat_error.provider_unavailable",
- r#"{"provider":"anthropic"}"#,
- ),
- ("generic", "chat_error.inference", "null"),
- ("fallback_chain", "chat_error.inference", "null"),
- (
- "be_rate_limited",
- "chat_error.managed_rate_limited",
- r#"{"provider":"openhuman","retry_after_secs":30}"#,
- ),
- (
- "be_credits",
- "chat_error.managed_budget_exhausted",
- r#"{"provider":"openhuman"}"#,
- ),
- (
- "be_upstream",
- "chat_error.managed_unavailable",
- r#"{"provider":"openhuman"}"#,
- ),
- (
- "be_model_unavailable",
- "chat_error.managed_unavailable",
- r#"{"provider":"openhuman"}"#,
- ),
- (
- "be_payload",
- "chat_error.payload_too_large",
- r#"{"provider":"openhuman"}"#,
- ),
- (
- "be_context",
- "chat_error.context_overflow",
- r#"{"provider":"openhuman"}"#,
- ),
- (
- "be_bad_request",
- "chat_error.managed_request_rejected",
- r#"{"provider":"openhuman"}"#,
- ),
- (
- "be_bad_request_malformed",
- "chat_error.managed_malformed_request",
- r#"{"provider":"openhuman"}"#,
- ),
- (
- "be_bad_request_history",
- "chat_error.malformed_history",
- r#"{"provider":"openhuman"}"#,
- ),
- (
- "be_internal",
- "chat_error.managed_internal",
- r#"{"provider":"openhuman"}"#,
- ),
-];
-
-#[test]
-fn every_failure_class_carries_its_i18n_key_and_params() {
- assert_eq!(EXPECTED_COPY_KEYS.len(), EXPECTED.len());
- for ((case, input, ..), (key_case, copy_key, params)) in
- EXPECTED.iter().zip(EXPECTED_COPY_KEYS.iter())
- {
- assert_eq!(case, key_case, "fixture rows out of order");
- let got = classify_inference_error(input);
- assert_eq!(got.copy_key, *copy_key, "{case}: copy_key");
- let got_params = got
- .copy_params
- .map(|v| v.to_string())
- .unwrap_or_else(|| "null".to_string());
- assert_eq!(got_params, *params, "{case}: copy_params");
- }
-}
-
-#[test]
-fn provider_detail_travels_as_a_param_and_the_message_still_quotes_it() {
- let got = classify_inference_error(
- r#"openai API error (400): {"error":{"message":"bad temperature for this model"}}"#,
- );
- let params = got.copy_params.expect("provider + detail params");
- let detail = params["detail"].as_str().expect("detail param");
- assert!(detail.contains("bad temperature"), "{detail}");
- assert!(
- got.message.ends_with(&format!("\n\n> {detail}")),
- "message must keep quoting the detail: {}",
- got.message
- );
-}
-#[test]
-fn chat_error_event_serializes_copy_key_and_params_to_literal_json() {
- let classified =
- classify_inference_error("openrouter API error (429 Too Many Requests): Retry-After: 30");
- let event = WebChannelEvent::ChatError {
- context: crate::web_chat::WebEventContext::default(),
- message: Some(classified.message.clone()),
- error_type: Some(classified.error_type.to_string()),
- error_source: None,
- error_retryable: None,
- error_retry_after_ms: None,
- error_provider: None,
- error_fallback_available: None,
- copy_key: Some(classified.copy_key.to_string()),
- copy_params: classified.copy_params,
- guardrail: None,
- };
- let json = serde_json::to_value(&event).expect("serializes");
- assert_eq!(json["copy_key"], "chat_error.rate_limited");
- assert_eq!(
- json["copy_params"],
- serde_json::json!({"provider": "openrouter", "retry_after_secs": 30})
- );
- assert_eq!(json["error_type"], "rate_limited");
- assert_eq!(json["message"], classified.message);
-
- // Older emitters (cancellation, guardrail) carry neither key.
- let bare = serde_json::to_value(WebChannelEvent::ChatError {
- context: crate::web_chat::WebEventContext::default(),
- message: None,
- error_type: None,
- error_source: None,
- error_retryable: None,
- error_retry_after_ms: None,
- error_provider: None,
- error_fallback_available: None,
- copy_key: None,
- copy_params: None,
- guardrail: None,
- })
- .expect("serializes");
- assert!(bare.get("copy_key").is_none() && bare.get("copy_params").is_none());
-}
+#[path = "web_tests_error_copy_wire_tests.rs"]
+mod wire_tests;
diff --git a/crates/openhuman-core/src/web_chat/web_tests_error_copy_wire_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_error_copy_wire_tests.rs
new file mode 100644
index 0000000000..4ebcce1fb2
--- /dev/null
+++ b/crates/openhuman-core/src/web_chat/web_tests_error_copy_wire_tests.rs
@@ -0,0 +1,213 @@
+//! Wire metadata assertions for the shared failure-copy table.
+
+use super::*;
+use crate::web_chat::WebChannelEvent;
+
+const EXPECTED_COPY_KEYS: &[(&str, &str, &str)] = &[
+ (
+ "codex_expired",
+ "chat_error.codex_session_expired",
+ r#"{"provider":"openai_codex"}"#,
+ ),
+ ("session_expired", "chat_error.session_expired", "null"),
+ (
+ "local_session_managed",
+ "chat_error.local_session_managed_unavailable",
+ "null",
+ ),
+ ("action_budget", "chat_error.action_budget", "null"),
+ ("max_iterations", "chat_error.max_iterations", "null"),
+ ("turn_timeout_marker", "chat_error.turn_timeout", "null"),
+ ("turn_timeout_harness", "chat_error.turn_timeout", "null"),
+ ("empty_response", "chat_error.empty_response", "null"),
+ (
+ "chat_template",
+ "chat_error.chat_template_rejected",
+ r#"{"provider":"openai"}"#,
+ ),
+ (
+ "rate_limited_transient",
+ "chat_error.rate_limited",
+ r#"{"provider":"openrouter","retry_after_secs":30}"#,
+ ),
+ (
+ "rate_limited_business",
+ "chat_error.rate_limited_billing",
+ r#"{"provider":"openai"}"#,
+ ),
+ ("timeout", "chat_error.timeout", "null"),
+ (
+ "auth_error",
+ "chat_error.auth_error",
+ r#"{"provider":"openai"}"#,
+ ),
+ (
+ "budget_402",
+ "chat_error.budget_exhausted",
+ r#"{"provider":"openai"}"#,
+ ),
+ ("budget_phrase", "chat_error.budget_exhausted", "null"),
+ (
+ "budget_phrase_provider_source",
+ "chat_error.budget_exhausted",
+ r#"{"provider":"openrouter"}"#,
+ ),
+ (
+ "provider_5xx",
+ "chat_error.provider_unavailable",
+ r#"{"provider":"anthropic"}"#,
+ ),
+ ("context_overflow", "chat_error.context_overflow", "null"),
+ (
+ "config_rejection",
+ "chat_error.model_unavailable",
+ r#"{"provider":"openai"}"#,
+ ),
+ ("model_unavailable", "chat_error.model_unavailable", "null"),
+ ("model_transient", "chat_error.provider_unavailable", "null"),
+ ("vision", "chat_error.capability_unsupported", "null"),
+ (
+ "malformed_history_byo",
+ "chat_error.malformed_history",
+ r#"{"provider":"openai"}"#,
+ ),
+ (
+ "request_rejected_4xx",
+ "chat_error.request_rejected",
+ r#"{"provider":"someprovider"}"#,
+ ),
+ ("network", "chat_error.network", "null"),
+ (
+ "transient_529",
+ "chat_error.provider_unavailable",
+ r#"{"provider":"anthropic"}"#,
+ ),
+ ("generic", "chat_error.inference", "null"),
+ ("fallback_chain", "chat_error.inference", "null"),
+ (
+ "be_rate_limited",
+ "chat_error.managed_rate_limited",
+ r#"{"provider":"openhuman","retry_after_secs":30}"#,
+ ),
+ (
+ "be_credits",
+ "chat_error.managed_budget_exhausted",
+ r#"{"provider":"openhuman"}"#,
+ ),
+ (
+ "be_upstream",
+ "chat_error.managed_unavailable",
+ r#"{"provider":"openhuman"}"#,
+ ),
+ (
+ "be_model_unavailable",
+ "chat_error.managed_unavailable",
+ r#"{"provider":"openhuman"}"#,
+ ),
+ (
+ "be_payload",
+ "chat_error.payload_too_large",
+ r#"{"provider":"openhuman"}"#,
+ ),
+ (
+ "be_context",
+ "chat_error.context_overflow",
+ r#"{"provider":"openhuman"}"#,
+ ),
+ (
+ "be_bad_request",
+ "chat_error.managed_request_rejected",
+ r#"{"provider":"openhuman"}"#,
+ ),
+ (
+ "be_bad_request_malformed",
+ "chat_error.managed_malformed_request",
+ r#"{"provider":"openhuman"}"#,
+ ),
+ (
+ "be_bad_request_history",
+ "chat_error.malformed_history",
+ r#"{"provider":"openhuman"}"#,
+ ),
+ (
+ "be_internal",
+ "chat_error.managed_internal",
+ r#"{"provider":"openhuman"}"#,
+ ),
+];
+
+#[test]
+fn every_failure_class_carries_its_i18n_key_and_params() {
+ assert_eq!(EXPECTED_COPY_KEYS.len(), EXPECTED.len());
+ for ((case, input, ..), (key_case, copy_key, params)) in
+ EXPECTED.iter().zip(EXPECTED_COPY_KEYS.iter())
+ {
+ assert_eq!(case, key_case, "fixture rows out of order");
+ let got = classify_inference_error(input);
+ assert_eq!(got.copy_key, *copy_key, "{case}: copy_key");
+ let got_params = got
+ .copy_params
+ .map(|v| v.to_string())
+ .unwrap_or_else(|| "null".to_string());
+ assert_eq!(got_params, *params, "{case}: copy_params");
+ }
+}
+
+#[test]
+fn provider_detail_travels_as_a_param_and_the_message_still_quotes_it() {
+ let got = classify_inference_error(
+ r#"openai API error (400): {"error":{"message":"bad temperature for this model"}}"#,
+ );
+ let params = got.copy_params.expect("provider + detail params");
+ let detail = params["detail"].as_str().expect("detail param");
+ assert!(detail.contains("bad temperature"), "{detail}");
+ assert!(
+ got.message.ends_with(&format!("\n\n> {detail}")),
+ "message must keep quoting the detail: {}",
+ got.message
+ );
+}
+
+#[test]
+fn chat_error_event_serializes_copy_key_and_params_to_literal_json() {
+ let classified =
+ classify_inference_error("openrouter API error (429 Too Many Requests): Retry-After: 30");
+ let event = WebChannelEvent::ChatError {
+ context: crate::web_chat::WebEventContext::default(),
+ message: Some(classified.message.clone()),
+ error_type: Some(classified.error_type.to_string()),
+ error_source: None,
+ error_retryable: None,
+ error_retry_after_ms: None,
+ error_provider: None,
+ error_fallback_available: None,
+ copy_key: Some(classified.copy_key.to_string()),
+ copy_params: classified.copy_params,
+ guardrail: None,
+ };
+ let json = serde_json::to_value(&event).expect("serializes");
+ assert_eq!(json["copy_key"], "chat_error.rate_limited");
+ assert_eq!(
+ json["copy_params"],
+ serde_json::json!({"provider": "openrouter", "retry_after_secs": 30})
+ );
+ assert_eq!(json["error_type"], "rate_limited");
+ assert_eq!(json["message"], classified.message);
+
+ // Older emitters (cancellation, guardrail) carry neither key.
+ let bare = serde_json::to_value(WebChannelEvent::ChatError {
+ context: crate::web_chat::WebEventContext::default(),
+ message: None,
+ error_type: None,
+ error_source: None,
+ error_retryable: None,
+ error_retry_after_ms: None,
+ error_provider: None,
+ error_fallback_available: None,
+ copy_key: None,
+ copy_params: None,
+ guardrail: None,
+ })
+ .expect("serializes");
+ assert!(bare.get("copy_key").is_none() && bare.get("copy_params").is_none());
+}