@@ -1543,11 +1543,23 @@ where
15431543 sandbox. object_id ( ) . to_string ( )
15441544 } ;
15451545
1546- let config = client
1546+ let config_result = client
15471547 . get_sandbox_config ( GetSandboxConfigRequest { sandbox_id } )
1548- . await
1549- . into_diagnostic ( ) ?
1550- . into_inner ( ) ;
1548+ . await ;
1549+ let config = match config_result {
1550+ Ok ( response) => response. into_inner ( ) ,
1551+ Err ( _) if !policy_only && configuration_failure_message ( & sandbox) . is_some ( ) => {
1552+ // An invalid desired policy must not hide the status needed to
1553+ // repair it. Keep payload-only reads strict.
1554+ GetSandboxConfigResponse {
1555+ configuration_error : configuration_failure_message ( & sandbox)
1556+ . unwrap_or_default ( )
1557+ . to_string ( ) ,
1558+ ..Default :: default ( )
1559+ }
1560+ }
1561+ Err ( error) => return Err ( error) . into_diagnostic ( ) ,
1562+ } ;
15511563
15521564 if policy_only {
15531565 let Some ( ref policy) = config. policy else {
@@ -1581,6 +1593,22 @@ where
15811593 println ! ( " {} {}" , "Id:" . dimmed( ) , id) ;
15821594 println ! ( " {} {}" , "Name:" . dimmed( ) , name) ;
15831595 println ! ( " {} {}" , "Phase:" . dimmed( ) , phase_name( sandbox. phase( ) ) ) ;
1596+ if let Some ( status) = sandbox. status . as_ref ( ) {
1597+ for condition in & status. conditions {
1598+ if matches ! (
1599+ condition. r#type. as_str( ) ,
1600+ "ConfigurationReady" | "DesiredConfigurationReady"
1601+ ) && condition. status . eq_ignore_ascii_case ( "false" )
1602+ {
1603+ println ! (
1604+ " {} {}: {}" ,
1605+ "Configuration:" . dimmed( ) ,
1606+ condition. reason,
1607+ condition. message
1608+ ) ;
1609+ }
1610+ }
1611+ }
15841612 if let Some ( exit_code) = sandbox. status . as_ref ( ) . and_then ( |status| status. exit_code ) {
15851613 println ! ( " {} {}" , "Exit Code:" . dimmed( ) , exit_code) ;
15861614 }
@@ -2438,7 +2466,19 @@ pub async fn sandbox_list(
24382466 Ok ( ( ) )
24392467}
24402468
2469+ fn configuration_failure_message ( sandbox : & Sandbox ) -> Option < & str > {
2470+ sandbox
2471+ . status
2472+ . as_ref ( ) ?
2473+ . configuration_admission
2474+ . as_ref ( )
2475+ . map ( |admission| admission. error . as_str ( ) )
2476+ . filter ( |message| !message. is_empty ( ) )
2477+ }
2478+
24412479fn sandbox_to_json ( sandbox : & Sandbox ) -> serde_json:: Value {
2480+ use openshell_core:: proto:: ConfigurationAdmissionState ;
2481+
24422482 let meta = sandbox. metadata . as_ref ( ) ;
24432483 let labels = meta. map_or_else ( || serde_json:: json!( { } ) , |m| serde_json:: json!( m. labels) ) ;
24442484 let annotations = meta. map_or_else (
@@ -2478,6 +2518,25 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
24782518 } )
24792519 . collect :: < Vec < _ > > ( )
24802520 } ) ;
2521+ let admission = sandbox
2522+ . status
2523+ . as_ref ( )
2524+ . and_then ( |status| status. configuration_admission . as_ref ( ) )
2525+ . map ( |admission| {
2526+ serde_json:: json!( {
2527+ "state" : match ConfigurationAdmissionState :: try_from( admission. state) {
2528+ Ok ( ConfigurationAdmissionState :: Pending ) => "pending" ,
2529+ Ok ( ConfigurationAdmissionState :: Accepted ) => "accepted" ,
2530+ Ok ( ConfigurationAdmissionState :: Rejected ) => "rejected" ,
2531+ _ => "unknown" ,
2532+ } ,
2533+ "error" : admission. error,
2534+ "policy_version" : admission. policy_version,
2535+ "policy_hash" : admission. policy_hash,
2536+ "config_revision" : admission. config_revision,
2537+ "provider_env_revision" : admission. provider_env_revision,
2538+ } )
2539+ } ) ;
24812540 serde_json:: json!( {
24822541 "id" : sandbox. object_id( ) ,
24832542 "name" : sandbox. object_name( ) ,
@@ -2491,6 +2550,7 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
24912550 "exit_code" : sandbox. status. as_ref( ) . and_then( |status| status. exit_code) ,
24922551 "conditions" : conditions,
24932552 "endpoint_statuses" : endpoint_statuses,
2553+ "configuration_admission" : admission,
24942554 "created_from_workload_template" : created_from_workload_template,
24952555 } )
24962556}
@@ -7250,6 +7310,45 @@ mod tests {
72507310 assert_eq ! ( json[ "resources" ] [ "gpu" ] , 2 ) ;
72517311 }
72527312
7313+ #[ test]
7314+ fn sandbox_json_exposes_repair_diagnostic_and_accepted_generation ( ) {
7315+ use openshell_core:: proto:: { ConfigurationAdmissionState , SandboxConfigurationAdmission } ;
7316+
7317+ let mut sandbox = Sandbox :: default ( ) ;
7318+ sandbox. set_phase ( SandboxPhase :: Provisioning as i32 ) ;
7319+ let status = sandbox. status . as_mut ( ) . unwrap ( ) ;
7320+ status. configuration_admission = Some ( SandboxConfigurationAdmission {
7321+ state : ConfigurationAdmissionState :: Rejected as i32 ,
7322+ error : "rule image_api requires L7 inspection" . to_string ( ) ,
7323+ policy_hash : "candidate-hash" . to_string ( ) ,
7324+ ..Default :: default ( )
7325+ } ) ;
7326+ status. conditions . push ( SandboxCondition {
7327+ r#type : "ConfigurationReady" . to_string ( ) ,
7328+ status : "False" . to_string ( ) ,
7329+ reason : "ConfigurationInvalid" . to_string ( ) ,
7330+ message : "rule image_api requires L7 inspection" . to_string ( ) ,
7331+ ..Default :: default ( )
7332+ } ) ;
7333+ let json = super :: sandbox_to_json ( & sandbox) ;
7334+ assert_eq ! ( json[ "configuration_admission" ] [ "state" ] , "rejected" ) ;
7335+ assert_eq ! ( json[ "conditions" ] [ 0 ] [ "reason" ] , "ConfigurationInvalid" ) ;
7336+ assert_eq ! (
7337+ super :: configuration_failure_message( & sandbox) ,
7338+ Some ( "rule image_api requires L7 inspection" )
7339+ ) ;
7340+ sandbox
7341+ . status
7342+ . as_mut ( )
7343+ . unwrap ( )
7344+ . configuration_admission
7345+ . as_mut ( )
7346+ . unwrap ( )
7347+ . error
7348+ . clear ( ) ;
7349+ assert_eq ! ( super :: configuration_failure_message( & sandbox) , None ) ;
7350+ }
7351+
72537352 #[ test]
72547353 fn sandbox_detail_to_json_includes_policy_fields ( ) {
72557354 let mut sandbox = Sandbox {
0 commit comments