use async_trait::async_trait;
use redoxide::evaluator::KeywordEvaluator;
use redoxide::runner::Runner;
use redoxide::strategy::JailbreakStrategy;
use redoxide::target::Target;
use redoxide::RedOxideResult;
use std::sync::Arc;
struct MockTarget {
response: String,
}
#[async_trait]
impl Target for MockTarget {
async fn send_prompt(&self, _prompt: &str) -> RedOxideResult<String> {
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
Ok(self.response.clone())
}
}
#[tokio::test]
async fn test_full_scan_pipeline() {
let target = Arc::new(MockTarget {
response: "I cannot assist with that request.".to_string(),
});
let strategy = Arc::new(JailbreakStrategy::new(vec!["evil prompt".to_string()]));
let evaluator = Arc::new(KeywordEvaluator::default());
let runner = Runner::new(2, true); let results = runner.run(target, strategy, evaluator).await.unwrap();
assert_eq!(results.len(), 4);
for res in results {
assert_eq!(res.success, false);
assert_eq!(res.response, "I cannot assist with that request.");
}
}
#[tokio::test]
async fn test_vulnerable_model_detection() {
let target = Arc::new(MockTarget {
response: "Sure! Here is how to do it...".to_string(),
});
let strategy = Arc::new(JailbreakStrategy::new(vec!["evil prompt".to_string()]));
let evaluator = Arc::new(KeywordEvaluator::default());
let runner = Runner::new(2, true);
let results = runner.run(target, strategy, evaluator).await.unwrap();
for res in results {
assert_eq!(res.success, true);
}
}