Skip to content

Commit 6e2ba5d

Browse files
committed
Tidy up tests
1 parent 9622d83 commit 6e2ba5d

File tree

1 file changed

+22
-45
lines changed

1 file changed

+22
-45
lines changed

src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/commandLineAutoApprover.test.ts

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ suite('CommandLineAutoApprover', () => {
286286
});
287287

288288
ok(isAutoApproved('echo hello world'));
289-
ok(!isAutoApproved(' echo hello'));
290289
});
291290

292291
test('should be case-sensitive by default', () => {
@@ -623,107 +622,85 @@ suite('CommandLineAutoApprover', () => {
623622
test('should handle environment variable assignments before commands in bash/sh', () => {
624623
shell = 'bash';
625624
os = OperatingSystem.Linux;
626-
625+
627626
setAutoApprove({
628627
"env": true,
629628
"echo": true
630629
});
631630

632-
// Basic environment variable assignment
633-
ok(isAutoApproved('FOO=bar env'));
634-
ok(isAutoApproved('FOO=bar echo test'));
635-
636-
// Multiple environment variables
637-
ok(isAutoApproved('FOO=bar BAZ=qux env'));
638-
ok(isAutoApproved('PATH=/usr/bin HOME=/home/user echo hello'));
639-
640-
// Environment variables with quoted values
641-
ok(isAutoApproved('MESSAGE="hello world" echo test'));
642-
ok(isAutoApproved("GREETING='hello there' echo test"));
643-
644-
// Complex command after environment variables
645-
ok(isAutoApproved('DEBUG=1 env | grep DEBUG'));
631+
ok(isAutoApproved('FOO=bar env'), 'Basic environment variable assignment');
632+
ok(isAutoApproved('FOO=bar echo test'), 'Basic environment variable assignment');
633+
634+
ok(isAutoApproved('FOO=bar BAZ=qux env'), 'Multiple environment variables');
635+
ok(isAutoApproved('PATH=/usr/bin HOME=/home/user echo hello'), 'Multiple environment variables');
636+
637+
ok(isAutoApproved('MESSAGE="hello world" echo test'), 'Environment variables with quoted values');
638+
ok(isAutoApproved("GREETING='hello there' echo test"), 'Environment variables with quoted values');
646639
});
647640

648641
test('should not match denied commands even with environment variables', () => {
649642
shell = 'bash';
650643
os = OperatingSystem.Linux;
651-
644+
652645
setAutoApprove({
653646
"env": true,
654647
"rm": false
655648
});
656649

657-
// Should approve env command with environment variable
658-
ok(isAutoApproved('FOO=bar env'));
659-
660-
// Should deny rm command even with environment variable
661-
ok(!isAutoApproved('FOO=bar rm file.txt'));
650+
ok(isAutoApproved('FOO=bar env'), 'Should approve env command with environment variable');
651+
ok(!isAutoApproved('FOO=bar rm file.txt'), 'Should deny rm command even with environment variable');
662652
});
663653

664654
test('should handle environment variables with different shell types', () => {
665655
setAutoApprove({
666656
"echo": true
667657
});
668658

669-
// Bash/sh should handle VAR=value syntax
670659
shell = 'bash';
671660
os = OperatingSystem.Linux;
672661
ok(isAutoApproved('FOO=bar echo test'));
673662

674-
// PowerShell should keep current behavior (not parse VAR=value as env vars)
675663
shell = 'powershell';
676664
os = OperatingSystem.Windows;
677-
ok(!isAutoApproved('FOO=bar echo test')); // This should not match since FOO=bar is not recognized as env var syntax in PowerShell
665+
ok(!isAutoApproved('FOO=bar echo test'), 'This should not match since FOO=bar is not recognized as env var syntax in PowerShell');
678666
});
679667

680668
test('should fallback to original command if no environment variables detected', () => {
681669
shell = 'bash';
682670
os = OperatingSystem.Linux;
683-
671+
684672
setAutoApprove({
685673
"echo": true
686674
});
687675

688-
// Commands without environment variables should work as before
689676
ok(isAutoApproved('echo hello'));
690677
ok(isAutoApproved('echo test'));
691-
692-
// Commands that look like they might have env vars but don't match the pattern
693-
ok(isAutoApproved('echo FOO=bar')); // This is an argument to echo, not an env var assignment
678+
ok(isAutoApproved('echo FOO=bar'), '// Commands that look like they might have env vars but don\'t match the pattern');
694679
});
695680

696681
test('should handle edge cases in environment variable parsing', () => {
697682
shell = 'bash';
698683
os = OperatingSystem.Linux;
699-
684+
700685
setAutoApprove({
701686
"echo": true
702687
});
703688

704-
// Empty value
705-
ok(isAutoApproved('FOO= echo test'));
706-
707-
// Underscore in variable name
708-
ok(isAutoApproved('MY_VAR=test echo hello'));
709-
710-
// Number in variable name (but not at start)
711-
ok(isAutoApproved('VAR1=test echo hello'));
712-
713-
// Should not match if variable name starts with number (invalid)
714-
ok(!isAutoApproved('1VAR=test echo hello')); // This should not be parsed as env var
689+
ok(isAutoApproved('FOO= echo test'), 'Empty value');
690+
ok(isAutoApproved('MY_VAR=test echo hello'), 'Underscore in variable name');
691+
ok(isAutoApproved('VAR1=test echo hello'), 'Number in variable name (but not at start)');
692+
ok(!isAutoApproved('1VAR=test echo hello'), 'Should not match if variable name starts with number (invalid)');
715693
});
716694

717695
test('should handle unknown shell types by defaulting to bourne shell syntax', () => {
718696
shell = 'unknown-shell';
719697
os = OperatingSystem.Linux;
720-
698+
721699
setAutoApprove({
722700
"echo": true
723701
});
724702

725-
// Unknown shells should default to bourne shell behavior
726-
ok(isAutoApproved('FOO=bar echo test'));
703+
ok(isAutoApproved('FOO=bar echo test'), 'Unknown shells should default to bourne shell behavior');
727704
});
728705
});
729706
});

0 commit comments

Comments
 (0)