"""The guard in front of a recursive delete. `sweep_orphans` rmtree's directories under `_HLS_ROOT`, and that root is admin-configurable (PLEX_HLS_DIR) — it can legitimately be a shared scratch path. `_SESSION_DIR_RE` is the ONLY thing that keeps the sweep off a neighbour's data, so the names it accepts are pinned here.""" import pytest from app.plex.stream import _SESSION_DIR_RE @pytest.mark.parametrize( "name", [ "12345_0", # legacy shape (pre multi-audio): {rating_key}_{start} "12345_842", "12345_0_None_+0.00", # current shape, single audio track (audio_ord None) "12345_0_2_+0.00", # current shape, explicit audio_ord "12345_842_multi_-1.25", # multi-audio, negative offset "12345_842_multi_+12.50", ], ) def test_our_session_directories_are_swept(name): assert _SESSION_DIR_RE.match(name) @pytest.mark.parametrize( "name", [ "backup_2024", # the class an "optional tail" pattern wrongly matched "release_10", "important_data_2024", "node_modules", "logs", "plex-hls", "12345", # no start offset — not a session dir "12345_0_multi", # truncated: missing the offset "12345_0_multi_1.25", # offset without its sign "snapshot_2024_backup_+1.00", # session-ish tail, but the key isn't a rating_key "backup_2024_multi_+0.00", ".config", ], ) def test_foreign_directories_are_left_alone(name): assert not _SESSION_DIR_RE.match(name)