修复搜索工具错误

This commit is contained in:
xiaoxixi 2026-07-16 22:34:06 +08:00
parent a73f9edda2
commit 1c59880f64

View File

@ -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();