"""Task A3 — file-backed spool 결정론 단위 테스트.

write_spool 은 이미지 바이트를 spool 디렉터리(projects_root/.capture_spool/<project>/)
하위의 고유(uuid) 파일에 기록하고 절대 경로를 반환한다. 메모리 큐 폭증 방지 — 큐엔
경로만 적재된다.
"""

from pathlib import Path

from app.core.config import settings
from app.services.image_capture.spool import write_spool


def _spool_root() -> Path:
    return Path(settings.projects_dir).parent / ".capture_spool"


def test_write_spool_creates_file_with_bytes():
    p = write_spool(b"PNGDATA", "proj-A3", "pose_guide")
    path = Path(p)
    assert path.is_absolute()
    assert path.exists()
    assert path.read_bytes() == b"PNGDATA"
    # spool 디렉터리 하위 + project 격리
    assert path.parent == _spool_root() / "proj-A3"
    assert path.suffix == ".png"


def test_write_spool_unique_paths():
    a = write_spool(b"a", "proj-A3-uniq", "stageX")
    b = write_spool(b"b", "proj-A3-uniq", "stageX")
    assert a != b
    assert Path(a).read_bytes() == b"a"
    assert Path(b).read_bytes() == b"b"
