Provider step 3: sanitised real-library catalogue pages as fixtures

Captured by the read-only shadow comparison on downstairs (9 November 2026, 5 pages, identical, catalogue untouched),
sanitised on the TV (titles, original titles and tags replaced, external id digits swapped, structure kept). Today's
reader and the provider path read them identically, page by page and as a whole import. Branch from the installed 314
build; no version change, nothing installed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 13:46:19 +00:00
co-authored by Claude Opus 5.5
parent 7b4e82a882
commit 29e1af4b9c
4 changed files with 60 additions and 0 deletions
@@ -0,0 +1,57 @@
package tv.orbit.classic
import org.json.JSONObject
import org.junit.Assert.*
import org.junit.Test
/**
* Step 3 with real-world shape (9 November 2026): three catalogue pages captured from Paul's library by the read-only
* shadow comparison on the downstairs TV, then sanitised (titles, original titles and tags replaced, external ids' digits
* swapped; every row, key and type kept). Today's reader and the provider path must read them identically.
*/
class RealCatalogueFixtureTest {
private val pages = (0..2).map { i -> javaClass.classLoader!!.getResource("catalogue-real/page-$i.json")!!.readText() }
/** Serves the captured pages by position, as the server did: 200 rows each, the total only when it's asked for. */
private val server = EmbyTransport { r ->
val start = Regex("StartIndex=(\\d+)").find(r.path)!!.groupValues[1].toInt()
val body = JSONObject(pages.getOrElse(start / 200) { """{"Items":[]}""" })
if (r.path.contains("EnableTotalRecordCount=false")) body.put("TotalRecordCount", 0) else body.put("TotalRecordCount", 600)
EmbyReply(200, body.toString())
}
private fun provider() = EmbyProvider(EmbySampleSession(server, "fixture-token-private", "fixtureuser", EmbySample(emptyList(), 0)), server, "fixtureuser",
{ "fixture-token-private" }, ProviderKind.Emby, "fixtureserver1", images = { null })
@Test fun everyCapturedPageReadsTheSameBothWays() {
val p = provider()
for (start in listOf(0L, 200L, 400L)) {
val today = fetchCataloguePage(server, "fixtureuser", { "x" }, start, 200, withTotal = start == 0L)
val via = cataloguePageVia(p, start, 200, withTotal = start == 0L)
assertEquals(today.records, via.records); assertEquals(today.rawCount, via.rawCount); assertEquals(today.total, via.total)
assertTrue(today.records.size > 150) // real pages: most rows are films and series with titles
}
}
@Test fun aWholeImportOfTheCapturedPagesWritesTheSameBothWays() {
class Capture : CatalogueSink {
var pos = 0L; val writes = mutableListOf<List<Any?>>()
override fun position(userId: String) = pos
override fun write(userId: String, records: List<CatalogueRecord>, nextStart: Long, total: Long?, finished: Boolean) { writes += listOf(records, nextStart, total, finished); pos = nextStart }
}
val today = Capture(); val via = Capture(); val p = provider()
importCatalogue(server, "fixtureuser", { "x" }, today, maxPages = 10)
importCatalogue(server, "fixtureuser", { "x" }, via, maxPages = 10, fetch = { s, n, w -> cataloguePageVia(p, s, n, w) })
assertEquals(today.writes, via.writes); assertEquals(3, today.writes.size)
}
@Test fun theCapturedPagesHoldNothingPersonal() {
for (page in pages) {
val rows = JSONObject(page).getJSONArray("Items")
for (i in 0 until rows.length()) {
val row = rows.getJSONObject(i)
assertTrue(row.optString("Name").let { it.isEmpty() || it.matches(Regex("Title \\d+")) })
assertFalse(row.has("Overview")); assertFalse(row.has("People")); assertFalse(row.has("Path"))
}
}
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long