Skip to content

Commit ebf090d

Browse files
committed
add tests
1 parent 4b522ec commit ebf090d

File tree

1 file changed

+97
-0
lines changed
  • crates/chat-cli/src/api_client

1 file changed

+97
-0
lines changed

crates/chat-cli/src/api_client/mod.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ mod tests {
633633
IdeCategory,
634634
OperatingSystem,
635635
};
636+
use bstr::ByteSlice;
636637

637638
use super::*;
638639
use crate::api_client::model::UserInputMessage;
@@ -708,4 +709,100 @@ mod tests {
708709
}
709710
assert_eq!(output_content, "Hello! How can I assist you today?");
710711
}
712+
713+
#[test]
714+
fn test_classify_error_kind() {
715+
use aws_smithy_runtime_api::http::Response;
716+
use aws_smithy_types::body::SdkBody;
717+
718+
use crate::api_client::error::{
719+
GenerateAssistantResponseError,
720+
SdkError,
721+
};
722+
723+
let mock_sdk_error = || {
724+
SdkError::service_error(
725+
GenerateAssistantResponseError::unhandled("test"),
726+
Response::new(500.try_into().unwrap(), SdkBody::empty()),
727+
)
728+
};
729+
730+
let test_cases: Vec<(Option<u16>, &[u8], Option<&str>, ConverseStreamErrorKind)> = vec![
731+
(
732+
Some(400),
733+
b"Input is too long.",
734+
None,
735+
ConverseStreamErrorKind::ContextWindowOverflow,
736+
),
737+
(
738+
Some(500),
739+
b"INSUFFICIENT_MODEL_CAPACITY",
740+
Some("model-1"),
741+
ConverseStreamErrorKind::ModelOverloadedError,
742+
),
743+
(
744+
Some(500),
745+
b"Encountered unexpectedly high load when processing the request, please try again.",
746+
Some("model-1"),
747+
ConverseStreamErrorKind::ModelOverloadedError,
748+
),
749+
(
750+
Some(429),
751+
b"Rate limit exceeded",
752+
None,
753+
ConverseStreamErrorKind::Throttling,
754+
),
755+
(
756+
Some(400),
757+
b"MONTHLY_REQUEST_COUNT exceeded",
758+
None,
759+
ConverseStreamErrorKind::MonthlyLimitReached,
760+
),
761+
(
762+
Some(429),
763+
b"Input is too long.",
764+
None,
765+
ConverseStreamErrorKind::ContextWindowOverflow,
766+
),
767+
(
768+
Some(429),
769+
b"INSUFFICIENT_MODEL_CAPACITY",
770+
Some("model-1"),
771+
ConverseStreamErrorKind::ModelOverloadedError,
772+
),
773+
(
774+
Some(500),
775+
b"Encountered unexpectedly high load when processing the request, please try again.",
776+
None,
777+
ConverseStreamErrorKind::Unknown {
778+
reason_code: "test".to_string(),
779+
},
780+
),
781+
(
782+
Some(400),
783+
b"Encountered unexpectedly high load when processing the request, please try again.",
784+
Some("model-1"),
785+
ConverseStreamErrorKind::Unknown {
786+
reason_code: "test".to_string(),
787+
},
788+
),
789+
(Some(500), b"Some other error", None, ConverseStreamErrorKind::Unknown {
790+
reason_code: "test".to_string(),
791+
}),
792+
];
793+
794+
for (status_code, body, model_id, expected) in test_cases {
795+
let result = classify_error_kind(status_code, body, model_id, &mock_sdk_error());
796+
assert_eq!(
797+
std::mem::discriminant(&result),
798+
std::mem::discriminant(&expected),
799+
"expected '{}', got '{}' | status_code: {:?}, body: '{}', model_id: '{:?}'",
800+
expected,
801+
result,
802+
status_code,
803+
body.to_str_lossy(),
804+
model_id
805+
);
806+
}
807+
}
711808
}

0 commit comments

Comments
 (0)