"""Area D-next-min — detail_steps _compute_forward_zoom_targets cascade tests.

Area D-next-min (2026-05-15) supersedes Area D-next (2026-05-14): kind enum
3종 → 2종 (environment / static_prop), immobilized_character 폐기. 본 cascade
test 도 fixture 가 enum 2종만 사용 — character 묘사는 keep_elements 가 다루지
않음 (별도 layer 책임).
"""
from __future__ import annotations

import inspect

import pytest


def test_e1_compute_forward_zoom_targets_forwards_dict_keep_elements():
    """Area D-next-min E1 — _compute_forward_zoom_targets 가 dict shape 그대로
    forward (enum 2종)."""
    from app.core.steps.detail_steps import _compute_forward_zoom_targets

    dependencies = [{
        "scene_index": 2,
        "shot_index": 1,
        "location_refs": [{
            "scene_index": 1,
            "shot_index": 2,
            "ref_usage": "zoom_in_detail",
            "keep_elements": [
                {"label": "wooden bench against the wall", "kind": "environment"},
                {"label": "open book on the desk", "kind": "static_prop"},
            ],
        }],
    }]
    shot_scenes_map = {2: [{"shot_index": 1, "shot_description": "Close-up"}]}

    out = _compute_forward_zoom_targets(
        dependencies, shot_scenes_map, scene_index=1, shot_index=2,
    )
    assert len(out) == 1
    assert out[0]["keep_elements"] == [
        {"label": "wooden bench against the wall", "kind": "environment"},
        {"label": "open book on the desk", "kind": "static_prop"},
    ]


def test_e2_detail_steps_str_branch_removed():
    """Area D-next E2 — defensive `else str(k)` branch 폐기."""
    from app.core.steps import detail_steps
    src = inspect.getsource(detail_steps)
    bad_patterns = [
        'else str(k)',
        '(k.get("description") if isinstance(k, dict) else str(k))',
    ]
    for pat in bad_patterns:
        assert pat not in src, (
            f"detail_steps.py 에 옛 str branch ({pat!r}) 잔존 — Task 4 미완."
        )
    assert 'k["label"]' in src or "k['label']" in src


def test_e3_docstring_reflects_dict_shape():
    """Area D-next E3 — _compute_forward_zoom_targets docstring 가 새 shape
    `list[{label, kind}]` 명시."""
    from app.core.steps.detail_steps import _compute_forward_zoom_targets

    doc = _compute_forward_zoom_targets.__doc__ or ""
    assert "list[{label, kind" in doc or (
        "label" in doc and "kind" in doc
    ), (
        f"docstring 에 새 shape 명시 누락 — got {doc!r}"
    )
