Add schema quality checks
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crank_core::{
|
||||
ToolDescription, ToolQualityFinding, ToolQualityReport, ToolQualitySeverity,
|
||||
analyze_tool_identity_quality,
|
||||
ToolDescription, ToolQualityFinding, ToolQualityReport, ToolQualitySchemaNode,
|
||||
ToolQualitySeverity, analyze_tool_identity_quality, analyze_tool_schema_quality,
|
||||
};
|
||||
|
||||
#[test]
|
||||
@@ -114,6 +114,73 @@ fn warns_about_short_description() {
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warns_about_object_schema_without_fields() {
|
||||
let schema = ToolQualitySchemaNode::object(None, vec![]);
|
||||
|
||||
let report = analyze_tool_schema_quality("input_schema", &schema);
|
||||
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"schema_object_without_fields",
|
||||
ToolQualitySeverity::Warning
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warns_about_parameter_without_description() {
|
||||
let schema = ToolQualitySchemaNode::object(
|
||||
Some("Входные параметры"),
|
||||
vec![("customer_id", ToolQualitySchemaNode::string(None))],
|
||||
);
|
||||
|
||||
let report = analyze_tool_schema_quality("input_schema", &schema);
|
||||
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"schema_field_missing_description",
|
||||
ToolQualitySeverity::Warning
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warns_about_multi_action_parameter_names() {
|
||||
let schema = ToolQualitySchemaNode::object(
|
||||
Some("Входные параметры"),
|
||||
vec![(
|
||||
"action",
|
||||
ToolQualitySchemaNode::string(Some("Что нужно сделать")),
|
||||
)],
|
||||
);
|
||||
|
||||
let report = analyze_tool_schema_quality("input_schema", &schema);
|
||||
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"schema_multi_action_parameter",
|
||||
ToolQualitySeverity::Warning
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recommends_enum_for_mode_like_string_parameter() {
|
||||
let schema = ToolQualitySchemaNode::object(
|
||||
Some("Входные параметры"),
|
||||
vec![(
|
||||
"mode",
|
||||
ToolQualitySchemaNode::string(Some("Режим поиска клиента")),
|
||||
)],
|
||||
);
|
||||
|
||||
let report = analyze_tool_schema_quality("input_schema", &schema);
|
||||
|
||||
assert!(has_finding(
|
||||
&report,
|
||||
"schema_enum_recommended",
|
||||
ToolQualitySeverity::Info
|
||||
));
|
||||
}
|
||||
|
||||
fn has_finding(report: &ToolQualityReport, code: &str, severity: ToolQualitySeverity) -> bool {
|
||||
report
|
||||
.findings
|
||||
|
||||
Reference in New Issue
Block a user