RandomZ / app /tests /test_photo_vision_cache.py
StormShadow308's picture
Prioritize production AI: photo vision fix, HF profile, and inspector on generate.
7fa723a
Raw
History Blame Contribute Delete
1.67 kB
"""Section photo vision disk cache."""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from app.services.photo_vision import (
_read_vision_cache,
_vision_cache_path,
_write_vision_cache,
invalidate_section_photo_vision_cache,
)
def test_vision_cache_roundtrip(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("app.services.photo_vision.settings.upload_dir", tmp_path / "uploads")
path = _vision_cache_path("t1", "r1", "E1")
_write_vision_cache(
path,
photo_ids=["a", "b"],
observations=["Crack in render"],
note=None,
)
out = _read_vision_cache(path, photo_ids=["b", "a"])
assert out is not None
obs, note = out
assert obs == ["Crack in render"]
assert note is None
def test_vision_cache_invalidates_on_photo_set_change(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("app.services.photo_vision.settings.upload_dir", tmp_path / "uploads")
path = _vision_cache_path("t1", "r1", "E1")
_write_vision_cache(path, photo_ids=["a"], observations=["x"], note=None)
assert _read_vision_cache(path, photo_ids=["a", "b"]) is None
def test_invalidate_removes_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("app.services.photo_vision.settings.upload_dir", tmp_path / "uploads")
path = _vision_cache_path("t1", "r1", "E1")
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps({"photo_ids": []}), encoding="utf-8")
invalidate_section_photo_vision_cache("t1", "r1", "E1")
assert not path.is_file()