From 8e12db3a9111c03fe0bc734e495991570c2584f0 Mon Sep 17 00:00:00 2001 From: 4t145 Date: Tue, 24 Jun 2025 16:49:55 +0800 Subject: [PATCH 1/2] chore: cov settings, update Python test dependencies and adjust command arguments --- .vscode/settings.json | 9 +++++++++ crates/rmcp/src/transport/common/client_side_sse.rs | 3 ++- crates/rmcp/src/transport/common/server_side_http.rs | 1 + crates/rmcp/tests/test_with_python.rs | 12 ++++++++---- crates/rmcp/tests/test_with_python/.gitignore | 1 + crates/rmcp/tests/test_with_python/pyproject.toml | 4 ++-- crates/rmcp/tests/test_with_python/server.py | 2 +- docs/CONTRIBUTE.MD | 12 +++++++++++- justfile | 5 ++++- 9 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..32557850 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "coverage-gutters.coverageFileNames": [ + "coverage.lcov", + ], + "coverage-gutters.coverageBaseDir": "target/llvm-cov-target", + "coverage-gutters.showLineCoverage": true, + "coverage-gutters.showRulerCoverage": true, + "coverage-gutters.showGutterCoverage": true +} \ No newline at end of file diff --git a/crates/rmcp/src/transport/common/client_side_sse.rs b/crates/rmcp/src/transport/common/client_side_sse.rs index 6fbf67ea..2a5a4465 100644 --- a/crates/rmcp/src/transport/common/client_side_sse.rs +++ b/crates/rmcp/src/transport/common/client_side_sse.rs @@ -134,7 +134,8 @@ impl SseAutoReconnectStream { } impl SseAutoReconnectStream> { - pub fn never_reconnect(stream: BoxedSseResponse, error_when_reconnect: E) -> Self { + #[allow(dead_code)] + pub(crate) fn never_reconnect(stream: BoxedSseResponse, error_when_reconnect: E) -> Self { Self { retry_policy: Arc::new(NeverRetry), last_event_id: None, diff --git a/crates/rmcp/src/transport/common/server_side_http.rs b/crates/rmcp/src/transport/common/server_side_http.rs index a26bbff4..c8128a49 100644 --- a/crates/rmcp/src/transport/common/server_side_http.rs +++ b/crates/rmcp/src/transport/common/server_side_http.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] use std::{convert::Infallible, fmt::Display, sync::Arc, time::Duration}; use bytes::{Buf, Bytes}; diff --git a/crates/rmcp/tests/test_with_python.rs b/crates/rmcp/tests/test_with_python.rs index a08691ff..9def1722 100644 --- a/crates/rmcp/tests/test_with_python.rs +++ b/crates/rmcp/tests/test_with_python.rs @@ -18,7 +18,7 @@ async fn init() -> anyhow::Result<()> { .with(tracing_subscriber::fmt::layer()) .try_init(); tokio::process::Command::new("uv") - .args(["pip", "install", "-r", "pyproject.toml"]) + .args(["sync"]) .current_dir("tests/test_with_python") .spawn()? .wait() @@ -38,8 +38,9 @@ async fn test_with_python_client() -> anyhow::Result<()> { let status = tokio::process::Command::new("uv") .arg("run") - .arg("tests/test_with_python/client.py") + .arg("client.py") .arg(format!("http://{BIND_ADDRESS}/sse")) + .current_dir("tests/test_with_python") .spawn()? .wait() .await?; @@ -88,8 +89,9 @@ async fn test_nested_with_python_client() -> anyhow::Result<()> { tokio::time::Duration::from_secs(5), tokio::process::Command::new("uv") .arg("run") - .arg("tests/test_with_python/client.py") + .arg("client.py") .arg(format!("http://{BIND_ADDRESS}/nested/sse")) + .current_dir("tests/test_with_python") .spawn()? .wait(), ) @@ -104,7 +106,9 @@ async fn test_with_python_server() -> anyhow::Result<()> { init().await?; let transport = TokioChildProcess::new(tokio::process::Command::new("uv").configure(|cmd| { - cmd.arg("run").arg("tests/test_with_python/server.py"); + cmd.arg("run") + .arg("server.py") + .current_dir("tests/test_with_python"); }))?; let client = ().serve(transport).await?; diff --git a/crates/rmcp/tests/test_with_python/.gitignore b/crates/rmcp/tests/test_with_python/.gitignore index e69de29b..c8e48944 100644 --- a/crates/rmcp/tests/test_with_python/.gitignore +++ b/crates/rmcp/tests/test_with_python/.gitignore @@ -0,0 +1 @@ +*.lock \ No newline at end of file diff --git a/crates/rmcp/tests/test_with_python/pyproject.toml b/crates/rmcp/tests/test_with_python/pyproject.toml index f4b5a700..9c8ce6ae 100644 --- a/crates/rmcp/tests/test_with_python/pyproject.toml +++ b/crates/rmcp/tests/test_with_python/pyproject.toml @@ -7,8 +7,8 @@ name = "test_with_python" version = "0.1.0" description = "Test Python client for RMCP" dependencies = [ - "mcp", + "fastmcp", ] [tool.setuptools] -py-modules = ["client", "server"] \ No newline at end of file +py-modules = ["client", "server"] diff --git a/crates/rmcp/tests/test_with_python/server.py b/crates/rmcp/tests/test_with_python/server.py index 1e33efa4..985cc33b 100644 --- a/crates/rmcp/tests/test_with_python/server.py +++ b/crates/rmcp/tests/test_with_python/server.py @@ -1,4 +1,4 @@ -from mcp.server.fastmcp import FastMCP +from fastmcp import FastMCP mcp = FastMCP("Demo") diff --git a/docs/CONTRIBUTE.MD b/docs/CONTRIBUTE.MD index 95e3a834..8421d40e 100644 --- a/docs/CONTRIBUTE.MD +++ b/docs/CONTRIBUTE.MD @@ -10,4 +10,14 @@ just fix # How Can I Rewrite My Commit Message? You can `git reset --soft upstream/main` and `git commit --forge`, this will merge your changes into one commit. -Or you also can use git rebase. But we will still merge them into one commit when it is merged. \ No newline at end of file +Or you also can use git rebase. But we will still merge them into one commit when it is merged. + +# Check Code Coverage +If you are developing on vscode, you can use vscode plugin [Coverage Gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters) + +And also need to install llvm-cov +```sh +cargo install cargo-llvm-cov + +rustup component add llvm-tools-preview +``` diff --git a/justfile b/justfile index 970aa1a5..c7579358 100644 --- a/justfile +++ b/justfile @@ -9,4 +9,7 @@ fix: fmt cargo clippy --fix --all-targets --all-features --allow-staged test: - cargo test --all-features \ No newline at end of file + cargo test --all-features + +cov: + cargo llvm-cov --lcov --output-path {{justfile_directory()}}/target/llvm-cov-target/coverage.lcov \ No newline at end of file From 449e16dc3f7f2461b88778cac007d8355e458862 Mon Sep 17 00:00:00 2001 From: 4t145 Date: Wed, 25 Jun 2025 11:00:54 +0800 Subject: [PATCH 2/2] fix: remove .vscode dir --- .vscode/settings.json | 9 --------- docs/CONTRIBUTE.MD | 10 ++++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 32557850..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "coverage-gutters.coverageFileNames": [ - "coverage.lcov", - ], - "coverage-gutters.coverageBaseDir": "target/llvm-cov-target", - "coverage-gutters.showLineCoverage": true, - "coverage-gutters.showRulerCoverage": true, - "coverage-gutters.showGutterCoverage": true -} \ No newline at end of file diff --git a/docs/CONTRIBUTE.MD b/docs/CONTRIBUTE.MD index 8421d40e..d261c8ea 100644 --- a/docs/CONTRIBUTE.MD +++ b/docs/CONTRIBUTE.MD @@ -21,3 +21,13 @@ cargo install cargo-llvm-cov rustup component add llvm-tools-preview ``` + +If you are using goverage gutters plugin, add these config to let it know lcov output. +```json +{ + "coverage-gutters.coverageFileNames": [ + "coverage.lcov", + ], + "coverage-gutters.coverageBaseDir": "target/llvm-cov-target", +} +``` \ No newline at end of file