//! Known upstream releases of the MCP conformance corpus.
//!
//! `mcptest conformance refresh --target-version latest` consults
//! this table. The upstream project does not yet publish a tag per
//! spec revision, so we ship the spec-version -> upstream-ref pin as
//! a hand-curated list here. Adding a new spec revision is a one-line
//! PR: prepend the tuple and the refresh subcommand picks it up.
//!
//! Once upstream tags releases by spec version, this table can be
//! deprecated in favor of a HEAD-derived lookup. Until then, the
//! pinned list is the source of truth.

/// One `(spec_version, upstream_ref)` pin.
pub type Release = (&'static str, &'static str);

/// Newest-first list of known upstream releases.
///
/// The first entry is the current pin; `refresh --target-version
/// latest` resolves to it. The list grows as upstream adds spec
/// revisions.
pub const KNOWN_RELEASES: &[Release] =
    &[("2026-07-28-rc", "7d3b897618927422a27c98e520c999ad07dcc9d6")];

/// Resolve the upstream ref for a spec version, or return `None`
/// when no pin exists.
pub fn ref_for(spec_version: &str) -> Option<&'static str> {
    KNOWN_RELEASES
        .iter()
        .find(|(v, _)| *v == spec_version)
        .map(|(_, r)| *r)
}

/// Return the latest spec version + its pinned upstream ref.
///
/// # Panics
///
/// Panics when `KNOWN_RELEASES` is empty. That is a build-time
/// invariant; the panic surfaces a future change that empties the
/// list rather than silently breaking refresh.
pub fn latest() -> Release {
    *KNOWN_RELEASES
        .first()
        .expect("KNOWN_RELEASES must contain at least one entry")
}

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

    #[test]
    fn known_releases_is_non_empty() {
        assert!(
            !KNOWN_RELEASES.is_empty(),
            "the refresh subcommand relies on at least one pin"
        );
    }

    #[test]
    fn latest_returns_the_first_entry() {
        let (v, r) = latest();
        assert_eq!((v, r), KNOWN_RELEASES[0]);
    }

    #[test]
    fn ref_for_finds_a_pinned_version() {
        assert_eq!(
            ref_for("2026-07-28-rc"),
            Some("7d3b897618927422a27c98e520c999ad07dcc9d6")
        );
    }

    #[test]
    fn ref_for_returns_none_for_an_unknown_version() {
        assert_eq!(ref_for("2099-01-01"), None);
    }
}
