"""A↔C agreement taxonomy. Encodes the cardinal lesson: never blame the metadata
for a parser miss — `unparsed` and `divergent` are NOT `conflict`."""
import build_catalog_view as bcv


def test_unparsed_is_not_conflict():
    # corner A empty (parser couldn't read it) ⇒ unparsed, never conflict
    r = bcv.agree([], ["drums_nes", "cpluck"])
    assert r["level"] == "unparsed"


def test_no_claim_when_metadata_silent():
    assert bcv.agree(["kick", "snare"], [])["level"] == "no-claim"


def test_empty_both_sides():
    assert bcv.agree([], [])["level"] == "empty"


def test_agree_when_claims_present_in_score():
    r = bcv.agree(["kick", "snare", "hat"], ["kick", "snare"])
    assert r["level"] == "agree"
    assert r["precision"] == 1.0
    assert r["metadata_only"] == []
    assert r["score_only"] == ["hat"]          # drums C omitted — benign


def test_partial_band():
    # 1 of 3 claimed present → precision .333 → partial
    r = bcv.agree(["kick", "x", "y"], ["kick", "a", "b"])
    assert r["level"] == "partial"


def test_conflict_thin_overlap():
    # 1 of 4 claimed present → .25 → conflict
    assert bcv.agree(["kick", "x"], ["kick", "a", "b", "c"])["level"] == "conflict"


def test_divergent_rich_disjoint():
    # zero overlap, both sides rich → wrong-link/identity collision (Blue Gold→ccc0)
    r = bcv.agree(["moog", "ccc", "909"], ["suns_keys", "suns_guitar"])
    assert r["level"] == "divergent"
    assert r["precision"] == 0.0


def test_conflict_when_disjoint_but_thin():
    # zero overlap but only 1 claimed → conflict, not divergent
    assert bcv.agree(["moog", "ccc"], ["zzz"])["level"] == "conflict"
