@@ -11,7 +11,6 @@ import {
1111 getSingleCommandDecision ,
1212 CommandValidator ,
1313 createCommandValidator ,
14- containsSubshell ,
1514} from "../command-validation"
1615
1716describe ( "Command Validation" , ( ) => {
@@ -43,66 +42,6 @@ describe("Command Validation", () => {
4342 expect ( parseCommand ( "diff <(sort f1) <(sort f2)" ) ) . toEqual ( [ "diff" , "sort f1" , "sort f2" ] )
4443 } )
4544
46- it ( "detects additional subshell patterns" , ( ) => {
47- // Test $[] arithmetic expansion detection
48- expect ( parseCommand ( "echo $[1 + 2]" ) ) . toEqual ( [ "echo $[1 + 2]" ] )
49-
50- // Verify containsSubshell detects all subshell patterns
51- expect ( containsSubshell ( "echo $[1 + 2]" ) ) . toBe ( true ) // $[] arithmetic expansion
52- expect ( containsSubshell ( "echo $((1 + 2))" ) ) . toBe ( true ) // $(()) arithmetic expansion
53- expect ( containsSubshell ( "echo $(date)" ) ) . toBe ( true ) // $() command substitution
54- expect ( containsSubshell ( "echo `date`" ) ) . toBe ( true ) // backtick substitution
55- expect ( containsSubshell ( "diff <(sort f1) <(sort f2)" ) ) . toBe ( true ) // process substitution
56- expect ( containsSubshell ( "echo hello" ) ) . toBe ( false ) // no subshells
57- } )
58-
59- it ( "detects subshell grouping patterns" , ( ) => {
60- // Basic subshell grouping with shell operators
61- expect ( containsSubshell ( "(ls; rm file)" ) ) . toBe ( true )
62- expect ( containsSubshell ( "(cd /tmp && rm -rf *)" ) ) . toBe ( true )
63- expect ( containsSubshell ( "(command1 || command2)" ) ) . toBe ( true )
64- expect ( containsSubshell ( "(ls | grep test)" ) ) . toBe ( true )
65- expect ( containsSubshell ( "(sleep 10 & echo done)" ) ) . toBe ( true )
66-
67- // Nested subshells
68- expect ( containsSubshell ( "(cd /tmp && (rm -rf * || echo failed))" ) ) . toBe ( true )
69-
70- // Multiple operators in subshell
71- expect ( containsSubshell ( "(cmd1; cmd2 && cmd3 | cmd4)" ) ) . toBe ( true )
72-
73- // Subshell with spaces
74- expect ( containsSubshell ( "( ls ; rm file )" ) ) . toBe ( true )
75- } )
76-
77- it ( "does NOT detect legitimate parentheses usage" , ( ) => {
78- // Function calls should not be flagged as subshells
79- expect ( containsSubshell ( "myfunction(arg1, arg2)" ) ) . toBe ( false )
80- expect ( containsSubshell ( "func( arg1, arg2 )" ) ) . toBe ( false )
81-
82- // Simple parentheses without operators
83- expect ( containsSubshell ( "(simple text)" ) ) . toBe ( false )
84-
85- // Parentheses in strings
86- expect ( containsSubshell ( 'echo "this (has) parentheses"' ) ) . toBe ( false )
87-
88- // Empty parentheses
89- expect ( containsSubshell ( "()" ) ) . toBe ( false )
90- } )
91-
92- it ( "handles mixed subshell patterns" , ( ) => {
93- // Mixed subshell types
94- expect ( containsSubshell ( "(echo $(date); rm file)" ) ) . toBe ( true )
95-
96- // Subshell with command substitution
97- expect ( containsSubshell ( "(ls `pwd`; echo done)" ) ) . toBe ( true )
98-
99- // No subshells
100- expect ( containsSubshell ( "echo hello world" ) ) . toBe ( false )
101-
102- // Empty string
103- expect ( containsSubshell ( "" ) ) . toBe ( false )
104- } )
105-
10645 it ( "handles empty and whitespace input" , ( ) => {
10746 expect ( parseCommand ( "" ) ) . toEqual ( [ ] )
10847 expect ( parseCommand ( " " ) ) . toEqual ( [ ] )
@@ -899,7 +838,6 @@ describe("Unified Command Decision Functions", () => {
899838
900839 expect ( details . decision ) . toBe ( "auto_approve" )
901840 expect ( details . subCommands ) . toEqual ( [ "npm install" , "echo done" ] )
902- expect ( details . hasSubshells ) . toBe ( false )
903841 expect ( details . allowedMatches ) . toHaveLength ( 2 )
904842 expect ( details . deniedMatches ) . toHaveLength ( 2 )
905843
@@ -912,12 +850,10 @@ describe("Unified Command Decision Functions", () => {
912850
913851 it ( "detects subshells correctly" , ( ) => {
914852 const details = validator . getValidationDetails ( "npm install $(echo test)" )
915- expect ( details . hasSubshells ) . toBe ( true )
916853 expect ( details . decision ) . toBe ( "auto_approve" ) // all commands are allowed
917854
918855 // Test with denied prefix in subshell
919856 const detailsWithDenied = validator . getValidationDetails ( "npm install $(npm test)" )
920- expect ( detailsWithDenied . hasSubshells ) . toBe ( true )
921857 expect ( detailsWithDenied . decision ) . toBe ( "auto_deny" ) // npm test is denied
922858 } )
923859
0 commit comments