@@ -11,7 +11,7 @@ import { workbenchInstantiationService } from '../../../../../test/browser/workb
11
11
import { TerminalChatAgentToolsSettingId } from '../../common/terminalChatAgentToolsConfiguration.js' ;
12
12
import { CommandLineAutoApprover } from '../../browser/commandLineAutoApprover.js' ;
13
13
import { ConfigurationTarget } from '../../../../../../platform/configuration/common/configuration.js' ;
14
- import { ok } from 'assert' ;
14
+ import { ok , strictEqual } from 'assert' ;
15
15
16
16
suite ( 'CommandLineAutoApprover' , ( ) => {
17
17
const store = ensureNoDisposablesAreLeakedInTestSuite ( ) ;
@@ -38,6 +38,10 @@ suite('CommandLineAutoApprover', () => {
38
38
setConfig ( TerminalChatAgentToolsSettingId . AutoApprove , value ) ;
39
39
}
40
40
41
+ function setAutoApproveWithCommandLine ( value : { [ key : string ] : { approve : boolean ; matchCommandLine ?: boolean } | boolean } ) {
42
+ setConfig ( TerminalChatAgentToolsSettingId . AutoApprove , value ) ;
43
+ }
44
+
41
45
function setConfig ( key : string , value : unknown ) {
42
46
configurationService . setUserConfiguration ( key , value ) ;
43
47
configurationService . onDidChangeConfigurationEmitter . fire ( {
@@ -331,10 +335,6 @@ suite('CommandLineAutoApprover', () => {
331
335
} ) ;
332
336
333
337
suite ( 'isCommandLineAutoApproved - matchCommandLine functionality' , ( ) => {
334
- function setAutoApproveWithCommandLine ( value : { [ key : string ] : { approve : boolean ; matchCommandLine : boolean } | boolean } ) {
335
- setConfig ( TerminalChatAgentToolsSettingId . AutoApprove , value ) ;
336
- }
337
-
338
338
test ( 'should auto-approve command line patterns with matchCommandLine: true' , ( ) => {
339
339
setAutoApproveWithCommandLine ( {
340
340
"echo" : { approve : true , matchCommandLine : true }
@@ -440,4 +440,44 @@ suite('CommandLineAutoApprover', () => {
440
440
ok ( ! isCommandLineAutoApproved ( 'powershell -File script.ps1 -ExecutionPolicy Bypass' ) ) ;
441
441
} ) ;
442
442
} ) ;
443
+
444
+ suite ( 'reasons' , ( ) => {
445
+ function getCommandReason ( command : string ) : string {
446
+ return commandLineAutoApprover . isCommandAutoApproved ( command , shell , os ) . reason ;
447
+ }
448
+
449
+ function getCommandLineReason ( commandLine : string ) : string {
450
+ return commandLineAutoApprover . isCommandLineAutoApproved ( commandLine ) . reason ;
451
+ }
452
+
453
+ suite ( 'command' , ( ) => {
454
+ test ( 'approved' , ( ) => {
455
+ setAutoApprove ( { echo : true } ) ;
456
+ strictEqual ( getCommandReason ( 'echo hello' ) , `Command 'echo hello' is approved by allow list rule: echo` ) ;
457
+ } ) ;
458
+ test ( 'not approved' , ( ) => {
459
+ setAutoApprove ( { echo : false } ) ;
460
+ strictEqual ( getCommandReason ( 'echo hello' ) , `Command 'echo hello' is denied by deny list rule: echo` ) ;
461
+ } ) ;
462
+ test ( 'no match' , ( ) => {
463
+ setAutoApprove ( { } ) ;
464
+ strictEqual ( getCommandReason ( 'echo hello' ) , `Command 'echo hello' has no matching auto approve entries` ) ;
465
+ } ) ;
466
+ } ) ;
467
+
468
+ suite ( 'command line' , ( ) => {
469
+ test ( 'approved' , ( ) => {
470
+ setAutoApproveWithCommandLine ( { echo : { approve : true , matchCommandLine : true } } ) ;
471
+ strictEqual ( getCommandLineReason ( 'echo hello' ) , `Command line 'echo hello' is approved by allow list rule: echo` ) ;
472
+ } ) ;
473
+ test ( 'not approved' , ( ) => {
474
+ setAutoApproveWithCommandLine ( { echo : { approve : false , matchCommandLine : true } } ) ;
475
+ strictEqual ( getCommandLineReason ( 'echo hello' ) , `Command line 'echo hello' is denied by deny list rule: echo` ) ;
476
+ } ) ;
477
+ test ( 'no match' , ( ) => {
478
+ setAutoApproveWithCommandLine ( { } ) ;
479
+ strictEqual ( getCommandLineReason ( 'echo hello' ) , `Command line 'echo hello' has no matching auto approve entries` ) ;
480
+ } ) ;
481
+ } ) ;
482
+ } ) ;
443
483
} ) ;
0 commit comments