0.101.0: Living Network Stage C, spotting what's new (report only): daily background library refresh, arrivals, new episodes by season and episode, booked works, Settings > New arrivals
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m8s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m32s

Booking fingerprints identical to 0.100.1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 18:22:23 +00:00
co-authored by Claude Opus 5.5
parent 8f2676afef
commit dc2ba8d633
11 changed files with 354 additions and 5 deletions
@@ -0,0 +1,71 @@
package tv.orbit.classic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.time.LocalDate
import java.time.ZoneId
/** Stage C: what's new, each label with its evidence, and nothing booked or changed. */
class NewArrivalsTest {
private val zone = ZoneId.of("Europe/London")
private fun at(date: String, hour: Int = 13) = LocalDate.parse(date).atTime(hour, 0).atZone(zone).toInstant().toEpochMilli()
private fun show(id: String, title: String, vararg marks: Pair<Int, Int>, prefix: String = id) =
PoolSeries(id, title, marks.map { (s, e) -> PoolEpisode("$prefix-$s-$e", "src", EpisodeMark(s, e), "E$e", 25 * 60_000L) })
@Test fun oneWorkWhicheverCopy() {
assertEquals("tmdb:312359", workKey(mapOf("Tmdb" to "312359", "Tvdb" to "473154"), "Dragon Ball Super: Beerus", 2026))
assertEquals(workKey(mapOf("Tmdb" to "312359"), "Beerus", 2026), workKey(mapOf("tmdb" to "312359", "Imdb" to "tt1"), "Dragon Ball Super: Beerus", 2026))
assertEquals("tvdb:9", workKey(mapOf("Tvdb" to "9"), "X", null))
assertEquals(workKey(emptyMap(), "Blue Planet III", 2026), workKey(emptyMap(), "Blue Planet III", 2026))
}
@Test fun newEpisodesAreMatchedBySeasonAndEpisodeNeverByFile() {
val before = listOf(show("1", "American Dad!", 1 to 1, 1 to 2, prefix = "copyA"), show("2", "QI", 1 to 1))
// American Dad! switched to another copy of the same two episodes: nothing new. QI gained an episode. A new show isn't "new episodes".
val after = listOf(show("1", "American Dad!", 1 to 1, 1 to 2, prefix = "copyB"), show("2", "QI", 1 to 1, 1 to 2), show("3", "Brand New Show", 1 to 1))
val found = newEpisodes(102, before, after, at("2026-11-05"))
assertEquals(listOf("QI" to EpisodeMark(1, 2)), found.map { it.show to it.mark })
assertEquals(1, mergeNewEpisodes(found, found, at("2026-11-05")).size)
}
@Test fun arrivalsKeepTheFirstSightingAndArePruned() {
val a = Arrival("1", "Series", "Blue Planet III", 2026, "2026-10-31", "tmdb:1", at("2026-11-05"))
val copy = a.copy(id = "2", firstSeenMs = at("2026-11-06"))
val merged = mergeArrivals(listOf(a), listOf(copy), at("2026-11-06"))
assertEquals(listOf("1"), merged.map { it.id })
assertTrue(mergeArrivals(merged, emptyList(), at("2027-03-01")).isEmpty())
}
@Test fun theRefreshRunsOnceADayAfterNoon() {
assertFalse(arrivalsRefreshDue(null, at("2026-11-05", 11), zone))
assertTrue(arrivalsRefreshDue(null, at("2026-11-05", 12), zone))
assertFalse(arrivalsRefreshDue(at("2026-11-05", 12), at("2026-11-05", 20), zone))
assertTrue(arrivalsRefreshDue(at("2026-11-05", 12), at("2026-11-06", 13), zone))
}
@Test fun eachLabelCarriesItsEvidence() {
val now = at("2026-11-06")
val blue = Arrival("10", "Series", "Blue Planet III", 2026, "2026-10-31", "tmdb:10", at("2026-11-05"))
val oldFilm = Arrival("11", "Movie", "Jaws", 1975, "1975-06-20", "tmdb:11", at("2026-11-05"))
val beerus = Arrival("12", "Series", "Dragon Ball Super: Beerus", 2026, "2026-10-10", "tmdb:12", 0)
val upcoming = Arrival("13", "Movie", "Not Out Yet", 2026, "2026-12-01", "tmdb:13", 0)
val report = arrivalsReport(listOf(blue, oldFilm), listOf(blue, beerus, upcoming), listOf(NewEpisode(102, "QI", EpisodeMark(1, 2), now)),
inPools = mapOf("tmdb:12" to "8016753", "tmdb:11" to "11"), booked = setOf("11"), nowMs = now, zone = zone)
// An old film added recently is new to the library but not newly released.
assertEquals(listOf("Blue Planet III (2026)", "Jaws (1975)"), report.newToLibrary.map { it.title })
assertEquals(listOf("New to the library"), report.newToLibrary.first { it.title.startsWith("Jaws") }.labels)
// Newly released excludes a premiere in the future.
assertEquals(listOf("Blue Planet III (2026)", "Dragon Ball Super: Beerus (2026)"), report.newlyReleased.map { it.title })
assertTrue(report.newlyReleased.first().evidence.contains("2026-10-31"))
// On a channel's list and never booked: Beerus. Jaws is booked, Blue Planet III isn't on a channel.
assertEquals(listOf("Dragon Ball Super: Beerus (2026)"), report.notYetOnOrbit.map { it.title })
assertTrue(report.newEpisodes.single().evidence.contains("S1 E2"))
}
@Test fun nothingInStageCTouchesScheduling() {
// Stage C has no booking path: its only outputs are reports. The four-week fingerprints are checked by the replays.
assertTrue(SmartChannels.none { it.dayParts.any { part -> part.titles.any { title -> title.contains("arrival", ignoreCase = true) } } })
}
}