//! Integration coverage for the missing-resource error-code probe.
//!
//! These tests exercise the migration doctor strictly through its public
//! surface (`mcptest_core::migration`), which the in-module unit tests
//! cannot do: a `#[cfg(test)] mod tests` reaches every private item via
//! `super::`, so it would still compile even if `MigrationCorpus`,
//! `check_resource_error_code`, `MigrationFinding`, or `FindingStatus`
//! were not actually exported. Running here, from outside the crate,
//! proves the symbols are reachable by real callers and pins the
//! user-facing remediation text the 2026-07-28 revision depends on:
//! a server still emitting the legacy `-32002` must be told to move to
//! the standard JSON-RPC `-32602` (Invalid Params).
//!
//! The two error-code constants are private to the module on purpose, so
//! these tests use the literal codes a server would return and assert on
//! the finding's public fields rather than on the constants.

use mcptest_core::migration::{FindingStatus, MigrationCorpus, MigrationKind};

#[test]
fn public_probe_flags_legacy_32002_and_names_32602_in_remediation_text() {
    let corpus = MigrationCorpus::builtin().unwrap();
    let finding = corpus
        .check_resource_error_code(-32002)
        .expect("builtin corpus carries the legacy-error-code case");

    assert_eq!(finding.kind, MigrationKind::LegacyErrorCode);
    assert_eq!(finding.status, FindingStatus::Fail);
    // The detail is what a developer reads in the report. It must name the
    // observed legacy code and the replacement code, in plain text,
    // through the public field.
    assert!(
        finding.detail.contains("-32002"),
        "detail should name the observed legacy code, got: {}",
        finding.detail
    );
    assert!(
        finding.detail.contains("-32602"),
        "detail should name the -32602 replacement, got: {}",
        finding.detail
    );
    // The remediation guidance is inherited from the corpus row and is the
    // line that tells the user what to change.
    assert!(
        finding.replacement.contains("-32602"),
        "replacement guidance should name -32602, got: {}",
        finding.replacement
    );
}

#[test]
fn public_probe_passes_when_server_already_returns_32602() {
    let corpus = MigrationCorpus::builtin().unwrap();
    let finding = corpus
        .check_resource_error_code(-32602)
        .expect("builtin corpus carries the legacy-error-code case");

    assert_eq!(finding.status, FindingStatus::Pass);
    // A passing row carries no detail: there is nothing to fix.
    assert!(
        finding.detail.is_empty(),
        "pass row should have an empty detail, got: {}",
        finding.detail
    );
}
