"""Area #3 W2 — shot_director.py mutation pattern residue gate.

`<identifier>["visible_entity_ids"] = assignment pattern` 이 production
code 안에서 0 hits 여야 한다 (Area #3 W2 closure 후). identifier-agnostic
이므로 variable rename evasion (ls → shot/item/entry 등) 도 차단.

Scope: backend/app/modules/pipeline/shot_director.py.
"""
import re
from pathlib import Path


REPO_ROOT = Path(__file__).resolve().parents[2]
SHOT_DIRECTOR_PY = REPO_ROOT / "backend" / "app" / "modules" / "pipeline" / "shot_director.py"


# Match `<identifier>["visible_entity_ids"] = ...` assignment,
# but NOT `... == ...` comparisons or `ls.get("visible_entity_ids", ...)` reads.
MUTATION_PATTERN = re.compile(r'\b\w+\["visible_entity_ids"\]\s*=(?!=)')


def test_no_visible_entity_ids_mutation_in_shot_director():
    """Area #3 W2 closure: visible_entity_ids assignment pattern 0 hits."""
    content = SHOT_DIRECTOR_PY.read_text(encoding="utf-8")
    matches = MUTATION_PATTERN.findall(content)
    assert len(matches) == 0, (
        f"Found {len(matches)} mutation pattern(s) in {SHOT_DIRECTOR_PY}. "
        f"Area #3 W2 requires mutation 권한 박탈."
    )
