Orbit Companion: the queue takes over a moment before the programme ends

The channel's own next programme had started loading before the queue switched.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-06 23:12:06 +00:00
co-authored by Claude Opus 5.5
parent 769ee3b0b2
commit d9bb698303
5 changed files with 19 additions and 11 deletions
@@ -210,15 +210,17 @@ class PhoneLinkTest {
assertEquals(guideTitleParts(companionChannels[1].at(end).media.item.title).first, OrbitCompanion.queue[0].title)
var anchor = OrbitCompanion.follow(screen, null, now)
assertEquals(101 to start, anchor)
anchor = OrbitCompanion.follow(screen, anchor, end - 1_000); assertTrue(tuned.isEmpty())
anchor = OrbitCompanion.follow(screen, anchor, end - 10_000); assertTrue(tuned.isEmpty())
// Changing channel moves the wait to the new programme instead of playing.
selected = 308; anchor = OrbitCompanion.follow(screen, anchor, end - 500); assertTrue(tuned.isEmpty())
selected = 101; anchor = OrbitCompanion.follow(screen, anchor, end - 400); assertTrue(tuned.isEmpty())
selected = 308; anchor = OrbitCompanion.follow(screen, anchor, end - 9_000); assertTrue(tuned.isEmpty())
selected = 101; anchor = OrbitCompanion.follow(screen, anchor, end - 8_000); assertTrue(tuned.isEmpty())
// Not watching: it waits.
watching = false; anchor = OrbitCompanion.follow(screen, anchor, end + 1_000); assertTrue(tuned.isEmpty())
watching = true; anchor = OrbitCompanion.follow(screen, anchor, end + 2_000); assertTrue(tuned.isEmpty())
val nextEnd = companionChannels[0].at(end + 2_000).endMs
OrbitCompanion.follow(screen, anchor, nextEnd + 1_000)
anchor = OrbitCompanion.follow(screen, anchor, nextEnd - 5_000); assertTrue(tuned.isEmpty())
// A moment before the end, so the channel's own next programme never starts.
OrbitCompanion.follow(screen, anchor, nextEnd - 2_000)
assertEquals(listOf(308 to 0L), tuned); assertTrue(OrbitCompanion.queue.isEmpty())
// Five at most.
repeat(5) { assertNotNull(OrbitCompanion.enqueue(screen, 101, null, now)) }