Skip to content

Computer use CLI for AI agents

test: add notification error and filter matching tests

Lahfir2374330bb1af
diff --git a/crates/core/src/error.rs b/crates/core/src/error.rs
index 8c3506b49..4fc1b4ff7 100644
--- a/crates/core/src/error.rs
+++ b/crates/core/src/error.rs
@@ -163,3 +163,23 @@ impl AppError {
AppError::Adapter(AdapterError::new(ErrorCode::InvalidArgs, msg))
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn notification_not_found_error_has_correct_code() {
+ let err = AdapterError::notification_not_found(5);
+ assert_eq!(err.code, ErrorCode::NotificationNotFound);
+ assert!(err.message.contains("5"));
+ assert!(err.suggestion.is_some());
+ }
+
+ #[test]
+ fn error_code_serialization() {
+ let code = ErrorCode::NotificationNotFound;
+ let json = serde_json::to_string(&code).unwrap();
+ assert_eq!(json, "\"NOTIFICATION_NOT_FOUND\"");
+ }
+}
diff --git a/crates/macos/src/notifications/list.rs b/crates/macos/src/notifications/list.rs
index 4e4928305..ae1b6e42b 100644
--- a/crates/macos/src/notifications/list.rs
+++ b/crates/macos/src/notifications/list.rs
@@ -231,3 +231,55 @@ fn matches_filters(
fn list_from_nc(_filter: &NotificationFilter) -> Result<Vec<NotificationInfo>, AdapterError> {
Err(AdapterError::not_supported("list_notifications"))
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn make_info(app: &str, title: &str, body: Option<&str>) -> NotificationInfo {
+ NotificationInfo {
+ index: 1,
+ app_name: app.into(),
+ title: title.into(),
+ body: body.map(String::from),
+ timestamp: None,
+ actions: vec![],
+ }
+ }
+
+ #[test]
+ fn matches_filters_no_filter() {
+ let info = make_info("Slack", "Hello", None);
+ assert!(matches_filters(&info, &None, &None));
+ }
+
+ #[test]
+ fn matches_filters_app_match() {
+ let info = make_info("Slack", "Hello", None);
+ assert!(matches_filters(&info, &Some("slack".into()), &None));
+ assert!(!matches_filters(&info, &Some("teams".into()), &None));
+ }
+
+ #[test]
+ fn matches_filters_text_match() {
+ let info = make_info("Slack", "Hello world", Some("body text"));
+ assert!(matches_filters(&info, &None, &Some("hello".into())));
+ assert!(matches_filters(&info, &None, &Some("body".into())));
+ assert!(!matches_filters(&info, &None, &Some("missing".into())));
+ }
+
+ #[test]
+ fn matches_filters_combined() {
+ let info = make_info("Slack", "Hello", None);
+ assert!(matches_filters(
+ &info,
+ &Some("slack".into()),
+ &Some("hello".into())
+ ));
+ assert!(!matches_filters(
+ &info,
+ &Some("teams".into()),
+ &Some("hello".into())
+ ));
+ }
+}