Skip to main content

faucet_cli/serve/handlers/
doctor.rs

1//! `POST /v1/doctor` — validate + probe a submitted config WITHOUT running it.
2//! Reuses the same preflight as `doctor_first`: 200 with the report when all
3//! probes pass, 422 with the report as `details` when any fail.
4
5use crate::serve::error::ServeError;
6use crate::serve::load::load_submission;
7use crate::serve::runner::{ConfigFormatWire, run_doctor_first};
8use crate::serve::state::ServerState;
9use axum::Json;
10use axum::extract::State;
11use serde::Deserialize;
12use serde_json::Value;
13
14#[derive(Debug, Deserialize)]
15pub struct DoctorRequest {
16    pub config: String,
17    #[serde(default)]
18    pub config_format: ConfigFormatWire,
19}
20
21/// `POST /v1/doctor` → 200 report (all pass) / 422 report (any fail) / 400 (bad config).
22pub async fn doctor(
23    State(state): State<ServerState>,
24    Json(req): Json<DoctorRequest>,
25) -> Result<Json<Value>, ServeError> {
26    let loaded = load_submission(
27        &req.config,
28        req.config_format.into(),
29        state.default_base().as_ref(),
30    )
31    .await?;
32    let report = run_doctor_first(&state, &loaded).await?;
33    Ok(Json(report))
34}