"""Migration 0119's data step, DB-lane: the stored `transcode_hw` facet follows the rule that it says whether the GPU does the encode, and a 10-bit decodable item is probed again so its HDR flag decides. The schema half is checked by test_migrations.py; a facet value left stale is invisible there. """ from alembic import command from alembic.config import Config from sqlalchemy import text from app.db import engine def test_the_stored_facet_is_rewritten_by_the_gpu_encode_rule(db): cfg = Config("alembic.ini") command.downgrade(cfg, "0118_videos_shuffle_key") try: with engine.begin() as conn: lib = conn.execute( text( "INSERT INTO plex_libraries (plex_key, title, kind, enabled)" " VALUES ('m1', 'Movies', 'movie', true) RETURNING id" ) ).scalar_one() def item(key, playable, codec, hw, depth=None, probed=False): conn.execute( text( "INSERT INTO plex_items (rating_key, library_id, kind, title, playable," " codec_video, transcode_hw, video_bit_depth, media_probed_at)" " VALUES (:k, :l, 'movie', :k, :p, :c, :hw, :d," " CASE WHEN :pr THEN now() END)" ), { "k": key, "l": lib, "p": playable, "c": codec, "hw": hw, "d": depth, "pr": probed, }, ) item("vc1", "transcode", "VC1", True, 8, probed=True) # the old list said decodable item("xvid", "transcode", "mpeg4", False) item("divx", "transcode", "msmpeg4v3", False) item("av1", "transcode", "av1", False) item("h8", "transcode", "hevc", True, 8, probed=True) item("h10", "transcode", "hevc", False, 10, probed=True) # SDR or HDR: unknown here item("remux", "remux", "h264", None) finally: command.upgrade(cfg, "head") with engine.connect() as conn: rows = { k: (hw, probed) for k, hw, probed in conn.execute( text("SELECT rating_key, transcode_hw, media_probed_at IS NOT NULL FROM plex_items") ).tuples() } assert rows == { "vc1": (True, True), "xvid": (True, False), "divx": (True, False), "av1": (False, False), "h8": (True, True), "h10": (False, False), # re-queued: the probe reads its HDR flag again "remux": (None, False), }