Mistletoe's 10-hour booking: a one-off adb fix, and a hold on odd running times

fix-booking replaces one booking that hasn't started with named films from the channel's own
pool, back to back, the last slot running to where it ended; nothing else moves, and the plan
file is kept aside. Films whose file runs over 5 hours are held for review (never on Ring X),
shown under Schedule health, and released from adb with release-runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 16:06:33 +00:00
co-authored by Claude Opus 5.5
parent da1f203071
commit 0e29d8748d
8 changed files with 216 additions and 3 deletions
@@ -0,0 +1,68 @@
package tv.orbit.classic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
/** Mistletoe's 10-hour booking (Paul, 23 November 2026), and the odd-running-time hold that follows from it. */
class BookingFixTest {
private val min = 60_000L
private val start = 1_795_000_000_000L
private fun film(id: String, minutes: Long) = PoolSeries(id, "Film $id", listOf(PoolEpisode(id, "src$id", EpisodeMark(1, 1), "Film $id", minutes * min)))
private fun entry(f: PoolSeries, at: Long) = ScheduleEntry(f.id, EpisodeMark(1, 1), ScheduledMedia(filmItem(f), "src${f.id}", f.episodes.first().durationMs), at, "w")
private val bad = film("bad", 600)
private val before = film("b", 90)
private val after = film("a", 95)
private val plan = ChannelPlan(listOf(entry(before, start - 90 * min), entry(bad, start), entry(after, start + 600 * min)), ScheduleCursor())
private val pool = listOf(bad, before, after) + (1..8).map { film("r$it", listOf(95L, 98L, 100L, 92L, 97L, 98L, 91L, 91L)[it - 1]) }
@Test fun theBookingIsReplacedAndNothingElseMoves() {
val (fixed, why) = BookingFix.replaced(plan, pool, start, "bad", listOf("r1", "r2", "r3", "r4", "r5", "r6"), start - 60 * min)
fixed!!
assertTrue(why, why.startsWith("replaced with 6 films"))
assertEquals(plan.entries.first(), fixed.entries.first())
assertEquals(plan.entries.last(), fixed.entries.last())
assertTrue(fixed.entries.none { it.seriesId == "bad" })
fixed.entries.zipWithNext().forEach { (a, b) -> assertEquals(a.endMs, b.startMs) }
// The last film's slot runs to where the bad booking ended; its real length is kept so the ident fills the rest.
val last = fixed.entries[fixed.entries.size - 2]
assertEquals(start + 600 * min, last.endMs)
assertEquals(98 * min, last.fileMs)
assertEquals(118 * min, last.media.durationMs)
assertTrue(fixed.tail.filmShown.keys.containsAll(listOf("r1", "r6")))
}
@Test fun itRefusesAnythingUnsafe() {
fun why(ids: List<String>, at: Long = start, old: String = "bad", now: Long = start - min) = BookingFix.replaced(plan, pool, at, old, ids, now)
assertNull(why(listOf("r1"), now = start + min).first) // already on air
assertNull(why(listOf("r1", "r2", "r3", "r4", "r5", "r6"), at = start + 1).first) // no such booking
assertNull(why(listOf("r1", "r1", "r2", "r3", "r4", "r5")).first) // named twice
assertNull(why(listOf("r1", "r2", "r3", "r4", "r5", "r6", "r7")).first) // runs past the slot
assertNull(why(listOf("r1", "r2", "r3", "r4", "r5")).first) // leaves too long a gap
assertNull(why(listOf("r1", "r2", "r3", "r4", "r5", "nope")).first) // not in the pool
assertNull(why(listOf("r1", "r2", "r3", "r4", "r5", "bad")).first) // the file itself
}
@Test fun anOddRunningTimeIsHeldUntilReleasedExceptOnRingX() {
val long = film("long", 10 * 60); val rotk = film("rotk", 263)
assertTrue(isOddRuntime(long, 701, emptySet()))
assertFalse(isOddRuntime(rotk, 301, emptySet()))
assertFalse(isOddRuntime(long, 401, emptySet()))
assertFalse(isOddRuntime(long, 701, setOf("long")))
assertEquals(listOf("rotk"), withoutOddRuntimes(listOf(long, rotk), 701, emptySet()).map { it.id })
// A series episode is never held by this rule.
val show = PoolSeries("s", "Show", listOf(PoolEpisode("e1", "x", EpisodeMark(1, 1), "One", 6 * 60 * min), PoolEpisode("e2", "x", EpisodeMark(1, 2), "Two", 30 * min)))
assertFalse(isOddRuntime(show, 701, emptySet()))
}
@Test fun releasesAreKept() {
val f = java.io.File.createTempFile("released", ".json").apply { delete(); deleteOnExit() }
val r = RuntimeReleases(f)
assertEquals(emptySet<String>(), r.load())
assertEquals("released 5551701", r.add("5551701"))
assertEquals(setOf("5551701"), r.load())
assertTrue(r.add("../x").startsWith("refused"))
}
}