ruvector/crates/rvAgent/rvagent-tools/tests/execute_tests.rs
ruvnet 96d8fdc172 chore(workspace): cargo fmt — mechanical whitespace fix across 427 files
Pre-existing rustfmt drift across the workspace was blocking CI's
`Rustfmt` check on PR #373 + PR #377. Running plain `cargo fmt`
reformats 427 files; no semantic changes, no logic changes, no
behavior changes — just what rustfmt already wanted.

None of the touched files are in ruvector-rabitq, ruvector-rulake,
or the new mirror-rulake workflow — those were already fmt-clean
per the per-crate checks on commits 5a4b0d782, 5f32fd450, f5003bc7b.
Drift is in cognitum-gate-kernel, mcp-brain, nervous-system,
prime-radiant, ruqu-core, ruvector-attention, ruvector-mincut,
ruvix/* and sub-crates, plus several examples.

Verified post-fmt:
  cargo check -p ruvector-rabitq -p ruvector-rulake            → clean
  cargo clippy -p ... -p ... --all-targets -- -D warnings      → clean
  cargo test   -p ... -p ... --release                         → 82/82 pass

Intentionally does NOT touch clippy drift — many more warnings
(missing docs, precision-loss casts, too-many-args, unsafe-safety-
docs) spread across unrelated crates, each category a cross-cutting
design decision that deserves its own review.

With this commit Rustfmt CI goes green on PR #373 and PR #377.
Clippy will still fail — that's honest pre-existing state for a
separate dedicated PR.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-04-24 10:44:02 -04:00

110 lines
3 KiB
Rust

//! Integration tests for the `execute` tool.
use rvagent_tools::{
Backend, BackendRef, ExecuteResponse, ExecuteTool, FileInfo, GrepMatch, Tool, ToolResult,
ToolRuntime, WriteResult,
};
use std::sync::Arc;
/// Mock backend that simulates command execution.
struct ExecMockBackend;
impl Backend for ExecMockBackend {
fn ls_info(&self, _: &str) -> Result<Vec<FileInfo>, String> {
Ok(vec![])
}
fn read(&self, _: &str, _: usize, _: usize) -> Result<String, String> {
Ok(String::new())
}
fn write(&self, _: &str, _: &str) -> WriteResult {
WriteResult::default()
}
fn edit(&self, _: &str, _: &str, _: &str, _: bool) -> WriteResult {
WriteResult::default()
}
fn glob_info(&self, _: &str, _: &str) -> Result<Vec<String>, String> {
Ok(vec![])
}
fn grep_raw(
&self,
_: &str,
_: Option<&str>,
_: Option<&str>,
) -> Result<Vec<GrepMatch>, String> {
Ok(vec![])
}
fn execute(&self, command: &str, _timeout: u32) -> Result<ExecuteResponse, String> {
if command.contains("echo hello_world") {
Ok(ExecuteResponse {
output: "hello_world\n".into(),
exit_code: 0,
})
} else if command.contains("exit 42") {
Ok(ExecuteResponse {
output: String::new(),
exit_code: 42,
})
} else if command.contains("sleep 30") {
Err("command timed out after 1 seconds".into())
} else {
Ok(ExecuteResponse {
output: format!("executed: {}", command),
exit_code: 0,
})
}
}
}
fn exec_runtime() -> ToolRuntime {
ToolRuntime::new(Arc::new(ExecMockBackend) as BackendRef)
}
#[test]
fn test_execute_echo() {
let runtime = exec_runtime();
let result = ExecuteTool.invoke(serde_json::json!({"command": "echo hello_world"}), &runtime);
match result {
ToolResult::Text(s) => {
assert!(
s.contains("hello_world"),
"should capture echo output, got: {}",
s
);
}
_ => panic!("expected Text result from execute"),
}
}
#[test]
fn test_execute_exit_code() {
let runtime = exec_runtime();
let result = ExecuteTool.invoke(serde_json::json!({"command": "exit 42"}), &runtime);
match result {
ToolResult::Text(s) => {
assert!(
s.contains("exit code: 42"),
"should report exit code 42, got: {}",
s
);
}
_ => panic!("expected Text result from execute"),
}
}
#[test]
fn test_execute_timeout() {
let runtime = exec_runtime();
let result = ExecuteTool.invoke(
serde_json::json!({"command": "sleep 30", "timeout": 1}),
&runtime,
);
match result {
ToolResult::Text(s) => {
assert!(s.contains("timed out"), "should report timeout, got: {}", s);
}
_ => panic!("expected Text timeout from execute"),
}
}