From 1c59880f64bdc1976c0cc9d82a3a9ede6db1d385 Mon Sep 17 00:00:00 2001 From: xiaoxixi Date: Thu, 16 Jul 2026 22:34:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=90=9C=E7=B4=A2=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tools/file_search.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/tools/file_search.rs b/src/tools/file_search.rs index 8ebff77..b9544a4 100644 --- a/src/tools/file_search.rs +++ b/src/tools/file_search.rs @@ -189,7 +189,6 @@ impl FileSearchTool { .arg(pattern) .arg("--color") .arg("never") - .arg("--strip-cwd-prefix") .arg("--max-results") .arg(max_results.to_string()) .stdout(Stdio::piped()) @@ -360,6 +359,45 @@ mod tests { use std::fs; use tempfile::TempDir; + #[cfg(unix)] + #[tokio::test] + async fn fd_search_path_does_not_use_incompatible_strip_cwd_prefix() { + use std::os::unix::fs::PermissionsExt; + + let dir = TempDir::new().unwrap(); + let fake_fd = dir.path().join("fd"); + fs::write( + &fake_fd, + r#"#!/bin/sh +for arg in "$@"; do + if [ "$arg" = "--strip-cwd-prefix" ]; then + echo "--strip-cwd-prefix conflicts with --search-path" >&2 + exit 2 + fi +done +printf '%s\n' 'example.rs' +"#, + ) + .unwrap(); + let mut permissions = fs::metadata(&fake_fd).unwrap().permissions(); + permissions.set_mode(0o755); + fs::set_permissions(&fake_fd, permissions).unwrap(); + + let tool = FileSearchTool::new(); + let results = tool + .search_with_fd( + "*.rs", + dir.path().to_str().unwrap(), + true, + 10, + fake_fd.to_str().unwrap(), + ) + .await + .unwrap(); + + assert_eq!(results, vec!["example.rs"]); + } + #[tokio::test] async fn test_file_search_rust_fallback() { let dir = TempDir::new().unwrap();