@@ -1567,11 +1567,23 @@ where
15671567 sandbox. object_id ( ) . to_string ( )
15681568 } ;
15691569
1570- let config = client
1570+ let config_result = client
15711571 . get_sandbox_config ( GetSandboxConfigRequest { sandbox_id } )
1572- . await
1573- . into_diagnostic ( ) ?
1574- . into_inner ( ) ;
1572+ . await ;
1573+ let config = match config_result {
1574+ Ok ( response) => response. into_inner ( ) ,
1575+ Err ( _) if !policy_only && configuration_failure_message ( & sandbox) . is_some ( ) => {
1576+ // An invalid desired policy must not hide the status needed to
1577+ // repair it. Keep payload-only reads strict.
1578+ GetSandboxConfigResponse {
1579+ configuration_error : configuration_failure_message ( & sandbox)
1580+ . unwrap_or_default ( )
1581+ . to_string ( ) ,
1582+ ..Default :: default ( )
1583+ }
1584+ }
1585+ Err ( error) => return Err ( error) . into_diagnostic ( ) ,
1586+ } ;
15751587
15761588 if policy_only {
15771589 let Some ( ref policy) = config. policy else {
@@ -1605,6 +1617,22 @@ where
16051617 println ! ( " {} {}" , "Id:" . dimmed( ) , id) ;
16061618 println ! ( " {} {}" , "Name:" . dimmed( ) , name) ;
16071619 println ! ( " {} {}" , "Phase:" . dimmed( ) , phase_name( sandbox. phase( ) ) ) ;
1620+ if let Some ( status) = sandbox. status . as_ref ( ) {
1621+ for condition in & status. conditions {
1622+ if matches ! (
1623+ condition. r#type. as_str( ) ,
1624+ "ConfigurationReady" | "DesiredConfigurationReady"
1625+ ) && condition. status . eq_ignore_ascii_case ( "false" )
1626+ {
1627+ println ! (
1628+ " {} {}: {}" ,
1629+ "Configuration:" . dimmed( ) ,
1630+ condition. reason,
1631+ condition. message
1632+ ) ;
1633+ }
1634+ }
1635+ }
16081636 if let Some ( exit_code) = sandbox. status . as_ref ( ) . and_then ( |status| status. exit_code ) {
16091637 println ! ( " {} {}" , "Exit Code:" . dimmed( ) , exit_code) ;
16101638 }
@@ -2467,7 +2495,19 @@ pub async fn sandbox_list(
24672495 Ok ( ( ) )
24682496}
24692497
2498+ fn configuration_failure_message ( sandbox : & Sandbox ) -> Option < & str > {
2499+ sandbox
2500+ . status
2501+ . as_ref ( ) ?
2502+ . configuration_admission
2503+ . as_ref ( )
2504+ . map ( |admission| admission. error . as_str ( ) )
2505+ . filter ( |message| !message. is_empty ( ) )
2506+ }
2507+
24702508fn sandbox_to_json ( sandbox : & Sandbox ) -> serde_json:: Value {
2509+ use openshell_core:: proto:: ConfigurationAdmissionState ;
2510+
24712511 let meta = sandbox. metadata . as_ref ( ) ;
24722512 let labels = meta. map_or_else ( || serde_json:: json!( { } ) , |m| serde_json:: json!( m. labels) ) ;
24732513 let annotations = meta. map_or_else (
@@ -2507,6 +2547,25 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
25072547 } )
25082548 . collect :: < Vec < _ > > ( )
25092549 } ) ;
2550+ let admission = sandbox
2551+ . status
2552+ . as_ref ( )
2553+ . and_then ( |status| status. configuration_admission . as_ref ( ) )
2554+ . map ( |admission| {
2555+ serde_json:: json!( {
2556+ "state" : match ConfigurationAdmissionState :: try_from( admission. state) {
2557+ Ok ( ConfigurationAdmissionState :: Pending ) => "pending" ,
2558+ Ok ( ConfigurationAdmissionState :: Accepted ) => "accepted" ,
2559+ Ok ( ConfigurationAdmissionState :: Rejected ) => "rejected" ,
2560+ _ => "unknown" ,
2561+ } ,
2562+ "error" : admission. error,
2563+ "policy_version" : admission. policy_version,
2564+ "policy_hash" : admission. policy_hash,
2565+ "config_revision" : admission. config_revision,
2566+ "provider_env_revision" : admission. provider_env_revision,
2567+ } )
2568+ } ) ;
25102569 serde_json:: json!( {
25112570 "id" : sandbox. object_id( ) ,
25122571 "name" : sandbox. object_name( ) ,
@@ -2520,6 +2579,7 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
25202579 "exit_code" : sandbox. status. as_ref( ) . and_then( |status| status. exit_code) ,
25212580 "conditions" : conditions,
25222581 "endpoint_statuses" : endpoint_statuses,
2582+ "configuration_admission" : admission,
25232583 "created_from_workload_template" : created_from_workload_template,
25242584 } )
25252585}
@@ -7365,6 +7425,45 @@ mod tests {
73657425 assert_eq ! ( json[ "resources" ] [ "gpu" ] , 2 ) ;
73667426 }
73677427
7428+ #[ test]
7429+ fn sandbox_json_exposes_repair_diagnostic_and_accepted_generation ( ) {
7430+ use openshell_core:: proto:: { ConfigurationAdmissionState , SandboxConfigurationAdmission } ;
7431+
7432+ let mut sandbox = Sandbox :: default ( ) ;
7433+ sandbox. set_phase ( SandboxPhase :: Provisioning as i32 ) ;
7434+ let status = sandbox. status . as_mut ( ) . unwrap ( ) ;
7435+ status. configuration_admission = Some ( SandboxConfigurationAdmission {
7436+ state : ConfigurationAdmissionState :: Rejected as i32 ,
7437+ error : "rule image_api requires L7 inspection" . to_string ( ) ,
7438+ policy_hash : "candidate-hash" . to_string ( ) ,
7439+ ..Default :: default ( )
7440+ } ) ;
7441+ status. conditions . push ( SandboxCondition {
7442+ r#type : "ConfigurationReady" . to_string ( ) ,
7443+ status : "False" . to_string ( ) ,
7444+ reason : "ConfigurationInvalid" . to_string ( ) ,
7445+ message : "rule image_api requires L7 inspection" . to_string ( ) ,
7446+ ..Default :: default ( )
7447+ } ) ;
7448+ let json = super :: sandbox_to_json ( & sandbox) ;
7449+ assert_eq ! ( json[ "configuration_admission" ] [ "state" ] , "rejected" ) ;
7450+ assert_eq ! ( json[ "conditions" ] [ 0 ] [ "reason" ] , "ConfigurationInvalid" ) ;
7451+ assert_eq ! (
7452+ super :: configuration_failure_message( & sandbox) ,
7453+ Some ( "rule image_api requires L7 inspection" )
7454+ ) ;
7455+ sandbox
7456+ . status
7457+ . as_mut ( )
7458+ . unwrap ( )
7459+ . configuration_admission
7460+ . as_mut ( )
7461+ . unwrap ( )
7462+ . error
7463+ . clear ( ) ;
7464+ assert_eq ! ( super :: configuration_failure_message( & sandbox) , None ) ;
7465+ }
7466+
73687467 #[ test]
73697468 fn sandbox_detail_to_json_includes_policy_fields ( ) {
73707469 let mut sandbox = Sandbox {
0 commit comments