"""render/runner.py の仕様ベーステスト（end-to-end smoke）．

仕様出典:
- docs/04_SPEC/SPEC_01_アーキテクチャ設計.md（render/runner 層の責務）
- docs/03_PLAN/PLAN_02_開発ステップ.md（Step 4 完了条件: 64×64 の合成シーンを最後まで
  レンダリングできる）
- docs/01_GUIDE/GUIDE_08_テスト方針.md（重いテストは @pytest.mark.slow 必須）

このテストは実レンダリングを伴うため @pytest.mark.slow を付ける．
通常実行（uv run pytest -m "not slow"）ではスキップされる．
"""

from __future__ import annotations

from pathlib import Path

import numpy
import pytest
import yaml

from sm_tias_lightsim.render.runner import render_scene
from sm_tias_lightsim.scene.schema import SceneConfig


@pytest.mark.slow
def test_render_scene_smoke_returns_image(sphere_stl_in_cwd: Path, minimal_scene_yaml: str):
    """64×64 シーンのレンダリングが成功し，正当な画像配列が返ること．

    仕様: Step 4 完了条件「64×64 程度の合成シーンを最後までレンダリングできる」
    (PLAN_02 Step 4 完了条件)

    検証:
    - shape: (64, 64, 3)
    - dtype: float32 または float64
    - mean > 0（光が物理的に届いている）
    """
    cfg = SceneConfig.model_validate(yaml.safe_load(minimal_scene_yaml))
    img = render_scene(cfg, project_root=sphere_stl_in_cwd.parent)
    assert img.shape == (64, 64, 3)
    assert img.dtype in (numpy.float32, numpy.float64)
    assert img.mean() > 0
