"""Mode B must classify Bloom's level with the canonical scripts/blooms.py
verb table, not a private divergent copy.

Issue #216 (ties to the already-merged #218). `alignment_mode_b.py` shipped
its own `BLOOM_VERBS` / `BLOOM_ORDER` tables that were smaller than, and
diverged from, the canonical `blooms.BLOOMS_VERBS` / `blooms.BLOOMS_LEVELS`
used by the other 9 importers (alignment_validator, preflight_checks,
mlo_extractor, assurance_inventory, objective_extractor, audit_mlo_drift,
audit_bloom_alignment, alignment_skill, assurance_audit). Concretely, Mode
B's old table:

  - had no entry anywhere for "interpret" or "articulate" (canonical
    Understand verbs), so objective text using only those verbs came back
    `bloom_undetermined` instead of Understand;
  - had no entry anywhere for "contrast" (canonical Analyze verb), same
    failure mode;
  - classified "compare" as Understand, while canonical (since #218)
    resolves it to Analyze only -- the same objective text landed on a
    *different determined level* depending on which importer ran it.

This module asserts Mode B's classification agrees with
`blooms.classify_blooms` for those verbs, and that the private tables are
gone (no duplicate copy left to re-diverge later).
"""

import os
import sys

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(HERE, "..", "scripts"))

import alignment_mode_b  # noqa: E402
import blooms  # noqa: E402


def _canonical_abbreviation(text: str) -> str:
    """Classify `text` with the canonical `blooms.classify_blooms` (which
    reads only the leading verb) and translate its level name into Mode
    B's own abbreviation space via Mode B's own BLOOM_ABBREVIATIONS."""
    _, level = blooms.classify_blooms(text)
    return alignment_mode_b.BLOOM_ABBREVIATIONS.get(level, alignment_mode_b.BLOOM_UNDETERMINED)


class TestModeBUsesCanonicalBloomVerbs:
    """Divergence verbs named in issue #216: previously absent from Mode
    B's private table anywhere, so text using only these verbs came back
    bloom_undetermined instead of a real level."""

    def test_interpret_classifies_as_understand(self):
        text = "Interpret the results of the experiment."
        assert alignment_mode_b.infer_bloom_abbreviation(text) == "U"
        assert alignment_mode_b.infer_bloom_abbreviation(text) == _canonical_abbreviation(text)

    def test_articulate_classifies_as_understand(self):
        text = "Articulate the theory in your own words."
        assert alignment_mode_b.infer_bloom_abbreviation(text) == "U"
        assert alignment_mode_b.infer_bloom_abbreviation(text) == _canonical_abbreviation(text)

    def test_contrast_classifies_as_analyze(self):
        text = "Contrast the two economic models."
        assert alignment_mode_b.infer_bloom_abbreviation(text) == "An"
        assert alignment_mode_b.infer_bloom_abbreviation(text) == _canonical_abbreviation(text)

    def test_distinguish_classifies_as_analyze(self):
        # "distinguish" was already present in Mode B's old Analyze set
        # (not itself a divergent verb) -- kept here as a regression check
        # that the swap to the canonical table didn't move it.
        text = "Distinguish between valid and invalid arguments."
        assert alignment_mode_b.infer_bloom_abbreviation(text) == "An"
        assert alignment_mode_b.infer_bloom_abbreviation(text) == _canonical_abbreviation(text)

    def test_compare_reclassifies_to_analyze_not_understand(self):
        # The sharpest divergence case: Mode B's old private table put
        # "compare" under Understand. Canonical (post-#218) resolves it to
        # Analyze only. Same objective text, must land on the same level
        # everywhere.
        text = "Compare the two budget scenarios."
        assert alignment_mode_b.infer_bloom_abbreviation(text) == "An"
        assert alignment_mode_b.infer_bloom_abbreviation(text) == _canonical_abbreviation(text)

    def test_bloom_verb_sets_are_sourced_from_canonical_table(self):
        """Every verb Mode B can match for a given level must be a subset
        of that level's canonical blooms.BLOOMS_VERBS entry -- i.e. no
        private verb list independent of blooms.py."""
        for level in alignment_mode_b.BLOOM_LEVELS:
            assert level in blooms.BLOOMS_VERBS


class TestPrivateBloomTablesRemoved:
    def test_bloom_verbs_table_is_gone(self):
        assert not hasattr(alignment_mode_b, "BLOOM_VERBS"), (
            "alignment_mode_b.BLOOM_VERBS is a private duplicate of "
            "blooms.BLOOMS_VERBS and must be removed."
        )

    def test_bloom_order_table_is_gone(self):
        assert not hasattr(alignment_mode_b, "BLOOM_ORDER"), (
            "alignment_mode_b.BLOOM_ORDER is a private duplicate of the "
            "ordinal ranking blooms.BLOOMS_LEVELS already provides and "
            "must be removed."
        )
