test(protocols,skills): add 90 tests for MCP types + skill loader/runner
zclaw-protocols: +43 tests covering mcp_types serde, ContentBlock variants, transport config builders, and domain type roundtrips. zclaw-skills: +47 tests covering SKILL.md/TOML parsing, auto-classify, PromptOnlySkill execution, and SkillManifest/SkillResult roundtrips. Batch 8 of audit plan (plans/stateless-petting-rossum.md).
This commit is contained in:
78
crates/zclaw-skills/tests/runner_tests.rs
Normal file
78
crates/zclaw-skills/tests/runner_tests.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
//! Tests for PromptOnlySkill runner
|
||||
|
||||
use zclaw_skills::*;
|
||||
use zclaw_types::SkillId;
|
||||
|
||||
/// Helper to create a minimal manifest
|
||||
fn test_manifest(mode: SkillMode) -> SkillManifest {
|
||||
SkillManifest {
|
||||
id: SkillId::new("test-prompt-skill"),
|
||||
name: "Test Prompt Skill".to_string(),
|
||||
description: "A test prompt skill".to_string(),
|
||||
version: "1.0.0".to_string(),
|
||||
author: None,
|
||||
mode,
|
||||
capabilities: vec![],
|
||||
input_schema: None,
|
||||
output_schema: None,
|
||||
tags: vec![],
|
||||
category: None,
|
||||
triggers: vec![],
|
||||
tools: vec![],
|
||||
enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn prompt_only_skill_returns_formatted_prompt() {
|
||||
let manifest = test_manifest(SkillMode::PromptOnly);
|
||||
let template = "Hello {{input}}, welcome!".to_string();
|
||||
let skill = PromptOnlySkill::new(manifest, template);
|
||||
|
||||
let ctx = SkillContext::default();
|
||||
let skill_ref: &dyn Skill = &skill;
|
||||
let result = skill_ref.execute(&ctx, serde_json::json!("World")).await.unwrap();
|
||||
|
||||
assert!(result.success);
|
||||
let output = result.output.as_str().unwrap();
|
||||
assert_eq!(output, "Hello World, welcome!");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn prompt_only_skill_json_input() {
|
||||
let manifest = test_manifest(SkillMode::PromptOnly);
|
||||
let template = "Input: {{input}}".to_string();
|
||||
let skill = PromptOnlySkill::new(manifest, template);
|
||||
|
||||
let ctx = SkillContext::default();
|
||||
let input = serde_json::json!({"key": "value"});
|
||||
let skill_ref: &dyn Skill = &skill;
|
||||
let result = skill_ref.execute(&ctx, input).await.unwrap();
|
||||
|
||||
assert!(result.success);
|
||||
let output = result.output.as_str().unwrap();
|
||||
assert!(output.contains("key"));
|
||||
assert!(output.contains("value"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn prompt_only_skill_no_placeholder() {
|
||||
let manifest = test_manifest(SkillMode::PromptOnly);
|
||||
let template = "Static prompt content".to_string();
|
||||
let skill = PromptOnlySkill::new(manifest, template);
|
||||
|
||||
let ctx = SkillContext::default();
|
||||
let skill_ref: &dyn Skill = &skill;
|
||||
let result = skill_ref.execute(&ctx, serde_json::json!("ignored")).await.unwrap();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(result.output.as_str().unwrap(), "Static prompt content");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn prompt_only_skill_manifest() {
|
||||
let manifest = test_manifest(SkillMode::PromptOnly);
|
||||
let skill = PromptOnlySkill::new(manifest.clone(), "prompt".to_string());
|
||||
assert_eq!(skill.manifest().id.as_str(), "test-prompt-skill");
|
||||
assert_eq!(skill.manifest().name, "Test Prompt Skill");
|
||||
}
|
||||
Reference in New Issue
Block a user