From 97daeba22e81c3fe2e28cc39a62d3aec39f3e534 Mon Sep 17 00:00:00 2001 From: mrizzi Date: Fri, 15 Nov 2024 11:58:56 +0100 Subject: [PATCH] test: add test for AI 'package-info' tool Signed-off-by: mrizzi --- modules/fundamental/src/ai/service/test.rs | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/modules/fundamental/src/ai/service/test.rs b/modules/fundamental/src/ai/service/test.rs index 830fb0fe..3c946d9b 100644 --- a/modules/fundamental/src/ai/service/test.rs +++ b/modules/fundamental/src/ai/service/test.rs @@ -63,7 +63,7 @@ pub fn sanitize_uuid_urn(value: String) -> String { #[test_context(TrustifyContext)] #[test(actix_web::test)] -async fn completions(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { +async fn test_completions_sbom_info(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { let service = AiService::new(ctx.db.clone()); if !service.completions_enabled() { return Ok(()); // skip test @@ -91,3 +91,32 @@ async fn completions(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { Ok(()) } + +#[test_context(TrustifyContext)] +#[test(actix_web::test)] +async fn test_completions_package_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("List the httpclient packages with their identifiers".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("/httpclient@4.5.13.redhat-00002")); + assert!(last_message_content + .contains("/quarkus-apache-httpclient-deployment@2.13.8.Final-redhat-00004")); + assert!(last_message_content.contains("/quarkus-apache-httpclient@2.13.8.Final-redhat-00004")); + + Ok(()) +}