| use std::path::PathBuf; |
|
|
| use derive_setters::Setters; |
| use schemars::JsonSchema; |
| use serde::{Deserialize, Serialize}; |
|
|
| |
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Setters, JsonSchema)] |
| #[setters(strip_option, into)] |
| pub struct Skill { |
| |
| pub name: String, |
|
|
| |
| pub path: Option<PathBuf>, |
|
|
| |
| pub command: String, |
|
|
| |
| pub description: String, |
|
|
| |
| pub resources: Vec<PathBuf>, |
| } |
|
|
| impl Skill { |
| |
| |
| |
| |
| |
| |
| |
| pub fn new( |
| name: impl Into<String>, |
| prompt: impl Into<String>, |
| description: impl Into<String>, |
| ) -> Self { |
| Self { |
| name: name.into(), |
| path: None, |
| command: prompt.into(), |
| description: description.into(), |
| resources: Vec::new(), |
| } |
| } |
| } |
|
|
| #[cfg(test)] |
| mod tests { |
| use pretty_assertions::assert_eq; |
|
|
| use super::*; |
|
|
| #[test] |
| fn test_skill_creation() { |
| |
| let fixture = Skill::new( |
| "code_review", |
| "Review this code", |
| "A skill for reviewing code quality", |
| ) |
| .path("/skills/code_review.md"); |
|
|
| |
| let actual = ( |
| fixture.name.clone(), |
| fixture.path.clone(), |
| fixture.command.clone(), |
| fixture.description.clone(), |
| ); |
|
|
| |
| let expected = ( |
| "code_review".to_string(), |
| Some("/skills/code_review.md".into()), |
| "Review this code".to_string(), |
| "A skill for reviewing code quality".to_string(), |
| ); |
| assert_eq!(actual, expected); |
| } |
|
|
| #[test] |
| fn test_skill_with_setters() { |
| |
| let fixture = Skill::new("test", "prompt", "desc") |
| .path("/path") |
| .name("updated_name") |
| .path("/updated/path") |
| .command("updated prompt") |
| .description("updated description"); |
|
|
| |
| let actual = fixture; |
|
|
| |
| let expected = Skill::new("updated_name", "updated prompt", "updated description") |
| .path("/updated/path"); |
| assert_eq!(actual, expected); |
| } |
| } |
|
|