Skip to content

Commit fd729ca

Browse files
kinohclaude
andcommitted
refactor: improve binary discovery using CARGO_BIN_EXE environment variable
- Use CARGO_BIN_EXE_scheduler provided by cargo test instead of manual path construction - Remove unnecessary ensure_binary_built() function and Command import - Add fallback to manual path construction for non-cargo execution contexts - Simplify test setup and make binary discovery more reliable Based on rust-lang/cargo#7697 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 982dca2 commit fd729ca

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

mcp/scheduler/tests/integration_scheduler.rs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde_json::{Value, json};
2-
use std::process::{Command, Stdio};
2+
use std::process::Stdio;
33
use std::time::Duration;
44
use tempfile::TempDir;
55
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, Lines};
@@ -17,9 +17,14 @@ pub struct McpClient {
1717
impl McpClient {
1818
/// Start scheduler server and create MCP client
1919
pub async fn new(temp_dir: &TempDir) -> Result<Self, Box<dyn std::error::Error>> {
20-
let binary_path = std::env::current_dir()
21-
.unwrap()
22-
.join("target/debug/scheduler");
20+
let binary_path = std::env::var("CARGO_BIN_EXE_scheduler").unwrap_or_else(|_| {
21+
// Fallback for manual execution
22+
std::env::current_dir()
23+
.unwrap()
24+
.join("target/debug/scheduler")
25+
.to_string_lossy()
26+
.to_string()
27+
});
2328

2429
let mut child = TokioCommand::new(binary_path)
2530
.env("TZ", "UTC")
@@ -191,24 +196,8 @@ fn setup_test_env() -> TempDir {
191196
TempDir::new().expect("Failed to create temporary directory")
192197
}
193198

194-
/// Build the scheduler binary before running tests
195-
fn ensure_binary_built() {
196-
let output = Command::new("cargo")
197-
.args(["build", "--bin", "scheduler"])
198-
.output()
199-
.expect("Failed to execute cargo build");
200-
201-
if !output.status.success() {
202-
panic!(
203-
"Failed to build scheduler binary: {}",
204-
String::from_utf8_lossy(&output.stderr)
205-
);
206-
}
207-
}
208-
209199
#[tokio::test]
210200
async fn test_server_initialization() {
211-
ensure_binary_built();
212201
let temp_dir = setup_test_env();
213202
let mut client = McpClient::new(&temp_dir).await.unwrap();
214203

@@ -222,7 +211,6 @@ async fn test_server_initialization() {
222211

223212
#[tokio::test]
224213
async fn test_list_tools() {
225-
ensure_binary_built();
226214
let temp_dir = setup_test_env();
227215
let mut client = McpClient::new(&temp_dir).await.unwrap();
228216

@@ -246,7 +234,6 @@ async fn test_list_tools() {
246234

247235
#[tokio::test]
248236
async fn test_list_resources() {
249-
ensure_binary_built();
250237
let temp_dir = setup_test_env();
251238
let mut client = McpClient::new(&temp_dir).await.unwrap();
252239

@@ -273,7 +260,6 @@ async fn test_list_resources() {
273260

274261
#[tokio::test]
275262
async fn test_set_schedule_daily() {
276-
ensure_binary_built();
277263
let temp_dir = setup_test_env();
278264
let mut client = McpClient::new(&temp_dir).await.unwrap();
279265

@@ -304,7 +290,6 @@ async fn test_set_schedule_daily() {
304290

305291
#[tokio::test]
306292
async fn test_set_schedule_one_time() {
307-
ensure_binary_built();
308293
let temp_dir = setup_test_env();
309294
let mut client = McpClient::new(&temp_dir).await.unwrap();
310295

@@ -332,7 +317,6 @@ async fn test_set_schedule_one_time() {
332317

333318
#[tokio::test]
334319
async fn test_set_schedule_validation_errors() {
335-
ensure_binary_built();
336320
let temp_dir = setup_test_env();
337321
let mut client = McpClient::new(&temp_dir).await.unwrap();
338322

@@ -391,7 +375,6 @@ async fn test_set_schedule_validation_errors() {
391375

392376
#[tokio::test]
393377
async fn test_remove_schedule() {
394-
ensure_binary_built();
395378
let temp_dir = setup_test_env();
396379
let mut client = McpClient::new(&temp_dir).await.unwrap();
397380

@@ -430,7 +413,6 @@ async fn test_remove_schedule() {
430413

431414
#[tokio::test]
432415
async fn test_remove_nonexistent_schedule() {
433-
ensure_binary_built();
434416
let temp_dir = setup_test_env();
435417
let mut client = McpClient::new(&temp_dir).await.unwrap();
436418

@@ -454,7 +436,6 @@ async fn test_remove_nonexistent_schedule() {
454436

455437
#[tokio::test]
456438
async fn test_data_persistence() {
457-
ensure_binary_built();
458439
let temp_dir = setup_test_env();
459440

460441
// First session: create schedule
@@ -503,7 +484,6 @@ async fn test_data_persistence() {
503484

504485
#[tokio::test]
505486
async fn test_read_fired_schedules_resource() {
506-
ensure_binary_built();
507487
let temp_dir = setup_test_env();
508488
let mut client = McpClient::new(&temp_dir).await.unwrap();
509489

0 commit comments

Comments
 (0)