Skip to content

Commit e6ba285

Browse files
committed
chore: run test using CARGO_BIN_EXE_stdio
Signed-off-by: mrizzi <mrizzi@redhat.com>
1 parent eb448b8 commit e6ba285

File tree

6 files changed

+50
-22
lines changed

6 files changed

+50
-22
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ jobs:
3535
- name: Check
3636
run: cargo check
3737
- name: Test
38-
run: cargo test
38+
run: cargo test -r

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ trustify-module-fundamental = { git = "https://github.com/trustification/trustif
3131
urlencoding = "2.1"
3232

3333
[dev-dependencies]
34+
log = "0.4"
35+
rmcp = { version = "0.1.5", features = ["client", "transport-child-process"] }
3436
#trustify-test-context = { git = "https://github.com/trustification/trustify.git", tag = "v0.3.0"}
3537
trustify-test-context = { git = "https://github.com/mrizzi/trustify.git", branch = "chore-env-not-defined"}

src/bin/common/trustify.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ impl ServerHandler for Trustify {
404404
capabilities: ServerCapabilities::builder()
405405
.enable_tools()
406406
.build(),
407-
server_info: Implementation::from_build_env(),
407+
server_info: Implementation {
408+
name: format!("{}-{}", env!("CARGO_PKG_NAME"), env!("CARGO_CRATE_NAME")).to_owned(),
409+
version: env!("CARGO_PKG_VERSION").to_owned(),
410+
},
408411
instructions: Some("This server provides tools for interacting with a Trustify remote instance. The tools are able to retrieve info about the Trustify instance itself, the list of the SBOMs ingested, the packages and the vulnerabilities related to each SBOM. Further it can retrieve the vulnerabilities information ingested. More information about Trustify at https://github.com/trustification/trustify".to_string()),
409412
}
410413
}

tests/integration_test.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1+
use anyhow::Error;
2+
use rmcp::{ServiceExt, transport::TokioChildProcess};
13
use serde_json::json;
2-
use std::process::Command;
4+
use std::{env, process::Command};
35
use trustify_test_context::subset::ContainsSubset;
46

57
#[test]
6-
fn tools_list() {
7-
let output = Command::new("sh").arg("-c").arg("npx @modelcontextprotocol/inspector --cli --config ./tests/mcp-inspector-tests-config.json --server trustify-stdio --method tools/list")
8-
// set timeouts (in milliseconds) in order to allow the `cargo run` from mcp-inspector-tests-config.json to run successfully
9-
.env("MCP_SERVER_REQUEST_TIMEOUT", "120000")
10-
.env("MCP_REQUEST_MAX_TOTAL_TIMEOUT", "120000")
8+
fn tools_list_mcp_inspector() {
9+
let inspector_commmand = format!(
10+
"npx @modelcontextprotocol/inspector --cli {} --method tools/list",
11+
env!("CARGO_BIN_EXE_stdio")
12+
);
13+
log::debug!("inspector command: {}", inspector_commmand);
14+
let output = Command::new("sh")
15+
.arg("-c")
16+
.arg(inspector_commmand)
17+
.env("API_URL", "")
18+
.env("OPENID_ISSUER_URL", "")
19+
.env("OPENID_CLIENT_ID", "")
20+
.env("OPENID_CLIENT_SECRET", "")
1121
.output()
1222
.expect("failed to execute process");
1323

1424
let result = serde_json::from_str(str::from_utf8(&output.stdout).unwrap_or_default())
1525
.unwrap_or_default();
26+
log::debug!("{:#?}", result);
27+
log::debug!("{:#?}", str::from_utf8(&output.stderr).unwrap_or_default());
1628
let expected_result = json!({
1729
"tools": [
1830
{
@@ -251,3 +263,27 @@ fn tools_list() {
251263
});
252264
assert!(expected_result.contains_subset(result));
253265
}
266+
267+
#[tokio::test]
268+
async fn tools_list_mcp_client() -> Result<(), Error> {
269+
let mut command = tokio::process::Command::new(env!("CARGO_BIN_EXE_stdio"));
270+
command
271+
.env("API_URL", "")
272+
.env("OPENID_ISSUER_URL", "")
273+
.env("OPENID_CLIENT_ID", "")
274+
.env("OPENID_CLIENT_SECRET", "");
275+
// Start server
276+
let service = ().serve(TokioChildProcess::new(&mut command)?).await?;
277+
278+
// Initialize
279+
let server_info = service.peer_info();
280+
log::debug!("Connected to server: {server_info:#?}");
281+
assert_eq!(server_info.server_info.name, "mcp-stdio");
282+
283+
// List tools
284+
let tools = service.list_all_tools().await?;
285+
log::debug!("Available tools: {tools:#?}");
286+
assert_eq!(tools.len(), 10);
287+
288+
Ok(())
289+
}

tests/mcp-inspector-tests-config.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)