@@ -31,6 +31,11 @@ import { attemptCompletionTool, AttemptCompletionCallbacks } from "../AttemptCom
3131import { Task } from "../../task/Task"
3232import { AskApproval , HandleError , PushToolResult } from "../../../shared/tools"
3333import * as vscode from "vscode"
34+ import { processUserContentMentions } from "../../mentions/processUserContentMentions"
35+ import { parseMentions } from "../../mentions/index"
36+ import { FileContextTracker } from "../../context-tracking/FileContextTracker"
37+
38+ vi . mock ( "../../mentions/index" , ( ) => ( { parseMentions : vi . fn ( ) } ) )
3439
3540describe ( "attemptCompletionTool" , ( ) => {
3641 let mockTask : Partial < Task >
@@ -1162,6 +1167,89 @@ describe("attemptCompletionTool", () => {
11621167 expect ( mockPushToolResult ) . toHaveBeenCalledTimes ( 1 )
11631168 } )
11641169
1170+ it ( "pushes an authorized feedback block that mention processing expands" , async ( ) => {
1171+ const block : ToolUse < "attempt_completion" > = {
1172+ type : "tool_use" ,
1173+ name : "attempt_completion" ,
1174+ params : { result : "Done" } ,
1175+ nativeArgs : { result : "Done" } ,
1176+ partial : false ,
1177+ }
1178+ mockTask . ask = vi . fn ( ) . mockResolvedValue ( {
1179+ response : "messageResponse" ,
1180+ text : "@/allowed" ,
1181+ images : [ ] ,
1182+ } )
1183+ vi . mocked ( parseMentions ) . mockImplementation ( async ( text ) => ( {
1184+ text : `parsed: ${ text } ` ,
1185+ contentBlocks : [ ] ,
1186+ } ) )
1187+ vi . mocked ( parseMentions ) . mockClear ( )
1188+
1189+ await attemptCompletionTool . handle ( mockTask as Task , block , {
1190+ askApproval : mockAskApproval ,
1191+ handleError : mockHandleError ,
1192+ pushToolResult : mockPushToolResult ,
1193+ toolCallId : "" ,
1194+ askFinishSubTaskApproval : mockAskFinishSubTaskApproval ,
1195+ toolDescription : mockToolDescription ,
1196+ } )
1197+
1198+ // Deleting the push in AttemptCompletionTool fails this assertion.
1199+ expect ( mockTask . userMessageContent ) . toHaveLength ( 1 )
1200+ const block0 = mockTask . userMessageContent ! [ 0 ]
1201+ expect ( block0 ) . toEqual ( { type : "text" , text : "<user_message>\n@/allowed\n</user_message>" } )
1202+
1203+ // The pushed block authorizes expansion of its input.
1204+ const result = await processUserContentMentions ( {
1205+ userContent : [ block0 ] ,
1206+ cwd : "/test" ,
1207+ fileContextTracker : { } as FileContextTracker ,
1208+ } )
1209+ expect ( vi . mocked ( parseMentions ) . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( "@/allowed" )
1210+ expect ( result . content ) . toEqual ( [
1211+ { type : "text" , text : "<user_message>\nparsed: @/allowed\n</user_message>" } ,
1212+ ] )
1213+ } )
1214+
1215+ it ( "does not authorize the feedback block when the feedback text is undefined" , async ( ) => {
1216+ const block : ToolUse < "attempt_completion" > = {
1217+ type : "tool_use" ,
1218+ name : "attempt_completion" ,
1219+ params : { result : "Done" } ,
1220+ nativeArgs : { result : "Done" } ,
1221+ partial : false ,
1222+ }
1223+ mockTask . ask = vi . fn ( ) . mockResolvedValue ( {
1224+ response : "messageResponse" ,
1225+ text : undefined ,
1226+ images : [ ] ,
1227+ } )
1228+ vi . mocked ( parseMentions ) . mockImplementation ( async ( text ) => ( {
1229+ text : `parsed: ${ text } ` ,
1230+ contentBlocks : [ ] ,
1231+ } ) )
1232+ vi . mocked ( parseMentions ) . mockClear ( )
1233+
1234+ await attemptCompletionTool . handle ( mockTask as Task , block , {
1235+ askApproval : mockAskApproval ,
1236+ handleError : mockHandleError ,
1237+ pushToolResult : mockPushToolResult ,
1238+ toolCallId : "" ,
1239+ askFinishSubTaskApproval : mockAskFinishSubTaskApproval ,
1240+ toolDescription : mockToolDescription ,
1241+ } )
1242+
1243+ expect ( mockTask . userMessageContent ) . toHaveLength ( 1 )
1244+ const result = await processUserContentMentions ( {
1245+ userContent : [ mockTask . userMessageContent ! [ 0 ] ] ,
1246+ cwd : "/test" ,
1247+ fileContextTracker : { } as FileContextTracker ,
1248+ } )
1249+ expect ( parseMentions ) . not . toHaveBeenCalled ( )
1250+ expect ( result . content ) . toEqual ( [ { type : "text" , text : "<user_message>\nundefined\n</user_message>" } ] )
1251+ } )
1252+
11651253 it ( "does not clear pending metadata when stale delegation continues without an action id" , async ( ) => {
11661254 const block : ToolUse < "attempt_completion" > = {
11671255 type : "tool_use" ,
0 commit comments