@@ -1561,11 +1561,23 @@ where
15611561 sandbox. object_id ( ) . to_string ( )
15621562 } ;
15631563
1564- let config = client
1564+ let config_result = client
15651565 . get_sandbox_config ( GetSandboxConfigRequest { sandbox_id } )
1566- . await
1567- . into_diagnostic ( ) ?
1568- . into_inner ( ) ;
1566+ . await ;
1567+ let config = match config_result {
1568+ Ok ( response) => response. into_inner ( ) ,
1569+ Err ( _) if !policy_only && configuration_failure_message ( & sandbox) . is_some ( ) => {
1570+ // An invalid desired policy must not hide the status needed to
1571+ // repair it. Keep payload-only reads strict.
1572+ GetSandboxConfigResponse {
1573+ configuration_error : configuration_failure_message ( & sandbox)
1574+ . unwrap_or_default ( )
1575+ . to_string ( ) ,
1576+ ..Default :: default ( )
1577+ }
1578+ }
1579+ Err ( error) => return Err ( error) . into_diagnostic ( ) ,
1580+ } ;
15691581
15701582 if policy_only {
15711583 let Some ( ref policy) = config. policy else {
@@ -1599,6 +1611,22 @@ where
15991611 println ! ( " {} {}" , "Id:" . dimmed( ) , id) ;
16001612 println ! ( " {} {}" , "Name:" . dimmed( ) , name) ;
16011613 println ! ( " {} {}" , "Phase:" . dimmed( ) , phase_name( sandbox. phase( ) ) ) ;
1614+ if let Some ( status) = sandbox. status . as_ref ( ) {
1615+ for condition in & status. conditions {
1616+ if matches ! (
1617+ condition. r#type. as_str( ) ,
1618+ "ConfigurationReady" | "DesiredConfigurationReady"
1619+ ) && condition. status . eq_ignore_ascii_case ( "false" )
1620+ {
1621+ println ! (
1622+ " {} {}: {}" ,
1623+ "Configuration:" . dimmed( ) ,
1624+ condition. reason,
1625+ condition. message
1626+ ) ;
1627+ }
1628+ }
1629+ }
16021630 if let Some ( exit_code) = sandbox. status . as_ref ( ) . and_then ( |status| status. exit_code ) {
16031631 println ! ( " {} {}" , "Exit Code:" . dimmed( ) , exit_code) ;
16041632 }
@@ -2461,7 +2489,19 @@ pub async fn sandbox_list(
24612489 Ok ( ( ) )
24622490}
24632491
2492+ fn configuration_failure_message ( sandbox : & Sandbox ) -> Option < & str > {
2493+ sandbox
2494+ . status
2495+ . as_ref ( ) ?
2496+ . configuration_admission
2497+ . as_ref ( )
2498+ . map ( |admission| admission. error . as_str ( ) )
2499+ . filter ( |message| !message. is_empty ( ) )
2500+ }
2501+
24642502fn sandbox_to_json ( sandbox : & Sandbox ) -> serde_json:: Value {
2503+ use openshell_core:: proto:: ConfigurationAdmissionState ;
2504+
24652505 let meta = sandbox. metadata . as_ref ( ) ;
24662506 let labels = meta. map_or_else ( || serde_json:: json!( { } ) , |m| serde_json:: json!( m. labels) ) ;
24672507 let annotations = meta. map_or_else (
@@ -2501,6 +2541,25 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
25012541 } )
25022542 . collect :: < Vec < _ > > ( )
25032543 } ) ;
2544+ let admission = sandbox
2545+ . status
2546+ . as_ref ( )
2547+ . and_then ( |status| status. configuration_admission . as_ref ( ) )
2548+ . map ( |admission| {
2549+ serde_json:: json!( {
2550+ "state" : match ConfigurationAdmissionState :: try_from( admission. state) {
2551+ Ok ( ConfigurationAdmissionState :: Pending ) => "pending" ,
2552+ Ok ( ConfigurationAdmissionState :: Accepted ) => "accepted" ,
2553+ Ok ( ConfigurationAdmissionState :: Rejected ) => "rejected" ,
2554+ _ => "unknown" ,
2555+ } ,
2556+ "error" : admission. error,
2557+ "policy_version" : admission. policy_version,
2558+ "policy_hash" : admission. policy_hash,
2559+ "config_revision" : admission. config_revision,
2560+ "provider_env_revision" : admission. provider_env_revision,
2561+ } )
2562+ } ) ;
25042563 serde_json:: json!( {
25052564 "id" : sandbox. object_id( ) ,
25062565 "name" : sandbox. object_name( ) ,
@@ -2514,6 +2573,7 @@ fn sandbox_to_json(sandbox: &Sandbox) -> serde_json::Value {
25142573 "exit_code" : sandbox. status. as_ref( ) . and_then( |status| status. exit_code) ,
25152574 "conditions" : conditions,
25162575 "endpoint_statuses" : endpoint_statuses,
2576+ "configuration_admission" : admission,
25172577 "created_from_workload_template" : created_from_workload_template,
25182578 } )
25192579}
@@ -7349,6 +7409,45 @@ mod tests {
73497409 assert_eq ! ( json[ "resources" ] [ "gpu" ] , 2 ) ;
73507410 }
73517411
7412+ #[ test]
7413+ fn sandbox_json_exposes_repair_diagnostic_and_accepted_generation ( ) {
7414+ use openshell_core:: proto:: { ConfigurationAdmissionState , SandboxConfigurationAdmission } ;
7415+
7416+ let mut sandbox = Sandbox :: default ( ) ;
7417+ sandbox. set_phase ( SandboxPhase :: Provisioning as i32 ) ;
7418+ let status = sandbox. status . as_mut ( ) . unwrap ( ) ;
7419+ status. configuration_admission = Some ( SandboxConfigurationAdmission {
7420+ state : ConfigurationAdmissionState :: Rejected as i32 ,
7421+ error : "rule image_api requires L7 inspection" . to_string ( ) ,
7422+ policy_hash : "candidate-hash" . to_string ( ) ,
7423+ ..Default :: default ( )
7424+ } ) ;
7425+ status. conditions . push ( SandboxCondition {
7426+ r#type : "ConfigurationReady" . to_string ( ) ,
7427+ status : "False" . to_string ( ) ,
7428+ reason : "ConfigurationInvalid" . to_string ( ) ,
7429+ message : "rule image_api requires L7 inspection" . to_string ( ) ,
7430+ ..Default :: default ( )
7431+ } ) ;
7432+ let json = super :: sandbox_to_json ( & sandbox) ;
7433+ assert_eq ! ( json[ "configuration_admission" ] [ "state" ] , "rejected" ) ;
7434+ assert_eq ! ( json[ "conditions" ] [ 0 ] [ "reason" ] , "ConfigurationInvalid" ) ;
7435+ assert_eq ! (
7436+ super :: configuration_failure_message( & sandbox) ,
7437+ Some ( "rule image_api requires L7 inspection" )
7438+ ) ;
7439+ sandbox
7440+ . status
7441+ . as_mut ( )
7442+ . unwrap ( )
7443+ . configuration_admission
7444+ . as_mut ( )
7445+ . unwrap ( )
7446+ . error
7447+ . clear ( ) ;
7448+ assert_eq ! ( super :: configuration_failure_message( & sandbox) , None ) ;
7449+ }
7450+
73527451 #[ test]
73537452 fn sandbox_detail_to_json_includes_policy_fields ( ) {
73547453 let mut sandbox = Sandbox {
0 commit comments