@@ -68,6 +68,166 @@ describe('run_shell_command', () => {
6868 validateModelOutput ( result , 'test-stdin' , 'Shell command stdin test' ) ;
6969 } ) ;
7070
71+ it ( 'should run allowed sub-command in non-interactive mode' , async ( ) => {
72+ const rig = new TestRig ( ) ;
73+ await rig . setup ( 'should run allowed sub-command in non-interactive mode' ) ;
74+
75+ const prompt = `use wc to tell me how many lines there are in /proc/meminfo` ;
76+
77+ // Provide the prompt via stdin to simulate non-interactive mode
78+ const result = await rig . run ( {
79+ stdin : prompt ,
80+ args : [ '--allowed-tools=run_shell_command(wc)' ] ,
81+ } ) ;
82+
83+ const foundToolCall = await rig . waitForToolCall ( 'run_shell_command' , 15000 ) ;
84+
85+ if ( ! foundToolCall ) {
86+ printDebugInfo ( rig , result , {
87+ 'Found tool call' : foundToolCall ,
88+ } ) ;
89+ }
90+
91+ expect (
92+ foundToolCall ,
93+ 'Expected to find a run_shell_command tool call' ,
94+ ) . toBeTruthy ( ) ;
95+ } ) ;
96+
97+ it ( 'should succeed with no parens in non-interactive mode' , async ( ) => {
98+ const rig = new TestRig ( ) ;
99+ await rig . setup ( 'should succeed with no parens in non-interactive mode' ) ;
100+
101+ const prompt = `use wc to tell me how many lines there are in /proc/meminfo` ;
102+
103+ const result = await rig . run ( {
104+ stdin : prompt ,
105+ args : [ '--allowed-tools=run_shell_command' ] ,
106+ } ) ;
107+
108+ const foundToolCall = await rig . waitForToolCall ( 'run_shell_command' , 15000 ) ;
109+
110+ if ( ! foundToolCall ) {
111+ printDebugInfo ( rig , result , {
112+ 'Found tool call' : foundToolCall ,
113+ } ) ;
114+ }
115+
116+ expect (
117+ foundToolCall ,
118+ 'Expected to find a run_shell_command tool call' ,
119+ ) . toBeTruthy ( ) ;
120+ } ) ;
121+
122+ it ( 'should succeed with --yolo mode' , async ( ) => {
123+ const rig = new TestRig ( ) ;
124+ await rig . setup ( 'should succeed with --yolo mode' ) ;
125+
126+ const prompt = `use wc to tell me how many lines there are in /proc/meminfo` ;
127+
128+ const result = await rig . run (
129+ {
130+ prompt : prompt ,
131+ } ,
132+ '--yolo' ,
133+ ) ;
134+
135+ const foundToolCall = await rig . waitForToolCall ( 'run_shell_command' , 15000 ) ;
136+
137+ if ( ! foundToolCall ) {
138+ printDebugInfo ( rig , result , {
139+ 'Found tool call' : foundToolCall ,
140+ } ) ;
141+ }
142+
143+ expect (
144+ foundToolCall ,
145+ 'Expected to find a run_shell_command tool call' ,
146+ ) . toBeTruthy ( ) ;
147+ expect ( result ) . toContain ( 'lines in /proc/meminfo' ) ;
148+ } ) ;
149+
150+ it ( 'should work with ShellTool alias' , async ( ) => {
151+ const rig = new TestRig ( ) ;
152+ await rig . setup ( 'should work with ShellTool alias' ) ;
153+
154+ const prompt = `use wc to tell me how many lines there are in /proc/meminfo` ;
155+
156+ const result = await rig . run ( {
157+ stdin : prompt ,
158+ args : [ '--allowed-tools=ShellTool(wc)' ] ,
159+ } ) ;
160+
161+ const foundToolCall = await rig . waitForToolCall ( 'run_shell_command' , 15000 ) ;
162+
163+ if ( ! foundToolCall ) {
164+ printDebugInfo ( rig , result , {
165+ 'Found tool call' : foundToolCall ,
166+ } ) ;
167+ }
168+
169+ expect (
170+ foundToolCall ,
171+ 'Expected to find a run_shell_command tool call' ,
172+ ) . toBeTruthy ( ) ;
173+ } ) ;
174+
175+ it ( 'should combine multiple --allowed-tools flags' , async ( ) => {
176+ const rig = new TestRig ( ) ;
177+ await rig . setup ( 'should combine multiple --allowed-tools flags' ) ;
178+
179+ const prompt = `use wc and ls` ;
180+
181+ const result = await rig . run ( {
182+ stdin : prompt ,
183+ args : [
184+ '--allowed-tools=run_shell_command(wc)' ,
185+ '--allowed-tools=run_shell_command(ls)' ,
186+ ] ,
187+ } ) ;
188+
189+ const foundToolCall = await rig . waitForToolCall ( 'run_shell_command' , 15000 ) ;
190+
191+ if ( ! foundToolCall ) {
192+ printDebugInfo ( rig , result , {
193+ 'Found tool call' : foundToolCall ,
194+ } ) ;
195+ }
196+
197+ expect (
198+ foundToolCall ,
199+ 'Expected to find a run_shell_command tool call' ,
200+ ) . toBeTruthy ( ) ;
201+ } ) ;
202+
203+ it ( 'should allow all with "ShellTool" and other specifics' , async ( ) => {
204+ const rig = new TestRig ( ) ;
205+ await rig . setup ( 'should allow all with "ShellTool" and other specifics' ) ;
206+
207+ const prompt = `use date` ;
208+
209+ const result = await rig . run ( {
210+ stdin : prompt ,
211+ args : [
212+ '--allowed-tools=run_shell_command(wc)' ,
213+ '--allowed-tools=run_shell_command' ,
214+ ] ,
215+ } ) ;
216+
217+ const foundToolCall = await rig . waitForToolCall ( 'run_shell_command' , 15000 ) ;
218+
219+ if ( ! foundToolCall ) {
220+ printDebugInfo ( rig , result , {
221+ 'Found tool call' : foundToolCall ,
222+ } ) ;
223+ }
224+
225+ expect (
226+ foundToolCall ,
227+ 'Expected to find a run_shell_command tool call' ,
228+ ) . toBeTruthy ( ) ;
229+ } ) ;
230+
71231 it ( 'should propagate environment variables to the child process' , async ( ) => {
72232 const rig = new TestRig ( ) ;
73233 await rig . setup ( 'should propagate environment variables' ) ;
0 commit comments