@@ -14,6 +14,35 @@ fn failing_pty_path() -> tempfile::TempDir {
1414 bin
1515}
1616
17+ fn failing_pty_spawn_path ( ) -> tempfile:: TempDir {
18+ let bin = tempfile:: tempdir ( ) . unwrap ( ) ;
19+ executable (
20+ & bin. path ( ) . join ( "pty" ) ,
21+ "#!/bin/sh\n if [ \" $1\" = list ]; then\n printf '[]\\ n'\n exit 0\n fi\n printf 'forced pty failure\\ n' >&2\n exit 42\n " ,
22+ ) ;
23+ bin
24+ }
25+
26+ fn assert_errors_once_exits_nonzero ( command : & mut Command ) {
27+ let output = command. output ( ) . unwrap ( ) ;
28+ assert ! (
29+ !output. status. success( ) ,
30+ "an errored --once pass reported success\n stdout:\n {}\n stderr:\n {}" ,
31+ String :: from_utf8_lossy( & output. stdout) ,
32+ String :: from_utf8_lossy( & output. stderr)
33+ ) ;
34+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
35+ assert ! (
36+ stderr. contains( "error: spawn" )
37+ && stderr. contains( "one-shot reconcile pass reported errors" ) ,
38+ "missing errored-pass report:\n {stderr}"
39+ ) ;
40+ assert ! (
41+ !stderr. contains( "pass skipped" ) ,
42+ "spawn failure incorrectly skipped the pass:\n {stderr}"
43+ ) ;
44+ }
45+
1746fn assert_skipped_once_exits_nonzero ( command : & mut Command ) {
1847 let output = command. output ( ) . unwrap ( ) ;
1948 assert ! (
@@ -53,6 +82,29 @@ fn catalog_up_once_exits_nonzero_when_the_pass_is_skipped() {
5382 ) ;
5483}
5584
85+ #[ test]
86+ fn catalog_up_once_exits_nonzero_when_the_report_has_errors ( ) {
87+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
88+ let bin = failing_pty_spawn_path ( ) ;
89+ let agent = tmp. path ( ) . join ( "catalog/agents/h/worker/agent.kdl" ) ;
90+ fs:: create_dir_all ( agent. parent ( ) . unwrap ( ) ) . unwrap ( ) ;
91+ fs:: write (
92+ & agent,
93+ "agent \" worker\" { host \" h\" ; command \" true\" }\n " ,
94+ )
95+ . unwrap ( ) ;
96+
97+ assert_errors_once_exits_nonzero (
98+ Command :: new ( env ! ( "CARGO_BIN_EXE_st2" ) )
99+ . arg ( "up" )
100+ . arg ( "--catalog" )
101+ . arg ( tmp. path ( ) . join ( "catalog" ) )
102+ . args ( [ "--host" , "h" , "--once" ] )
103+ . env ( "PATH" , bin. path ( ) )
104+ . env ( "XDG_STATE_HOME" , tmp. path ( ) . join ( "state" ) ) ,
105+ ) ;
106+ }
107+
56108#[ test]
57109fn spec_up_once_exits_nonzero_when_the_pass_is_skipped ( ) {
58110 let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
@@ -73,3 +125,24 @@ fn spec_up_once_exits_nonzero_when_the_pass_is_skipped() {
73125 . env ( "XDG_STATE_HOME" , tmp. path ( ) . join ( "state" ) ) ,
74126 ) ;
75127}
128+
129+ #[ test]
130+ fn spec_up_once_exits_nonzero_when_the_report_has_errors ( ) {
131+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
132+ let bin = failing_pty_spawn_path ( ) ;
133+ let spec = tmp. path ( ) . join ( "fleet.kdl" ) ;
134+ fs:: write (
135+ & spec,
136+ "host \" h\" \n team \" fleet\" { agent \" worker\" { command \" true\" } }\n " ,
137+ )
138+ . unwrap ( ) ;
139+
140+ assert_errors_once_exits_nonzero (
141+ Command :: new ( env ! ( "CARGO_BIN_EXE_st2" ) )
142+ . arg ( "up" )
143+ . arg ( & spec)
144+ . args ( [ "--host" , "h" , "--once" ] )
145+ . env ( "PATH" , bin. path ( ) )
146+ . env ( "XDG_STATE_HOME" , tmp. path ( ) . join ( "state" ) ) ,
147+ ) ;
148+ }
0 commit comments