返回 CodeWhale
tests.rs
根目录 / crates / error-taxonomy / src / tests.rs
1 use super::*;
2
3 #[test]
4 fn model_output_truncated_classifies_as_invalid_input_not_tool() {
5 // The turn-level "Model output truncated" error is a provider/model
6 // condition, not a tool failure: it must land in the same bucket as
7 // `LlmError::ModelError` so the exec termination classifier reduces it
8 // to `RunTerminationReason::ModelError` (never Resolved).
9 assert_eq!(
10 classify_error_message(
11 "Model output truncated: provider stop reason `max_output_tokens`; no complete response or tool call was accepted."
12 ),
13 ErrorCategory::InvalidInput
14 );
15 assert_eq!(
16 classify_error_message(
17 "Model output truncated: provider stop reason `max_tokens`; no complete response or tool call was accepted."
18 ),
19 ErrorCategory::InvalidInput
20 );
21 assert_eq!(
22 classify_error_message(
23 "Model response incomplete: provider stop reason `content_filter`; no complete response or tool call was accepted."
24 ),
25 ErrorCategory::InvalidInput
26 );
27 }
28
29 #[test]
30 fn raw_rate_and_quota_phrases_remain_coarse_rate_limit_diagnostics() {
31 for message in [
32 "Rate limit reached for gpt-4",
33 "Too Many Requests",
34 "HTTP 429 from upstream",
35 "Your quota has been exceeded",
36 "Authorization failed: You've reached your usage limit for this billing cycle",
37 ] {
38 assert_eq!(classify_error_message(message), ErrorCategory::RateLimit);
39 }
40 }
41
42 #[test]
43 fn model_not_exist_rejection_is_a_terminal_invalid_input_error() {
44 // The reported incident: a provider switch left GLM-5.3 selected on a
45 // Model Studio route; the next message failed with
46 // `Model error: Model not exist.` and the transcript rendered it as a
47 // dismissable *warning* because the stringified error fell through to
48 // `Internal` + `recoverable`. A wrong-model rejection is terminal for
49 // the request: it must classify as InvalidInput so it renders at Error
50 // severity and never as recoverable noise.
51 for message in [
52 "Model error: Model not exist.",
53 "Model not exist",
54 "Model not found: glm-5.3 on this endpoint",
55 "Unknown model identifier",
56 "Invalid model: qwen-flash",
57 ] {
58 let envelope = ErrorEnvelope::classify(message.to_string(), true);
59 assert_eq!(
60 envelope.category,
61 ErrorCategory::InvalidInput,
62 "message must classify as InvalidInput: {message}"
63 );
64 assert_eq!(
65 envelope.severity,
66 ErrorSeverity::Error,
67 "wrong-model rejections must render at Error severity: {message}"
68 );
69 // `recoverable` governs offline-mode semantics, not transcript
70 // severity: a wrong-model rejection keeps the session online so the
71 // operator can repair the route.
72 assert!(envelope.recoverable, "session stays online: {message}");
73 }
74 }
75
76 /// #6843: determinate rejections and Codewhale's own stops used to fall to
77 /// `Internal`, which `classify` renders as an amber warning. Each text below
78 /// is a row of the report's measured table.
79 #[test]
80 fn determinate_rejections_and_own_stops_are_not_internal() {
81 for (message, expected) in [
82 (
83 r#"Invalid request (400): {"message":"a single path expansion cannot exceed 512 candidates","type":"invalid_request_error"}"#,
84 ErrorCategory::InvalidInput,
85 ),
86 (
87 "SSE stream request failed: HTTP 422 Unprocessable Entity",
88 ErrorCategory::InvalidInput,
89 ),
90 (
91 "The request still exceeds this model's context budget and automatic recovery did not complete. The conversation is saved; retry or choose a larger context route.",
92 ErrorCategory::InvalidInput,
93 ),
94 (
95 "Model returned terminal stop reason `stop` with no answer or tool call (after 2 retries).",
96 ErrorCategory::InvalidInput,
97 ),
98 (
99 "Turn failed: Per-turn wall-clock budget exhausted after 86418s (limit: 86400s). The turn was stopped before another model request.",
100 ErrorCategory::Budget,
101 ),
102 ("ERROR", ErrorCategory::Parse),
103 (" error. ", ErrorCategory::Parse),
104 // Still transient, still resumable: only determinate rejections moved.
105 (
106 "Provider returned an empty response",
107 ErrorCategory::Network,
108 ),
109 ("HTTP 500 Internal Server Error", ErrorCategory::Network),
110 ("Upstream idle timeout exceeded", ErrorCategory::Timeout),
111 ] {
112 assert_eq!(classify_error_message(message), expected, "{message}");
113 }
114
115 // A rejection classified here renders as an error, not an amber warning,
116 // even through the fallback that assumes `recoverable`.
117 let envelope = ErrorEnvelope::classify(
118 "Invalid request (400): {\"type\":\"invalid_request_error\"}".to_string(),
119 true,
120 );
121 assert_eq!(envelope.category, ErrorCategory::InvalidInput);
122 assert_eq!(envelope.severity, ErrorSeverity::Error);
123 }
124
125 #[test]
126 fn bare_numbers_are_not_http_statuses() {
127 // The status vocabulary needs an "HTTP"/"status" lead-in: a count, an ID
128 // or a URL segment that happens to read 400 must not classify a failure.
129 for message in [
130 "read 400 lines from the file",
131 "https://example.com/v1/items/422",
132 "request id 500123",
133 "HTTP 4000 is not a status",
134 ] {
135 assert_eq!(
136 classify_error_message(message),
137 ErrorCategory::Internal,
138 "{message}"
139 );
140 }
141 }
142
143 #[test]
144 fn unreadable_error_notice_states_it_and_classifies_as_parse() {
145 let notice = unreadable_error_notice("ERROR").expect("bare placeholder");
146 assert!(notice.contains("unreadable error"), "{notice}");
147 assert_eq!(classify_error_message(&notice), ErrorCategory::Parse);
148 assert!(unreadable_error_notice("").is_some());
149 assert!(unreadable_error_notice("Provider returned an empty response").is_none());
150 assert!(unreadable_error_notice("model error: boom").is_none());
151 }
152
153 #[test]
154 fn a_failure_that_ended_the_work_is_never_a_warning() {
155 // #6795: an error frame that fails the turn passes `recoverable = false`.
156 // Network is a transient class, but an ended turn is an error.
157 for message in ["Provider returned an empty response", "rate limit reached"] {
158 let ended = ErrorEnvelope::classify(message.to_string(), false);
159 assert_eq!(ended.severity, ErrorSeverity::Error, "{message}");
160 assert!(!ended.recoverable);
161 let ongoing = ErrorEnvelope::classify(message.to_string(), true);
162 assert_eq!(ongoing.severity, ErrorSeverity::Warning, "{message}");
163 }
164 }
165
166 #[test]
167 fn budget_stop_is_an_error_card_that_keeps_the_session_online() {
168 let envelope = ErrorEnvelope::budget_stop("Maximum model steps reached before completion");
169 assert_eq!(envelope.category, ErrorCategory::Budget);
170 assert_eq!(envelope.severity, ErrorSeverity::Error);
171 assert!(envelope.recoverable);
172 }
173
173 lines RUST