fix: PlayRelease always materialises a defensive copy so Items alias can't wipe the queue on jump; add aliasing regression test

This commit is contained in:
daniel-c-harvey
2026-06-19 15:23:20 -04:00
parent fe3819f378
commit 9d0ce99a5d
2 changed files with 28 additions and 1 deletions
+27
View File
@@ -144,6 +144,33 @@ public class QueueServiceTests
});
}
[Test]
public async Task PlayRelease_ViaLiveQueueItems_PreservesTracksAndJumpsToIndex()
{
// Regression guard for the aliasing bug: OnQueueJump calls PlayRelease(QueueService.Items, index).
// Items returns the backing list directly; without a defensive copy, the cast
// "tracks as IReadOnlyList<TrackDto>" aliases _items, so _items.Clear() also clears list,
// and _items.AddRange(list) adds nothing — wiping the queue and playing nothing.
await _queue.PlayRelease(Tracks(4)); // populate the live queue
// Jump to index 2 via the live Items reference, exactly as OnQueueJump does.
await _queue.PlayRelease(_queue.Items, 2);
Assert.Multiple(() =>
{
// The queue must survive — all four tracks still present, in order.
Assert.That(_queue.Items, Has.Count.EqualTo(4));
Assert.That(_queue.Items.Select(t => t.EntryKey),
Is.EqualTo(new[] { "track-1", "track-2", "track-3", "track-4" }));
// CurrentIndex must be the jumped-to slot.
Assert.That(_queue.CurrentIndex, Is.EqualTo(2));
// Current must be the right track.
Assert.That(_queue.Current!.EntryKey, Is.EqualTo("track-3"));
// The player must have streamed the jumped-to track.
Assert.That(_player.SelectedTracks.Last().EntryKey, Is.EqualTo("track-3"));
});
}
// --- Arm: prerender-safe load without streaming (release embed) ---
[Test]