0.111.0 candidate: Paul's approved premiere dates as gated editorial slots, with editorial competition
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m13s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m41s

Avatar: Fire and Ash on Friday 27 November and Spider-Man: Brand New Day on
Friday 11 December, both 20:00 on Orbit Premiere (approved by Paul on 5
November 2026; Saturday 28 November stays the Arnie Triple Bill's). Each
debut is a fixed slot like Advent's doors, from the film verified on the box
by item, IMDb ID and decoder (read and logged also while booking is off).
Premiere carries the film from its debut (both keep Premiere eligibility)
and its genre home from the end of the window; until then no other channel
shows it. All gated by PREMIERE_BOOKING_ACTIVE, still off: approved dates
aren't permission to book.

Editorial competition (Paul): a debut never shares its evening's airtime
with another headline event (Drive-In events, Advent doors, Naughty List
nights, other premieres), even without a technical clash.

Release check (PremiereReplayTest, box copies of 5 November, premieres on):
both debuts booked on their evenings, no competing events, no showing
before its time, 193+ h between Premiere repeats, all 25 Advent doors and 6
Naughty nights booked, no overlaps or duplicate titles, committed plans
unchanged. Built on 0.108.11's features; versionCode 172.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-05 16:34:05 +00:00
co-authored by Claude Opus 5.5
parent 655b6585b2
commit 25e6d4f669
8 changed files with 275 additions and 15 deletions
@@ -47,14 +47,37 @@ class DirectorPremiereTest {
assertNotNull(report(OrbitStatus.Never, studios = listOf("CAPCOM")).premieres.singleOrNull())
}
@Test fun theDebutIsAFridayOrSaturdayNightAfterTheCommittedPlan() {
@Test fun theDebutIsAFridayOrSaturdayNightAfterTheCommittedPlanAndNoOtherHeadline() {
// Editorial competition: Hammer (Fri 13), Universal Monsters (Sat 14) and Shaw Brothers (Fri 20) own their evenings.
val debut = debutSlot(at(11, 12, 6), at(11, 5, 12), emptyList(), london)!!
val t = Instant.ofEpochMilli(debut).atZone(london)
assertEquals(DayOfWeek.FRIDAY, t.dayOfWeek); assertEquals(13, t.dayOfMonth); assertEquals(20, t.hour)
// Kept clear of another fixed slot that night: Saturday instead.
assertEquals(at(11, 14, 20), debutSlot(at(11, 12, 6), at(11, 5, 12), listOf(at(11, 13, 18)), london))
// Never inside the committed plan, even on a Friday.
assertEquals(at(11, 14, 20), debutSlot(at(11, 13, 21), at(11, 5, 12), emptyList(), london))
assertEquals(DayOfWeek.SATURDAY, t.dayOfWeek); assertEquals(21, t.dayOfMonth); assertEquals(20, t.hour)
assertNotNull(competingEvent(at(11, 13, 20), at(11, 13, 23), london)); assertNull(competingEvent(debut, debut + 3 * 3_600_000L, london))
// With Saturday 21 taken by a fixed slot, Avatar's approved evening (Fri 27) and the Arnie Triple Bill (Sat 28) fill the
// rest of the three weeks it looks ahead: no debut is offered, rather than one that competes.
assertNull(debutSlot(at(11, 12, 6), at(11, 5, 12), listOf(at(11, 21, 18)), london))
// Never inside the committed plan.
assertTrue(debutSlot(at(11, 21, 21), at(11, 5, 12), emptyList(), london)!! > at(11, 21, 21))
}
@Test fun approvedDatesAreTheirOwnEvenings() {
val avatar = ApprovedDebuts.single { it.film.itemId == "7789551" }; val spidey = ApprovedDebuts.single { it.film.itemId == "8006401" }
assertEquals(at(11, 27, 20), avatar.startMs(london)); assertEquals(at(12, 11, 20), spidey.startMs(london))
assertNull(competingEvent(avatar.startMs(london), avatar.startMs(london) + 197 * minute, london, except = avatar.film.itemId))
assertNull(competingEvent(spidey.startMs(london), spidey.startMs(london) + 145 * minute, london, except = spidey.film.itemId))
// Saturday 28 November stays the Arnie Triple Bill's.
assertTrue(competingEvent(at(11, 28, 20), at(11, 28, 22), london)!!.contains("Arnie"))
// Booking off: no slots, no rotation; the first run is still protected from other channels until the window ends.
val film = PoolSeries("7789551", "Avatar: Fire and Ash", emptyList())
assertTrue(approvedDebutSlots(mapOf("7789551" to film), london).isEmpty()); assertTrue(premiereRotation(303, mapOf("7789551" to film), at(12, 30, 12), london).isEmpty())
assertTrue(premiereHeld(303, london)(film, at(12, 20, 12))); assertFalse(premiereHeld(303, london)(film, at(12, 26, 12)))
assertFalse(premiereHeld(PREMIERE_NUMBER, london)(film, at(12, 1, 12)))
// Active: the debut is a slot, Premiere carries it from then on (it keeps Premiere eligibility), Sci-Fi after the window.
assertEquals(1, approvedDebutSlots(mapOf("7789551" to film), london, active = true).size)
assertTrue(premiereRotation(PREMIERE_NUMBER, mapOf("7789551" to film), at(11, 26, 12), london, active = true).isEmpty())
assertEquals(1, premiereRotation(PREMIERE_NUMBER, mapOf("7789551" to film), at(12, 1, 12), london, active = true).size)
assertTrue(premiereRotation(303, mapOf("7789551" to film), at(12, 20, 12), london, active = true).isEmpty())
assertEquals(1, premiereRotation(303, mapOf("7789551" to film), at(12, 26, 12), london, active = true).size)
}
@Test fun placingSetsADebutAndTheWindowMovesItHome() {
@@ -0,0 +1,123 @@
package tv.orbit.classic
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assume.assumeTrue
import org.junit.Test
import java.io.File
import java.time.Instant
import java.time.ZoneId
/**
* The release check for Paul's approved premiere dates, run by hand on copies of the box's own files:
* ORBIT_REPLAY_DIR=<copies of the schedule folder, plus advent-films.json and premiere-films.json> ./gradlew :app:testDebugUnitTest --tests '*PremiereReplayTest*'
* Tops up every channel day by day to mid-January, as the box does, with Advent, The Naughty List and the approved premieres
* switched on (booking active, as it would be once approved), and once without the premieres. Writes premiere-checks.txt there:
* each debut as booked, every other showing of the two films on any channel, the editorial competition check, film rest on
* Premiere, committed plans, overlaps, Advent's doors, and what else changed against the run without premieres.
*/
class PremiereReplayTest {
private val dir = System.getenv("ORBIT_REPLAY_DIR")?.let(::File)
private val zone = ZoneId.of("Europe/London")
private fun plan(file: File): ChannelPlan? {
if (!file.exists()) return null
val root = JSONObject(file.readText()); val rows = root.getJSONArray("entries"); val t = root.getJSONObject("tail"); val marks = t.getJSONObject("marks")
val entries = (0 until rows.length()).map { i ->
val o = rows.getJSONObject(i); val d = o.getLong("d"); val n = o.getJSONArray("n")
ScheduleEntry(o.getString("s"), EpisodeMark(n.getInt(0), n.getInt(1)), ScheduledMedia(SampleItem(o.getString("t"), o.optString("k", "Episode"), d / 60_000, "", o.getString("i"), d), o.getString("c"), d),
o.getLong("a"), o.optString("w"), o.optString("p"))
}
return ChannelPlan(entries, ScheduleCursor(if (t.isNull("last")) null else t.getString("last"),
marks.keys().asSequence().associateWith { id -> marks.getJSONArray(id).let { EpisodeMark(it.getInt(0), it.getInt(1)) } },
t.optJSONObject("shown")?.let { s -> s.keys().asSequence().associateWith { s.getLong(it) } }.orEmpty(),
t.optJSONObject("blocks")?.let { b -> b.keys().asSequence().associateWith { b.getString(it) } }.orEmpty()))
}
private fun pool(file: File): List<PoolSeries> {
val rows = JSONObject(file.readText()).getJSONArray("series")
return (0 until rows.length()).map { i ->
val o = rows.getJSONObject(i); val eps = o.getJSONArray("episodes")
PoolSeries(o.getString("id"), o.getString("title"), (0 until eps.length()).map { j ->
val e = eps.getJSONArray(j); PoolEpisode(e.getString(0), e.getString(1), EpisodeMark(e.getInt(2), e.getInt(3)), e.getString(4), e.getLong(5))
}, o.optString("group"))
}
}
private fun films(name: String): Map<String, PoolSeries> {
val listed = JSONArray(File(dir, name).readText())
return (0 until listed.length()).map { listed.getJSONObject(it) }.associate { o ->
o.getString("id") to PoolSeries(o.getString("id"), o.getString("title"), listOf(PoolEpisode(o.getString("id"), "src", EpisodeMark(1, 1), o.getString("title"), o.getLong("ms"))))
}
}
private val end = java.time.LocalDate.of(2027, 1, 15).atStartOfDay(zone).toInstant().toEpochMilli()
private fun run(premieresOn: Boolean): Map<Int, List<ScheduleEntry>> {
val seasonal = films("advent-films.json"); val premieres = films("premiere-films.json")
val held = seasonalHeld(zone)
val channels = SmartChannels.sortedBy { it.number }.filter { File(dir, "schedule-${it.number}.json").exists() && File(dir, "episodes-${it.number}.json").exists() }
val plans = channels.associate { it.number to plan(File(dir, "schedule-${it.number}.json"))!! }.toMutableMap()
val pools = channels.associate { it.number to pool(File(dir, "episodes-${it.number}.json")) }
val all = plans.mapValues { it.value.entries.toMutableList() }.toMutableMap()
var now = System.getenv("ORBIT_REPLAY_NOW")?.toLong() ?: plans.values.minOf { it.entries.first().startMs }
while (now < end) {
for (programming in channels) {
val number = programming.number
val others = clashesWith(plans.filterKeys { it != number }.values.toList())
val fixed = (if (programming.filmRestMs != null) adventSlots(number, seasonal, zone) + naughtySlots(number, seasonal, zone) else emptyList()) +
(if (premieresOn && number == PREMIERE_NUMBER) approvedDebutSlots(premieres, zone, active = true) else emptyList())
val extra = if (premieresOn) premiereRotation(number, premieres, now, zone, active = true).filter { p -> pools[number]!!.none { it.id == p.id } } else emptyList()
val premiereHold = premiereHeld(number, zone)
val next = topUpPlan(plans[number], ScheduleCursor(), pools[number]!! + extra, now, programming.filmRestMs, programming.finishTogether, programming.dayParts, zone, others,
shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = programming.tierWeights?.let { programming::weightOf },
adaptiveRest = programming.adaptiveFilmRest, stories = programming.storyGrouping, fixed = fixed,
held = { f, at -> held(f, at) || (premieresOn && premiereHold(f, at)) }) ?: continue
plans[number] = next
next.entries.filter { e -> all[number]!!.none { it.startMs == e.startMs } }.forEach { all[number]!! += it }
}
now += 6 * 60 * 60_000L
}
return all
}
private fun at(ms: Long) = Instant.ofEpochMilli(ms).atZone(zone).let { "%s %02d:%02d".format(it.toLocalDate(), it.hour, it.minute) }
@Test fun releaseChecks() {
assumeTrue(dir != null && File(dir, "premiere-films.json").exists() && File(dir, "advent-films.json").exists())
val with = run(true); val without = run(false)
val out = StringBuilder()
for (d in ApprovedDebuts) {
val debut = d.startMs(zone)
val booked = with[PREMIERE_NUMBER].orEmpty().firstOrNull { it.why.startsWith(PREMIERE_WHY) && it.seriesId == d.film.itemId }
out.appendLine("${d.film.title}: approved ${at(debut)} on Orbit Premiere -> " +
if (booked == null) "NOT BOOKED" else "booked ${at(booked.startMs)} to ${at(booked.endMs)} (${(booked.startMs - debut) / 60_000} min late)")
out.appendLine(" competing headline events that evening: ${competingEvent(debut, debut + (booked?.media?.durationMs ?: 3 * 3_600_000L), zone, except = d.film.itemId) ?: "none"}")
val showings = with.flatMap { (n, es) -> es.filter { it.seriesId == d.film.itemId || seriesKey(it.media.item.title) == seriesKey(d.film.title) }.map { n to it } }.sortedBy { it.second.startMs }
showings.forEach { (n, e) -> out.appendLine(" $n ${at(e.startMs)} ${e.why.take(60)}") }
val early = showings.filter { (n, e) -> !e.why.startsWith(PREMIERE_WHY) && (e.startMs < debut || (n != PREMIERE_NUMBER && e.startMs < d.windowEndMs(zone))) }
out.appendLine(" showings before their time (on Premiere before the debut, elsewhere before the window ends): ${early.size}")
val onPremiere = showings.filter { it.first == PREMIERE_NUMBER }.map { it.second.startMs }
out.appendLine(" shortest gap between Premiere showings: ${onPremiere.zipWithNext { a, b -> (b - a) / 3_600_000 }.minOrNull()?.let { "$it h" } ?: "one showing only"}")
out.appendLine(" advent hold applies: ${seasonalHeld(zone)(PoolSeries(d.film.itemId, d.film.title, emptyList()), debut)}")
}
val overlaps = with.mapValues { (_, e) -> e.sortedBy { it.startMs }.zipWithNext().count { (a, b) -> a.endMs > b.startMs } }.filterValues { it > 0 }
val committed = SmartChannels.mapNotNull { p -> plan(File(dir, "schedule-${p.number}.json"))?.let { p.number to it } }
.count { (number, plan) -> with[number]?.take(plan.entries.size) != plan.entries }
val doors = AdventDoors.count { d -> with[d.channel].orEmpty().any { it.why.startsWith("$ADVENT_WHY${d.door};") } }
val doorsWithout = AdventDoors.count { d -> without[d.channel].orEmpty().any { it.why.startsWith("$ADVENT_WHY${d.door};") } }
val naughty = with[AFTER_DARK_NUMBER].orEmpty().count { it.why.startsWith(NAUGHTY_WHY) }
// Duplicate titles: the same title airing on two channels at once anywhere on the network.
val airings = with.flatMap { (n, es) -> es.map { n to it } }.groupBy { seriesKey(it.second.media.item.title) }
val dupes = airings.values.sumOf { list -> list.sortedBy { it.second.startMs }.zipWithNext().count { (a, b) -> a.first != b.first && a.second.endMs > b.second.startMs } }
val changed = with.keys.filter { with[it] != without[it] }.sorted()
out.appendLine()
out.appendLine("overlaps: $overlaps")
out.appendLine("committed plans changed: $committed")
out.appendLine("Advent doors booked: $doors of ${AdventDoors.size} (without the premieres: $doorsWithout); Naughty List nights booked: $naughty")
out.appendLine("same title on two channels at once: $dupes")
out.appendLine("channels whose bookings differ from the run without premieres: $changed")
File(dir, "premiere-checks.txt").writeText(out.toString())
println(out)
}
}