Skip to content

Commit

Permalink
test: add test for AI 'advisory-info' tool
Browse files Browse the repository at this point in the history
Signed-off-by: mrizzi <[email protected]>
  • Loading branch information
mrizzi committed Nov 19, 2024
1 parent 66c20fd commit ebad071
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions modules/fundamental/src/ai/service/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub async fn ingest_fixtures(ctx: &TrustifyContext) -> Result<(), anyhow::Error>
.await?;
ctx.ingest_document("quarkus/v1/quarkus-bom-2.13.8.Final-redhat-00004.json")
.await?;
ctx.ingest_document("csaf/rhsa-2024_3666.json").await?;

Ok(())
}
Expand Down Expand Up @@ -148,3 +149,33 @@ async fn test_completions_cve_info(ctx: &TrustifyContext) -> Result<(), anyhow::

Ok(())
}

#[test_context(TrustifyContext)]
#[test(actix_web::test)]
async fn test_completions_advisory_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 the RHSA-2024_3666 advisory".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("RHSA-2024_3666"));
assert!(last_message_content.contains("Apache Tomcat"));
assert!(last_message_content.contains("CVE-2024-23672"));
assert!(last_message_content.contains("CVE-2024-24549"));
assert!(last_message_content.contains("DoS"));

Ok(())
}

0 comments on commit ebad071

Please sign in to comment.