from pathlib import Path

from src.domain.codegen.runtime_ownership import classify_runtime_file, content_fingerprint


def test_generator_provenance_without_lock_is_managed_unmodified():
    path = Path("src/domain/codegen/runtime/p2hs-app-client.js")

    evidence = classify_runtime_file(
        path="src/lib/p2hs-app.js",
        origin_revision="a1",
        origin_sha="sha1",
        origin_evidence="p2hs:initial generated commit",
        current_sha="sha1",
        origin_fingerprint=content_fingerprint(path),
        current_fingerprint=content_fingerprint(path),
    )

    assert evidence.ownership_class == "P2HS_MANAGED_UNMODIFIED"


def test_customer_change_is_not_hidden_by_platform_provenance():
    evidence = classify_runtime_file(
        path="src/lib/p2hs-app.js",
        origin_revision="a1",
        origin_sha="sha1",
        origin_evidence="p2hs:initial generated commit",
        current_sha="sha2",
        origin_fingerprint="sha256:old",
        current_fingerprint="sha256:new",
        customer_change=True,
    )

    assert evidence.ownership_class == "P2HS_MANAGED_CUSTOMER_MODIFIED"


def test_platform_evolution_is_distinct_from_customer_change():
    evidence = classify_runtime_file(
        path="src/lib/p2hs-app.js",
        origin_revision="a1",
        origin_sha="sha1",
        origin_evidence="p2hs:initial generated commit",
        current_sha="sha2",
        origin_fingerprint="sha256:old",
        current_fingerprint="sha256:new",
        later_platform_change=True,
    )

    assert evidence.ownership_class == "P2HS_MANAGED_PLATFORM_EVOLVED"
