@@ -1559,11 +1559,23 @@ where
15591559 sandbox. object_id ( ) . to_string ( )
15601560 } ;
15611561
1562- let config = client
1562+ let config_result = client
15631563 . get_sandbox_config ( GetSandboxConfigRequest { sandbox_id } )
1564- . await
1565- . into_diagnostic ( ) ?
1566- . into_inner ( ) ;
1564+ . await ;
1565+ let config = match config_result {
1566+ Ok ( response) => response. into_inner ( ) ,
1567+ Err ( _) if !policy_only && configuration_failure_message ( & sandbox) . is_some ( ) => {
1568+ // An invalid desired policy must not hide the status needed to
1569+ // repair it. Keep payload-only reads strict.
1570+ GetSandboxConfigResponse {
1571+ configuration_error : configuration_failure_message ( & sandbox)
1572+ . unwrap_or_default ( )
1573+ . to_string ( ) ,
1574+ ..Default :: default ( )
1575+ }
1576+ }
1577+ Err ( error) => return Err ( error) . into_diagnostic ( ) ,
1578+ } ;
15671579
15681580 if policy_only {
15691581 let Some ( ref policy) = config. policy else {
@@ -1597,6 +1609,22 @@ where
15971609 println ! ( " {} {}" , "Id:" . dimmed( ) , id) ;
15981610 println ! ( " {} {}" , "Name:" . dimmed( ) , name) ;
15991611 println ! ( " {} {}" , "Phase:" . dimmed( ) , phase_name( sandbox. phase( ) ) ) ;
1612+ if let Some ( status) = sandbox. status . as_ref ( ) {
1613+ for condition in & status. conditions {
1614+ if matches ! (
1615+ condition. r#type. as_str( ) ,
1616+ "ConfigurationReady" | "DesiredConfigurationReady"
1617+ ) && condition. status . eq_ignore_ascii_case ( "false" )
1618+ {
1619+ println ! (
1620+ " {} {}: {}" ,
1621+ "Configuration:" . dimmed( ) ,
1622+ condition. reason,
1623+ condition. message
1624+ ) ;
1625+ }
1626+ }
1627+ }
16001628 if let Some ( exit_code) = sandbox. status . as_ref ( ) . and_then ( |status| status. exit_code ) {
16011629 println ! ( " {} {}" , "Exit Code:" . dimmed( ) , exit_code) ;
16021630 }
@@ -2459,7 +2487,19 @@ pub async fn sandbox_list(
24592487 Ok ( ( ) )
24602488}
24612489
2490+ fn configuration_failure_message ( sandbox : & Sandbox ) -> Option < & str > {
2491+ sandbox
2492+ . status
2493+ . as_ref ( ) ?
2494+ . configuration_admission
2495+ . as_ref ( )
2496+ . map ( |admission| admission. error . as_str ( ) )
2497+ . filter ( |message| !message. is_empty ( ) )
2498+ }
2499+
24622500fn sandbox_to_json ( sandbox : & Sandbox ) -> serde_json:: Value {
2501+ use openshell_core:: proto:: ConfigurationAdmissionState ;
2502+
24632503 let meta = sandbox. metadata . as_ref ( ) ;
24642504 let labels = meta. map_or_else ( || serde_json:: json!( { } ) , |m| serde_json:: json!( m. labels) ) ;
24652505 let annotations = meta. map_or_else (
@@ -2499,6 +2539,25 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
24992539 } )
25002540 . collect :: < Vec < _ > > ( )
25012541 } ) ;
2542+ let admission = sandbox
2543+ . status
2544+ . as_ref ( )
2545+ . and_then ( |status| status. configuration_admission . as_ref ( ) )
2546+ . map ( |admission| {
2547+ serde_json:: json!( {
2548+ "state" : match ConfigurationAdmissionState :: try_from( admission. state) {
2549+ Ok ( ConfigurationAdmissionState :: Pending ) => "pending" ,
2550+ Ok ( ConfigurationAdmissionState :: Accepted ) => "accepted" ,
2551+ Ok ( ConfigurationAdmissionState :: Rejected ) => "rejected" ,
2552+ _ => "unknown" ,
2553+ } ,
2554+ "error" : admission. error,
2555+ "policy_version" : admission. policy_version,
2556+ "policy_hash" : admission. policy_hash,
2557+ "config_revision" : admission. config_revision,
2558+ "provider_env_revision" : admission. provider_env_revision,
2559+ } )
2560+ } ) ;
25022561 serde_json:: json!( {
25032562 "id" : sandbox. object_id( ) ,
25042563 "name" : sandbox. object_name( ) ,
@@ -2512,6 +2571,7 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
25122571 "exit_code" : sandbox. status. as_ref( ) . and_then( |status| status. exit_code) ,
25132572 "conditions" : conditions,
25142573 "endpoint_statuses" : endpoint_statuses,
2574+ "configuration_admission" : admission,
25152575 "created_from_workload_template" : created_from_workload_template,
25162576 } )
25172577}
@@ -7332,6 +7392,45 @@ mod tests {
73327392 assert_eq ! ( json[ "resources" ] [ "gpu" ] , 2 ) ;
73337393 }
73347394
7395+ #[ test]
7396+ fn sandbox_json_exposes_repair_diagnostic_and_accepted_generation ( ) {
7397+ use openshell_core:: proto:: { ConfigurationAdmissionState , SandboxConfigurationAdmission } ;
7398+
7399+ let mut sandbox = Sandbox :: default ( ) ;
7400+ sandbox. set_phase ( SandboxPhase :: Provisioning as i32 ) ;
7401+ let status = sandbox. status . as_mut ( ) . unwrap ( ) ;
7402+ status. configuration_admission = Some ( SandboxConfigurationAdmission {
7403+ state : ConfigurationAdmissionState :: Rejected as i32 ,
7404+ error : "rule image_api requires L7 inspection" . to_string ( ) ,
7405+ policy_hash : "candidate-hash" . to_string ( ) ,
7406+ ..Default :: default ( )
7407+ } ) ;
7408+ status. conditions . push ( SandboxCondition {
7409+ r#type : "ConfigurationReady" . to_string ( ) ,
7410+ status : "False" . to_string ( ) ,
7411+ reason : "ConfigurationInvalid" . to_string ( ) ,
7412+ message : "rule image_api requires L7 inspection" . to_string ( ) ,
7413+ ..Default :: default ( )
7414+ } ) ;
7415+ let json = super :: sandbox_to_json ( & sandbox) ;
7416+ assert_eq ! ( json[ "configuration_admission" ] [ "state" ] , "rejected" ) ;
7417+ assert_eq ! ( json[ "conditions" ] [ 0 ] [ "reason" ] , "ConfigurationInvalid" ) ;
7418+ assert_eq ! (
7419+ super :: configuration_failure_message( & sandbox) ,
7420+ Some ( "rule image_api requires L7 inspection" )
7421+ ) ;
7422+ sandbox
7423+ . status
7424+ . as_mut ( )
7425+ . unwrap ( )
7426+ . configuration_admission
7427+ . as_mut ( )
7428+ . unwrap ( )
7429+ . error
7430+ . clear ( ) ;
7431+ assert_eq ! ( super :: configuration_failure_message( & sandbox) , None ) ;
7432+ }
7433+
73357434 #[ test]
73367435 fn sandbox_detail_to_json_includes_policy_fields ( ) {
73377436 let mut sandbox = Sandbox {
0 commit comments