@@ -86,6 +86,123 @@ describe("Code Action Prompts", () => {
8686 } )
8787 } )
8888
89+ describe ( "ADD_TO_CONTEXT action" , ( ) => {
90+ it ( "should format ADD_TO_CONTEXT prompt correctly with all parameters" , ( ) => {
91+ const prompt = supportPrompt . create ( "ADD_TO_CONTEXT" , {
92+ name : "Roo" ,
93+ place : "Workspace" ,
94+ filePath : testFilePath ,
95+ selectedText : testCode ,
96+ startLine : "1" ,
97+ endLine : "1" ,
98+ diagnostics : [ ] ,
99+ } )
100+ const expected = `${ testFilePath } :1-1\n\`\`\`\n${ testCode } \n\`\`\``
101+ expect ( prompt ) . toBe ( expected )
102+ } )
103+
104+ it ( "should format ADD_TO_CONTEXT prompt with diagnostics" , ( ) => {
105+ const diagnostics = [ { message : "Error 1" } , { source : "Linter" , message : "Warning 2" } ]
106+ const prompt = supportPrompt . create ( "ADD_TO_CONTEXT" , {
107+ filePath : testFilePath ,
108+ selectedText : testCode ,
109+ startLine : "10" ,
110+ endLine : "20" ,
111+ diagnostics,
112+ } )
113+ const expected = `${ testFilePath } :10-20\n\`\`\`\n${ testCode } \n\`\`\``
114+ expect ( prompt ) . toBe ( expected )
115+ } )
116+
117+ it ( "should not replace placeholders within parameter values" , ( ) => {
118+ const prompt = supportPrompt . create ( "ADD_TO_CONTEXT" , {
119+ value1 : "This is ${value2}" ,
120+ value2 : "Actual Value 2" ,
121+ filePath : testFilePath ,
122+ selectedText : testCode ,
123+ startLine : "5" ,
124+ endLine : "15" ,
125+ } )
126+ const expected = `${ testFilePath } :5-15\n\`\`\`\n${ testCode } \n\`\`\``
127+ expect ( prompt ) . toBe ( expected )
128+ } )
129+
130+ it ( "should replace remaining placeholders (not in params) with empty strings" , ( ) => {
131+ const prompt = supportPrompt . create ( "ADD_TO_CONTEXT" , {
132+ name : "Roo" ,
133+ filePath : testFilePath ,
134+ selectedText : testCode ,
135+ startLine : "1" ,
136+ endLine : "1" ,
137+ } ) // 'status' is missing
138+ const expected = `${ testFilePath } :1-1\n\`\`\`\n${ testCode } \n\`\`\``
139+ expect ( prompt ) . toBe ( expected )
140+ } )
141+
142+ it ( "should handle placeholders in values that are not in the template" , ( ) => {
143+ const prompt = supportPrompt . create ( "ADD_TO_CONTEXT" , {
144+ data : "Some data with ${extraInfo}" ,
145+ filePath : testFilePath ,
146+ selectedText : testCode ,
147+ startLine : "1" ,
148+ endLine : "1" ,
149+ } )
150+ const expected = `${ testFilePath } :1-1\n\`\`\`\n${ testCode } \n\`\`\``
151+ expect ( prompt ) . toBe ( expected )
152+ } )
153+
154+ it ( "should handle minimal params object" , ( ) => {
155+ const prompt = supportPrompt . create ( "ADD_TO_CONTEXT" , {
156+ filePath : testFilePath ,
157+ selectedText : testCode ,
158+ startLine : "1" ,
159+ endLine : "1" ,
160+ } )
161+ const expected = `${ testFilePath } :1-1\n\`\`\`\n${ testCode } \n\`\`\``
162+ expect ( prompt ) . toBe ( expected )
163+ } )
164+
165+ it ( "should handle params with non-string values" , ( ) => {
166+ const prompt = supportPrompt . create ( "ADD_TO_CONTEXT" , {
167+ count : "5" ,
168+ isActive : "true" ,
169+ filePath : testFilePath ,
170+ selectedText : testCode ,
171+ startLine : "1" ,
172+ endLine : "1" ,
173+ } ) // Convert to strings
174+ const expected = `${ testFilePath } :1-1\n\`\`\`\n${ testCode } \n\`\`\``
175+ expect ( prompt ) . toBe ( expected )
176+ } )
177+
178+ it ( "should handle keys with special regex characters" , ( ) => {
179+ const prompt = supportPrompt . create ( "ADD_TO_CONTEXT" , {
180+ "key.with.dots" : "Dotty" ,
181+ value : "Simple" ,
182+ filePath : testFilePath ,
183+ selectedText : testCode ,
184+ startLine : "1" ,
185+ endLine : "1" ,
186+ } )
187+ const expected = `${ testFilePath } :1-1\n\`\`\`\n${ testCode } \n\`\`\``
188+ expect ( prompt ) . toBe ( expected )
189+ } )
190+
191+ it ( "should handle bash script selection" , ( ) => {
192+ const bashText =
193+ 'if [ "${#usecase_deployments[@]}" -gt 0 ] && [ ${{ parameters.single_deployment_per_environment }} = true ]; then'
194+ const prompt = supportPrompt . create ( "ADD_TO_CONTEXT" , {
195+ selectedText : bashText ,
196+ filePath : testFilePath ,
197+ startLine : "1" ,
198+ endLine : "1" ,
199+ diagnostics : [ ] ,
200+ } )
201+ const expected = `${ testFilePath } :1-1\n\`\`\`\n${ bashText } \n\`\`\``
202+ expect ( prompt ) . toBe ( expected )
203+ } )
204+ } )
205+
89206 describe ( "get template" , ( ) => {
90207 it ( "should return default template when no custom prompts provided" , ( ) => {
91208 const template = supportPrompt . get ( undefined , "EXPLAIN" )
0 commit comments