@@ -22,6 +22,7 @@ describe("skillTool", () => {
2222 recordToolError : vi . fn ( ) ,
2323 didToolFailInCurrentTurn : false ,
2424 sayAndCreateMissingParamError : vi . fn ( ) . mockResolvedValue ( "Missing parameter error" ) ,
25+ ask : vi . fn ( ) . mockResolvedValue ( { } ) ,
2526 providerRef : {
2627 deref : vi . fn ( ) . mockReturnValue ( {
2728 getState : vi . fn ( ) . mockResolvedValue ( { mode : "code" } ) ,
@@ -31,6 +32,7 @@ describe("skillTool", () => {
3132 }
3233
3334 mockCallbacks = {
35+ askApproval : vi . fn ( ) . mockResolvedValue ( true ) ,
3436 handleError : vi . fn ( ) ,
3537 pushToolResult : vi . fn ( ) ,
3638 }
@@ -97,7 +99,7 @@ describe("skillTool", () => {
9799 )
98100 } )
99101
100- it ( "should successfully load built-in skill without approval " , async ( ) => {
102+ it ( "should successfully load built-in skill" , async ( ) => {
101103 const block : ToolUse < "skill" > = {
102104 type : "tool_use" as const ,
103105 name : "skill" as const ,
@@ -119,7 +121,17 @@ describe("skillTool", () => {
119121
120122 await skillTool . handle ( mockTask as Task , block , mockCallbacks )
121123
122- // Skills execute directly without approval
124+ expect ( mockCallbacks . askApproval ) . toHaveBeenCalledWith (
125+ "tool" ,
126+ JSON . stringify ( {
127+ tool : "skill" ,
128+ skill : "create-mcp-server" ,
129+ args : undefined ,
130+ source : "built-in" ,
131+ description : "Instructions for creating MCP servers" ,
132+ } ) ,
133+ )
134+
123135 expect ( mockCallbacks . pushToolResult ) . toHaveBeenCalledWith (
124136 `Skill: create-mcp-server
125137Description: Instructions for creating MCP servers
@@ -166,6 +178,57 @@ Step 1: Create the server...`,
166178 )
167179 } )
168180
181+ it ( "should handle user rejection" , async ( ) => {
182+ const block : ToolUse < "skill" > = {
183+ type : "tool_use" as const ,
184+ name : "skill" as const ,
185+ params : { } ,
186+ partial : false ,
187+ nativeArgs : {
188+ skill : "create-mcp-server" ,
189+ } ,
190+ }
191+
192+ mockSkillsManager . getSkillContent . mockResolvedValue ( {
193+ name : "create-mcp-server" ,
194+ description : "Test" ,
195+ source : "built-in" ,
196+ instructions : "Test instructions" ,
197+ } )
198+
199+ mockCallbacks . askApproval . mockResolvedValue ( false )
200+
201+ await skillTool . handle ( mockTask as Task , block , mockCallbacks )
202+
203+ expect ( mockCallbacks . pushToolResult ) . not . toHaveBeenCalled ( )
204+ } )
205+
206+ it ( "should handle partial block" , async ( ) => {
207+ const block : ToolUse < "skill" > = {
208+ type : "tool_use" as const ,
209+ name : "skill" as const ,
210+ params : {
211+ skill : "create-mcp-server" ,
212+ args : "" ,
213+ } ,
214+ partial : true ,
215+ }
216+
217+ await skillTool . handle ( mockTask as Task , block , mockCallbacks )
218+
219+ expect ( mockTask . ask ) . toHaveBeenCalledWith (
220+ "tool" ,
221+ JSON . stringify ( {
222+ tool : "skill" ,
223+ skill : "create-mcp-server" ,
224+ args : "" ,
225+ } ) ,
226+ true ,
227+ )
228+
229+ expect ( mockCallbacks . pushToolResult ) . not . toHaveBeenCalled ( )
230+ } )
231+
169232 it ( "should handle errors during execution" , async ( ) => {
170233 const block : ToolUse < "skill" > = {
171234 type : "tool_use" as const ,
@@ -236,7 +299,7 @@ Step 1: Create the server...`,
236299 )
237300 } )
238301
239- it ( "should load project skill without approval " , async ( ) => {
302+ it ( "should load project skill" , async ( ) => {
240303 const block : ToolUse < "skill" > = {
241304 type : "tool_use" as const ,
242305 name : "skill" as const ,
@@ -258,7 +321,17 @@ Step 1: Create the server...`,
258321
259322 await skillTool . handle ( mockTask as Task , block , mockCallbacks )
260323
261- // Skills execute directly without approval
324+ expect ( mockCallbacks . askApproval ) . toHaveBeenCalledWith (
325+ "tool" ,
326+ JSON . stringify ( {
327+ tool : "skill" ,
328+ skill : "my-project-skill" ,
329+ args : undefined ,
330+ source : "project" ,
331+ description : "A custom project skill" ,
332+ } ) ,
333+ )
334+
262335 expect ( mockCallbacks . pushToolResult ) . toHaveBeenCalledWith (
263336 `Skill: my-project-skill
264337Description: A custom project skill
0 commit comments