//! The "did you mean a different subcommand?" hint for `mcptest run`.
//!
//! When `run` finds no tests, a suite that still carries an `evals:` or
//! `compliance:` block is not really empty, it just needs `mcptest eval` or
//! `mcptest compliance`. This lives next to the run handler so the empty-suite
//! dead-end is self-correcting. Compositions are run by `mcptest run` itself,
//! so they are not listed here.

/// Return a one-line pointer to the subcommand a non-`tests:` suite needs, or
/// `None` when the suite has neither an `evals:` nor a `compliance:` block.
pub(super) fn other_block_hint(yaml: &serde_yaml::Value) -> Option<&'static str> {
    let map = yaml.as_mapping()?;
    let present = |key: &str| {
        map.get(serde_yaml::Value::String(key.to_string()))
            .map(|v| match v {
                serde_yaml::Value::Null => false,
                serde_yaml::Value::Sequence(s) => !s.is_empty(),
                serde_yaml::Value::Mapping(m) => !m.is_empty(),
                _ => true,
            })
            .unwrap_or(false)
    };
    if present("evals") {
        Some("this suite has an `evals:` block but no `tests:`; run `mcptest eval --config <file>`")
    } else if present("compliance") {
        Some(
            "this suite has a `compliance:` block but no `tests:`; run `mcptest compliance run --config <file>`",
        )
    } else {
        None
    }
}

#[cfg(test)]
mod tests {
    use super::other_block_hint;

    fn yaml(s: &str) -> serde_yaml::Value {
        serde_yaml::from_str(s).unwrap()
    }

    #[test]
    fn evals_block_routes_to_eval_command() {
        let hint = other_block_hint(&yaml("evals:\n  - name: x\n    rubric: good\n")).unwrap();
        assert!(hint.contains("mcptest eval"));
    }

    #[test]
    fn compliance_block_routes_to_compliance_command() {
        let hint =
            other_block_hint(&yaml("compliance:\n  grade_delta:\n    baseline: b.json\n")).unwrap();
        assert!(hint.contains("mcptest compliance"));
    }

    #[test]
    fn plain_test_suite_gets_no_hint() {
        assert!(other_block_hint(&yaml("tests:\n  - name: x\n")).is_none());
        // An empty evals: list is not a real block.
        assert!(other_block_hint(&yaml("evals: []\n")).is_none());
    }
}
