1+ import { mkdtemp , mkdir , rm , writeFile } from "fs/promises" ;
2+ import os from "os" ;
3+ import path from "path" ;
4+ import {
5+ listProjectSkillManifests ,
6+ loadSkillMarkdown ,
7+ } from "../../plugins/adminforth-agent/agent/skills/registry.js" ;
8+
9+ const SKILL_MARKDOWN = ( name : string , description : string , body : string ) => `name: ${ name }
10+ description: ${ description }
11+ ---
12+
13+ ${ body }
14+ ` ;
15+
16+ describe ( "adminforth-agent skills registry" , ( ) => {
17+ let customComponentsDir : string ;
18+
19+ beforeEach ( async ( ) => {
20+ customComponentsDir = await mkdtemp (
21+ path . join ( os . tmpdir ( ) , "adminforth-agent-skills-" ) ,
22+ ) ;
23+ } ) ;
24+
25+ afterEach ( async ( ) => {
26+ await rm ( customComponentsDir , { recursive : true , force : true } ) ;
27+ } ) ;
28+
29+ it ( "collects skills from both user custom skill directories" , async ( ) => {
30+ const rootSkillDir = path . join ( customComponentsDir , "skills" , "root-skill" ) ;
31+ const pluginSkillDir = path . join (
32+ customComponentsDir ,
33+ "plugins" ,
34+ "adminforth-agent" ,
35+ "skills" ,
36+ "plugin-skill" ,
37+ ) ;
38+
39+ await mkdir ( rootSkillDir , { recursive : true } ) ;
40+ await mkdir ( pluginSkillDir , { recursive : true } ) ;
41+
42+ await writeFile (
43+ path . join ( rootSkillDir , "SKILL.md" ) ,
44+ SKILL_MARKDOWN ( "root-skill" , "Root custom skill" , "Root body" ) ,
45+ "utf8" ,
46+ ) ;
47+ await writeFile (
48+ path . join ( pluginSkillDir , "SKILL.md" ) ,
49+ SKILL_MARKDOWN ( "plugin-skill" , "Plugin custom skill" , "Plugin body" ) ,
50+ "utf8" ,
51+ ) ;
52+
53+ const skills = await listProjectSkillManifests ( customComponentsDir ) ;
54+
55+ expect ( skills . map ( ( skill ) => skill . name ) ) . toEqual ( [
56+ "root-skill" ,
57+ "plugin-skill" ,
58+ ] ) ;
59+ } ) ;
60+
61+ it ( "loads markdown from the plugin-scoped user custom directory" , async ( ) => {
62+ const pluginSkillDir = path . join (
63+ customComponentsDir ,
64+ "plugins" ,
65+ "adminforth-agent" ,
66+ "skills" ,
67+ "plugin-skill" ,
68+ ) ;
69+
70+ await mkdir ( pluginSkillDir , { recursive : true } ) ;
71+ await writeFile (
72+ path . join ( pluginSkillDir , "SKILL.md" ) ,
73+ SKILL_MARKDOWN ( "plugin-skill" , "Plugin custom skill" , "Plugin body" ) ,
74+ "utf8" ,
75+ ) ;
76+
77+ await expect ( loadSkillMarkdown ( "plugin-skill" , customComponentsDir ) ) . resolves . toContain (
78+ "Plugin body" ,
79+ ) ;
80+ } ) ;
81+ } ) ;
0 commit comments