test: add 29 new tests for cleanup, orchestrator, findings, tool registry, models
Some checks failed
CI / Check (pull_request) Failing after 6m3s
CI / Detect Changes (pull_request) Has been skipped
CI / Deploy Agent (pull_request) Has been skipped
CI / Deploy Dashboard (pull_request) Has been skipped
CI / Deploy Docs (pull_request) Has been skipped
CI / Deploy MCP (pull_request) Has been skipped
Some checks failed
CI / Check (pull_request) Failing after 6m3s
CI / Detect Changes (pull_request) Has been skipped
CI / Deploy Agent (pull_request) Has been skipped
CI / Deploy Dashboard (pull_request) Has been skipped
CI / Deploy Docs (pull_request) Has been skipped
CI / Deploy MCP (pull_request) Has been skipped
- cleanup.rs: 8 tests — routing logic, skip conditions, missing config errors - orchestrator.rs: 7 tests — summarize_tool_output (screenshot strip, truncation, recursion) - findings.rs: 6 tests — empty state, severity grouping, SAST correlation, evidence table - tools/mod.rs: 4 tests — registry completeness, schema validation, browser action enum - models.rs: 4 tests — TestUserRecord serde, IdentityProvider variants, BSON roundtrip Total: 326 tests (was 297) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -612,3 +612,95 @@ fn summarize_tool_output(data: &serde_json::Value) -> serde_json::Value {
|
||||
}
|
||||
serde_json::Value::Object(summarized)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn test_summarize_strips_screenshot() {
|
||||
let input = json!({
|
||||
"screenshot_base64": "iVBOR...",
|
||||
"url": "https://example.com"
|
||||
});
|
||||
let result = summarize_tool_output(&input);
|
||||
assert_eq!(
|
||||
result["screenshot_base64"],
|
||||
"[screenshot captured and saved to report]"
|
||||
);
|
||||
assert_eq!(result["url"], "https://example.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_summarize_truncates_html() {
|
||||
let long_html = "x".repeat(3000);
|
||||
let input = json!({ "html": long_html });
|
||||
let result = summarize_tool_output(&input);
|
||||
let s = result["html"].as_str().unwrap_or_default();
|
||||
assert!(s.contains("[truncated, 3000 chars total]"));
|
||||
assert!(s.starts_with(&"x".repeat(2000)));
|
||||
assert!(s.len() < 3000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_summarize_truncates_text() {
|
||||
let long_text = "a".repeat(2000);
|
||||
let input = json!({ "text": long_text });
|
||||
let result = summarize_tool_output(&input);
|
||||
let s = result["text"].as_str().unwrap_or_default();
|
||||
assert!(s.contains("[truncated]"));
|
||||
assert!(s.starts_with(&"a".repeat(1500)));
|
||||
assert!(s.len() < 2000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_summarize_trims_large_arrays() {
|
||||
let elements: Vec<serde_json::Value> = (0..20).map(|i| json!(format!("el-{i}"))).collect();
|
||||
let input = json!({ "elements": elements });
|
||||
let result = summarize_tool_output(&input);
|
||||
let arr = result["elements"].as_array();
|
||||
assert!(arr.is_some());
|
||||
if let Some(arr) = arr {
|
||||
// 15 kept + 1 summary entry
|
||||
assert_eq!(arr.len(), 16);
|
||||
assert_eq!(arr[15], json!("... and 5 more"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_summarize_preserves_small_data() {
|
||||
let input = json!({
|
||||
"url": "https://example.com",
|
||||
"status": 200,
|
||||
"title": "Example"
|
||||
});
|
||||
let result = summarize_tool_output(&input);
|
||||
assert_eq!(result, input);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_summarize_recursive() {
|
||||
let input = json!({
|
||||
"page": {
|
||||
"screenshot_base64": "iVBORw0KGgoAAAA...",
|
||||
"url": "https://example.com"
|
||||
}
|
||||
});
|
||||
let result = summarize_tool_output(&input);
|
||||
assert_eq!(
|
||||
result["page"]["screenshot_base64"],
|
||||
"[screenshot captured and saved to report]"
|
||||
);
|
||||
assert_eq!(result["page"]["url"], "https://example.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_summarize_non_object() {
|
||||
let string_val = json!("just a string");
|
||||
assert_eq!(summarize_tool_output(&string_val), string_val);
|
||||
|
||||
let num_val = json!(42);
|
||||
assert_eq!(summarize_tool_output(&num_val), num_val);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user