Skip to content

Commit

Permalink
test: add test for AI 'package-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 15, 2024
1 parent ed72d87 commit 97daeba
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion modules/fundamental/src/ai/service/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("/[email protected]"));
assert!(last_message_content
.contains("/[email protected]"));
assert!(last_message_content.contains("/[email protected]"));

Ok(())
}

0 comments on commit 97daeba

Please sign in to comment.