# [DEF:backend.tests.services.clean_release.test_manifest_builder:Module]
# @TIER: CRITICAL
# @SEMANTICS: tests, clean-release, manifest, deterministic
# @PURPOSE: Validate deterministic manifest generation behavior for US1.
# @LAYER: Domain
# @RELATION: VERIFIES -> backend.src.services.clean_release.manifest_builder
# @INVARIANT: Same input artifacts produce identical deterministic hash.

from src.services.clean_release.manifest_builder import build_distribution_manifest


# [DEF:test_manifest_deterministic_hash_for_same_input:Function]
# @PURPOSE: Ensure hash is stable for same candidate/policy/artifact input.
# @PRE: Same input lists are passed twice.
# @POST: Hash and summary remain identical.
def test_manifest_deterministic_hash_for_same_input():
    artifacts = [
        {"path": "a.yaml", "category": "system-init", "classification": "required-system", "reason": "required"},
        {"path": "b.yaml", "category": "test-data", "classification": "excluded-prohibited", "reason": "prohibited"},
    ]

    manifest1 = build_distribution_manifest(
        manifest_id="m1",
        candidate_id="2026.03.03-rc1",
        policy_id="policy-enterprise-clean-v1",
        generated_by="tester",
        artifacts=artifacts,
    )
    manifest2 = build_distribution_manifest(
        manifest_id="m2",
        candidate_id="2026.03.03-rc1",
        policy_id="policy-enterprise-clean-v1",
        generated_by="tester",
        artifacts=artifacts,
    )

    assert manifest1.deterministic_hash == manifest2.deterministic_hash
    assert manifest1.summary.included_count == manifest2.summary.included_count
    assert manifest1.summary.excluded_count == manifest2.summary.excluded_count
# [/DEF:test_manifest_deterministic_hash_for_same_input:Function]
# [/DEF:backend.tests.services.clean_release.test_manifest_builder:Module]