"""Unit tests for the StandardIngester engine (Parser 4)."""

from services.standard_ingester import StandardSpec, build_upload_unit, standard_meta

SPEC = StandardSpec(
    source_id="nist_csf_2_0", short="NIST CSF 2.0",
    title="NIST Cybersecurity Framework 2.0", publisher="NIST",
    url="https://nist.gov/csf", license="public_domain", version_date="2024-02-26",
)


def test_standard_meta_is_best_practice_not_primary():
    m = standard_meta(SPEC)
    assert m["source_class"] == "technical_standard"
    assert m["authority_weight"] == 80
    assert m["bindingness"] == "best_practice"
    assert m["use_for_primary"] is False
    assert m["chunk_scope"] == "standard"
    assert m["regulation_short"] == "NIST CSF 2.0"
    assert m["issuer"] == "NIST"
    assert m["license"] == "public_domain"


def test_build_upload_unit_tags_version_and_collection():
    unit = build_upload_unit(SPEC, "A" * 300, "run9")
    assert unit.document_version == "run9-nist_csf_2_0"
    assert unit.collection == "bp_compliance_ce"
    assert unit.filename == "nist_csf_2_0.txt"
    assert unit.meta["use_for_primary"] is False


def test_noncommercial_license_is_carried_for_the_gate():
    ccm = StandardSpec(source_id="csa_ccm", short="CSA CCM", title="Cloud Controls Matrix",
                       publisher="CSA", url="https://...", license="CC-BY-NC")
    assert standard_meta(ccm)["license"] == "CC-BY-NC"  # commercial gate can refuse it
