@@ -1510,11 +1510,23 @@ pub async fn sandbox_get(
15101510 sandbox. object_id ( ) . to_string ( )
15111511 } ;
15121512
1513- let config = client
1513+ let config_result = client
15141514 . get_sandbox_config ( GetSandboxConfigRequest { sandbox_id } )
1515- . await
1516- . into_diagnostic ( ) ?
1517- . into_inner ( ) ;
1515+ . await ;
1516+ let config = match config_result {
1517+ Ok ( response) => response. into_inner ( ) ,
1518+ Err ( _) if !policy_only && configuration_failure_message ( & sandbox) . is_some ( ) => {
1519+ // An invalid desired policy must not hide the status needed to
1520+ // repair it. Keep payload-only reads strict.
1521+ GetSandboxConfigResponse {
1522+ configuration_error : configuration_failure_message ( & sandbox)
1523+ . unwrap_or_default ( )
1524+ . to_string ( ) ,
1525+ ..Default :: default ( )
1526+ }
1527+ }
1528+ Err ( error) => return Err ( error) . into_diagnostic ( ) ,
1529+ } ;
15181530
15191531 if policy_only {
15201532 let Some ( ref policy) = config. policy else {
@@ -1548,6 +1560,22 @@ pub async fn sandbox_get(
15481560 println ! ( " {} {}" , "Id:" . dimmed( ) , id) ;
15491561 println ! ( " {} {}" , "Name:" . dimmed( ) , name) ;
15501562 println ! ( " {} {}" , "Phase:" . dimmed( ) , phase_name( sandbox. phase( ) ) ) ;
1563+ if let Some ( status) = sandbox. status . as_ref ( ) {
1564+ for condition in & status. conditions {
1565+ if matches ! (
1566+ condition. r#type. as_str( ) ,
1567+ "ConfigurationReady" | "DesiredConfigurationReady"
1568+ ) && condition. status . eq_ignore_ascii_case ( "false" )
1569+ {
1570+ println ! (
1571+ " {} {}: {}" ,
1572+ "Configuration:" . dimmed( ) ,
1573+ condition. reason,
1574+ condition. message
1575+ ) ;
1576+ }
1577+ }
1578+ }
15511579 if let Some ( exit_code) = sandbox. status . as_ref ( ) . and_then ( |status| status. exit_code ) {
15521580 println ! ( " {} {}" , "Exit Code:" . dimmed( ) , exit_code) ;
15531581 }
@@ -2405,7 +2433,19 @@ pub async fn sandbox_list(
24052433 Ok ( ( ) )
24062434}
24072435
2436+ fn configuration_failure_message ( sandbox : & Sandbox ) -> Option < & str > {
2437+ sandbox
2438+ . status
2439+ . as_ref ( ) ?
2440+ . configuration_admission
2441+ . as_ref ( )
2442+ . map ( |admission| admission. error . as_str ( ) )
2443+ . filter ( |message| !message. is_empty ( ) )
2444+ }
2445+
24082446fn sandbox_to_json ( sandbox : & Sandbox ) -> serde_json:: Value {
2447+ use openshell_core:: proto:: ConfigurationAdmissionState ;
2448+
24092449 let meta = sandbox. metadata . as_ref ( ) ;
24102450 let labels = meta. map_or_else ( || serde_json:: json!( { } ) , |m| serde_json:: json!( m. labels) ) ;
24112451 let annotations = meta. map_or_else (
@@ -2445,6 +2485,25 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
24452485 } )
24462486 . collect :: < Vec < _ > > ( )
24472487 } ) ;
2488+ let admission = sandbox
2489+ . status
2490+ . as_ref ( )
2491+ . and_then ( |status| status. configuration_admission . as_ref ( ) )
2492+ . map ( |admission| {
2493+ serde_json:: json!( {
2494+ "state" : match ConfigurationAdmissionState :: try_from( admission. state) {
2495+ Ok ( ConfigurationAdmissionState :: Pending ) => "pending" ,
2496+ Ok ( ConfigurationAdmissionState :: Accepted ) => "accepted" ,
2497+ Ok ( ConfigurationAdmissionState :: Rejected ) => "rejected" ,
2498+ _ => "unknown" ,
2499+ } ,
2500+ "error" : admission. error,
2501+ "policy_version" : admission. policy_version,
2502+ "policy_hash" : admission. policy_hash,
2503+ "config_revision" : admission. config_revision,
2504+ "provider_env_revision" : admission. provider_env_revision,
2505+ } )
2506+ } ) ;
24482507 serde_json:: json!( {
24492508 "id" : sandbox. object_id( ) ,
24502509 "name" : sandbox. object_name( ) ,
@@ -2458,6 +2517,7 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
24582517 "exit_code" : sandbox. status. as_ref( ) . and_then( |status| status. exit_code) ,
24592518 "conditions" : conditions,
24602519 "endpoint_statuses" : endpoint_statuses,
2520+ "configuration_admission" : admission,
24612521 "created_from_workload_template" : created_from_workload_template,
24622522 } )
24632523}
@@ -7217,6 +7277,45 @@ mod tests {
72177277 assert_eq ! ( json[ "resources" ] [ "gpu" ] , 2 ) ;
72187278 }
72197279
7280+ #[ test]
7281+ fn sandbox_json_exposes_repair_diagnostic_and_accepted_generation ( ) {
7282+ use openshell_core:: proto:: { ConfigurationAdmissionState , SandboxConfigurationAdmission } ;
7283+
7284+ let mut sandbox = Sandbox :: default ( ) ;
7285+ sandbox. set_phase ( SandboxPhase :: Provisioning as i32 ) ;
7286+ let status = sandbox. status . as_mut ( ) . unwrap ( ) ;
7287+ status. configuration_admission = Some ( SandboxConfigurationAdmission {
7288+ state : ConfigurationAdmissionState :: Rejected as i32 ,
7289+ error : "rule image_api requires L7 inspection" . to_string ( ) ,
7290+ policy_hash : "candidate-hash" . to_string ( ) ,
7291+ ..Default :: default ( )
7292+ } ) ;
7293+ status. conditions . push ( SandboxCondition {
7294+ r#type : "ConfigurationReady" . to_string ( ) ,
7295+ status : "False" . to_string ( ) ,
7296+ reason : "ConfigurationInvalid" . to_string ( ) ,
7297+ message : "rule image_api requires L7 inspection" . to_string ( ) ,
7298+ ..Default :: default ( )
7299+ } ) ;
7300+ let json = super :: sandbox_to_json ( & sandbox) ;
7301+ assert_eq ! ( json[ "configuration_admission" ] [ "state" ] , "rejected" ) ;
7302+ assert_eq ! ( json[ "conditions" ] [ 0 ] [ "reason" ] , "ConfigurationInvalid" ) ;
7303+ assert_eq ! (
7304+ super :: configuration_failure_message( & sandbox) ,
7305+ Some ( "rule image_api requires L7 inspection" )
7306+ ) ;
7307+ sandbox
7308+ . status
7309+ . as_mut ( )
7310+ . unwrap ( )
7311+ . configuration_admission
7312+ . as_mut ( )
7313+ . unwrap ( )
7314+ . error
7315+ . clear ( ) ;
7316+ assert_eq ! ( super :: configuration_failure_message( & sandbox) , None ) ;
7317+ }
7318+
72207319 #[ test]
72217320 fn sandbox_detail_to_json_includes_policy_fields ( ) {
72227321 let mut sandbox = Sandbox {
0 commit comments