From 2bb653010e71999554b760bbe89575e9e0a95db1 Mon Sep 17 00:00:00 2001 From: mrizzi Date: Mon, 18 Nov 2024 14:15:55 +0100 Subject: [PATCH] test: add test for AI 'cve-info' tool Signed-off-by: mrizzi --- modules/fundamental/src/ai/service/test.rs | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/fundamental/src/ai/service/test.rs b/modules/fundamental/src/ai/service/test.rs index 28fb1453..3de2c55a 100644 --- a/modules/fundamental/src/ai/service/test.rs +++ b/modules/fundamental/src/ai/service/test.rs @@ -120,3 +120,31 @@ async fn test_completions_package_info(ctx: &TrustifyContext) -> Result<(), anyh Ok(()) } + +#[test_context(TrustifyContext)] +#[test(actix_web::test)] +async fn test_completions_cve_info(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { + let service = AiService::new(ctx.db.clone()); + if !service.completions_enabled() { + return Ok(()); // skip test + } + + ingest_fixtures(ctx).await?; + + let mut req = ChatState::new(); + req.add_human_message("Give me details for CVE-2021-32714".into()); + + let result = service.completions(&req, ()).await?; + + log::info!("result: {:#?}", result); + let last_message_content = result.messages.last().unwrap().content.clone(); + println!( + "Test formatted output:\n\n{}\n", + termimad::inline(last_message_content.as_str()) + ); + assert!(last_message_content.contains("CVE-2021-32714")); + assert!(last_message_content.contains("hyper")); + assert!(last_message_content.contains("0.14.10")); + + Ok(()) +}