@@ -304,10 +304,10 @@ impl MxcComputeBackend {
304304 if sandbox
305305 . spec
306306 . as_ref ( )
307- . is_some_and ( |spec| spec. await_main_process_attachment )
307+ . is_some_and ( |spec| spec. await_main_process_attachment && spec . tty )
308308 {
309309 return Err ( tonic:: Status :: failed_precondition (
310- "MXC does not support foreground attachment to the main process. Create the sandbox with --detach." ,
310+ "MXC does not support an interactive terminal for the main process. Create the sandbox with --no-tty or --detach." ,
311311 ) ) ;
312312 }
313313 openshell_core:: resource_admission:: check_sandbox_driver_config (
@@ -1931,21 +1931,37 @@ mod tests {
19311931 }
19321932
19331933 #[ tokio:: test]
1934- async fn foreground_attachment_is_rejected_before_provisioning ( ) {
1934+ async fn foreground_terminal_attachment_is_rejected_before_provisioning ( ) {
19351935 let ( backend, mut sandbox, _dir) = preflight_fixture ( ) ;
1936- sandbox. spec . as_mut ( ) . unwrap ( ) . command =
1937- vec ! [ "cmd.exe" . into( ) , "/c" . into( ) , "exit 0" . into( ) ] ;
1938- sandbox. spec . as_mut ( ) . unwrap ( ) . await_main_process_attachment = true ;
1936+ let spec = sandbox. spec . as_mut ( ) . unwrap ( ) ;
1937+ spec. command = vec ! [ "cmd.exe" . into( ) , "/c" . into( ) , "exit 0" . into( ) ] ;
1938+ spec. await_main_process_attachment = true ;
1939+ spec. tty = true ;
19391940 let error = backend. validate_sandbox_create ( & sandbox) . unwrap_err ( ) ;
19401941 assert_eq ! ( error. code( ) , tonic:: Code :: FailedPrecondition ) ;
1941- assert ! ( error. message( ) . contains( "--detach " ) ) ;
1942+ assert ! ( error. message( ) . contains( "--no-tty " ) ) ;
19421943 let error = backend. create_sandbox ( & sandbox) . await . unwrap_err ( ) ;
19431944 assert_eq ! ( error. code( ) , tonic:: Code :: FailedPrecondition ) ;
1944- assert ! ( error. message( ) . contains( "foreground attachment " ) ) ;
1945+ assert ! ( error. message( ) . contains( "interactive terminal " ) ) ;
19451946 assert ! ( backend. get_sandbox( & sandbox. id) . await . is_none( ) ) ;
19461947 assert ! ( !backend. config. state_dir. exists( ) ) ;
1947- sandbox. spec . as_mut ( ) . unwrap ( ) . await_main_process_attachment = false ;
1948- assert ! ( backend. validate_sandbox_create( & sandbox) . is_ok( ) ) ;
1948+ }
1949+
1950+ #[ test]
1951+ fn non_terminal_foreground_and_detached_creates_are_admitted ( ) {
1952+ let ( backend, mut sandbox, _dir) = preflight_fixture ( ) ;
1953+ let spec = sandbox. spec . as_mut ( ) . unwrap ( ) ;
1954+ spec. command = vec ! [ "cmd.exe" . into( ) , "/c" . into( ) , "exit 0" . into( ) ] ;
1955+ // Foreground without a terminal streams output over the SSH attachment.
1956+ for ( await_attachment, tty) in [ ( true , false ) , ( false , false ) , ( false , true ) ] {
1957+ let spec = sandbox. spec . as_mut ( ) . unwrap ( ) ;
1958+ spec. await_main_process_attachment = await_attachment;
1959+ spec. tty = tty;
1960+ assert ! (
1961+ backend. validate_sandbox_create( & sandbox) . is_ok( ) ,
1962+ "await_main_process_attachment={await_attachment} tty={tty} must be admitted"
1963+ ) ;
1964+ }
19491965 }
19501966
19511967 #[ test]
0 commit comments