Premiere as a broadcast stage: first-run event, then the genre home
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m7s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m27s

Paul's policy, 5 November 2026. The Director's Chair makes two
recommendations: a genre home (Premiere is never one) and, for a film
never booked on Orbit that suits an event debut, a first run on Orbit
Premiere. 'Premiere, then <home>' puts it on Premiere's list with a debut
as a fixed slot on the first Friday or Saturday at 20:00 after Premiere's
committed plan (clear of Advent's doors), branded FIRST ON ORBIT. Four weeks
after the debut it leaves Premiere's list for its home's, for that
channel's future schedule. Nothing already booked changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-05 11:30:30 +00:00
co-authored by Claude Opus 5.5
parent 451e1d7b22
commit f85fd03b62
6 changed files with 278 additions and 28 deletions
@@ -0,0 +1,91 @@
package tv.orbit.classic
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.*
import org.junit.Test
import java.io.File
import java.time.DayOfWeek
import java.time.Instant
import java.time.ZoneId
import java.time.ZonedDateTime
/** Premiere as a broadcast stage: two recommendations, a debut that only appends, a window, then the film's genre home. */
class DirectorPremiereTest {
private val london = ZoneId.of("Europe/London")
private val minute = 60_000L
private val day = 24 * 60 * minute
private fun at(month: Int, d: Int, h: Int, m: Int = 0) = ZonedDateTime.of(2026, month, d, h, m, 0, 0, london).toInstant().toEpochMilli()
private val user = "a1b2c3"
private fun store() = ScheduleStore(kotlin.io.path.createTempDirectory("premiere").toFile().apply { deleteOnExit() })
private val fighter = JSONObject().put("id", "8100001").put("type", "Movie").put("name", "Street Brawlers").put("year", 2026)
.put("overview", "An epic battle: a hero on a mission joins the world fighting tournament, where an agent seeks revenge in every fight.")
.put("genres", JSONArray(listOf("Action", "Adventure", "Science Fiction"))).put("studios", JSONObject.NULL).put("rating", "PG-13")
.put("countries", JSONArray(listOf("United States"))).put("taglines", JSONObject.NULL)
private fun report(aired: Set<String>): DeskReport {
val evidence = File.createTempFile("evidence", ".jsonl").apply { deleteOnExit(); writeText("$fighter\n") }
val sets = File.createTempFile("collections", ".jsonl").apply { delete(); deleteOnExit() }
return buildDeskReport(evidence, sets, emptyMap(), listOf(Arrival("8100001", "Movie", "Street Brawlers", 2026, "2026-10-30", "tmdb:81", 0)), emptySet(), emptyMap(), 1, true,
DirectorMode.Surprise, at(11, 5, 12), london, aired = aired)
}
@Test fun premiereIsAStageNotAHomeAndOnlyForAFirstAiring() {
val r = report(emptySet())
val pick = (r.picks.map { it.options to it.firstRun } + r.asks.map { it.options to it.firstRun }).single()
assertTrue(pick.first.none { it.number == PREMIERE_NUMBER }) // never offered as a home
assertEquals(302, pick.first.first().number) // its genre home: Orbit Action
assertEquals(PREMIERE_NUMBER, pick.second!!.number) // and its first-run event
// Booked on Orbit before, by this item or another copy of the same work: new, but no premiere.
listOf(setOf("8100001"), setOf("tmdb:81")).forEach { aired ->
val again = report(aired)
assertTrue((again.picks.map { it.firstRun } + again.asks.map { it.firstRun }).all { it == null })
}
val back = DeskReport.of(r.toJson())
assertEquals(PREMIERE_NUMBER, (back.picks.map { it.firstRun } + back.asks.map { it.firstRun }).single()!!.number)
}
@Test fun theDebutIsAFridayOrSaturdayNightAfterTheCommittedPlan() {
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))
}
@Test fun placingSetsADebutAndTheWindowMovesItHome() {
val store = store()
val debut = placePremiereFromChair(store, user, "8100001", "Street Brawlers", 2026, 302, at(11, 5, 12), london)!!
assertEquals(listOf("8100001"), store.loadChoices(user, PREMIERE_NUMBER).accepted.map { it.id })
assertTrue(store.loadChoices(user, 302).accepted.isEmpty())
assertEquals(debut, placePremiereFromChair(store, user, "8100001", "Street Brawlers", 2026, 302, at(11, 5, 13), london)) // once only
assertTrue(loadDecisions(store.decisionsFile()).single().premiere)
// The debut is a fixed slot, booked only after the committed plan, branded as a first airing on Orbit.
val film = PoolSeries("8100001", "Street Brawlers", listOf(PoolEpisode("8100001", "s1", EpisodeMark(1, 1), "Street Brawlers", 110 * minute)))
val pool = (1..40).map { PoolSeries("f$it", "Film $it", listOf(PoolEpisode("f$it", "sf$it", EpisodeMark(1, 1), "Film $it", (90L + it % 30) * minute))) } + film
val slots = premiereSlots(loadPremiereRuns(store.premiereRunsFile()), pool.associateBy { it.id })
val plan = extendFilmSchedule(pool, ScheduleCursor(), at(11, 5, 6), debut + 2 * day, 7 * day, zone = london, fixed = slots)
val first = plan.entries.first { it.seriesId == "8100001" }
assertTrue(first.startMs in debut..debut + 20 * minute)
assertTrue(PREMIERE_WHY in first.why)
assertEquals("FIRST ON ORBIT", whatsOnPage(mapOf(PREMIERE_NUMBER to plan), null, debut - 6 * 60 * minute, london).let { p -> (listOfNotNull(p.pick) + p.tonight + p.comingUp).first { it.title.contains("Street Brawlers") }.tag })
// Before its window ends nothing moves; after, it leaves Premiere's list for Action's. Its bookings aren't touched here.
assertTrue(graduatePremieres(store, user, debut + PREMIERE_WINDOW_MS - 1).isEmpty())
assertEquals(setOf(PREMIERE_NUMBER, 302), graduatePremieres(store, user, debut + PREMIERE_WINDOW_MS))
assertTrue(store.loadChoices(user, PREMIERE_NUMBER).accepted.isEmpty())
assertEquals(listOf("8100001"), store.loadChoices(user, 302).accepted.map { it.id })
assertTrue(premiereSlots(loadPremiereRuns(store.premiereRunsFile()), pool.associateBy { it.id }).isEmpty())
assertTrue(graduatePremieres(store, user, debut + PREMIERE_WINDOW_MS + day).isEmpty()) // once only
}
@Test fun aFilmAlreadyBookedOnOrbitGetsNoPremiere() {
val store = store()
store.saveBooked(user, setOf("8100001"))
assertNull(placePremiereFromChair(store, user, "8100001", "Street Brawlers", 2026, 302, at(11, 5, 12), london))
assertTrue(store.loadChoices(user, PREMIERE_NUMBER).accepted.isEmpty())
assertThrows(IllegalArgumentException::class.java) { placePremiereFromChair(store, user, "8100002", "Another", 2026, PREMIERE_NUMBER, at(11, 5, 12), london) }
}
}