from lyra_worker.adapters._streamrip import _flatten_audio def test_flatten_moves_nested_audio_up_and_counts(tmp_path): nested = tmp_path / "John Mayer - Continuum (2006) [FLAC] [24B-96kHz]" nested.mkdir() (nested / "01. Waiting.flac").write_bytes(b"x") (nested / "02. Belief.flac").write_bytes(b"x") (nested / "cover.jpg").write_bytes(b"x") # non-audio stays behind count = _flatten_audio(str(tmp_path)) assert count == 2 assert (tmp_path / "01. Waiting.flac").exists() assert (tmp_path / "02. Belief.flac").exists() assert not (nested / "01. Waiting.flac").exists() # audio moved out of the nested folder def test_flatten_counts_flat_files_and_ignores_non_audio(tmp_path): (tmp_path / "a.flac").write_bytes(b"x") (tmp_path / "b.mp3").write_bytes(b"x") (tmp_path / "notes.txt").write_bytes(b"x") assert _flatten_audio(str(tmp_path)) == 2 def test_flatten_partial_download_reports_true_short_count(tmp_path): # streamrip continues past per-track failures; only 3 of an album's tracks landed. nested = tmp_path / "sub" nested.mkdir() for n in ["01.flac", "02.flac", "03.flac"]: (nested / n).write_bytes(b"x") assert _flatten_audio(str(tmp_path)) == 3 # not the album's metadata count assert not nested.exists() # emptied subfolder removed