Refactor API integration and enhance command handling
- Removed unused modules and updated module paths for clarity. - Added autocomplete functionality for command input in InputState. - Updated AppStateRest to include a method for checking if a turn is in flight. - Refactored subagent engine to use new API client structure. - Changed default provider from "openrouter" to "zen" with updated API keys and models. - Implemented tests for memory management and edit log functionalities. - Enhanced error handling in API requests and improved response parsing. - Updated UI components to reflect new API provider and status indicators.
This commit is contained in:
@@ -115,3 +115,123 @@ impl Default for Harness {
|
||||
Harness
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::app::state::types::AgentMode;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn test_verdict_is_allowed() {
|
||||
assert!(Verdict::Allow.is_allowed());
|
||||
assert!(!Verdict::Block("test".to_string()).is_allowed());
|
||||
assert!(!Verdict::Escalate.is_allowed());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_classify_auto_mode_allows() {
|
||||
assert_eq!(Harness::classify("write", &AgentMode::Auto), Verdict::Allow);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_classify_yolo_mode_allows() {
|
||||
assert_eq!(Harness::classify("write", &AgentMode::Yolo), Verdict::Allow);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_classify_plan_mode_blocks() {
|
||||
let result = Harness::classify("write", &AgentMode::Plan);
|
||||
assert!(matches!(result, Verdict::Block(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_classify_normal_mode_escalates() {
|
||||
assert_eq!(Harness::classify("write", &AgentMode::Normal), Verdict::Escalate);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gate_tool_non_risky_always_allows() {
|
||||
let mode = AgentMode::Normal;
|
||||
let roots: &[&std::path::Path] = &[];
|
||||
let result = Harness::gate_tool_call("read", &json!({"path": "test.txt"}), &mode, roots);
|
||||
assert_eq!(result, Verdict::Allow);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gate_tool_bash_non_destructive_allowed_in_auto() {
|
||||
let mode = AgentMode::Auto;
|
||||
let roots: &[&std::path::Path] = &[];
|
||||
let result = Harness::gate_tool_call("bash", &json!({"command": "ls -la"}), &mode, roots);
|
||||
assert_eq!(result, Verdict::Allow);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gate_tool_bash_destructive_blocked() {
|
||||
let mode = AgentMode::Auto;
|
||||
let roots: &[&std::path::Path] = &[];
|
||||
let result = Harness::gate_tool_call("bash", &json!({"command": "dd if=/dev/zero of=/dev/sda"}), &mode, roots);
|
||||
assert!(matches!(result, Verdict::Block(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gate_tool_git_operator_destructive_blocked() {
|
||||
let mode = AgentMode::Auto;
|
||||
let roots: &[&std::path::Path] = &[];
|
||||
let result = Harness::gate_tool_call(
|
||||
"git_operator",
|
||||
&json!({"operation": "push", "args": ["--force"]}),
|
||||
&mode,
|
||||
roots,
|
||||
);
|
||||
assert!(matches!(result, Verdict::Block(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_verdict_json_allow() {
|
||||
let v = parse_verdict(r#"{"verdict": "allow"}"#);
|
||||
assert_eq!(v, Some(Verdict::Allow));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_verdict_json_block() {
|
||||
let v = parse_verdict(r#"{"verdict": "block", "reason": "dangerous operation"}"#);
|
||||
assert_eq!(v, Some(Verdict::Block("dangerous operation".to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_verdict_json_escalate() {
|
||||
let v = parse_verdict(r#"{"verdict": "escalate"}"#);
|
||||
assert_eq!(v, Some(Verdict::Escalate));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_verdict_text_allow() {
|
||||
let v = parse_verdict("Verdict: Allow");
|
||||
assert_eq!(v, Some(Verdict::Allow));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_verdict_text_block() {
|
||||
let v = parse_verdict("Verdict: Block - this operation is not allowed");
|
||||
assert!(matches!(v, Some(Verdict::Block(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_verdict_fallback_allow() {
|
||||
let v = parse_verdict("I think we should allow this operation");
|
||||
assert_eq!(v, Some(Verdict::Allow));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_verdict_fallback_block() {
|
||||
let v = parse_verdict("This request should be blocked");
|
||||
assert!(matches!(v, Some(Verdict::Block(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_verdict_unparseable() {
|
||||
let v = parse_verdict("completely unrelated text with no keywords");
|
||||
assert_eq!(v, None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user