Add day parts to the shared engine, on Vortex and After Dark (0.42.0 in testing)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m47s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m19s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-02 06:47:09 +00:00
co-authored by Claude Opus 5.5
parent 5eba2e6533
commit 8b1d081b2d
6 changed files with 106 additions and 16 deletions
@@ -342,4 +342,67 @@ class ChannelScheduleTest {
file.writeText(JSONObject(file.readText()).apply { remove("signature") }.toString())
assertEquals("", old.loadPool(user, 140)!!.signature)
}
private val london = java.time.ZoneId.of("Europe/London")
private fun localHour(ms: Long) = java.time.Instant.ofEpochMilli(ms).atZone(london).hour
private fun at(y: Int, m: Int, d: Int, h: Int) = java.time.ZonedDateTime.of(y, m, d, h, 0, 0, 0, london).toInstant().toEpochMilli()
private val cartoons = show("Cartoon", 3, 40, 22)
private val anime = show("Anime", 9, 33, 24)
private val parts = listOf(DayPart(6, 18, listOf("Show Cartoon")), DayPart(18, 6, listOf("Show Anime")))
@Test fun aDayPartCoversItsHoursAcrossMidnight() {
assertTrue(DayPart(18, 6).covers(23)); assertTrue(DayPart(18, 6).covers(5)); assertFalse(DayPart(18, 6).covers(6))
assertTrue(DayPart(6, 18).covers(6)); assertFalse(DayPart(6, 18).covers(18))
}
@Test fun programmesStartOnlyInTheirOwnBlock() {
val start = at(2026, 11, 2, 7)
extendSchedule(listOf(cartoons, anime), ScheduleCursor(), start, start + 7 * day, dayParts = parts, zone = london).entries.forEach {
assertEquals(if (localHour(it.startMs) in 6 until 18) "Cartoon" else "Anime", it.seriesId)
}
}
@Test fun aProgrammeMayRunPastTheBlockButNothingOverlaps() {
val start = at(2026, 11, 2, 7)
val entries = extendSchedule(listOf(cartoons, anime), ScheduleCursor(), start, start + 2 * day, dayParts = parts, zone = london).entries
assertTrue(entries.zipWithNext().all { (a, b) -> a.endMs == b.startMs })
}
@Test fun blocksFollowTheWallClockWhenTheClocksChange() {
for (start in listOf(at(2026, 10, 24, 12), at(2027, 3, 27, 12))) {
extendSchedule(listOf(cartoons, anime), ScheduleCursor(), start, start + 3 * day, dayParts = parts, zone = london).entries.forEach {
assertEquals(if (localHour(it.startMs) in 6 until 18) "Cartoon" else "Anime", it.seriesId)
}
}
}
@Test fun eachShowKeepsItsPlaceAcrossBlocks() {
val start = at(2026, 11, 2, 7)
val entries = extendSchedule(listOf(show("Cartoon", 9, 40, 22), anime), ScheduleCursor(), start, start + 7 * day, dayParts = parts, zone = london).entries
entries.groupBy { it.seriesId }.values.forEach { shows -> assertEquals(shows.map { it.mark }.sorted(), shows.map { it.mark }) }
}
@Test fun aBlockWithNoTitlesInThePoolUsesEverythingRatherThanGoingOffAir() {
val noMatch = listOf(DayPart(0, 12, listOf("Not In The Pool")))
assertEquals(2, dayPartPool(listOf(cartoons, anime), noMatch, at(2026, 11, 2, 7), london).size)
assertEquals(2, dayPartPool(listOf(cartoons, anime), listOf(DayPart(0, 12)), at(2026, 11, 2, 7), london).size)
}
@Test fun lateOnlyFilmsNeverStartBeforeTheLateBlock() {
val day = (1..20).map { film("Day$it") }
val late = (1..13).map { film("Late$it") }
val filmParts = listOf(DayPart(21, 5), DayPart(5, 21, day.map { it.title }))
val start = at(2026, 11, 2, 12)
val entries = extendSchedule(day + late, ScheduleCursor(), start, start + 7 * this.day, rest, dayParts = filmParts, zone = london).entries
entries.filter { it.seriesId.startsWith("Late") }.forEach { assertFalse(localHour(it.startMs) in 5 until 21) }
assertTrue(entries.any { it.seriesId.startsWith("Late") })
}
@Test fun finishedShowsOnlyWaitWithinTheirOwnBlock() {
val short = show("s", 1, 1, 60); val other = show("o", 1, 200, 60)
val noon = at(2026, 11, 2, 12)
val entries = extendSchedule(listOf(short, other), ScheduleCursor(), noon, noon + 12 * 60 * minute, finishTogether = true,
dayParts = listOf(DayPart(6, 18, listOf("Show s")), DayPart(18, 6, listOf("Show o"))), zone = london).entries
assertEquals(List(6) { "s" }, entries.filter { localHour(it.startMs) in 6 until 18 }.map { it.seriesId })
}
}