|
1 | 1 | use super::*; |
2 | 2 |
|
| 3 | +#[test] |
| 4 | +fn missing_google_thought_signature_errors_explain_recovery() { |
| 5 | + for detail in [ |
| 6 | + "Function call is missing a thought_signature in functionCall parts.", |
| 7 | + "Function call is missing thought_signature.", |
| 8 | + "The thought_signature is missing from the function call.", |
| 9 | + ] { |
| 10 | + for body in [ |
| 11 | + detail.to_string(), |
| 12 | + serde_json::json!({"error": {"message": detail, "code": 400}}).to_string(), |
| 13 | + serde_json::json!({"error": "Bad Request", "message": detail}).to_string(), |
| 14 | + ] { |
| 15 | + let message = sanitize_http_error_body(Some("Custom"), 400, &body); |
| 16 | + assert!(message.contains("built-in `google` provider"), "{message}"); |
| 17 | + assert!(message.contains("start a new session"), "{message}"); |
| 18 | + assert!(message.contains(detail), "provider detail must survive"); |
| 19 | + assert_eq!(sanitize_http_error_body(None, 400, &message), message); |
| 20 | + let error = LlmError::from_http_response(400, &message); |
| 21 | + assert!(matches!( |
| 22 | + error, |
| 23 | + LlmError::InvalidRequest { status: 400, .. } |
| 24 | + )); |
| 25 | + assert!(!error.is_retryable()); |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +#[test] |
| 31 | +fn google_thought_signature_hint_requires_a_missing_signature_400() { |
| 32 | + for (status, detail) in [ |
| 33 | + (400, "Invalid model name"), |
| 34 | + (400, "Invalid thought_signature in functionCall parts"), |
| 35 | + (400, "Unsupported parameter: thought_signature"), |
| 36 | + ( |
| 37 | + 401, |
| 38 | + "Function call is missing a thought_signature in functionCall parts.", |
| 39 | + ), |
| 40 | + ( |
| 41 | + 429, |
| 42 | + "Function call is missing a thought_signature in functionCall parts.", |
| 43 | + ), |
| 44 | + ( |
| 45 | + 500, |
| 46 | + "Function call is missing a thought_signature in functionCall parts.", |
| 47 | + ), |
| 48 | + ] { |
| 49 | + let body = serde_json::json!({"error": {"message": detail}}).to_string(); |
| 50 | + assert_eq!( |
| 51 | + sanitize_http_error_body(Some("Custom"), status, &body), |
| 52 | + detail |
| 53 | + ); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +#[test] |
| 58 | +fn google_thought_signature_hint_keeps_large_provider_errors_bounded() { |
| 59 | + let body = format!( |
| 60 | + "Function call is missing a thought_signature in functionCall parts. {}", |
| 61 | + "界".repeat(3_000) |
| 62 | + ); |
| 63 | + let message = sanitize_http_error_body(None, 400, &body); |
| 64 | + assert!(message.contains("start a new session")); |
| 65 | + assert!(message.chars().count() < 2_000); |
| 66 | + assert_eq!(sanitize_http_error_body(None, 400, &message), message); |
| 67 | +} |
| 68 | + |
| 69 | +#[test] |
| 70 | +fn google_thought_signature_hint_preserves_quota_and_html_handling() { |
| 71 | + let detail = "Function call is missing a thought_signature in functionCall parts."; |
| 72 | + let body = serde_json::json!({ |
| 73 | + "error": {"message": detail, "code": "insufficient_quota"} |
| 74 | + }) |
| 75 | + .to_string(); |
| 76 | + let message = sanitize_http_error_body(None, 400, &body); |
| 77 | + assert!(matches!( |
| 78 | + LlmError::from_http_response(400, &message), |
| 79 | + LlmError::QuotaExhausted(_) |
| 80 | + )); |
| 81 | + let html = format!("<!doctype html><html><body>{detail}</body></html>"); |
| 82 | + let message = sanitize_http_error_body(None, 400, &html); |
| 83 | + assert!(message.contains("HTML error page")); |
| 84 | + assert!(!message.contains("<html>")); |
| 85 | +} |
| 86 | + |
3 | 87 | #[test] |
4 | 88 | fn retryability_distinguishes_transient_failures_from_durable_failures() { |
5 | 89 | for error in [ |
|
0 commit comments