chore: re-add tests, tidy up goose-cli/Cargo.toml, send + sync logic (#1193)

This commit is contained in:
Kalvin C
2025-02-11 10:16:05 -08:00
committed by GitHub
parent 2386a6a864
commit 145cdf2937
4 changed files with 66 additions and 12 deletions

View File

@@ -47,7 +47,6 @@ chrono = "0.4"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json", "time"] }
tracing-appender = "0.2"
once_cell = "1.20.2"
winapi = { version = "0.3", features = ["wincred"], optional = true }
[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["wincred"] }

View File

@@ -4,10 +4,6 @@ use std::process::Command;
pub struct MacOSAutomation;
// MacOSAutomation is Send + Sync because it contains no shared state
unsafe impl Send for MacOSAutomation {}
unsafe impl Sync for MacOSAutomation {}
impl SystemAutomation for MacOSAutomation {
fn execute_system_script(&self, script: &str) -> std::io::Result<String> {
let output = Command::new("osascript").arg("-e").arg(script).output()?;

View File

@@ -4,10 +4,6 @@ use std::process::Command;
pub struct WindowsAutomation;
// WindowsAutomation is Send + Sync because it contains no shared state
unsafe impl Send for WindowsAutomation {}
unsafe impl Sync for WindowsAutomation {}
impl SystemAutomation for WindowsAutomation {
fn execute_system_script(&self, script: &str) -> std::io::Result<String> {
let output = Command::new("powershell")

View File

@@ -996,6 +996,69 @@ mod tests {
assert!(result.is_ok());
}
#[tokio::test]
#[serial]
async fn test_text_editor_size_limits() {
// Create temp directory first so it stays in scope for the whole test
let temp_dir = tempfile::tempdir().unwrap();
std::env::set_current_dir(&temp_dir).unwrap();
// Get router after setting current directory
let router = get_router().await;
// Test file size limit
{
let large_file_path = temp_dir.path().join("large.txt");
let large_file_str = large_file_path.to_str().unwrap();
// Create a file larger than 2MB
let content = "x".repeat(3 * 1024 * 1024); // 3MB
std::fs::write(&large_file_path, content).unwrap();
let result = router
.call_tool(
"text_editor",
json!({
"command": "view",
"path": large_file_str
}),
)
.await;
assert!(result.is_err());
let err = result.err().unwrap();
assert!(matches!(err, ToolError::ExecutionError(_)));
assert!(err.to_string().contains("too large"));
}
// Test character count limit
{
let many_chars_path = temp_dir.path().join("many_chars.txt");
let many_chars_str = many_chars_path.to_str().unwrap();
// Create a file with more than 400K characters but less than 400KB
let content = "x".repeat(405_000);
std::fs::write(&many_chars_path, content).unwrap();
let result = router
.call_tool(
"text_editor",
json!({
"command": "view",
"path": many_chars_str
}),
)
.await;
assert!(result.is_err());
let err = result.err().unwrap();
assert!(matches!(err, ToolError::ExecutionError(_)));
assert!(err.to_string().contains("too many characters"));
}
// Let temp_dir drop naturally at end of scope
}
#[tokio::test]
#[serial]
async fn test_text_editor_write_and_view_file() {