@@ -1558,11 +1558,23 @@ where
15581558 sandbox. object_id ( ) . to_string ( )
15591559 } ;
15601560
1561- let config = client
1561+ let config_result = client
15621562 . get_sandbox_config ( GetSandboxConfigRequest { sandbox_id } )
1563- . await
1564- . into_diagnostic ( ) ?
1565- . into_inner ( ) ;
1563+ . await ;
1564+ let config = match config_result {
1565+ Ok ( response) => response. into_inner ( ) ,
1566+ Err ( _) if !policy_only && configuration_failure_message ( & sandbox) . is_some ( ) => {
1567+ // An invalid desired policy must not hide the status needed to
1568+ // repair it. Keep payload-only reads strict.
1569+ GetSandboxConfigResponse {
1570+ configuration_error : configuration_failure_message ( & sandbox)
1571+ . unwrap_or_default ( )
1572+ . to_string ( ) ,
1573+ ..Default :: default ( )
1574+ }
1575+ }
1576+ Err ( error) => return Err ( error) . into_diagnostic ( ) ,
1577+ } ;
15661578
15671579 if policy_only {
15681580 let Some ( ref policy) = config. policy else {
@@ -1596,6 +1608,22 @@ where
15961608 println ! ( " {} {}" , "Id:" . dimmed( ) , id) ;
15971609 println ! ( " {} {}" , "Name:" . dimmed( ) , name) ;
15981610 println ! ( " {} {}" , "Phase:" . dimmed( ) , phase_name( sandbox. phase( ) ) ) ;
1611+ if let Some ( status) = sandbox. status . as_ref ( ) {
1612+ for condition in & status. conditions {
1613+ if matches ! (
1614+ condition. r#type. as_str( ) ,
1615+ "ConfigurationReady" | "DesiredConfigurationReady"
1616+ ) && condition. status . eq_ignore_ascii_case ( "false" )
1617+ {
1618+ println ! (
1619+ " {} {}: {}" ,
1620+ "Configuration:" . dimmed( ) ,
1621+ condition. reason,
1622+ condition. message
1623+ ) ;
1624+ }
1625+ }
1626+ }
15991627 if let Some ( exit_code) = sandbox. status . as_ref ( ) . and_then ( |status| status. exit_code ) {
16001628 println ! ( " {} {}" , "Exit Code:" . dimmed( ) , exit_code) ;
16011629 }
@@ -2458,7 +2486,19 @@ pub async fn sandbox_list(
24582486 Ok ( ( ) )
24592487}
24602488
2489+ fn configuration_failure_message ( sandbox : & Sandbox ) -> Option < & str > {
2490+ sandbox
2491+ . status
2492+ . as_ref ( ) ?
2493+ . configuration_admission
2494+ . as_ref ( )
2495+ . map ( |admission| admission. error . as_str ( ) )
2496+ . filter ( |message| !message. is_empty ( ) )
2497+ }
2498+
24612499fn sandbox_to_json ( sandbox : & Sandbox ) -> serde_json:: Value {
2500+ use openshell_core:: proto:: ConfigurationAdmissionState ;
2501+
24622502 let meta = sandbox. metadata . as_ref ( ) ;
24632503 let labels = meta. map_or_else ( || serde_json:: json!( { } ) , |m| serde_json:: json!( m. labels) ) ;
24642504 let annotations = meta. map_or_else (
@@ -2498,6 +2538,25 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
24982538 } )
24992539 . collect :: < Vec < _ > > ( )
25002540 } ) ;
2541+ let admission = sandbox
2542+ . status
2543+ . as_ref ( )
2544+ . and_then ( |status| status. configuration_admission . as_ref ( ) )
2545+ . map ( |admission| {
2546+ serde_json:: json!( {
2547+ "state" : match ConfigurationAdmissionState :: try_from( admission. state) {
2548+ Ok ( ConfigurationAdmissionState :: Pending ) => "pending" ,
2549+ Ok ( ConfigurationAdmissionState :: Accepted ) => "accepted" ,
2550+ Ok ( ConfigurationAdmissionState :: Rejected ) => "rejected" ,
2551+ _ => "unknown" ,
2552+ } ,
2553+ "error" : admission. error,
2554+ "policy_version" : admission. policy_version,
2555+ "policy_hash" : admission. policy_hash,
2556+ "config_revision" : admission. config_revision,
2557+ "provider_env_revision" : admission. provider_env_revision,
2558+ } )
2559+ } ) ;
25012560 serde_json:: json!( {
25022561 "id" : sandbox. object_id( ) ,
25032562 "name" : sandbox. object_name( ) ,
@@ -2511,6 +2570,7 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
25112570 "exit_code" : sandbox. status. as_ref( ) . and_then( |status| status. exit_code) ,
25122571 "conditions" : conditions,
25132572 "endpoint_statuses" : endpoint_statuses,
2573+ "configuration_admission" : admission,
25142574 "created_from_workload_template" : created_from_workload_template,
25152575 } )
25162576}
@@ -7306,6 +7366,45 @@ mod tests {
73067366 assert_eq ! ( json[ "resources" ] [ "gpu" ] , 2 ) ;
73077367 }
73087368
7369+ #[ test]
7370+ fn sandbox_json_exposes_repair_diagnostic_and_accepted_generation ( ) {
7371+ use openshell_core:: proto:: { ConfigurationAdmissionState , SandboxConfigurationAdmission } ;
7372+
7373+ let mut sandbox = Sandbox :: default ( ) ;
7374+ sandbox. set_phase ( SandboxPhase :: Provisioning as i32 ) ;
7375+ let status = sandbox. status . as_mut ( ) . unwrap ( ) ;
7376+ status. configuration_admission = Some ( SandboxConfigurationAdmission {
7377+ state : ConfigurationAdmissionState :: Rejected as i32 ,
7378+ error : "rule image_api requires L7 inspection" . to_string ( ) ,
7379+ policy_hash : "candidate-hash" . to_string ( ) ,
7380+ ..Default :: default ( )
7381+ } ) ;
7382+ status. conditions . push ( SandboxCondition {
7383+ r#type : "ConfigurationReady" . to_string ( ) ,
7384+ status : "False" . to_string ( ) ,
7385+ reason : "ConfigurationInvalid" . to_string ( ) ,
7386+ message : "rule image_api requires L7 inspection" . to_string ( ) ,
7387+ ..Default :: default ( )
7388+ } ) ;
7389+ let json = super :: sandbox_to_json ( & sandbox) ;
7390+ assert_eq ! ( json[ "configuration_admission" ] [ "state" ] , "rejected" ) ;
7391+ assert_eq ! ( json[ "conditions" ] [ 0 ] [ "reason" ] , "ConfigurationInvalid" ) ;
7392+ assert_eq ! (
7393+ super :: configuration_failure_message( & sandbox) ,
7394+ Some ( "rule image_api requires L7 inspection" )
7395+ ) ;
7396+ sandbox
7397+ . status
7398+ . as_mut ( )
7399+ . unwrap ( )
7400+ . configuration_admission
7401+ . as_mut ( )
7402+ . unwrap ( )
7403+ . error
7404+ . clear ( ) ;
7405+ assert_eq ! ( super :: configuration_failure_message( & sandbox) , None ) ;
7406+ }
7407+
73097408 #[ test]
73107409 fn sandbox_detail_to_json_includes_policy_fields ( ) {
73117410 let mut sandbox = Sandbox {
0 commit comments