from __future__ import annotations import json import pytest from app.animations.store import AnimationStore from scripts.generate_animation_preview_fixture import ( FixtureError, generate_fixture, validate_empty_test_root, ) def test_fixture_requires_empty_explicit_test_directory(tmp_path): wrong_name = tmp_path / "ordinary" wrong_name.mkdir() with pytest.raises(FixtureError, match="name must start"): validate_empty_test_root(wrong_name) root = tmp_path / "matrix-screen-controller-preview-perf-unit" root.mkdir() (root / "existing.txt").write_text("keep", encoding="utf-8") with pytest.raises(FixtureError, match="must be empty"): validate_empty_test_root(root) assert (root / "existing.txt").read_text(encoding="utf-8") == "keep" def test_fixture_rejects_production_root(monkeypatch, tmp_path): root = tmp_path / "matrix-screen-controller-preview-perf-production" root.mkdir() monkeypatch.setattr( "scripts.generate_animation_preview_fixture.PRODUCTION_DATA_ROOT", root, ) with pytest.raises(FixtureError, match="production data root"): validate_empty_test_root(root) def test_fixture_generates_distinct_complete_animations(tmp_path): root = tmp_path / "matrix-screen-controller-preview-perf-small" root.mkdir() checked = validate_empty_test_root(root) result = generate_fixture( checked, animation_count=2, frames_per_animation=3, duration_ms=50, ) assert result["total_frames"] == 6 store = AnimationStore(root, cleanup_playback=False) listing = store.list()["animations"] assert len(listing) == 2 assert all(item["frame_count"] == 3 for item in listing) detail = store.get(listing[0]["id"]) assert [frame["duration_ms"] for frame in detail["frames"]] == [50, 50, 50] assert len({frame["digest"] for item in listing for frame in store.get(item["id"])["frames"]}) == 6 for item in listing: document = json.loads( (root / "animations" / item["id"] / "animation.json").read_text(encoding="utf-8") ) assert document["schema_version"] == 2