@@ -62,8 +62,7 @@ describe("auditAutoApprove", () => {
6262 vi . clearAllMocks ( ) ;
6363 } ) ;
6464
65- afterAll ( ( ) => {
66- } ) ;
65+ afterAll ( ( ) => { } ) ;
6766
6867 it ( "should pass when no risky patterns found" , async ( ) => {
6968 // Mock file structure - return proper Dirent-like objects
@@ -153,6 +152,63 @@ describe("auditAutoApprove", () => {
153152 ) ;
154153 } ) ;
155154
155+ it ( "should detect risky patterns in user settings" , async ( ) => {
156+ mockReaddirSync . mockImplementation ( ( dir : string , options ?: any ) => {
157+ if ( dir === "/test" ) {
158+ return [
159+ { name : ".vscode" , isDirectory : ( ) => true , isFile : ( ) => false } ,
160+ ] as any ;
161+ }
162+ if ( dir === "/test/.vscode" ) {
163+ return [
164+ {
165+ name : "settings.json" ,
166+ isDirectory : ( ) => false ,
167+ isFile : ( ) => true ,
168+ } ,
169+ ] as any ;
170+ }
171+ return [ ] ;
172+ } ) ;
173+
174+ mockReadFileSync . mockImplementation ( ( path : string ) => {
175+ if (
176+ path ===
177+ "/mock-home/Library/Application Support/Code/User/settings.json"
178+ ) {
179+ return JSON . stringify ( {
180+ "chat.tools.terminal.autoApprove" : {
181+ ":risky-task" : true ,
182+ } ,
183+ } ) ;
184+ }
185+ if ( path === "/test/.vscode/settings.json" ) {
186+ return JSON . stringify ( {
187+ "chat.tools.terminal.autoApprove" : {
188+ ":safe-task" : true ,
189+ } ,
190+ } ) ;
191+ }
192+ return "{}" ;
193+ } ) ;
194+
195+ await auditAutoApprove ( {
196+ allowPrefix : "safe" ,
197+ failOnRisk : false ,
198+ json : false ,
199+ silent : false ,
200+ } ) ;
201+
202+ expect ( consoleSpy ) . toHaveBeenCalledWith ( "⚠️ Found issues in 2 file(s):" ) ;
203+ expect ( consoleSpy ) . toHaveBeenCalledWith (
204+ "- /mock-home/Library/Application Support/Code/User/settings.json" ,
205+ ) ;
206+ expect ( consoleSpy ) . toHaveBeenCalledWith (
207+ " \x1b[31m✖ risky (enabled & not allowed):\x1b[37m :risky-task\x1b[0m" ,
208+ ) ;
209+ expect ( consoleSpy ) . toHaveBeenCalledWith ( "- /test/.vscode/settings.json" ) ;
210+ } ) ;
211+
156212 it ( "should exit with code 1 when failOnRisk is true and risks found" , async ( ) => {
157213 mockReaddirSync . mockImplementation ( ( dir : string , options ?: any ) => {
158214 if ( dir === "/test" ) {
0 commit comments