22//! answers, what a call leaves for the next, the time limit, the output
33//! cap, and the arguments a call may pass.
44
5- use runvil_plugin_sdk:: ToolErrorKind ;
5+ use runvil_plugin_sdk:: { Caller , ToolErrorKind } ;
66use serde_json:: json;
77
88use super :: { OUTPUT_CAP , middle_cut, quoted} ;
9- use crate :: fixture:: { PACK , answer, loaded, run, shell} ;
9+ use crate :: fixture:: { PACK , answer, loaded, run, shell, shell_as } ;
1010
1111#[ test]
1212fn a_command_answers_its_exit_code_and_its_output ( ) {
@@ -84,8 +84,9 @@ fn a_variable_or_a_function_from_one_call_is_gone_in_the_next() {
8484fn a_command_past_its_time_limit_is_stopped_and_the_call_fails_with_the_limit ( ) {
8585 let loaded = loaded ( ) ;
8686 let pack = loaded. new_pack ( PACK ) . expect ( "the Pack instance is made" ) ;
87- let stopped = shell (
87+ let stopped = shell_as (
8888 & pack,
89+ Caller :: Script ,
8990 & json ! ( { "command" : "sleep 20" , "block_until_ms" : 50 } ) ,
9091 )
9192 . expect_err ( "the command runs past its limit" ) ;
@@ -113,8 +114,12 @@ fn a_time_limit_over_the_ceiling_is_lowered_to_it() {
113114fn a_command_that_does_not_parse_fails_with_the_shells_reason ( ) {
114115 let loaded = loaded ( ) ;
115116 let pack = loaded. new_pack ( PACK ) . expect ( "the Pack instance is made" ) ;
116- let error = shell ( & pack, & json ! ( { "command" : "if true; then" } ) )
117- . expect_err ( "the command does not parse" ) ;
117+ let error = shell_as (
118+ & pack,
119+ Caller :: Script ,
120+ & json ! ( { "command" : "if true; then" } ) ,
121+ )
122+ . expect_err ( "the command does not parse" ) ;
118123 assert_eq ! ( error. kind( ) , ToolErrorKind :: Backend ) ;
119124 assert_eq ! (
120125 error. message( ) ,
@@ -138,8 +143,12 @@ fn a_command_the_shell_does_not_have_is_an_output_that_says_so() {
138143fn a_command_that_loops_without_end_is_stopped_by_the_shells_limits ( ) {
139144 let loaded = loaded ( ) ;
140145 let pack = loaded. new_pack ( PACK ) . expect ( "the Pack instance is made" ) ;
141- let error = shell ( & pack, & json ! ( { "command" : "while true; do :; done" } ) )
142- . expect_err ( "the loop passes a limit" ) ;
146+ let error = shell_as (
147+ & pack,
148+ Caller :: Script ,
149+ & json ! ( { "command" : "while true; do :; done" } ) ,
150+ )
151+ . expect_err ( "the loop passes a limit" ) ;
143152 assert_eq ! ( error. kind( ) , ToolErrorKind :: Backend ) ;
144153 assert_eq ! (
145154 error. message( ) ,
@@ -224,7 +233,7 @@ fn arguments_that_do_not_match_the_parameters_are_refused() {
224233 "invalid value" ,
225234 ) ,
226235 ] {
227- let error = shell ( & pack, & args) . expect_err ( "the arguments are refused" ) ;
236+ let error = shell_as ( & pack, Caller :: Script , & args) . expect_err ( "the arguments are refused" ) ;
228237 assert_eq ! ( error. kind( ) , ToolErrorKind :: InvalidArguments , "{args}" ) ;
229238 assert ! (
230239 error. message( ) . starts_with( "Shell: " ) && error. message( ) . contains( part) ,
@@ -234,6 +243,44 @@ fn arguments_that_do_not_match_the_parameters_are_refused() {
234243 }
235244}
236245
246+ #[ test]
247+ fn model_calls_return_invalid_arguments_and_backend_errors_as_trusted_output ( ) {
248+ let loaded = loaded ( ) ;
249+ let pack = loaded. new_pack ( PACK ) . expect ( "the Pack instance is made" ) ;
250+
251+ let invalid = shell ( & pack, & json ! ( { "command" : "true" , "block_until_ms" : 0 } ) )
252+ . expect ( "a model call receives invalid-arguments errors as output" ) ;
253+ assert ! ( invalid. is_trusted( ) ) ;
254+ assert ! (
255+ invalid. text( ) . starts_with( "Shell: " )
256+ && invalid
257+ . text( )
258+ . contains( "block_until_ms is 0, and it must be at least 1" ) ,
259+ "{}" ,
260+ invalid. text( )
261+ ) ;
262+
263+ let timed_out = shell (
264+ & pack,
265+ & json ! ( { "command" : "sleep 20" , "block_until_ms" : 50 } ) ,
266+ )
267+ . expect ( "a model call receives timeout errors as output" ) ;
268+ assert ! ( timed_out. is_trusted( ) ) ;
269+ assert_eq ! (
270+ timed_out. text( ) ,
271+ "Shell: the command was stopped at its time limit of 50 ms, before it finished."
272+ ) ;
273+
274+ let parse_error = shell ( & pack, & json ! ( { "command" : "if true; then" } ) )
275+ . expect ( "a model call receives backend errors as output" ) ;
276+ assert ! ( parse_error. is_trusted( ) ) ;
277+ assert_eq ! (
278+ parse_error. text( ) ,
279+ "Shell: the shell did not finish the command: parse error at line 2, column 1: syntax \
280+ error: unexpected end of file"
281+ ) ;
282+ }
283+
237284#[ test]
238285fn a_description_and_null_for_an_optional_parameter_are_accepted ( ) {
239286 let loaded = loaded ( ) ;
0 commit comments