fix(events): emit TRACK_DOWNLOADED once per track after decryption

This commit is contained in:
imSp4rky
2026-11-28 14:15:31 -07:00
parent 053d83874d
commit 4743e2f32c
7 changed files with 118 additions and 34 deletions
+9 -6
View File
@@ -324,7 +324,7 @@ def no_hook(monkeypatch):
monkeypatch.setattr(verify, "DECRYPT_HOOK", None)
def test_complete_track_emits_downloaded_then_decrypts_then_cleans_up(tmp_path, seen, no_hook):
def test_complete_track_decrypts_then_cleans_up(tmp_path, seen, no_hook):
ctx = make_ctx(tmp_path)
ctx.save_dir.mkdir()
ctx.save_path.write_bytes(b"merged")
@@ -333,8 +333,8 @@ def test_complete_track_emits_downloaded_then_decrypts_then_cleans_up(tmp_path,
complete_track(track, ctx, drm) # type: ignore[arg-type]
assert drm.events_before == ["downloaded"]
assert seen == [("downloaded", ctx.save_path), ("decrypted", drm)]
assert drm.events_before == []
assert seen == [("decrypted", drm)]
assert ctx.save_path.read_bytes() == b"clear:merged"
assert track.path == ctx.save_path and track.drm is None
assert ctx.statuses == ["Decrypting", "Decrypted", "Downloaded"]
@@ -349,14 +349,17 @@ def test_complete_track_after_segment_decryption_only_checks(tmp_path, seen, no_
complete_track(SimpleNamespace(path=None, drm=[drm]), ctx, drm, decrypt=False) # type: ignore[arg-type]
assert ctx.save_path.read_bytes() == b"merged"
assert [name for name, _ in seen] == ["downloaded", "decrypted"]
assert [name for name, _ in seen] == ["decrypted"]
def test_complete_track_without_drm_skips_the_decryption(tmp_path, seen):
ctx = make_ctx(tmp_path)
ctx.save_path.write_bytes(b"merged")
complete_track(SimpleNamespace(path=None, drm=None), ctx, None) # type: ignore[arg-type]
track = SimpleNamespace(path=None, drm=None)
assert seen == [("downloaded", ctx.save_path)]
complete_track(track, ctx, None) # type: ignore[arg-type]
assert seen == []
assert track.path == ctx.save_path
assert ctx.statuses == ["Downloaded"]