(ctx: &PolicyLocalContext, body: &[u8])
| 460 | } |
| 461 | |
| 462 | async fn submit_proposal(ctx: &PolicyLocalContext, body: &[u8]) -> (u16, serde_json::Value) { |
| 463 | let Some(endpoint) = ctx.gateway_endpoint.as_deref() else { |
| 464 | return ( |
| 465 | 503, |
| 466 | serde_json::json!({ |
| 467 | "error": "gateway_unavailable", |
| 468 | "detail": "policy proposal submission requires a gateway-connected sandbox" |
| 469 | }), |
| 470 | ); |
| 471 | }; |
| 472 | let Some(sandbox_name) = ctx |
| 473 | .sandbox_name |
| 474 | .as_deref() |
| 475 | .map(str::trim) |
| 476 | .filter(|name| !name.is_empty()) |
| 477 | else { |
| 478 | return ( |
| 479 | 503, |
| 480 | serde_json::json!({ |
| 481 | "error": "sandbox_name_unavailable", |
| 482 | "detail": "policy proposal submission requires a sandbox name" |
| 483 | }), |
| 484 | ); |
| 485 | }; |
| 486 | |
| 487 | let chunks = match proposal_chunks_from_body(body) { |
| 488 | Ok(chunks) => chunks, |
| 489 | Err(error) => return (400, error_payload("invalid_proposal", error)), |
| 490 | }; |
| 491 | |
| 492 | let client = match openshell_core::grpc_client::CachedOpenShellClient::connect(endpoint).await { |
| 493 | Ok(client) => client, |
| 494 | Err(error) => { |
| 495 | return ( |
| 496 | 502, |
| 497 | serde_json::json!({ |
| 498 | "error": "gateway_connect_failed", |
| 499 | "detail": error.to_string() |
| 500 | }), |
| 501 | ); |
| 502 | } |
| 503 | }; |
| 504 | |
| 505 | // Pre-compute the audit summaries before handing `chunks` to the |
| 506 | // gateway client (which consumes the vec). The summaries pair up with |
| 507 | // the gateway's `accepted_chunk_ids` by index for the propose events |
| 508 | // emitted after submit returns. |
| 509 | let audit_summaries: Vec<String> = chunks.iter().map(summarize_chunk_for_audit).collect(); |
| 510 | |
| 511 | let response = match client |
| 512 | .submit_policy_analysis(sandbox_name, vec![], chunks, vec![], "agent_authored") |
| 513 | .await |
| 514 | { |
| 515 | Ok(response) => response, |
| 516 | Err(error) => { |
| 517 | return ( |
| 518 | 502, |
| 519 | serde_json::json!({ |
no test coverage detected