use std::path::Path;
use crate::languages::runner::resolve_tool_in;
use crate::languages::spec::ToolSpec;
use crate::test_support::make_executable;
#[test]
fn path_lookup_skips_non_executable_then_returns_it_when_executable() {
let dir = tempfile::tempdir().expect("tempdir");
let tool = dir.path().join("mytool");
std::fs::write(&tool, "#!/bin/sh\necho ok\n").expect("write tool");
let spec = ToolSpec {
name: "mytool",
command: &["mytool"],
local_paths: &[],
..ToolSpec::default()
};
let path = std::env::join_paths([dir.path()]).expect("a single dir joins");
let root = Path::new("/nonexistent-root-for-test");
assert!(
resolve_tool_in(&spec, root, Some(path.as_os_str())).is_none(),
"a non-executable PATH entry must be skipped"
);
make_executable(&tool);
assert_eq!(
resolve_tool_in(&spec, root, Some(path.as_os_str())).as_deref(),
Some(tool.as_path()),
"after chmod +x, the lookup must return the same file"
);
}