Add tool identity quality checks
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use crank_core::{ToolQualityFinding, ToolQualityReport, ToolQualitySeverity};
|
||||
use crank_core::{
|
||||
ToolDescription, ToolQualityFinding, ToolQualityReport, ToolQualitySeverity,
|
||||
analyze_tool_identity_quality,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn serializes_tool_quality_finding_contract() {
|
||||
@@ -30,3 +33,90 @@ fn report_is_blocking_when_error_finding_exists() {
|
||||
assert!(report.blocking);
|
||||
assert_eq!(report.findings.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reports_missing_tool_name_as_blocking_error() {
|
||||
let report = analyze_tool_identity_quality(
|
||||
" ",
|
||||
&ToolDescription {
|
||||
title: "Create lead".to_owned(),
|
||||
description: "Создает новый лид в CRM, когда пользователь просит добавить потенциального клиента.".to_owned(),
|
||||
tags: Vec::new(),
|
||||
examples: Vec::new(),
|
||||
},
|
||||
);
|
||||
|
||||
assert!(report.blocking);
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"tool_name_missing",
|
||||
ToolQualitySeverity::Error
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warns_about_generic_tool_name() {
|
||||
let report = analyze_tool_identity_quality(
|
||||
"call_api",
|
||||
&ToolDescription {
|
||||
title: "Call API".to_owned(),
|
||||
description: "Получает данные клиента по идентификатору, когда пользователю нужна карточка клиента.".to_owned(),
|
||||
tags: Vec::new(),
|
||||
examples: Vec::new(),
|
||||
},
|
||||
);
|
||||
|
||||
assert!(!report.blocking);
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"tool_name_too_generic",
|
||||
ToolQualitySeverity::Warning
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reports_unsafe_tool_name_format_as_blocking_error() {
|
||||
let report = analyze_tool_identity_quality(
|
||||
"Create Lead!",
|
||||
&ToolDescription {
|
||||
title: "Create lead".to_owned(),
|
||||
description: "Создает новый лид в CRM, когда пользователь просит добавить потенциального клиента.".to_owned(),
|
||||
tags: Vec::new(),
|
||||
examples: Vec::new(),
|
||||
},
|
||||
);
|
||||
|
||||
assert!(report.blocking);
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"tool_name_invalid_format",
|
||||
ToolQualitySeverity::Error
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warns_about_short_description() {
|
||||
let report = analyze_tool_identity_quality(
|
||||
"create_lead",
|
||||
&ToolDescription {
|
||||
title: "Create lead".to_owned(),
|
||||
description: "Создает лид.".to_owned(),
|
||||
tags: Vec::new(),
|
||||
examples: Vec::new(),
|
||||
},
|
||||
);
|
||||
|
||||
assert!(!report.blocking);
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"tool_description_too_short",
|
||||
ToolQualitySeverity::Warning
|
||||
));
|
||||
}
|
||||
|
||||
fn has_finding(report: &ToolQualityReport, code: &str, severity: ToolQualitySeverity) -> bool {
|
||||
report
|
||||
.findings
|
||||
.iter()
|
||||
.any(|finding| finding.code == code && finding.severity == severity)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user