"""capture 를 끈 scope — 신원·trace 는 얻고 자산은 안 만든다.

★scope 를 여는 것은 그 자체로 capture 를 켜는 것이다(sink 의
default-capture-off 규약). still-recipe 는 자기 손으로 자산을 저장하므로
여기서 또 포착하면 중간물 행이 무더기로 새로 생긴다 — 이 일은 기록
체계화지 자산 늘리기가 아니다.
"""
from app.services.image_capture.context import (
    current_context, generation_context)


def test_capture_off_context_still_carries_identity(tmp_path, monkeypatch):
    monkeypatch.setenv("PROJECTS_DIR", str(tmp_path))
    with generation_context("p", "e", stage="still_recipe",
                            still_id="abc", scene_index=1, shot_index=2,
                            capture=False):
        ctx = current_context()
        assert ctx.still_id == "abc"
        assert ctx.scene_index == 1
        assert ctx.capture_enabled is False


def test_capture_off_queue_stays_empty(tmp_path, monkeypatch):
    monkeypatch.setenv("PROJECTS_DIR", str(tmp_path))
    from app.services.image_capture.sink import capture_generated_image

    with generation_context("p", "e", stage="still_recipe",
                            still_id="abc", capture=False) as q:
        capture_generated_image(b"\x89PNG-fake", role="roll",
                                disposition="diagnostic")
        assert q._items == []


def test_capture_on_is_unchanged(tmp_path, monkeypatch):
    """기존 자리는 그대로 포착한다 — 바이트 동일."""
    monkeypatch.setenv("PROJECTS_DIR", str(tmp_path))
    from app.services.image_capture.sink import capture_generated_image

    with generation_context("p", "e", stage="background_render",
                            still_id="abc") as q:
        capture_generated_image(b"\x89PNG-fake", role="bg",
                                disposition="accepted")
        assert len(q._items) == 1
