//! Populate the run report's metadata block with policy-readable
//! fields (WOR-853).
//!
//! Extracted from `run_live.rs` so the parent stays under the
//! production-module-size cap. The helper is pure aside from the
//! best-effort env capture that `RunMetadata::collect` does
//! internally.

use crate::cli::args::RunArgs;

/// Populate the report's `metadata` block with the run profile and
/// per-server transport + auth posture so the enterprise policy
/// evaluator can enforce policy rules without re-reading the
/// user's args. Best-effort: a CI environment that lacks git or
/// the env vars `RunMetadata::collect` reads still produces a
/// populated metadata object with the new fields filled in.
pub(super) fn attach_run_metadata(
    report: &mut mcptest_core::report::Report,
    args: &RunArgs,
    suite: &mcptest_core::suite::ResolvedSuite,
) {
    let mut metadata = mcptest_core::report::RunMetadata::collect(env!("CARGO_PKG_VERSION"));
    metadata.profile = args.profile.clone();
    metadata.servers = suite
        .servers
        .iter()
        .map(|(name, spec)| mcptest_core::report::metadata::ServerPosture::from_spec(name, spec))
        .collect();
    report.metadata = Some(metadata);
}
