//! Integration test for strip_locations against captured stderr from
//! real `ail check` / `ail parse` failures (parent spec §Testing strategy).
//! Each fixture is verbatim from a current-HEAD invocation; goldens
//! are the strip_locations output the model should see.

use std::path::PathBuf;
use xmodel_harness::strip_locations::strip_locations;

fn fixtures_dir() -> PathBuf {
    PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("tests").join("fixtures")
}

fn read_fixture(name: &str) -> String {
    let path = fixtures_dir().join(name);
    std::fs::read_to_string(&path)
        .unwrap_or_else(|e| panic!("read {}: {e}", path.display()))
}

#[test]
fn check_unbound_var_strips_to_class_plus_message() {
    let input = read_fixture("check_unbound_var.stderr");
    let out = strip_locations(input.trim_end());
    assert_eq!(out, "error: [unbound-var] main: unknown identifier: `does_not_exist`");
}

#[test]
fn check_type_mismatch_strips_to_class_plus_message() {
    let input = read_fixture("check_type_mismatch.stderr");
    let out = strip_locations(input.trim_end());
    assert_eq!(out, "error: [type-mismatch] main: type mismatch: expected Int, got Bool");
}

#[test]
fn check_bare_xmod_passes_through_unchanged() {
    let input = read_fixture("check_bare_xmod.stderr");
    let out = strip_locations(input.trim_end());
    // No location info to strip; passthrough.
    assert!(out.contains("bare type name `Ordering`"));
    assert!(!out.contains("Caused by:"));
}

#[test]
fn check_schema_missing_field_strips_locations_and_collapses_chain() {
    let input = read_fixture("check_schema_missing_field.stderr");
    let out = strip_locations(input.trim_end());
    assert!(!out.contains("line "));
    assert!(!out.contains("column "));
    assert!(!out.contains("Caused by:"));
    assert!(out.contains("missing field `type`"));
}

#[test]
fn parse_unclosed_strips_byte_offset() {
    let input = read_fixture("parse_unclosed.stderr");
    let out = strip_locations(input.trim_end());
    assert!(!out.contains("at byte"));
    assert!(out.contains("expected `)`"));
}
