Skip to content

Commit

Permalink
AI Add 'sbom-info' tool test
Browse files Browse the repository at this point in the history
Signed-off-by: mrizzi <[email protected]>
  • Loading branch information
mrizzi committed Nov 13, 2024
1 parent a6e9a09 commit bb742b1
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 6 deletions.
103 changes: 103 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion modules/fundamental/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ tokio-util = { workspace = true }
trustify-cvss = { workspace = true }
trustify-test-context = { workspace = true }
urlencoding = { workspace = true }
walkdir = { workspace = true }
walkdir = { workspace = true }
zip = { workspace = true }
termimad = "0.31.0"

[[bench]]
name = "bench"
Expand Down
9 changes: 7 additions & 2 deletions modules/fundamental/src/ai/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn configure(ctx: &TrustifyContext) -> anyhow::Result<()> {

let app = caller(ctx).await?;
let mut req = ChatState::new();
req.add_human_message("What is the latest version of Trusted Profile Analyzer?".into());
req.add_human_message("Give me information about the SBOMs available for quarkus reporting its name, SHA and URL.".into());

let request = TestRequest::post()
.uri("/api/v1/ai/completions")
Expand All @@ -36,7 +36,12 @@ async fn configure(ctx: &TrustifyContext) -> anyhow::Result<()> {

let result: ChatState = actix_web::test::read_body_json(response).await;
log::info!("result: {:?}", result);
assert!(result.messages.last().unwrap().content.contains("37.17.9"));
assert!(result
.messages
.last()
.unwrap()
.content
.contains("quarkus-bom"));

Ok(())
}
Expand Down
18 changes: 15 additions & 3 deletions modules/fundamental/src/ai/service/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub async fn ingest_fixtures(ctx: &TrustifyContext) -> Result<(), anyhow::Error>

ctx.ingest_documents(["osv/RUSTSEC-2021-0079.json", "cve/CVE-2021-32714.json"])
.await?;
ctx.ingest_document("quarkus/v1/quarkus-bom-2.13.8.Final-redhat-00004.json")
.await?;

Ok(())
}
Expand Down Expand Up @@ -70,12 +72,22 @@ async fn completions(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
ingest_fixtures(ctx).await?;

let mut req = ChatState::new();
req.add_human_message("What is the latest version of Trusted Profile Analyzer?".into());
req.add_human_message(
"Give me information about the SBOMs available for quarkus reporting its name, SHA and URL."
.into(),
);

let result = service.completions(&req, ()).await?;

log::info!("result: {:?}", result);
assert!(result.messages.last().unwrap().content.contains("37.17.9"));
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("quarkus-bom"));
assert!(last_message_content
.contains("5a370574a991aa42f7ecc5b7d88754b258f81c230a73bea247c0a6fcc6f608ab"));

Ok(())
}

0 comments on commit bb742b1

Please sign in to comment.